Skip to content

Commit 89da9f3

Browse files
committed
add search toggle
1 parent b48ba36 commit 89da9f3

6 files changed

Lines changed: 90 additions & 11 deletions

File tree

src/components/List/List.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,19 @@ export default function List(props: ListProps) {
3838
return;
3939
}
4040
setSearchSelected(false);
41+
onSearch("", "");
4142
const offset = categoryBarRef.current!.getBoundingClientRect().height;
4243
const y = categoryRefs[filter].current!.getBoundingClientRect().bottom + window.scrollY - offset;
4344

4445
window.scrollTo({top: y, behavior: "smooth"});
4546
}
4647

47-
function onQueryRun(query: string, unicodeRepr: string) {
48+
function onSearch(query: string, unicodeRepr: string) {
4849
const listItems = document.querySelectorAll("button.list-item");
4950
for (let i = 0; i < listItems.length; i++) {
5051
const item = listItems[i] as HTMLElement;
5152
item.removeAttribute("hidden");
53+
if (!searchSelected) continue;
5254
let notFound = unicodeRepr !== item.id;
5355
notFound = notFound ? !item.dataset.name.toLowerCase().includes(query) : notFound;
5456
for (const j of item.dataset.keywords.split(" ")) {
@@ -61,6 +63,7 @@ export default function List(props: ListProps) {
6163
item.setAttribute("hidden", "");
6264
}
6365
}
66+
return searchSelected ? 1 : 0;
6467
}
6568

6669
return (
@@ -90,7 +93,7 @@ export default function List(props: ListProps) {
9093
})
9194
}
9295
</div>
93-
<ListSearch onQueryRun={onQueryRun} />
96+
<ListSearch key={onSearch("", "")} searchSelected={searchSelected} onSearch={onSearch} />
9497
</div>
9598
);
9699
}

src/components/List/ListCategoryButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import activities from "img/categories/Activities.svg?url";
1515
import objects from "img/categories/Objects.svg?url";
1616
import symbols from "img/categories/Symbols.svg?url";
1717
import flags from "img/categories/Flags.svg?url";
18+
import search from "img/categories/Search.svg?url";
1819

1920
const categoryIcons: {[category: string]: string} = {
2021
"Smileys & Emotion": smileysandemotion,
@@ -25,7 +26,8 @@ const categoryIcons: {[category: string]: string} = {
2526
"Activities": activities,
2627
"Objects": objects,
2728
"Symbols": symbols,
28-
"Flags": flags
29+
"Flags": flags,
30+
"Search": search
2931
};
3032

3133
export default function ListCategoryButton(props: ListCategoryButtonProps) {

src/components/List/ListFilter.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ export default function ListFilter(props: ListFilterProps) {
6262
<div id="filters" ref={props.barRef}
6363
aria-label="Filter Toolbar" role="toolbar"
6464
onKeyDown={tabulate}>
65-
{/* <ListCategoryButton category="Search" onCategoryChange={changeCategory} selected={props.searchSelected} /> */}
65+
<ListCategoryButton key="Search" category="Search"
66+
onCategoryChange={changeCategory} selected={props.searchSelected}
67+
/>
6668
{
6769
categories.map((category: string) => {
6870
return (
6971
<ListCategoryButton key={category} category={category}
70-
onCategoryChange={changeCategory} selected={category === selectedCategory ? true : false}
72+
onCategoryChange={changeCategory} selected={!props.searchSelected && category === selectedCategory}
7173
/>
7274
);
7375
})

src/components/List/ListSearch.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ import React from "react";
33
import "css/components/ListSearch.css";
44

55
interface ListSearchProps {
6-
onQueryRun: (query: string, unicodeRepr: string) => void;
6+
searchSelected: boolean;
7+
onSearch: (query: string, unicodeRepr: string) => void;
78
}
89

910
export default function ListSearch(props: ListSearchProps) {
10-
function runQuery(e) {
11+
function search(e) {
1112
const query = String(e.target.value);
1213
const unicodeRepr = Array.from(query)
1314
.map(s => s.codePointAt(0))
1415
.map(c => c.toString(16))
1516
.map(n => (n.length > 3 ? "" : "0".repeat(4 - n.length)) + n)
1617
.join("-");
17-
props.onQueryRun(query.toLowerCase(), unicodeRepr);
18+
props.onSearch(query.toLowerCase(), unicodeRepr);
1819
}
1920

2021
return (
21-
<div id="search" role="search">
22-
{/* <SearchBar handleSearch={props.handleSearch} /> */}
22+
<div id="search" role="search" data-active={props.searchSelected}>
2323
<input
2424
type="search"
2525
placeholder="Search"
2626
defaultValue=""
27-
onChange={runQuery}
27+
onChange={search}
2828
></input>
2929
</div>
3030
);

src/css/ListSearch.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
div#search {
2+
position: fixed;
3+
bottom: 20pt;
4+
right: 20pt;
5+
6+
background-color: white;
7+
filter: drop-shadow(0 2pt 8pt #00000066);
8+
9+
border-radius: 24pt;
10+
overflow: hidden;
11+
12+
z-index: 4;
13+
14+
display: flex;
15+
justify-content: center;
16+
}
17+
18+
div#search[data-active="false"] {
19+
display: none;
20+
}
21+
22+
div#search input {
23+
box-sizing: border-box;
24+
25+
width: 200pt;
26+
height: 48pt;
27+
28+
padding: 16pt;
29+
30+
appearance: none;
31+
border: none;
32+
33+
font-family: "Manrope", sans-serif;
34+
font-size: 12pt;
35+
background-color: white;
36+
}

src/img/categories/Search.svg

Lines changed: 36 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)