feat: adding scroll to filters

This commit is contained in:
Chubby Granny Chaser 2024-12-20 18:59:51 +00:00
parent a557bbb948
commit 3af0ae9f85
No known key found for this signature in database

View File

@ -18,23 +18,16 @@ export function FilterSection<T extends string | number>({
onSelect, onSelect,
}: FilterSectionProps<T>) { }: FilterSectionProps<T>) {
const [search, setSearch] = useState(""); const [search, setSearch] = useState("");
const [showMore, setShowMore] = useState(false);
const filteredItems = useMemo(() => { const filteredItems = useMemo(() => {
if (search.length > 0) { if (search.length > 0) {
return items return items.filter((item) =>
.filter((item) => item.label.toLowerCase().includes(search.toLowerCase())
item.label.toLowerCase().includes(search.toLowerCase()) );
)
.slice(0, 10);
} }
if (showMore) { return items;
return items; }, [items, search]);
}
return items.slice(0, 10);
}, [items, search, showMore]);
const onSearch = useCallback((value: string) => { const onSearch = useCallback((value: string) => {
setSearch(value); setSearch(value);
@ -66,7 +59,15 @@ export function FilterSection<T extends string | number>({
theme="dark" theme="dark"
/> />
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}> <div
style={{
display: "flex",
flexDirection: "column",
gap: 8,
overflowY: "auto",
maxHeight: 28 * 10,
}}
>
{filteredItems.map((item) => ( {filteredItems.map((item) => (
<div key={item.value}> <div key={item.value}>
<CheckboxField <CheckboxField
@ -76,23 +77,6 @@ export function FilterSection<T extends string | number>({
/> />
</div> </div>
))} ))}
{!search && items.length > 10 && (
<button
type="button"
style={{
color: "#fff",
fontSize: 14,
textAlign: "left",
marginTop: 8,
textDecoration: "underline",
cursor: "pointer",
}}
onClick={() => setShowMore(!showMore)}
>
{showMore ? "Show less" : `Show more (${items.length - 10})`}
</button>
)}
</div> </div>
</div> </div>
); );