Created
July 10, 2025 01:02
-
-
Save yehezkieldio/f4773303869e691ecc20777f8c5993de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use client"; | |
| import React from "react"; | |
| import { Button } from "#/components/ui/button"; | |
| import { Checkbox } from "#/components/ui/checkbox"; | |
| import { | |
| Command, | |
| CommandEmpty, | |
| CommandGroup, | |
| CommandInput, | |
| CommandItem, | |
| CommandList, | |
| } from "#/components/ui/command"; | |
| import { | |
| Popover, | |
| PopoverContent, | |
| PopoverTrigger, | |
| } from "#/components/ui/popover"; | |
| export default function CatalogFilter() { | |
| const [open, setOpen] = React.useState(false); | |
| const [selectedCategories, setSelectedCategories] = React.useState< | |
| string[] | |
| >([]); | |
| const categories = ["Electronics", "Books", "Clothing", "Home & Garden"]; | |
| const handleCategoryChange = (category: string) => { | |
| setSelectedCategories((prev) => | |
| prev.includes(category) | |
| ? prev.filter((c) => c !== category) | |
| : [...prev, category] | |
| ); | |
| }; | |
| return ( | |
| <Popover onOpenChange={setOpen} open={open}> | |
| <PopoverTrigger asChild> | |
| <Button variant="outline"> | |
| Filters ( | |
| {selectedCategories.length > 0 | |
| ? selectedCategories.length | |
| : 0} | |
| ) | |
| </Button> | |
| </PopoverTrigger> | |
| <PopoverContent className="w-[300px] p-0"> | |
| <Command> | |
| <CommandInput placeholder="Search categories..." /> | |
| <CommandList> | |
| <CommandEmpty>No categories found.</CommandEmpty> | |
| <CommandGroup heading="Categories"> | |
| {categories.map((category) => ( | |
| <CommandItem | |
| className="flex items-center space-x-2" | |
| key={category} | |
| onSelect={() => | |
| handleCategoryChange(category) | |
| } | |
| > | |
| <Checkbox | |
| checked={selectedCategories.includes( | |
| category | |
| )} | |
| id={category} | |
| onCheckedChange={() => | |
| handleCategoryChange(category) | |
| } | |
| /> | |
| <label | |
| className="cursor-pointer" | |
| htmlFor={category} | |
| > | |
| {category} | |
| </label> | |
| </CommandItem> | |
| ))} | |
| </CommandGroup> | |
| </CommandList> | |
| </Command> | |
| <div className="border-t p-4"> | |
| <Button onClick={() => setOpen(false)} size="sm"> | |
| Apply Filters | |
| </Button> | |
| <Button | |
| onClick={() => setSelectedCategories([])} | |
| size="sm" | |
| variant="ghost" | |
| > | |
| Clear | |
| </Button> | |
| </div> | |
| </PopoverContent> | |
| </Popover> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment