Icon Picker
ui-components/icon-pickerFreeBlock
A simple icon picker component.
Install it
npx shadcn@latest add https://ui.raulcarini.dev/r/icon-picker.jsonSource
1"use client";23import * as React from "react";4import { icons } from "lucide-react";56import { cn } from "@/lib/utils";7import { useDebounce } from "@/hooks/use-debounce";89import { Input } from "@/components/ui/input";10import { ScrollArea } from "@/components/ui/scroll-area";1112const IconItem = React.memo(13 ({14 iconName,15 setSelectedIcon,16 selectedIcon,17 }: {18 iconName: string;19 setSelectedIcon?: (iconName: string) => void;20 selectedIcon?: string | null;21 }) => {22 const Icon = icons[iconName as keyof typeof icons];2324 const handleClick = React.useCallback(() => {25 setSelectedIcon?.(iconName);26 }, [iconName, setSelectedIcon]);2728 return (29 <button30 className={cn(31 "flex items-center justify-center size-7 rounded-md cursor-pointer text-popover-foreground/70 hover:bg-muted hover:text-popover-foreground transition-colors",32 selectedIcon === iconName &&33 "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground",34 )}35 onClick={handleClick}36 title={iconName}37 aria-label={`Select ${iconName} icon`}38 aria-pressed={selectedIcon === iconName}39 >40 <Icon size={16} />41 </button>42 );43 },44);4546IconItem.displayName = "IconItem";4748const IconPicker = React.memo(49 ({50 setSelectedIcon,51 selectedIcon,52 className,53 ...props54 }: {55 setSelectedIcon?: (iconName: string) => void;56 selectedIcon?: string | null;57 } & React.ComponentProps<"div">) => {58 const [searchQuery, setSearchQuery] = React.useState("");59 const debouncedSearchQuery = useDebounce(searchQuery, 200);6061 const iconsMap = React.useMemo(() => Object.keys(icons), []);6263 const filteredIcons = React.useMemo(() => {64 if (!debouncedSearchQuery.trim()) return iconsMap;65 return iconsMap.filter((iconName) =>66 iconName.toLowerCase().includes(debouncedSearchQuery.toLowerCase()),67 );68 }, [iconsMap, debouncedSearchQuery]);6970 const handleSearchChange = React.useCallback(71 (e: React.ChangeEvent<HTMLInputElement>) => {72 setSearchQuery(e.target.value);73 },74 [],75 );7677 return (78 <div79 className={cn(80 "max-w-72 bg-popover rounded-lg border shadow-md",81 className,82 )}83 aria-label="Icon picker"84 {...props}85 >86 <div className="relative mt-1.5 mx-1.5">87 <Input88 autoComplete="off"89 autoCorrect="off"90// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from UI Components
All 25 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| GitHub Contributionsgithub-contributions | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Advancedgithub-contributions-advanced | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Advanced Fetchergithub-contributions-advanced-fetcher | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Fetchergithub-contributions-fetcher | UI Components | Blocks | Free | no deps | |
| GitHub Forksgithub-forks | UI Components | Blocks | Free | 1 dep | |
| GitHub Issuesgithub-issues | UI Components | Blocks | Free | 1 dep | |
| GitHub Pull Requestsgithub-pr | UI Components | Blocks | Free | 1 dep | |
| GitHub Starsgithub-stars | UI Components | Blocks | Free | 1 dep |
