Filter Sidebar
A faceted filter column described as data: single choice lists with icons and counts, checkboxes, tag chips, a price range or custom blocks. Collapses behind a toggle on mobile, sticky from lg.
npx shadcn@latest add https://ui.develop-better-solutions.com/r/filter-sidebar.jsonDependencies:
lucide-reactUsage
filter-sidebar-example.tsx
"use client";
import { useState } from "react";
import { Citrus, Cookie, GlassWater, Leaf } from "lucide-react";
import { FilterSidebar } from "@dbs/ui";
export default function FilterSidebarExample() {
const [cat, setCat] = useState("all");
const [flags, setFlags] = useState<string[]>(["organic"]);
const [range, setRange] = useState<[number, number]>([20, 300]);
const [tags, setTags] = useState<string[]>([]);
return (
<div className="w-full max-w-xs rounded-2xl border border-line p-6">
<FilterSidebar
stickyTop={24}
activeCount={flags.length + tags.length + (cat === "all" ? 0 : 1)}
groups={[
{
id: "cat",
type: "single",
title: <>Refine by <strong className="font-bold">category</strong></>,
value: cat,
onChange: setCat,
options: [
{ id: "all", label: "All", icon: Leaf, count: 20 },
{ id: "fruits", label: "Fruits", icon: Citrus, count: 8 },
{ id: "juices", label: "Juices", icon: GlassWater, count: 5 },
{ id: "dried", label: "Dried", icon: Cookie, count: 7 },
],
},
{
id: "flags",
type: "checkbox",
title: "Highlights",
value: flags,
onChange: setFlags,
options: [
{ id: "organic", label: "Organic" },
{ id: "local", label: "Grown locally" },
{ id: "sale", label: "On sale" },
],
},
{ id: "price", type: "range", title: "Price range", min: 0, max: 500, step: 10, value: range, onChange: setRange, format: (n) => `${n} MAD` },
{ id: "tags", type: "tags", title: "Tags", options: ["vegan", "gluten free", "raw", "seasonal"], value: tags, onChange: setTags },
]}
/>
</div>
);
}