-
Notifications
You must be signed in to change notification settings - Fork 32
feat: add inline variant to Filters component (#1) #365
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,27 +16,26 @@ import { useFiltersContext } from './FiltersContext'; | |||||
|
|
||||||
| function separateLeadingItem<T>(items: Models.Filters.FilterItem<T>[]) { | ||||||
| let leadingItem: Models.Filters.FilterItem<T> | undefined; | ||||||
| let viewModeToggle: Models.Filters.FilterViewModeToggle | undefined; | ||||||
| const filteredItems: Models.Filters.FilterItem<T>[] = []; | ||||||
|
|
||||||
| for (const item of items) { | ||||||
| if (item.__typename === 'FilterViewModeToggle') { | ||||||
| viewModeToggle = item; | ||||||
| } else if (item.isLeading === true && leadingItem === undefined) { | ||||||
| if ('isLeading' in item && item.isLeading === true && leadingItem === undefined) { | ||||||
| leadingItem = item; | ||||||
| } else { | ||||||
| filteredItems.push(item); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return { leadingItem, viewModeToggle, filteredItems }; | ||||||
| return { leadingItem, filteredItems }; | ||||||
|
marcinkrasowski marked this conversation as resolved.
|
||||||
| } | ||||||
|
|
||||||
| export const Filters = <T, S extends FormikValues>({ | ||||||
| filters, | ||||||
| initialValues, | ||||||
| onSubmit, | ||||||
| onReset, | ||||||
| hasLeadingItem, | ||||||
| variant = 'drawer', | ||||||
| labels, | ||||||
| }: Readonly<FiltersProps<T, S>>) => { | ||||||
| const [filtersOpen, setFiltersOpen] = useState(false); | ||||||
|
|
@@ -48,14 +47,67 @@ export const Filters = <T, S extends FormikValues>({ | |||||
|
|
||||||
| const { label, title, description, submit, reset, items, removeFilters } = filters; | ||||||
|
|
||||||
| const { leadingItem, viewModeToggle, filteredItems } = separateLeadingItem(items); | ||||||
| const { leadingItem, filteredItems } = hasLeadingItem | ||||||
| ? separateLeadingItem(items) | ||||||
| : { leadingItem: undefined, filteredItems: items }; | ||||||
|
|
||||||
| const handleReset = (e: React.MouseEvent) => { | ||||||
| e.preventDefault(); | ||||||
| countActiveFilters(initialFilters); | ||||||
| onReset(); | ||||||
| }; | ||||||
|
|
||||||
| // Inline variant: render filters directly without drawer | ||||||
| if (variant === 'inline') { | ||||||
| return ( | ||||||
| <div className="w-full"> | ||||||
| <Formik<S> | ||||||
| initialValues={initialValues} | ||||||
| enableReinitialize={true} | ||||||
| onSubmit={(values) => { | ||||||
| countActiveFilters(values); | ||||||
| onSubmit(values); | ||||||
| }} | ||||||
| > | ||||||
| {({ submitForm, setFieldValue }) => ( | ||||||
| <Form> | ||||||
| <div className="flex flex-col gap-4"> | ||||||
|
marcinkrasowski marked this conversation as resolved.
|
||||||
| {/* Filters container - grid layout for desktop, full-width rows for mobile */} | ||||||
| <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4"> | ||||||
| {items.map((item) => ( | ||||||
|
||||||
| {items.map((item) => ( | |
| {filteredItems.map((item) => ( |
Uh oh!
There was an error while loading. Please reload this page.