parent
3301f7de2f
commit
5a09053c73
@ -0,0 +1,62 @@
|
|||||||
|
import { MagnifyingGlassIcon } from '@heroicons/react/24/outline';
|
||||||
|
import { Collapsible, TextInput } from '@tih/ui';
|
||||||
|
|
||||||
|
import Checkbox from '../ui-patch/Checkbox';
|
||||||
|
|
||||||
|
export type FilterOptions = {
|
||||||
|
checked: boolean;
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type FilterSectionProps = {
|
||||||
|
label: string;
|
||||||
|
onOptionChange: (optionValue: string, checked: boolean) => void;
|
||||||
|
options: Array<FilterOptions>;
|
||||||
|
} & (
|
||||||
|
| {
|
||||||
|
searchPlaceholder: string;
|
||||||
|
showAll?: never;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
searchPlaceholder?: never;
|
||||||
|
showAll: true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default function FilterSection({
|
||||||
|
label,
|
||||||
|
options,
|
||||||
|
searchPlaceholder,
|
||||||
|
showAll,
|
||||||
|
onOptionChange,
|
||||||
|
}: FilterSectionProps) {
|
||||||
|
return (
|
||||||
|
<div className="mx-2">
|
||||||
|
<Collapsible defaultOpen={true} label={label}>
|
||||||
|
<div className="-mx-2 flex flex-col items-stretch gap-2">
|
||||||
|
{!showAll && (
|
||||||
|
<TextInput
|
||||||
|
isLabelHidden={true}
|
||||||
|
label={label}
|
||||||
|
placeholder={searchPlaceholder}
|
||||||
|
startAddOn={MagnifyingGlassIcon}
|
||||||
|
startAddOnType="icon"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<div className="mx-1">
|
||||||
|
{options.map((option) => (
|
||||||
|
<Checkbox
|
||||||
|
key={option.value}
|
||||||
|
{...option}
|
||||||
|
onChange={(checked) => {
|
||||||
|
onOptionChange(option.value, checked);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Collapsible>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import { useId } from 'react';
|
||||||
|
|
||||||
|
export type CheckboxProps = {
|
||||||
|
checked: boolean;
|
||||||
|
label: string;
|
||||||
|
onChange: (checked: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function Checkbox({ label, checked, onChange }: CheckboxProps) {
|
||||||
|
const id = useId();
|
||||||
|
return (
|
||||||
|
<div className="flex items-center">
|
||||||
|
<input
|
||||||
|
checked={checked}
|
||||||
|
className="text-primary-600 focus:ring-primary-500 h-4 w-4 rounded border-gray-300"
|
||||||
|
id={id}
|
||||||
|
type="checkbox"
|
||||||
|
onChange={(event) => onChange(event.target.checked)}
|
||||||
|
/>
|
||||||
|
<label className="ml-3 min-w-0 flex-1 text-gray-700" htmlFor={id}>
|
||||||
|
{label}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in new issue