Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Make search work in Filters story #837

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/organisms/Filter/Filter.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const Wrapper: FC<FilterStoryProps> = (props) => {
const [manufacturerDate, setManufacturerDate] = useState<Date | undefined>(
undefined
);
const [search, setSearch] = useState<string | undefined>(undefined);

const values = useMemo(() => {
const all: FilterProps['values'] = [];
Expand Down Expand Up @@ -64,8 +65,12 @@ const Wrapper: FC<FilterStoryProps> = (props) => {
});
}

if (search) {
all.push({ value: 'search', label: `Search: ${search}` });
}

return all;
}, [carSize, manufacturer, manufacturerDate, props.withIcons]);
}, [carSize, manufacturer, manufacturerDate, props.withIcons, search]);

const handleOnSelectEnvironment = (
value: SelectOptionRequired | undefined
Expand All @@ -88,19 +93,27 @@ const Wrapper: FC<FilterStoryProps> = (props) => {
setCarSize(undefined);
} else if (value === 'manufacturer-date') {
setManufacturerDate(undefined);
} else if (value === 'search') {
setSearch(undefined);
}
};

const handleOnClearAllFilters = () => {
setCarSize(undefined);
setManufacturer(undefined);
setManufacturerDate(undefined);
setSearch(undefined);
};

const handleOnSearch = (value: string) => {
setSearch(value);
};

return (
<Filter
{...props}
values={values}
onSearch={handleOnSearch}
onClearFilter={handleOnClearFilter}
onClearAllFilters={handleOnClearAllFilters}
>
Expand Down