Skip to content

Commit 053d380

Browse files
committed
Abstact away the filter for the search bar
1 parent 0c6bfc7 commit 053d380

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

stories/ColorHelper/ColorHelper.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@ import { useStyles } from "./makeStyles";
1313
import { ColorDecisionCard } from "./ColorDecisionCard";
1414
import type { Props as SearchProps } from "./Search";
1515

16+
const colors = Array.from(
17+
new Set(
18+
colorDecisionAndCorrespondingOption.map(
19+
({ parsedColorDecisionName }) => parsedColorDecisionName.colorName
20+
)
21+
)
22+
);
23+
24+
const contextes = Array.from(
25+
new Set(
26+
colorDecisionAndCorrespondingOption.map(
27+
({ parsedColorDecisionName }) => parsedColorDecisionName.context
28+
)
29+
)
30+
);
31+
32+
const usages = Array.from(
33+
new Set(
34+
colorDecisionAndCorrespondingOption.map(
35+
({ parsedColorDecisionName }) => parsedColorDecisionName.usage
36+
)
37+
)
38+
);
39+
1640
const { useDebounce } = createUseDebounce({ "delay": 400 });
1741

1842
const fzf = new Fzf<readonly ColorDecisionAndCorrespondingOption[]>(
@@ -94,10 +118,13 @@ export function ColorHelper() {
94118
evtAction={evtSearchAction}
95119
onSearchChange={search => setSearch(search)}
96120
search={search}
121+
contextes={contextes}
97122
context={context}
98123
onContextChange={setContext}
124+
colors={colors}
99125
color={color}
100126
onColorChange={setColor}
127+
usages={usages}
101128
usage={usage}
102129
onUsageChange={setUsage}
103130
/>

stories/ColorHelper/Search.tsx

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,21 @@ import { fr } from "../../dist/fr";
66
import { NonPostableEvt } from "evt";
77
import { useEvt } from "evt/hooks";
88
import { Select } from "../../dist/Select";
9-
import { colorDecisionAndCorrespondingOption } from "../../dist/fr/generatedFromCss/colorDecisionAndCorrespondingOptions";
10-
11-
const colors = Array.from(
12-
new Set(
13-
colorDecisionAndCorrespondingOption.map(
14-
({ parsedColorDecisionName }) => parsedColorDecisionName.colorName
15-
)
16-
)
17-
);
18-
const contextes = Array.from(
19-
new Set(
20-
colorDecisionAndCorrespondingOption.map(
21-
({ parsedColorDecisionName }) => parsedColorDecisionName.context
22-
)
23-
)
24-
);
25-
const usages = Array.from(
26-
new Set(
27-
colorDecisionAndCorrespondingOption.map(
28-
({ parsedColorDecisionName }) => parsedColorDecisionName.usage
29-
)
30-
)
31-
);
329

3310
export type Props = {
3411
className?: string;
3512
search: string;
3613
onSearchChange: (search: string) => void;
3714
evtAction: NonPostableEvt<"scroll to">;
38-
context: typeof contextes[number] | undefined;
39-
onContextChange: (context: typeof contextes[number] | undefined) => void;
40-
color: typeof colors[number] | undefined;
41-
onColorChange: (color: typeof colors[number] | undefined) => void;
42-
usage: typeof usages[number] | undefined;
43-
onUsageChange: (usage: typeof usages[number] | undefined) => void;
15+
contextes: string[];
16+
context: string | undefined;
17+
onContextChange: (context: string | undefined) => void;
18+
colors: string[];
19+
color: string | undefined;
20+
onColorChange: (color: string | undefined) => void;
21+
usages: string[];
22+
usage: string | undefined;
23+
onUsageChange: (usage: string | undefined) => void;
4424
};
4525

4626
export function Search(props: Props) {
@@ -49,10 +29,13 @@ export function Search(props: Props) {
4929
search,
5030
onSearchChange,
5131
evtAction,
32+
contextes,
5233
context,
5334
onContextChange,
35+
colors,
5436
color,
5537
onColorChange,
38+
usages,
5639
usage,
5740
onUsageChange
5841
} = props;

0 commit comments

Comments
 (0)