import Icon from "@mdi/react"; import { useState } from "react"; import { Button } from "~/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "~/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger } from "~/components/ui/popover"; import { type Icon as IconType, type IconName, icons } from "~/lib/icon"; type IconPickerProps = ({ onChange?: (icon: IconName) => void; withNone?: false; } | { onChange?: (icon?: IconName) => void; withNone: true; }) & { initialValue?: IconName; className?: string; } // TODO: Make this faster by not showing all icons at once export function IconPicker(props: IconPickerProps) { const [value, setValue] = useState(props.initialValue); const [open, setOpen] = useState(false); return ( No icon found. {props.withNone && { setValue(undefined) setOpen(false) props.onChange && props.onChange(undefined) }}> } {Object.entries(icons).map(([key, value]) => ( { setValue(currentValue as IconName) setOpen(false) props.onChange && props.onChange(currentValue as IconName) }} > ))} ); } function Entry(props: { icon?: IconType, withLabel?: boolean }) { const withLabel = props.withLabel ?? false; return (
{props.icon && }
{withLabel && {props.icon?.name ?? "None"}}
); }