@gerege-systems/ui 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +6 -6
  2. package/dist-lib/components/ui/Alert.js +11 -9
  3. package/dist-lib/components/ui/Alert.js.map +1 -1
  4. package/dist-lib/components/ui/Button.js +4 -4
  5. package/dist-lib/components/ui/Button.js.map +1 -1
  6. package/dist-lib/components/ui/Calendar.js +3 -1
  7. package/dist-lib/components/ui/Calendar.js.map +1 -1
  8. package/dist-lib/components/ui/Carousel.js.map +1 -1
  9. package/dist-lib/components/ui/Chart.js +55 -55
  10. package/dist-lib/components/ui/Chart.js.map +1 -1
  11. package/dist-lib/components/ui/Combobox.js +19 -18
  12. package/dist-lib/components/ui/Combobox.js.map +1 -1
  13. package/dist-lib/components/ui/FileUpload.js +34 -35
  14. package/dist-lib/components/ui/FileUpload.js.map +1 -1
  15. package/dist-lib/components/ui/Icon.js +12 -12
  16. package/dist-lib/components/ui/Icon.js.map +1 -1
  17. package/dist-lib/components/ui/IconButton.js +4 -4
  18. package/dist-lib/components/ui/IconButton.js.map +1 -1
  19. package/dist-lib/components/ui/Pagination.js +35 -33
  20. package/dist-lib/components/ui/Pagination.js.map +1 -1
  21. package/dist-lib/components/ui/Spinner.d.ts +1 -1
  22. package/dist-lib/components/ui/Spinner.js.map +1 -1
  23. package/dist-lib/components/ui/Toast.js +0 -1
  24. package/dist-lib/components/ui/Toast.js.map +1 -1
  25. package/dist-lib/hooks/use-debounce.js +14 -17
  26. package/dist-lib/hooks/use-debounce.js.map +1 -1
  27. package/dist-lib/hooks/use-delayed-loading.js +8 -8
  28. package/dist-lib/hooks/use-delayed-loading.js.map +1 -1
  29. package/dist-lib/hooks/use-modifier-key.d.ts +0 -4
  30. package/dist-lib/hooks/use-modifier-key.js +11 -12
  31. package/dist-lib/hooks/use-modifier-key.js.map +1 -1
  32. package/dist-lib/styles.css +1 -1
  33. package/dist-lib/theme.css +38 -28
  34. package/package.json +5 -11
@@ -1 +1 @@
1
- {"version":3,"file":"Combobox.js","sources":["../../../src/components/ui/Combobox.tsx"],"sourcesContent":["'use client';\n\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { Command as CommandPrimitive } from 'cmdk';\nimport { Check, ChevronsUpDown, Loader2, X } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { useStrings } from '@/hooks/use-strings';\nimport { useFieldIds } from '@/hooks/use-field-ids';\nimport { IconButton } from './IconButton';\n\nexport interface ComboboxOption {\n value: string;\n label: string;\n description?: string;\n disabled?: boolean;\n}\n\nexport interface ComboboxProps {\n /** Currently selected value (controlled). */\n value: string | null;\n /** Called when a value is picked or cleared. */\n onChange: (value: string | null) => void;\n /** Static options. Ignored if `loadOptions` is provided. */\n options?: ComboboxOption[];\n /**\n * Async loader called with the current query each time it changes.\n * Use for server-side search.\n */\n loadOptions?: (query: string) => Promise<ComboboxOption[]>;\n /**\n * Label to show for a preset `value` in `loadOptions` mode before the\n * first search has resolved (the component has no option list yet).\n */\n selectedLabel?: string;\n /** Visible label above the field. */\n label?: ReactNode;\n /** Hint below the field. Hidden when `error` is set. */\n helperText?: ReactNode;\n /** Validation error. */\n error?: ReactNode;\n /** Placeholder shown when no value is selected. */\n placeholder?: string;\n /** Search placeholder inside the popover. */\n searchPlaceholder?: string;\n /** Empty state copy when nothing matches. */\n emptyText?: string;\n /** Message shown when `loadOptions` rejects. */\n loadErrorText?: string;\n /** Allow clearing the selection with an inline ×. */\n clearable?: boolean;\n /** Disable the entire field. */\n disabled?: boolean;\n /** Field size, matches Input. */\n size?: 'sm' | 'md' | 'lg';\n /** Consumer-supplied id for the trigger (label association). */\n id?: string;\n className?: string;\n}\n\n/**\n * Single-select with typeahead. Use `options` for client-side filtering or\n * `loadOptions` for server-side search.\n *\n * @example Client-side\n * <Combobox label=\"Country\" options={countries} value={c} onChange={setC} />\n *\n * @example Server-side\n * <Combobox label=\"Assignee\"\n * value={user}\n * onChange={setUser}\n * loadOptions={async (q) => api.searchUsers(q)} />\n *\n * @do Use Combobox over Select for >12 options or when the user is expected\n * to know what they want.\n * @dont Re-query on every keystroke without debouncing — pass a debounced\n * `loadOptions` to avoid hammering the server.\n */\nexport const Combobox = forwardRef<HTMLDivElement, ComboboxProps>(function Combobox(\n {\n value,\n onChange,\n options,\n loadOptions,\n selectedLabel,\n label,\n helperText,\n error,\n placeholder: placeholderProp,\n searchPlaceholder: searchPlaceholderProp,\n emptyText: emptyTextProp,\n loadErrorText: loadErrorTextProp,\n clearable = true,\n disabled,\n size = 'md',\n id,\n className,\n },\n ref,\n) {\n const strings = useStrings();\n const placeholder = placeholderProp ?? strings.combobox.placeholder;\n const searchPlaceholder = searchPlaceholderProp ?? strings.combobox.searchPlaceholder;\n const emptyText = emptyTextProp ?? strings.combobox.empty;\n const loadErrorText = loadErrorTextProp ?? strings.combobox.loadError;\n const isError = Boolean(error);\n const { fieldId, helperId, errorId, describedBy } = useFieldIds(id, {\n hasHelper: Boolean(helperText),\n hasError: isError,\n });\n // cmdk assigns its own id to the list, so read it back from the node once\n // the portal mounts; aria-controls is only set while the listbox exists.\n const [listId, setListId] = useState<string | undefined>(undefined);\n const listRef = useCallback((el: HTMLDivElement | null) => setListId(el?.id), []);\n\n const [open, setOpen] = useState(false);\n const [query, setQuery] = useState('');\n const [loaded, setLoaded] = useState<ComboboxOption[]>([]);\n const [loading, setLoading] = useState(false);\n const [loadError, setLoadError] = useState(false);\n // In async mode the option list only exists after the first search, so the\n // chosen option is remembered here to keep its label on the trigger.\n const [selectedOption, setSelectedOption] = useState<ComboboxOption | null>(null);\n\n // Resolve options: static or async-loaded.\n const items = useMemo(\n () => (loadOptions ? loaded : (options ?? [])),\n [loadOptions, loaded, options],\n );\n\n // Latest loader in a ref so an inline `loadOptions={async q => …}` does not\n // retrigger the fetch on every parent render — only query / open do.\n const loadRef = useRef(loadOptions);\n useEffect(() => {\n loadRef.current = loadOptions;\n });\n const hasLoader = Boolean(loadOptions);\n useEffect(() => {\n const load = loadRef.current;\n if (!load || !open) return;\n let cancelled = false;\n setLoading(true);\n setLoadError(false);\n load(query)\n .then((res) => {\n if (!cancelled) setLoaded(res);\n })\n .catch(() => {\n if (!cancelled) {\n setLoaded([]);\n setLoadError(true);\n }\n })\n .finally(() => {\n if (!cancelled) setLoading(false);\n });\n return () => {\n cancelled = true;\n };\n }, [query, open, hasLoader]);\n\n const selected = useMemo<ComboboxOption | null>(() => {\n if (value === null || value === undefined) return null;\n const fromItems = items.find((o) => o.value === value);\n if (fromItems) return fromItems;\n if (selectedOption?.value === value) return selectedOption;\n if (selectedLabel !== undefined) return { value, label: selectedLabel };\n return null;\n }, [items, value, selectedOption, selectedLabel]);\n\n const triggerHeight = size === 'sm' ? 'h-8' : size === 'lg' ? 'h-10' : 'h-9';\n const triggerPadding = size === 'sm' ? 'px-2.5' : size === 'lg' ? 'px-3.5' : 'px-3';\n // Leave room on the right for the clear button + chevron.\n const triggerPaddingRight = clearable ? 'pr-14' : 'pr-9';\n\n const handleClear = useCallback(() => {\n setSelectedOption(null);\n onChange(null);\n }, [onChange]);\n\n return (\n <div ref={ref} className={cn('flex flex-col gap-1.5', className)}>\n {label && (\n <label\n id={`${fieldId}-label`}\n htmlFor={fieldId}\n className=\"text-foreground text-sm font-medium\"\n >\n {label}\n </label>\n )}\n\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n <div className=\"relative w-full\">\n <PopoverPrimitive.Trigger asChild>\n <button\n id={fieldId}\n data-slot=\"combobox\"\n type=\"button\"\n role=\"combobox\"\n aria-expanded={open}\n aria-haspopup=\"listbox\"\n aria-controls={open ? listId : undefined}\n // role=combobox takes no name from content, so the placeholder\n // must be exposed explicitly. A consumer `id` implies an external\n // <label htmlFor>, which aria-label would override.\n aria-labelledby={label ? `${fieldId}-label` : undefined}\n aria-label={label || id ? undefined : placeholder}\n aria-invalid={isError || undefined}\n aria-describedby={describedBy}\n disabled={disabled}\n className={cn(\n 'bg-card text-foreground inline-flex w-full items-center justify-between gap-2 rounded-md border text-sm',\n 'transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]',\n 'focus-visible:ring-offset-background outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2',\n 'disabled:cursor-not-allowed disabled:opacity-50',\n triggerHeight,\n triggerPadding,\n triggerPaddingRight,\n isError\n ? 'border-danger focus-visible:border-danger focus-visible:ring-danger'\n : 'border-border-input focus-visible:border-accent focus-visible:ring-ring',\n )}\n >\n <span\n className={cn('truncate', !selected && 'text-foreground-subtle')}\n title={selected ? selected.label : undefined}\n >\n {selected ? selected.label : placeholder}\n </span>\n </button>\n </PopoverPrimitive.Trigger>\n\n {/* Controls sit outside the trigger: a button inside a button is invalid HTML. */}\n <span className=\"pointer-events-none absolute inset-y-0 right-0 flex items-center gap-0.5 pr-2\">\n {clearable && selected && !disabled && (\n <IconButton\n size=\"sm\"\n variant=\"ghost\"\n aria-label={strings.combobox.clear}\n icon={<X />}\n onClick={handleClear}\n className=\"text-foreground-subtle hover:text-foreground pointer-events-auto size-6\"\n />\n )}\n <ChevronsUpDown className=\"text-foreground-subtle size-4\" aria-hidden />\n </span>\n </div>\n\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n data-slot=\"popover-content\"\n // Radix gives the popover role=\"dialog\"; name it after the field.\n aria-labelledby={label ? `${fieldId}-label` : undefined}\n aria-label={label ? undefined : placeholder}\n align=\"start\"\n sideOffset={4}\n className={cn(\n 'border-border bg-popover text-popover-foreground z-[var(--z-popover)] w-[var(--radix-popover-trigger-width)] overflow-hidden rounded-lg border shadow-md',\n 'data-[state=open]:animate-in data-[state=closed]:animate-out',\n 'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',\n 'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',\n )}\n >\n <CommandPrimitive shouldFilter={!loadOptions} className=\"flex h-full w-full flex-col\">\n <div className=\"border-border flex items-center border-b px-3\">\n <CommandPrimitive.Input\n value={query}\n onValueChange={setQuery}\n placeholder={searchPlaceholder}\n className=\"placeholder:text-foreground-subtle flex h-9 w-full bg-transparent py-2 text-lg outline-hidden md:text-sm\"\n />\n {loading && (\n <Loader2 className=\"text-foreground-subtle size-4 animate-spin\" aria-hidden />\n )}\n </div>\n <CommandPrimitive.List\n ref={listRef}\n label={strings.command.suggestions}\n className=\"max-h-64 overflow-y-auto p-1\"\n >\n {items.map((opt) => {\n const isSelected = opt.value === value;\n return (\n <CommandPrimitive.Item\n key={opt.value}\n value={opt.value}\n // cmdk matches on value + keywords; users type the label, not the id.\n keywords={opt.description ? [opt.label, opt.description] : [opt.label]}\n disabled={opt.disabled}\n onSelect={(v) => {\n setSelectedOption(opt);\n onChange(v);\n setOpen(false);\n }}\n className={cn(\n 'text-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm',\n 'data-[selected=true]:bg-background-muted',\n 'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50',\n )}\n >\n <span className=\"flex-1\">{opt.label}</span>\n {opt.description && (\n <span className=\"text-foreground-subtle text-xs\">{opt.description}</span>\n )}\n {isSelected && <Check className=\"text-accent size-4\" aria-hidden />}\n </CommandPrimitive.Item>\n );\n })}\n {loadError && !loading && (\n <div className=\"text-danger-text px-2 py-6 text-center text-sm\">\n {loadErrorText}\n </div>\n )}\n {/* cmdk only shows Empty when no item matches the query, so it can always be mounted. */}\n {!loading && !loadError && (\n <CommandPrimitive.Empty className=\"text-foreground-subtle px-2 py-6 text-center text-sm\">\n {emptyText}\n </CommandPrimitive.Empty>\n )}\n </CommandPrimitive.List>\n </CommandPrimitive>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n\n {error ? (\n <p id={errorId} className=\"text-danger-text text-xs\">\n {error}\n </p>\n ) : helperText ? (\n <p id={helperId} className=\"text-foreground-subtle text-xs\">\n {helperText}\n </p>\n ) : null}\n </div>\n );\n});\n\nCombobox.displayName = 'Combobox';\n"],"names":["Combobox","forwardRef","value","onChange","options","loadOptions","selectedLabel","label","helperText","error","placeholderProp","searchPlaceholderProp","emptyTextProp","loadErrorTextProp","clearable","disabled","size","id","className","ref","strings","useStrings","placeholder","searchPlaceholder","emptyText","loadErrorText","isError","fieldId","helperId","errorId","describedBy","useFieldIds","listId","setListId","useState","listRef","useCallback","el","open","setOpen","query","setQuery","loaded","setLoaded","loading","setLoading","loadError","setLoadError","selectedOption","setSelectedOption","items","useMemo","loadRef","useRef","useEffect","load","cancelled","res","selected","fromItems","o","triggerHeight","triggerPadding","triggerPaddingRight","handleClear","cn","jsx","PopoverPrimitive","jsxs","IconButton","X","ChevronsUpDown","CommandPrimitive","Loader2","opt","isSelected","v","Check"],"mappings":";;;;;;;;;;AAsFO,MAAMA,KAAWC,GAA0C,SAChE;AAAA,EACE,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,aAAAC;AAAA,EACA,eAAAC;AAAA,EACA,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAaC;AAAA,EACb,mBAAmBC;AAAA,EACnB,WAAWC;AAAA,EACX,eAAeC;AAAA,EACf,WAAAC,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,IAAAC;AAAA,EACA,WAAAC;AACF,GACAC,GACA;AACA,QAAMC,IAAUC,GAAA,GACVC,IAAcZ,KAAmBU,EAAQ,SAAS,aAClDG,IAAoBZ,KAAyBS,EAAQ,SAAS,mBAC9DI,IAAYZ,KAAiBQ,EAAQ,SAAS,OAC9CK,IAAgBZ,KAAqBO,EAAQ,SAAS,WACtDM,IAAU,EAAQjB,GAClB,EAAE,SAAAkB,GAAS,UAAAC,GAAU,SAAAC,GAAS,aAAAC,EAAA,IAAgBC,GAAYd,GAAI;AAAA,IAClE,WAAW,EAAQT;AAAA,IAC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A,kBACA5B,KAAa,CAACF,uBACZ,OAAA,EAAI,WAAU,kDACZ,UAAAnB,GACH;AAAA,kBAGD,CAACmB,KAAW,CAACE,KACZ,gBAAAoB,EAACM,EAAiB,OAAjB,EAAuB,WAAU,wDAC/B,UAAAhD,EAAA,CACH;AAAA,gBAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UAEJ,EAAA,CACF;AAAA,QAAA;AAAA,MAAA,EACF,CACF;AAAA,IAAA,GACF;AAAA,IAECf,IACC,gBAAAyD,EAAC,KAAA,EAAE,IAAIrC,GAAS,WAAU,4BACvB,UAAApB,EAAA,CACH,IACED,sBACD,KAAA,EAAE,IAAIoB,GAAU,WAAU,kCACxB,aACH,IACE;AAAA,EAAA,GACN;AAEJ,CAAC;AAED5B,GAAS,cAAc;"}
1
+ {"version":3,"file":"Combobox.js","sources":["../../../src/components/ui/Combobox.tsx"],"sourcesContent":["'use client';\n\nimport {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { Command as CommandPrimitive } from 'cmdk';\nimport { Check, ChevronsUpDown, X } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { useStrings } from '@/hooks/use-strings';\nimport { useFieldIds } from '@/hooks/use-field-ids';\nimport { IconButton } from './IconButton';\nimport { Spinner } from './Spinner';\n\nexport interface ComboboxOption {\n value: string;\n label: string;\n description?: string;\n disabled?: boolean;\n}\n\nexport interface ComboboxProps {\n /** Currently selected value (controlled). */\n value: string | null;\n /** Called when a value is picked or cleared. */\n onChange: (value: string | null) => void;\n /** Static options. Ignored if `loadOptions` is provided. */\n options?: ComboboxOption[];\n /**\n * Async loader called with the current query each time it changes.\n * Use for server-side search.\n */\n loadOptions?: (query: string) => Promise<ComboboxOption[]>;\n /**\n * Label to show for a preset `value` in `loadOptions` mode before the\n * first search has resolved (the component has no option list yet).\n */\n selectedLabel?: string;\n /** Visible label above the field. */\n label?: ReactNode;\n /** Hint below the field. Hidden when `error` is set. */\n helperText?: ReactNode;\n /** Validation error. */\n error?: ReactNode;\n /** Placeholder shown when no value is selected. */\n placeholder?: string;\n /** Search placeholder inside the popover. */\n searchPlaceholder?: string;\n /** Empty state copy when nothing matches. */\n emptyText?: string;\n /** Message shown when `loadOptions` rejects. */\n loadErrorText?: string;\n /** Allow clearing the selection with an inline ×. */\n clearable?: boolean;\n /** Disable the entire field. */\n disabled?: boolean;\n /** Field size, matches Input. */\n size?: 'sm' | 'md' | 'lg';\n /** Consumer-supplied id for the trigger (label association). */\n id?: string;\n className?: string;\n}\n\n/**\n * Single-select with typeahead. Use `options` for client-side filtering or\n * `loadOptions` for server-side search.\n *\n * @example Client-side\n * <Combobox label=\"Country\" options={countries} value={c} onChange={setC} />\n *\n * @example Server-side\n * <Combobox label=\"Assignee\"\n * value={user}\n * onChange={setUser}\n * loadOptions={async (q) => api.searchUsers(q)} />\n *\n * @do Use Combobox over Select for >12 options or when the user is expected\n * to know what they want.\n * @dont Re-query on every keystroke without debouncing — pass a debounced\n * `loadOptions` to avoid hammering the server.\n */\nexport const Combobox = forwardRef<HTMLDivElement, ComboboxProps>(function Combobox(\n {\n value,\n onChange,\n options,\n loadOptions,\n selectedLabel,\n label,\n helperText,\n error,\n placeholder: placeholderProp,\n searchPlaceholder: searchPlaceholderProp,\n emptyText: emptyTextProp,\n loadErrorText: loadErrorTextProp,\n clearable = true,\n disabled,\n size = 'md',\n id,\n className,\n },\n ref,\n) {\n const strings = useStrings();\n const placeholder = placeholderProp ?? strings.combobox.placeholder;\n const searchPlaceholder = searchPlaceholderProp ?? strings.combobox.searchPlaceholder;\n const emptyText = emptyTextProp ?? strings.combobox.empty;\n const loadErrorText = loadErrorTextProp ?? strings.combobox.loadError;\n const isError = Boolean(error);\n const { fieldId, helperId, errorId, describedBy } = useFieldIds(id, {\n hasHelper: Boolean(helperText),\n hasError: isError,\n });\n // cmdk assigns its own id to the list, so read it back from the node once\n // the portal mounts; aria-controls is only set while the listbox exists.\n const [listId, setListId] = useState<string | undefined>(undefined);\n const listRef = useCallback((el: HTMLDivElement | null) => setListId(el?.id), []);\n\n const [open, setOpen] = useState(false);\n const [query, setQuery] = useState('');\n const [loaded, setLoaded] = useState<ComboboxOption[]>([]);\n const [loading, setLoading] = useState(false);\n const [loadError, setLoadError] = useState(false);\n // In async mode the option list only exists after the first search, so the\n // chosen option is remembered here to keep its label on the trigger.\n const [selectedOption, setSelectedOption] = useState<ComboboxOption | null>(null);\n\n // Resolve options: static or async-loaded.\n const items = useMemo(\n () => (loadOptions ? loaded : (options ?? [])),\n [loadOptions, loaded, options],\n );\n\n // Latest loader in a ref so an inline `loadOptions={async q => …}` does not\n // retrigger the fetch on every parent render — only query / open do.\n const loadRef = useRef(loadOptions);\n useEffect(() => {\n loadRef.current = loadOptions;\n });\n const hasLoader = Boolean(loadOptions);\n useEffect(() => {\n const load = loadRef.current;\n if (!load || !open) return;\n let cancelled = false;\n setLoading(true);\n setLoadError(false);\n load(query)\n .then((res) => {\n if (!cancelled) setLoaded(res);\n })\n .catch(() => {\n if (!cancelled) {\n setLoaded([]);\n setLoadError(true);\n }\n })\n .finally(() => {\n if (!cancelled) setLoading(false);\n });\n return () => {\n cancelled = true;\n };\n }, [query, open, hasLoader]);\n\n const selected = useMemo<ComboboxOption | null>(() => {\n if (value === null || value === undefined) return null;\n const fromItems = items.find((o) => o.value === value);\n if (fromItems) return fromItems;\n if (selectedOption?.value === value) return selectedOption;\n if (selectedLabel !== undefined) return { value, label: selectedLabel };\n return null;\n }, [items, value, selectedOption, selectedLabel]);\n\n const triggerHeight = size === 'sm' ? 'h-8' : size === 'lg' ? 'h-10' : 'h-9';\n const triggerPadding = size === 'sm' ? 'px-2.5' : size === 'lg' ? 'px-3.5' : 'px-3';\n // Leave room on the right for the clear button + chevron.\n const triggerPaddingRight = clearable ? 'pr-14' : 'pr-9';\n\n const handleClear = useCallback(() => {\n setSelectedOption(null);\n onChange(null);\n }, [onChange]);\n\n return (\n <div ref={ref} className={cn('flex flex-col gap-1.5', className)}>\n {label && (\n <label\n id={`${fieldId}-label`}\n htmlFor={fieldId}\n className=\"text-foreground text-sm font-medium\"\n >\n {label}\n </label>\n )}\n\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n <div className=\"relative w-full\">\n <PopoverPrimitive.Trigger asChild>\n <button\n id={fieldId}\n data-slot=\"combobox\"\n type=\"button\"\n role=\"combobox\"\n aria-expanded={open}\n aria-haspopup=\"listbox\"\n aria-controls={open ? listId : undefined}\n // role=combobox takes no name from content, so the placeholder\n // must be exposed explicitly. A consumer `id` implies an external\n // <label htmlFor>, which aria-label would override.\n aria-labelledby={label ? `${fieldId}-label` : undefined}\n aria-label={label || id ? undefined : placeholder}\n aria-invalid={isError || undefined}\n aria-describedby={describedBy}\n disabled={disabled}\n className={cn(\n 'bg-card text-foreground inline-flex w-full items-center justify-between gap-2 rounded-md border text-sm',\n 'transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]',\n 'focus-visible:ring-offset-background outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2',\n 'disabled:cursor-not-allowed disabled:opacity-50',\n triggerHeight,\n triggerPadding,\n triggerPaddingRight,\n isError\n ? 'border-danger focus-visible:border-danger focus-visible:ring-danger'\n : 'border-border-input focus-visible:border-accent focus-visible:ring-ring',\n )}\n >\n <span\n className={cn('truncate', !selected && 'text-foreground-subtle')}\n title={selected ? selected.label : undefined}\n >\n {selected ? selected.label : placeholder}\n </span>\n </button>\n </PopoverPrimitive.Trigger>\n\n {/* Controls sit outside the trigger: a button inside a button is invalid HTML. */}\n <span className=\"pointer-events-none absolute inset-y-0 right-0 flex items-center gap-0.5 pr-2\">\n {clearable && selected && !disabled && (\n <IconButton\n size=\"sm\"\n variant=\"ghost\"\n aria-label={strings.combobox.clear}\n icon={<X />}\n onClick={handleClear}\n className=\"text-foreground-subtle hover:text-foreground pointer-events-auto size-6\"\n />\n )}\n <ChevronsUpDown className=\"text-foreground-subtle size-4\" aria-hidden />\n </span>\n </div>\n\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n data-slot=\"popover-content\"\n // Radix gives the popover role=\"dialog\"; name it after the field.\n aria-labelledby={label ? `${fieldId}-label` : undefined}\n aria-label={label ? undefined : placeholder}\n align=\"start\"\n sideOffset={4}\n className={cn(\n 'border-border bg-popover text-popover-foreground z-[var(--z-popover)] w-[var(--radix-popover-trigger-width)] overflow-hidden rounded-lg border shadow-md',\n 'data-[state=open]:animate-in data-[state=closed]:animate-out',\n 'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',\n 'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',\n )}\n >\n <CommandPrimitive shouldFilter={!loadOptions} className=\"flex h-full w-full flex-col\">\n <div className=\"border-border flex items-center border-b px-3\">\n <CommandPrimitive.Input\n value={query}\n onValueChange={setQuery}\n placeholder={searchPlaceholder}\n className=\"placeholder:text-foreground-subtle flex h-9 w-full bg-transparent py-2 text-lg outline-hidden md:text-sm\"\n />\n {loading && <Spinner decorative tone=\"neutral\" />}\n </div>\n <CommandPrimitive.List\n ref={listRef}\n label={strings.command.suggestions}\n className=\"max-h-64 overflow-y-auto p-1\"\n >\n {items.map((opt) => {\n const isSelected = opt.value === value;\n return (\n <CommandPrimitive.Item\n key={opt.value}\n value={opt.value}\n // cmdk matches on value + keywords; users type the label, not the id.\n keywords={opt.description ? [opt.label, opt.description] : [opt.label]}\n disabled={opt.disabled}\n onSelect={(v) => {\n setSelectedOption(opt);\n onChange(v);\n setOpen(false);\n }}\n className={cn(\n 'text-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm',\n 'data-[selected=true]:bg-background-muted',\n 'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50',\n )}\n >\n <span className=\"flex-1\">{opt.label}</span>\n {opt.description && (\n <span className=\"text-foreground-subtle text-xs\">{opt.description}</span>\n )}\n {isSelected && <Check className=\"text-accent size-4\" aria-hidden />}\n </CommandPrimitive.Item>\n );\n })}\n {loadError && !loading && (\n <div className=\"text-danger-text px-2 py-6 text-center text-sm\">\n {loadErrorText}\n </div>\n )}\n {/* cmdk only shows Empty when no item matches the query, so it can always be mounted. */}\n {!loading && !loadError && (\n <CommandPrimitive.Empty className=\"text-foreground-subtle px-2 py-6 text-center text-sm\">\n {emptyText}\n </CommandPrimitive.Empty>\n )}\n </CommandPrimitive.List>\n </CommandPrimitive>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n\n {error ? (\n <p id={errorId} className=\"text-danger-text text-xs\">\n {error}\n </p>\n ) : helperText ? (\n <p id={helperId} className=\"text-foreground-subtle text-xs\">\n {helperText}\n </p>\n ) : null}\n </div>\n );\n});\n\nCombobox.displayName = 'Combobox';\n"],"names":["Combobox","forwardRef","value","onChange","options","loadOptions","selectedLabel","label","helperText","error","placeholderProp","searchPlaceholderProp","emptyTextProp","loadErrorTextProp","clearable","disabled","size","id","className","ref","strings","useStrings","placeholder","searchPlaceholder","emptyText","loadErrorText","isError","fieldId","helperId","errorId","describedBy","useFieldIds","listId","setListId","useState","listRef","useCallback","el","open","setOpen","query","setQuery","loaded","setLoaded","loading","setLoading","loadError","setLoadError","selectedOption","setSelectedOption","items","useMemo","loadRef","useRef","useEffect","load","cancelled","res","selected","fromItems","o","triggerHeight","triggerPadding","triggerPaddingRight","handleClear","cn","jsx","PopoverPrimitive","jsxs","IconButton","X","ChevronsUpDown","CommandPrimitive","Spinner","opt","isSelected","v","Check"],"mappings":";;;;;;;;;;;AAuFO,MAAMA,KAAWC,GAA0C,SAChE;AAAA,EACE,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,aAAAC;AAAA,EACA,eAAAC;AAAA,EACA,OAAAC;AAAA,EACA,YAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAaC;AAAA,EACb,mBAAmBC;AAAA,EACnB,WAAWC;AAAA,EACX,eAAeC;AAAA,EACf,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ACVrC,EAAQ,EAAK;AAAA,wBACf;AAAA,wBACA,WAAW0B;AAAA,0BACT;AAAA,0BACA;AAAA,0BACA;AAAA,wBAAA;AAAA,wBAGF,UAAA;AAAA,0BAAA,gBAAAC,EAAC,QAAA,EAAK,WAAU,UAAU,UAAAQ,EAAI,OAAM;AAAA,0BACnCA,EAAI,eACH,gBAAAR,EAAC,UAAK,WAAU,kCAAkC,YAAI,aAAY;AAAA,0BAEnES,KAAc,gBAAAT,EAACW,IAAA,EAAM,WAAU,sBAAqB,eAAW,GAAA,CAAC;AAAA,wBAAA;AAAA,sBAAA;AAAA,sBApB5DH,EAAI;AAAA,oBAAA;AAAA,kBAuBf,CAAC;AAAA,kBACA5B,KAAa,CAACF,uBACZ,OAAA,EAAI,WAAU,kDACZ,UAAAnB,GACH;AAAA,kBAGD,CAACmB,KAAW,CAACE,KACZ,gBAAAoB,EAACM,EAAiB,OAAjB,EAAuB,WAAU,wDAC/B,UAAAhD,EAAA,CACH;AAAA,gBAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UAEJ,EAAA,CACF;AAAA,QAAA;AAAA,MAAA,EACF,CACF;AAAA,IAAA,GACF;AAAA,IAECf,IACC,gBAAAyD,EAAC,KAAA,EAAE,IAAIrC,GAAS,WAAU,4BACvB,UAAApB,EAAA,CACH,IACED,sBACD,KAAA,EAAE,IAAIoB,GAAU,WAAU,kCACxB,aACH,IACE;AAAA,EAAA,GACN;AAEJ,CAAC;AAED5B,GAAS,cAAc;"}
@@ -1,38 +1,38 @@
1
1
  "use client";
2
2
  import { jsxs as g, jsx as t } from "react/jsx-runtime";
3
- import { forwardRef as _, useRef as L, useId as q, useState as k, useCallback as $ } from "react";
4
- import { Upload as G, File as H, X as J } from "../../icons/index.js";
5
- import { cn as I } from "../../lib/utils.js";
6
- import { useStrings as K } from "../../hooks/use-strings.js";
3
+ import { forwardRef as S, useId as X, useState as k, useRef as _, useCallback as L } from "react";
4
+ import { Upload as q, File as G, X as H } from "../../icons/index.js";
5
+ import { cn as $ } from "../../lib/utils.js";
6
+ import { useStrings as J } from "../../hooks/use-strings.js";
7
7
  import { formatString as h } from "../../lib/strings.js";
8
- function W(o, n) {
9
- return o < 1024 ? h(n.bytes, { n: o }) : o < 1024 * 1024 ? h(n.kilobytes, { n: (o / 1024).toFixed(1) }) : h(n.megabytes, { n: (o / 1024 / 1024).toFixed(1) });
8
+ function I(s, o) {
9
+ return s < 1024 ? h(o.bytes, { n: s }) : s < 1024 * 1024 ? h(o.kilobytes, { n: (s / 1024).toFixed(1) }) : h(o.megabytes, { n: (s / 1024 / 1024).toFixed(1) });
10
10
  }
11
- function P(o, n) {
12
- if (!n) return !0;
13
- const a = n.split(",").map((r) => r.trim().toLowerCase()).filter(Boolean);
11
+ function K(s, o) {
12
+ if (!o) return !0;
13
+ const a = o.split(",").map((r) => r.trim().toLowerCase()).filter(Boolean);
14
14
  if (!a.length) return !0;
15
- const l = o.name.toLowerCase(), d = o.type.toLowerCase();
15
+ const l = s.name.toLowerCase(), d = s.type.toLowerCase();
16
16
  return a.some((r) => r.startsWith(".") ? l.endsWith(r) : r.endsWith("/*") ? d.startsWith(r.slice(0, -1)) : d === r);
17
17
  }
18
- const Q = _(function({ accept: n, multiple: a, maxSize: l, value: d, onChange: r, onReject: i, hint: F, error: x, disabled: b, className: T }, A) {
19
- const c = K(), M = L(null), y = q(), [O, B] = k([]), [C, w] = k(!1), [v, E] = k(null), z = `${y}-error`, u = L(0), m = d ?? O, U = $(
18
+ const P = S(function({ accept: o, multiple: a, maxSize: l, value: d, onChange: r, onReject: i, hint: F, error: x, disabled: b, className: W }, T) {
19
+ const c = J(), y = X(), [A, M] = k([]), [O, w] = k(!1), [v, B] = k(null), z = `${y}-error`, u = _(0), m = d ?? A, U = L(
20
20
  (e) => {
21
- d === void 0 && B(e), r == null || r(e);
21
+ d === void 0 && M(e), r == null || r(e);
22
22
  },
23
23
  [r, d]
24
- ), D = $(
24
+ ), D = L(
25
25
  (e) => {
26
- const s = [], f = [], N = [];
26
+ const n = [], f = [], N = [];
27
27
  for (const p of Array.from(e))
28
- P(p, n) ? l && p.size > l ? f.push(p) : s.push(p) : N.push(p);
29
- N.length && (i == null || i(N, "type")), f.length && (i == null || i(f, "size")), E(f.length ? "size" : N.length ? "type" : null), s.length && U(a ? [...m, ...s] : s.slice(0, 1));
28
+ K(p, o) ? l && p.size > l ? f.push(p) : n.push(p) : N.push(p);
29
+ N.length && (i == null || i(N, "type")), f.length && (i == null || i(f, "size")), B(f.length ? "size" : N.length ? "type" : null), n.length && U(a ? [...m, ...n] : n.slice(0, 1));
30
30
  },
31
- [n, m, l, a, i, U]
32
- ), S = (e) => U(m.filter((s, f) => f !== e)), X = (e) => {
31
+ [o, m, l, a, i, U]
32
+ ), C = (e) => U(m.filter((n, f) => f !== e)), E = (e) => {
33
33
  e.preventDefault(), u.current = 0, w(!1), !b && D(e.dataTransfer.files);
34
34
  };
35
- return /* @__PURE__ */ g("div", { ref: A, className: I("flex flex-col gap-3", T), children: [
35
+ return /* @__PURE__ */ g("div", { ref: T, className: $("flex flex-col gap-3", W), children: [
36
36
  /* @__PURE__ */ g(
37
37
  "label",
38
38
  {
@@ -45,18 +45,18 @@ const Q = _(function({ accept: n, multiple: a, maxSize: l, value: d, onChange: r
45
45
  onDragLeave: () => {
46
46
  u.current = Math.max(0, u.current - 1), u.current === 0 && w(!1);
47
47
  },
48
- onDrop: X,
49
- className: I(
48
+ onDrop: E,
49
+ className: $(
50
50
  "group relative flex cursor-pointer flex-col items-center justify-center gap-2",
51
51
  "border-border-input bg-background-subtle rounded-md border border-dashed px-6 py-8",
52
52
  "text-center transition-colors",
53
53
  "hover:border-border-strong hover:bg-background-muted",
54
54
  "focus-within:ring-ring focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2",
55
- C && "border-accent bg-accent-soft",
55
+ O && "border-accent bg-accent-soft",
56
56
  b && "pointer-events-none opacity-50"
57
57
  ),
58
58
  children: [
59
- /* @__PURE__ */ t(G, { className: "text-foreground-muted size-5", "aria-hidden": !0 }),
59
+ /* @__PURE__ */ t(q, { className: "text-foreground-muted size-5", "aria-hidden": !0 }),
60
60
  /* @__PURE__ */ g("div", { className: "space-y-1", children: [
61
61
  /* @__PURE__ */ t("p", { className: "text-sm font-medium", children: c.fileUpload.drop }),
62
62
  F && /* @__PURE__ */ t("p", { className: "text-foreground-muted text-xs", children: F })
@@ -64,10 +64,9 @@ const Q = _(function({ accept: n, multiple: a, maxSize: l, value: d, onChange: r
64
64
  /* @__PURE__ */ t(
65
65
  "input",
66
66
  {
67
- ref: M,
68
67
  id: y,
69
68
  type: "file",
70
- accept: n,
69
+ accept: o,
71
70
  multiple: a,
72
71
  disabled: b,
73
72
  "aria-invalid": x || v ? !0 : void 0,
@@ -82,36 +81,36 @@ const Q = _(function({ accept: n, multiple: a, maxSize: l, value: d, onChange: r
82
81
  }
83
82
  ),
84
83
  (x || v) && /* @__PURE__ */ t("p", { id: z, role: "alert", className: "text-danger-text text-xs", children: x ?? (v === "size" ? h(c.fileUpload.tooLarge, {
85
- max: W(l ?? 0, c.fileUpload)
84
+ max: I(l ?? 0, c.fileUpload)
86
85
  }) : c.fileUpload.wrongType) }),
87
- m.length > 0 && /* @__PURE__ */ t("ul", { className: "flex flex-col gap-2", children: m.map((e, s) => /* @__PURE__ */ g(
86
+ m.length > 0 && /* @__PURE__ */ t("ul", { className: "flex flex-col gap-2", children: m.map((e, n) => /* @__PURE__ */ g(
88
87
  "li",
89
88
  {
90
89
  className: "border-border bg-card flex items-center gap-3 rounded-md border px-3 py-2",
91
90
  children: [
92
- /* @__PURE__ */ t(H, { className: "text-foreground-muted size-4 shrink-0", "aria-hidden": !0 }),
91
+ /* @__PURE__ */ t(G, { className: "text-foreground-muted size-4 shrink-0", "aria-hidden": !0 }),
93
92
  /* @__PURE__ */ g("div", { className: "min-w-0 flex-1", children: [
94
93
  /* @__PURE__ */ t("p", { className: "truncate text-sm", title: e.name, children: e.name }),
95
- /* @__PURE__ */ t("p", { className: "text-foreground-muted text-xs", children: W(e.size, c.fileUpload) })
94
+ /* @__PURE__ */ t("p", { className: "text-foreground-muted text-xs", children: I(e.size, c.fileUpload) })
96
95
  ] }),
97
96
  /* @__PURE__ */ t(
98
97
  "button",
99
98
  {
100
99
  type: "button",
101
- onClick: () => S(s),
100
+ onClick: () => C(n),
102
101
  className: "text-foreground-muted hover:bg-background-muted hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background rounded-sm p-1 outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2",
103
102
  "aria-label": h(c.fileUpload.remove, { name: e.name }),
104
- children: /* @__PURE__ */ t(J, { className: "size-4", "aria-hidden": !0 })
103
+ children: /* @__PURE__ */ t(H, { className: "size-4", "aria-hidden": !0 })
105
104
  }
106
105
  )
107
106
  ]
108
107
  },
109
- `${e.name}-${e.size}-${e.lastModified}-${s}`
108
+ `${e.name}-${e.size}-${e.lastModified}-${n}`
110
109
  )) })
111
110
  ] });
112
111
  });
113
- Q.displayName = "FileUpload";
112
+ P.displayName = "FileUpload";
114
113
  export {
115
- Q as FileUpload
114
+ P as FileUpload
116
115
  };
117
116
  //# sourceMappingURL=FileUpload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FileUpload.js","sources":["../../../src/components/ui/FileUpload.tsx"],"sourcesContent":["'use client';\n\nimport {\n forwardRef,\n useCallback,\n useId,\n useRef,\n useState,\n type DragEvent as ReactDragEvent,\n type ReactNode,\n} from 'react';\nimport { File as FileIcon, Upload, X } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { useStrings } from '@/hooks/use-strings';\nimport { formatString, type UiStrings } from '@/lib/strings';\n\nexport type FileRejectReason = 'size' | 'type';\n\nexport interface FileUploadProps {\n /** Accepted file types, e.g. `image/*` or `.pdf,.docx`. */\n accept?: string;\n /** Allow multiple files. */\n multiple?: boolean;\n /** Max file size in bytes. Files larger than this are rejected. */\n maxSize?: number;\n /** Controlled file list. */\n value?: File[];\n /** Called when files are added or removed. */\n onChange?: (files: File[]) => void;\n /** Called with the files that were dropped because of `maxSize` or `accept`. */\n onReject?: (files: File[], reason: FileRejectReason) => void;\n /** Helper text inside the drop zone. */\n hint?: ReactNode;\n /**\n * Failure to show under the drop zone (an upload that did not go through).\n * Rejections for `accept` / `maxSize` are shown here automatically, in the\n * library's strings, until the next accepted file.\n */\n error?: ReactNode;\n /** Disable the picker entirely. */\n disabled?: boolean;\n className?: string;\n}\n\nfunction formatSize(bytes: number, s: UiStrings['fileUpload']) {\n if (bytes < 1024) return formatString(s.bytes, { n: bytes });\n if (bytes < 1024 * 1024) return formatString(s.kilobytes, { n: (bytes / 1024).toFixed(1) });\n return formatString(s.megabytes, { n: (bytes / 1024 / 1024).toFixed(1) });\n}\n\n/** Mirror the browser's `accept` matching for dropped files (which skip the picker filter). */\nfunction matchesAccept(file: File, accept?: string): boolean {\n if (!accept) return true;\n const rules = accept\n .split(',')\n .map((r) => r.trim().toLowerCase())\n .filter(Boolean);\n if (!rules.length) return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return rules.some((rule) => {\n if (rule.startsWith('.')) return name.endsWith(rule);\n if (rule.endsWith('/*')) return type.startsWith(rule.slice(0, -1));\n return type === rule;\n });\n}\n\n/**\n * Drag-and-drop file picker with an inline file list. Uncontrolled by default;\n * pass `value` + `onChange` to control externally.\n */\nexport const FileUpload = forwardRef<HTMLDivElement, FileUploadProps>(function FileUpload(\n { accept, multiple, maxSize, value, onChange, onReject, hint, error, disabled, className },\n ref,\n) {\n const strings = useStrings();\n const inputRef = useRef<HTMLInputElement>(null);\n const inputId = useId();\n const [internal, setInternal] = useState<File[]>([]);\n const [over, setOver] = useState(false);\n const [rejection, setRejection] = useState<FileRejectReason | null>(null);\n const errorId = `${inputId}-error`;\n // dragenter/dragleave fire for every child element; count nesting depth so\n // the highlight does not flicker while the pointer crosses the label's children.\n const dragDepth = useRef(0);\n const files = value ?? internal;\n\n const update = useCallback(\n (next: File[]) => {\n if (value === undefined) setInternal(next);\n onChange?.(next);\n },\n [onChange, value],\n );\n\n const addFiles = useCallback(\n (incoming: FileList | File[]) => {\n const accepted: File[] = [];\n const tooLarge: File[] = [];\n const wrongType: File[] = [];\n for (const f of Array.from(incoming)) {\n if (!matchesAccept(f, accept)) wrongType.push(f);\n else if (maxSize && f.size > maxSize) tooLarge.push(f);\n else accepted.push(f);\n }\n if (wrongType.length) onReject?.(wrongType, 'type');\n if (tooLarge.length) onReject?.(tooLarge, 'size');\n // One notice at a time; a size problem is the more actionable of the two.\n setRejection(tooLarge.length ? 'size' : wrongType.length ? 'type' : null);\n if (!accepted.length) return;\n update(multiple ? [...files, ...accepted] : accepted.slice(0, 1));\n },\n [accept, files, maxSize, multiple, onReject, update],\n );\n\n const remove = (idx: number) => update(files.filter((_, i) => i !== idx));\n\n const onDrop = (e: ReactDragEvent<HTMLLabelElement>) => {\n e.preventDefault();\n dragDepth.current = 0;\n setOver(false);\n if (disabled) return;\n addFiles(e.dataTransfer.files);\n };\n\n return (\n <div ref={ref} className={cn('flex flex-col gap-3', className)}>\n <label\n data-slot=\"file-upload\"\n htmlFor={inputId}\n onDragEnter={() => {\n dragDepth.current += 1;\n if (!disabled) setOver(true);\n }}\n onDragOver={(e) => e.preventDefault()}\n onDragLeave={() => {\n dragDepth.current = Math.max(0, dragDepth.current - 1);\n if (dragDepth.current === 0) setOver(false);\n }}\n onDrop={onDrop}\n className={cn(\n 'group relative flex cursor-pointer flex-col items-center justify-center gap-2',\n 'border-border-input bg-background-subtle rounded-md border border-dashed px-6 py-8',\n 'text-center transition-colors',\n 'hover:border-border-strong hover:bg-background-muted',\n 'focus-within:ring-ring focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',\n over && 'border-accent bg-accent-soft',\n disabled && 'pointer-events-none opacity-50',\n )}\n >\n <Upload className=\"text-foreground-muted size-5\" aria-hidden />\n <div className=\"space-y-1\">\n <p className=\"text-sm font-medium\">{strings.fileUpload.drop}</p>\n {hint && <p className=\"text-foreground-muted text-xs\">{hint}</p>}\n </div>\n <input\n ref={inputRef}\n id={inputId}\n type=\"file\"\n accept={accept}\n multiple={multiple}\n disabled={disabled}\n aria-invalid={error || rejection ? true : undefined}\n aria-describedby={error || rejection ? errorId : undefined}\n className=\"sr-only\"\n onChange={(e) => {\n if (e.target.files) addFiles(e.target.files);\n // Allow re-selecting the same file after removing it.\n e.target.value = '';\n }}\n />\n </label>\n\n {(error || rejection) && (\n <p id={errorId} role=\"alert\" className=\"text-danger-text text-xs\">\n {error ??\n (rejection === 'size'\n ? formatString(strings.fileUpload.tooLarge, {\n max: formatSize(maxSize ?? 0, strings.fileUpload),\n })\n : strings.fileUpload.wrongType)}\n </p>\n )}\n\n {files.length > 0 && (\n <ul className=\"flex flex-col gap-2\">\n {files.map((file, idx) => (\n <li\n key={`${file.name}-${file.size}-${file.lastModified}-${idx}`}\n className=\"border-border bg-card flex items-center gap-3 rounded-md border px-3 py-2\"\n >\n <FileIcon className=\"text-foreground-muted size-4 shrink-0\" aria-hidden />\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate text-sm\" title={file.name}>\n {file.name}\n </p>\n <p className=\"text-foreground-muted text-xs\">\n {formatSize(file.size, strings.fileUpload)}\n </p>\n </div>\n <button\n type=\"button\"\n onClick={() => remove(idx)}\n className=\"text-foreground-muted hover:bg-background-muted hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background rounded-sm p-1 outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2\"\n aria-label={formatString(strings.fileUpload.remove, { name: file.name })}\n >\n <X className=\"size-4\" aria-hidden />\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n});\nFileUpload.displayName = 'FileUpload';\n"],"names":["formatSize","bytes","s","formatString","matchesAccept","file","accept","rules","name","type","rule","FileUpload","forwardRef","multiple","maxSize","value","onChange","onReject","hint","error","disabled","className","ref","strings","useStrings","inputRef","useRef","inputId","useId","internal","setInternal","useState","over","setOver","rejection","setRejection","errorId","dragDepth","files","update","useCallback","next","addFiles","inco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"}
1
+ {"version":3,"file":"FileUpload.js","sources":["../../../src/components/ui/FileUpload.tsx"],"sourcesContent":["'use client';\n\nimport {\n forwardRef,\n useCallback,\n useId,\n useRef,\n useState,\n type DragEvent as ReactDragEvent,\n type ReactNode,\n} from 'react';\nimport { File as FileIcon, Upload, X } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { useStrings } from '@/hooks/use-strings';\nimport { formatString, type UiStrings } from '@/lib/strings';\n\nexport type FileRejectReason = 'size' | 'type';\n\nexport interface FileUploadProps {\n /** Accepted file types, e.g. `image/*` or `.pdf,.docx`. */\n accept?: string;\n /** Allow multiple files. */\n multiple?: boolean;\n /** Max file size in bytes. Files larger than this are rejected. */\n maxSize?: number;\n /** Controlled file list. */\n value?: File[];\n /** Called when files are added or removed. */\n onChange?: (files: File[]) => void;\n /** Called with the files that were dropped because of `maxSize` or `accept`. */\n onReject?: (files: File[], reason: FileRejectReason) => void;\n /** Helper text inside the drop zone. */\n hint?: ReactNode;\n /**\n * Failure to show under the drop zone (an upload that did not go through).\n * Rejections for `accept` / `maxSize` are shown here automatically, in the\n * library's strings, until the next accepted file.\n */\n error?: ReactNode;\n /** Disable the picker entirely. */\n disabled?: boolean;\n className?: string;\n}\n\nfunction formatSize(bytes: number, s: UiStrings['fileUpload']) {\n if (bytes < 1024) return formatString(s.bytes, { n: bytes });\n if (bytes < 1024 * 1024) return formatString(s.kilobytes, { n: (bytes / 1024).toFixed(1) });\n return formatString(s.megabytes, { n: (bytes / 1024 / 1024).toFixed(1) });\n}\n\n/** Mirror the browser's `accept` matching for dropped files (which skip the picker filter). */\nfunction matchesAccept(file: File, accept?: string): boolean {\n if (!accept) return true;\n const rules = accept\n .split(',')\n .map((r) => r.trim().toLowerCase())\n .filter(Boolean);\n if (!rules.length) return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return rules.some((rule) => {\n if (rule.startsWith('.')) return name.endsWith(rule);\n if (rule.endsWith('/*')) return type.startsWith(rule.slice(0, -1));\n return type === rule;\n });\n}\n\n/**\n * Drag-and-drop file picker with an inline file list. Uncontrolled by default;\n * pass `value` + `onChange` to control externally.\n */\nexport const FileUpload = forwardRef<HTMLDivElement, FileUploadProps>(function FileUpload(\n { accept, multiple, maxSize, value, onChange, onReject, hint, error, disabled, className },\n ref,\n) {\n const strings = useStrings();\n const inputId = useId();\n const [internal, setInternal] = useState<File[]>([]);\n const [over, setOver] = useState(false);\n const [rejection, setRejection] = useState<FileRejectReason | null>(null);\n const errorId = `${inputId}-error`;\n // dragenter/dragleave fire for every child element; count nesting depth so\n // the highlight does not flicker while the pointer crosses the label's children.\n const dragDepth = useRef(0);\n const files = value ?? internal;\n\n const update = useCallback(\n (next: File[]) => {\n if (value === undefined) setInternal(next);\n onChange?.(next);\n },\n [onChange, value],\n );\n\n const addFiles = useCallback(\n (incoming: FileList | File[]) => {\n const accepted: File[] = [];\n const tooLarge: File[] = [];\n const wrongType: File[] = [];\n for (const f of Array.from(incoming)) {\n if (!matchesAccept(f, accept)) wrongType.push(f);\n else if (maxSize && f.size > maxSize) tooLarge.push(f);\n else accepted.push(f);\n }\n if (wrongType.length) onReject?.(wrongType, 'type');\n if (tooLarge.length) onReject?.(tooLarge, 'size');\n // One notice at a time; a size problem is the more actionable of the two.\n setRejection(tooLarge.length ? 'size' : wrongType.length ? 'type' : null);\n if (!accepted.length) return;\n update(multiple ? [...files, ...accepted] : accepted.slice(0, 1));\n },\n [accept, files, maxSize, multiple, onReject, update],\n );\n\n const remove = (idx: number) => update(files.filter((_, i) => i !== idx));\n\n const onDrop = (e: ReactDragEvent<HTMLLabelElement>) => {\n e.preventDefault();\n dragDepth.current = 0;\n setOver(false);\n if (disabled) return;\n addFiles(e.dataTransfer.files);\n };\n\n return (\n <div ref={ref} className={cn('flex flex-col gap-3', className)}>\n <label\n data-slot=\"file-upload\"\n htmlFor={inputId}\n onDragEnter={() => {\n dragDepth.current += 1;\n if (!disabled) setOver(true);\n }}\n onDragOver={(e) => e.preventDefault()}\n onDragLeave={() => {\n dragDepth.current = Math.max(0, dragDepth.current - 1);\n if (dragDepth.current === 0) setOver(false);\n }}\n onDrop={onDrop}\n className={cn(\n 'group relative flex cursor-pointer flex-col items-center justify-center gap-2',\n 'border-border-input bg-background-subtle rounded-md border border-dashed px-6 py-8',\n 'text-center transition-colors',\n 'hover:border-border-strong hover:bg-background-muted',\n 'focus-within:ring-ring focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',\n over && 'border-accent bg-accent-soft',\n disabled && 'pointer-events-none opacity-50',\n )}\n >\n <Upload className=\"text-foreground-muted size-5\" aria-hidden />\n <div className=\"space-y-1\">\n <p className=\"text-sm font-medium\">{strings.fileUpload.drop}</p>\n {hint && <p className=\"text-foreground-muted text-xs\">{hint}</p>}\n </div>\n <input\n id={inputId}\n type=\"file\"\n accept={accept}\n multiple={multiple}\n disabled={disabled}\n aria-invalid={error || rejection ? true : undefined}\n aria-describedby={error || rejection ? errorId : undefined}\n className=\"sr-only\"\n onChange={(e) => {\n if (e.target.files) addFiles(e.target.files);\n // Allow re-selecting the same file after removing it.\n e.target.value = '';\n }}\n />\n </label>\n\n {(error || rejection) && (\n <p id={errorId} role=\"alert\" className=\"text-danger-text text-xs\">\n {error ??\n (rejection === 'size'\n ? formatString(strings.fileUpload.tooLarge, {\n max: formatSize(maxSize ?? 0, strings.fileUpload),\n })\n : strings.fileUpload.wrongType)}\n </p>\n )}\n\n {files.length > 0 && (\n <ul className=\"flex flex-col gap-2\">\n {files.map((file, idx) => (\n <li\n key={`${file.name}-${file.size}-${file.lastModified}-${idx}`}\n className=\"border-border bg-card flex items-center gap-3 rounded-md border px-3 py-2\"\n >\n <FileIcon className=\"text-foreground-muted size-4 shrink-0\" aria-hidden />\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate text-sm\" title={file.name}>\n {file.name}\n </p>\n <p className=\"text-foreground-muted text-xs\">\n {formatSize(file.size, strings.fileUpload)}\n </p>\n </div>\n <button\n type=\"button\"\n onClick={() => remove(idx)}\n className=\"text-foreground-muted hover:bg-background-muted hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background rounded-sm p-1 outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2\"\n aria-label={formatString(strings.fileUpload.remove, { name: file.name })}\n >\n <X className=\"size-4\" aria-hidden />\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n});\nFileUpload.displayName = 'FileUpload';\n"],"names":["formatSize","bytes","s","formatString","matchesAccept","file","accept","rules","name","type","rule","FileUpload","forwardRef","multiple","maxSize","value","onChange","onReject","hint","error","disabled","className","ref","strings","useStrings","inputId","useId","internal","setInternal","useState","over","setOver","rejection","setRejection","errorId","dragDepth","useRef","files","update","useCallback","next","addFiles","incoming","accepted","tooLarge","wrongType","f","remove","idx","_","i","onDrop","cn","jsxs","jsx","Upload","FileIcon","X"],"mappings":";;;;;;;AA4CA,SAASA,EAAWC,GAAeC,GAA4B;AAC7D,SAAID,IAAQ,OAAaE,EAAaD,EAAE,OAAO,EAAE,GAAGD,GAAO,IACvDA,IAAQ,OAAO,OAAaE,EAAaD,EAAE,WAAW,EAAE,IAAID,IAAQ,MAAM,QAAQ,CAAC,GAAG,IACnFE,EAAaD,EAAE,WAAW,EAAE,IAAID,IAAQ,OAAO,MAAM,QAAQ,CAAC,EAAA,CAAG;AAC1E;AAGA,SAASG,EAAcC,GAAYC,GAA0B;AAC3D,MAAI,CAACA,EAAQ,QAAO;AACpB,QAAMC,IAAQD,EACX,MAAM,GAAG,EACT,IAAI,CAAC,MAAM,EAAE,OAAO,YAAA,CAAa,EACjC,OAAO,OAAO;AACjB,MAAI,CAACC,EAAM,OAAQ,QAAO;AAC1B,QAAMC,IAAOH,EAAK,KAAK,YAAA,GACjBI,IAAOJ,EAAK,KAAK,YAAA;AACvB,SAAOE,EAAM,KAAK,CAACG,MACbA,EAAK,WAAW,GAAG,IAAUF,EAAK,SAASE,CAAI,IAC/CA,EAAK,SAAS,IAAI,IAAUD,EAAK,WAAWC,EAAK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AS,MAAMP,EAAOC,CAAG;AAAA,cACzB,WAAU;AAAA,cACV,cAAY7C,EAAaoB,EAAQ,WAAW,QAAQ,EAAE,MAAMlB,EAAK,MAAM;AAAA,cAEvE,UAAA,gBAAAiD,EAACG,GAAA,EAAE,WAAU,UAAS,eAAW,GAAA,CAAC;AAAA,YAAA;AAAA,UAAA;AAAA,QACpC;AAAA,MAAA;AAAA,MAnBK,GAAGpD,EAAK,IAAI,IAAIA,EAAK,IAAI,IAAIA,EAAK,YAAY,IAAI2C,CAAG;AAAA,IAAA,CAqB7D,EAAA,CACH;AAAA,EAAA,GAEJ;AAEJ,CAAC;AACDrC,EAAW,cAAc;"}
@@ -1,21 +1,21 @@
1
1
  "use client";
2
2
  import { jsx as o } from "react/jsx-runtime";
3
- import { useMemo as a, Suspense as d, lazy as u } from "react";
3
+ import { Suspense as l, lazy as d } from "react";
4
4
  import r from "lucide-react/dynamicIconImports";
5
- const y = Object.keys(r), s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set();
6
- function f(e) {
7
- const t = s.get(e);
5
+ const p = Object.keys(r), i = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
6
+ function u(e) {
7
+ const t = i.get(e);
8
8
  if (t) return t;
9
9
  const n = r[e];
10
10
  if (typeof n != "function")
11
- return typeof process < "u" && process.env.NODE_ENV !== "production" && !i.has(e) && (i.add(e), console.warn(
11
+ return typeof process < "u" && process.env.NODE_ENV !== "production" && !s.has(e) && (s.add(e), console.warn(
12
12
  `[@gerege-systems/ui] <Icon name="${e}"> is not a lucide icon; rendering nothing.`
13
13
  )), null;
14
- const c = u(n);
15
- return s.set(e, c), c;
14
+ const c = d(n);
15
+ return i.set(e, c), c;
16
16
  }
17
- function g({ name: e, fallback: t, ...n }) {
18
- const c = a(() => f(e), [e]), l = t ?? /* @__PURE__ */ o(
17
+ function y({ name: e, fallback: t, ...n }) {
18
+ const c = u(e), a = t ?? /* @__PURE__ */ o(
19
19
  "span",
20
20
  {
21
21
  "aria-hidden": !0,
@@ -23,10 +23,10 @@ function g({ name: e, fallback: t, ...n }) {
23
23
  style: { display: "inline-block", width: n.size ?? "1em", height: n.size ?? "1em" }
24
24
  }
25
25
  );
26
- return c ? /* @__PURE__ */ o(d, { fallback: l, children: /* @__PURE__ */ o(c, { ...n }) }) : null;
26
+ return c ? /* @__PURE__ */ o(l, { fallback: a, children: /* @__PURE__ */ o(c, { ...n }) }) : null;
27
27
  }
28
28
  export {
29
- g as Icon,
30
- y as iconNames
29
+ y as Icon,
30
+ p as iconNames
31
31
  };
32
32
  //# sourceMappingURL=Icon.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Icon.js","sources":["../../../src/components/ui/Icon.tsx"],"sourcesContent":["'use client';\n\nimport { lazy, Suspense, useMemo, type LazyExoticComponent, type ReactNode } from 'react';\nimport dynamicIconImports from 'lucide-react/dynamicIconImports';\nimport type { LucideIcon, LucideProps } from 'lucide-react';\n\n/** Every lucide icon name, kebab-case — e.g. `calendar`, `chevrons-up-down`. */\nexport type IconName = keyof typeof dynamicIconImports;\n\n/** All available icon names (useful for pickers and docs). */\nexport const iconNames = Object.keys(dynamicIconImports) as IconName[];\n\n// lazy() must return a stable component per name or React remounts (and\n// re-suspends) on every render.\nconst cache = new Map<IconName, LazyExoticComponent<LucideIcon>>();\nconst warned = new Set<string>();\n\nfunction getIcon(name: IconName): LazyExoticComponent<LucideIcon> | null {\n const cached = cache.get(name);\n if (cached) return cached;\n const loader = dynamicIconImports[name];\n if (typeof loader !== 'function') {\n // Unknown name (data-driven input) → render nothing, warn once in dev.\n if (\n typeof process !== 'undefined' &&\n process.env.NODE_ENV !== 'production' &&\n !warned.has(name)\n ) {\n warned.add(name);\n console.warn(\n `[@gerege-systems/ui] <Icon name=\"${name}\"> is not a lucide icon; rendering nothing.`,\n );\n }\n return null;\n }\n const created = lazy(loader);\n cache.set(name, created);\n return created;\n}\n\nexport interface IconProps extends Omit<LucideProps, 'ref'> {\n /** Lucide icon name in kebab-case, e.g. `name=\"calendar\"`. Autocompletes. */\n name: IconName;\n /**\n * Shown while the icon chunk loads (first use only — icons are cached).\n * Defaults to an invisible square so layout doesn't shift.\n */\n fallback?: ReactNode;\n}\n\n/**\n * Name-addressed lucide icon. Use when the icon is dynamic (data-driven\n * nav items, user-configurable dashboards) or when importing components for\n * every icon is friction.\n *\n * Each icon is code-split and loaded on first use, so referencing the full\n * lucide set costs nothing up front — `<Icon name=\"rocket\" />` ships only\n * the rocket.\n *\n * @example\n * <Icon name=\"calendar\" className=\"size-4\" />\n * <Icon name=\"chevrons-up-down\" size={16} strokeWidth={1.5} />\n *\n * @do Use `size-4` (16px) inline with text, `size-5` (20px) inside buttons.\n * @dont Reach for this in hot lists with hundreds of distinct icons on first\n * paint — statically imported icons from `Icons` skip the lazy hop.\n */\nexport function Icon({ name, fallback, ...props }: IconProps) {\n const LucideIcon = useMemo(() => getIcon(name), [name]);\n\n const placeholder = fallback ?? (\n <span\n aria-hidden\n className={props.className}\n style={{ display: 'inline-block', width: props.size ?? '1em', height: props.size ?? '1em' }}\n />\n );\n\n if (!LucideIcon) return null;\n\n return (\n <Suspense fallback={placeholder}>\n <LucideIcon {...props} />\n </Suspense>\n );\n}\n"],"names":["iconNames","dynamicIconImports","cache","warned","getIcon","name","cached","loader","created","lazy","Icon","fallback","props","LucideIcon","useMemo","placeholder","jsx","Suspense"],"mappings":";;;;AAUO,MAAMA,IAAY,OAAO,KAAKC,CAAkB,GAIjDC,wBAAY,IAAA,GACZC,wBAAa,IAAA;AAEnB,SAASC,EAAQC,GAAwD;AACvE,QAAMC,IAASJ,EAAM,IAAIG,CAAI;AAC7B,MAAIC,EAAQ,QAAOA;AACnB,QAAMC,IAASN,EAAmBI,CAAI;AACtC,MAAI,OAAOE,KAAW;AAEpB,WACE,OAAO,UAAY,OACnB,QAAQ,IAAI,aAAa,gBACzB,CAACJ,EAAO,IAAIE,CAAI,MAEhBF,EAAO,IAAIE,CAAI,GACf,QAAQ;AAAA,MACN,oCAAoCA,CAAI;AAAA,IAAA,IAGrC;AAET,QAAMG,IAAUC,EAAKF,CAAM;AAC3B,SAAAL,EAAM,IAAIG,GAAMG,CAAO,GAChBA;AACT;AA6BO,SAASE,EAAK,EAAE,MAAAL,GAAM,UAAAM,GAAU,GAAGC,KAAoB;AAC5D,QAAMC,IAAaC,EAAQ,MAAMV,EAAQC,CAAI,GAAG,CAACA,CAAI,CAAC,GAEhDU,IAAcJ,KAClB,gBAAAK;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,eAAW;AAAA,MACX,WAAWJ,EAAM;AAAA,MACjB,OAAO,EAAE,SAAS,gBAAgB,OAAOA,EAAM,QAAQ,OAAO,QAAQA,EAAM,QAAQ,MAAA;AAAA,IAAM;AAAA,EAAA;AAI9F,SAAKC,IAGH,gBAAAG,EAACC,KAAS,UAAUF,GAClB,4BAACF,GAAA,EAAY,GAAGD,GAAO,EAAA,CACzB,IALsB;AAO1B;"}
1
+ {"version":3,"file":"Icon.js","sources":["../../../src/components/ui/Icon.tsx"],"sourcesContent":["'use client';\n\nimport { lazy, Suspense, type LazyExoticComponent, type ReactNode } from 'react';\nimport dynamicIconImports from 'lucide-react/dynamicIconImports';\nimport type { LucideIcon, LucideProps } from 'lucide-react';\n\n/** Every lucide icon name, kebab-case — e.g. `calendar`, `chevrons-up-down`. */\nexport type IconName = keyof typeof dynamicIconImports;\n\n/** All available icon names (useful for pickers and docs). */\nexport const iconNames = Object.keys(dynamicIconImports) as IconName[];\n\n// lazy() must return a stable component per name or React remounts (and\n// re-suspends) on every render.\nconst cache = new Map<IconName, LazyExoticComponent<LucideIcon>>();\nconst warned = new Set<string>();\n\nfunction getIcon(name: IconName): LazyExoticComponent<LucideIcon> | null {\n const cached = cache.get(name);\n if (cached) return cached;\n const loader = dynamicIconImports[name];\n if (typeof loader !== 'function') {\n // Unknown name (data-driven input) → render nothing, warn once in dev.\n if (\n typeof process !== 'undefined' &&\n process.env.NODE_ENV !== 'production' &&\n !warned.has(name)\n ) {\n warned.add(name);\n console.warn(\n `[@gerege-systems/ui] <Icon name=\"${name}\"> is not a lucide icon; rendering nothing.`,\n );\n }\n return null;\n }\n const created = lazy(loader);\n cache.set(name, created);\n return created;\n}\n\nexport interface IconProps extends Omit<LucideProps, 'ref'> {\n /** Lucide icon name in kebab-case, e.g. `name=\"calendar\"`. Autocompletes. */\n name: IconName;\n /**\n * Shown while the icon chunk loads (first use only — icons are cached).\n * Defaults to an invisible square so layout doesn't shift.\n */\n fallback?: ReactNode;\n}\n\n/**\n * Name-addressed lucide icon. Use when the icon is dynamic (data-driven\n * nav items, user-configurable dashboards) or when importing components for\n * every icon is friction.\n *\n * Each icon is code-split and loaded on first use, so referencing the full\n * lucide set costs nothing up front — `<Icon name=\"rocket\" />` ships only\n * the rocket.\n *\n * @example\n * <Icon name=\"calendar\" className=\"size-4\" />\n * <Icon name=\"chevrons-up-down\" size={16} strokeWidth={1.5} />\n *\n * @do Use `size-4` (16px) inline with text, `size-5` (20px) inside buttons.\n * @dont Reach for this in hot lists with hundreds of distinct icons on first\n * paint — statically imported icons from `Icons` skip the lazy hop.\n */\nexport function Icon({ name, fallback, ...props }: IconProps) {\n // getIcon caches one lazy component per name at module level, so this is a\n // lookup, not a component created during render — the rule cannot see the cache.\n const LucideIcon = getIcon(name);\n\n const placeholder = fallback ?? (\n <span\n aria-hidden\n className={props.className}\n style={{ display: 'inline-block', width: props.size ?? '1em', height: props.size ?? '1em' }}\n />\n );\n\n if (!LucideIcon) return null;\n\n return (\n <Suspense fallback={placeholder}>\n {/* eslint-disable-next-line react-hooks/static-components -- module-level cache, stable per name */}\n <LucideIcon {...props} />\n </Suspense>\n );\n}\n"],"names":["iconNames","dynamicIconImports","cache","warned","getIcon","name","cached","loader","created","lazy","Icon","fallback","props","LucideIcon","placeholder","jsx","Suspense"],"mappings":";;;;AAUO,MAAMA,IAAY,OAAO,KAAKC,CAAkB,GAIjDC,wBAAY,IAAA,GACZC,wBAAa,IAAA;AAEnB,SAASC,EAAQC,GAAwD;AACvE,QAAMC,IAASJ,EAAM,IAAIG,CAAI;AAC7B,MAAIC,EAAQ,QAAOA;AACnB,QAAMC,IAASN,EAAmBI,CAAI;AACtC,MAAI,OAAOE,KAAW;AAEpB,WACE,OAAO,UAAY,OACnB,QAAQ,IAAI,aAAa,gBACzB,CAACJ,EAAO,IAAIE,CAAI,MAEhBF,EAAO,IAAIE,CAAI,GACf,QAAQ;AAAA,MACN,oCAAoCA,CAAI;AAAA,IAAA,IAGrC;AAET,QAAMG,IAAUC,EAAKF,CAAM;AAC3B,SAAAL,EAAM,IAAIG,GAAMG,CAAO,GAChBA;AACT;AA6BO,SAASE,EAAK,EAAE,MAAAL,GAAM,UAAAM,GAAU,GAAGC,KAAoB;AAG5D,QAAMC,IAAaT,EAAQC,CAAI,GAEzBS,IAAcH,KAClB,gBAAAI;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,eAAW;AAAA,MACX,WAAWH,EAAM;AAAA,MACjB,OAAO,EAAE,SAAS,gBAAgB,OAAOA,EAAM,QAAQ,OAAO,QAAQA,EAAM,QAAQ,MAAA;AAAA,IAAM;AAAA,EAAA;AAI9F,SAAKC,IAGH,gBAAAE,EAACC,KAAS,UAAUF,GAElB,4BAACD,GAAA,EAAY,GAAGD,GAAO,EAAA,CACzB,IANsB;AAQ1B;"}
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as o } from "react/jsx-runtime";
3
3
  import { forwardRef as g } from "react";
4
- import { Loader2 as b } from "../../icons/index.js";
5
- import { cn as f } from "../../lib/utils.js";
4
+ import { cn as b } from "../../lib/utils.js";
5
+ import { Loader2 as f } from "../../icons/index.js";
6
6
  import { cva as m } from "class-variance-authority";
7
7
  const l = m(
8
8
  [
@@ -48,10 +48,10 @@ const l = m(
48
48
  "aria-busy": e || void 0,
49
49
  "aria-disabled": e || void 0,
50
50
  disabled: s,
51
- className: f(l({ variant: n, size: i }), r),
51
+ className: b(l({ variant: n, size: i }), r),
52
52
  onClick: e ? p : d,
53
53
  ...u,
54
- children: e ? /* @__PURE__ */ o(b, { className: "animate-spin", "aria-hidden": "true" }) : a
54
+ children: e ? /* @__PURE__ */ o(f, { className: "animate-spin", "aria-hidden": "true" }) : a
55
55
  }
56
56
  );
57
57
  });
@@ -1 +1 @@
1
- {"version":3,"file":"IconButton.js","sources":["../../../src/components/ui/IconButton.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, type ButtonHTMLAttributes, type ReactNode, type SyntheticEvent } from 'react';\nimport { Loader2 } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { cva, type VariantProps } from '@/lib/cva';\n\nconst iconButton = cva(\n [\n 'inline-flex items-center justify-center shrink-0',\n 'rounded-md',\n 'transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]',\n 'outline-hidden',\n 'focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n 'focus-visible:ring-offset-background',\n 'disabled:pointer-events-none disabled:opacity-50',\n 'aria-busy:pointer-events-none',\n '[&_svg]:pointer-events-none',\n ],\n {\n variants: {\n variant: {\n primary: 'bg-accent text-on-accent hover:bg-accent-hover active:bg-accent-active',\n secondary:\n 'bg-secondary text-foreground hover:bg-secondary-hover active:bg-secondary-active',\n outline:\n 'border border-border-input bg-transparent text-foreground hover:bg-background-muted',\n ghost:\n 'bg-transparent text-foreground-muted hover:bg-background-muted hover:text-foreground',\n destructive: 'bg-danger text-on-danger hover:bg-danger-hover active:bg-danger-active',\n },\n size: {\n // Matches Button heights: sm 32 / md 36 / lg 40 / xl 44 (touch / marketing).\n sm: 'h-8 w-8 [&_svg]:size-4',\n md: 'h-9 w-9 [&_svg]:size-4',\n lg: 'h-10 w-10 [&_svg]:size-5',\n xl: 'h-11 w-11 [&_svg]:size-5',\n },\n },\n defaultVariants: {\n variant: 'ghost',\n size: 'md',\n },\n },\n);\n\nexport interface IconButtonProps\n extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof iconButton> {\n /**\n * Accessible label for screen readers. **Required** — an icon-only button\n * with no label is invisible to assistive tech.\n */\n 'aria-label': string;\n /** The Lucide icon to render. */\n icon: ReactNode;\n /** Show a spinner instead of the icon; blocks interaction but keeps focus (`aria-disabled`). */\n loading?: boolean;\n}\n\n/**\n * Square, icon-only button. Default variant is `ghost` because most\n * IconButtons sit in dense toolbars or tables. Always pass `aria-label`.\n *\n * @example Toolbar action\n * <IconButton aria-label=\"Edit row\" icon={<Edit2 />} onClick={onEdit} />\n *\n * @example Dismissible chip\n * <IconButton aria-label=\"Remove tag\" size=\"sm\" icon={<X />} />\n *\n * @do Use `ghost` for in-row actions; `outline` when next to a label-less\n * primary button you want users to consider as an alternative.\n * @dont Use IconButton when the action's meaning isn't universally\n * recognised. If users need to learn the icon, ship a Button with text.\n */\nexport const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(\n { className, variant, size, icon, loading, disabled, type = 'button', onClick, ...props },\n ref,\n) {\n return (\n <button\n data-slot=\"icon-button\"\n ref={ref}\n type={type}\n aria-busy={loading || undefined}\n aria-disabled={loading || undefined}\n disabled={disabled}\n className={cn(iconButton({ variant, size }), className)}\n onClick={loading ? blockEvent : onClick}\n {...props}\n >\n {loading ? <Loader2 className=\"animate-spin\" aria-hidden=\"true\" /> : icon}\n </button>\n );\n});\n\nIconButton.displayName = 'IconButton';\n\nfunction blockEvent(e: SyntheticEvent) {\n e.preventDefault();\n e.stopPropagation();\n}\n"],"names":["iconButton","cva","IconButton","forwardRef","className","variant","size","icon","loading","disabled","type","onClick","props","ref","jsx","cn","blockEvent","Loader2","e"],"mappings":";;;;;;AAOA,MAAMA,IAAaC;AAAA,EACjB;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAAA,EAEF;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,WACE;AAAA,QACF,SACE;AAAA,QACF,OACE;AAAA,QACF,aAAa;AAAA,MAAA;AAAA,MAEf,MAAM;AAAA;AAAA,QAEJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MAAA;AAAA,IACN;AAAA,IAEF,iBAAiB;AAAA,MACf,SAAS;AAAA,MACT,MAAM;AAAA,IAAA;AAAA,EACR;AAEJ,GA8BaC,IAAaC,EAA+C,SACvE,EAAE,WAAAC,GAAW,SAAAC,GAAS,MAAAC,GAAM,MAAAC,GAAM,SAAAC,GAAS,UAAAC,GAAU,MAAAC,IAAO,UAAU,SAAAC,GAAS,GAAGC,EAAA,GAClFC,GACA;AACA,SACE,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAU;AAAA,MACV,KAAAD;AAAA,MACA,MAAAH;AAAA,MACA,aAAWF,KAAW;AAAA,MACtB,iBAAeA,KAAW;AAAA,MAC1B,UAAAC;AAAA,MACA,WAAWM,EAAGf,EAAW,EAAE,SAAAK,GAAS,MAAAC,EAAA,CAAM,GAAGF,CAAS;AAAA,MACtD,SAASI,IAAUQ,IAAaL;AAAA,MAC/B,GAAGC;AAAA,MAEH,cAAU,gBAAAE,EAACG,GAAA,EAAQ,WAAU,gBAAe,eAAY,QAAO,IAAKV;AAAA,IAAA;AAAA,EAAA;AAG3E,CAAC;AAEDL,EAAW,cAAc;AAEzB,SAASc,EAAWE,GAAmB;AACrC,EAAAA,EAAE,eAAA,GACFA,EAAE,gBAAA;AACJ;"}
1
+ {"version":3,"file":"IconButton.js","sources":["../../../src/components/ui/IconButton.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, type ButtonHTMLAttributes, type ReactNode, type SyntheticEvent } from 'react';\nimport { cn } from '@/lib/utils';\nimport { cva, type VariantProps } from '@/lib/cva';\nimport { Loader2 } from '@/icons';\n\nconst iconButton = cva(\n [\n 'inline-flex items-center justify-center shrink-0',\n 'rounded-md',\n 'transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]',\n 'outline-hidden',\n 'focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n 'focus-visible:ring-offset-background',\n 'disabled:pointer-events-none disabled:opacity-50',\n 'aria-busy:pointer-events-none',\n '[&_svg]:pointer-events-none',\n ],\n {\n variants: {\n variant: {\n primary: 'bg-accent text-on-accent hover:bg-accent-hover active:bg-accent-active',\n secondary:\n 'bg-secondary text-foreground hover:bg-secondary-hover active:bg-secondary-active',\n outline:\n 'border border-border-input bg-transparent text-foreground hover:bg-background-muted',\n ghost:\n 'bg-transparent text-foreground-muted hover:bg-background-muted hover:text-foreground',\n destructive: 'bg-danger text-on-danger hover:bg-danger-hover active:bg-danger-active',\n },\n size: {\n // Matches Button heights: sm 32 / md 36 / lg 40 / xl 44 (touch / marketing).\n sm: 'h-8 w-8 [&_svg]:size-4',\n md: 'h-9 w-9 [&_svg]:size-4',\n lg: 'h-10 w-10 [&_svg]:size-5',\n xl: 'h-11 w-11 [&_svg]:size-5',\n },\n },\n defaultVariants: {\n variant: 'ghost',\n size: 'md',\n },\n },\n);\n\nexport interface IconButtonProps\n extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof iconButton> {\n /**\n * Accessible label for screen readers. **Required** — an icon-only button\n * with no label is invisible to assistive tech.\n */\n 'aria-label': string;\n /** The Lucide icon to render. */\n icon: ReactNode;\n /** Show a spinner instead of the icon; blocks interaction but keeps focus (`aria-disabled`). */\n loading?: boolean;\n}\n\n/**\n * Square, icon-only button. Default variant is `ghost` because most\n * IconButtons sit in dense toolbars or tables. Always pass `aria-label`.\n *\n * @example Toolbar action\n * <IconButton aria-label=\"Edit row\" icon={<Edit2 />} onClick={onEdit} />\n *\n * @example Dismissible chip\n * <IconButton aria-label=\"Remove tag\" size=\"sm\" icon={<X />} />\n *\n * @do Use `ghost` for in-row actions; `outline` when next to a label-less\n * primary button you want users to consider as an alternative.\n * @dont Use IconButton when the action's meaning isn't universally\n * recognised. If users need to learn the icon, ship a Button with text.\n */\nexport const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(\n { className, variant, size, icon, loading, disabled, type = 'button', onClick, ...props },\n ref,\n) {\n return (\n <button\n data-slot=\"icon-button\"\n ref={ref}\n type={type}\n aria-busy={loading || undefined}\n aria-disabled={loading || undefined}\n disabled={disabled}\n className={cn(iconButton({ variant, size }), className)}\n onClick={loading ? blockEvent : onClick}\n {...props}\n >\n {loading ? <Loader2 className=\"animate-spin\" aria-hidden=\"true\" /> : icon}\n </button>\n );\n});\n\nIconButton.displayName = 'IconButton';\n\nfunction blockEvent(e: SyntheticEvent) {\n e.preventDefault();\n e.stopPropagation();\n}\n"],"names":["iconButton","cva","IconButton","forwardRef","className","variant","size","icon","loading","disabled","type","onClick","props","ref","jsx","cn","blockEvent","Loader2","e"],"mappings":";;;;;;AAOA,MAAMA,IAAaC;AAAA,EACjB;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAAA,EAEF;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SAAS;AAAA,QACT,WACE;AAAA,QACF,SACE;AAAA,QACF,OACE;AAAA,QACF,aAAa;AAAA,MAAA;AAAA,MAEf,MAAM;AAAA;AAAA,QAEJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MAAA;AAAA,IACN;AAAA,IAEF,iBAAiB;AAAA,MACf,SAAS;AAAA,MACT,MAAM;AAAA,IAAA;AAAA,EACR;AAEJ,GA8BaC,IAAaC,EAA+C,SACvE,EAAE,WAAAC,GAAW,SAAAC,GAAS,MAAAC,GAAM,MAAAC,GAAM,SAAAC,GAAS,UAAAC,GAAU,MAAAC,IAAO,UAAU,SAAAC,GAAS,GAAGC,EAAA,GAClFC,GACA;AACA,SACE,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAU;AAAA,MACV,KAAAD;AAAA,MACA,MAAAH;AAAA,MACA,aAAWF,KAAW;AAAA,MACtB,iBAAeA,KAAW;AAAA,MAC1B,UAAAC;AAAA,MACA,WAAWM,EAAGf,EAAW,EAAE,SAAAK,GAAS,MAAAC,EAAA,CAAM,GAAGF,CAAS;AAAA,MACtD,SAASI,IAAUQ,IAAaL;AAAA,MAC/B,GAAGC;AAAA,MAEH,cAAU,gBAAAE,EAACG,GAAA,EAAQ,WAAU,gBAAe,eAAY,QAAO,IAAKV;AAAA,IAAA;AAAA,EAAA;AAG3E,CAAC;AAEDL,EAAW,cAAc;AAEzB,SAASc,EAAWE,GAAmB;AACrC,EAAAA,EAAE,eAAA,GACFA,EAAE,gBAAA;AACJ;"}
@@ -1,38 +1,38 @@
1
1
  "use client";
2
- import { jsxs as c, jsx as i } from "react/jsx-runtime";
2
+ import { jsxs as d, jsx as i } from "react/jsx-runtime";
3
3
  import { forwardRef as A, useId as B, useMemo as E } from "react";
4
4
  import { ChevronsLeft as T, ChevronLeft as V, ChevronRight as _, ChevronsRight as $ } from "../../icons/index.js";
5
5
  import { cn as g } from "../../lib/utils.js";
6
6
  import { useStrings as q } from "../../hooks/use-strings.js";
7
- import { defaultStrings as z, formatString as b } from "../../lib/strings.js";
7
+ import { defaultStrings as z, formatString as h } from "../../lib/strings.js";
8
8
  import { Select as D, SelectTrigger as G, SelectContent as H, SelectItem as K } from "./Select.js";
9
- function y(r) {
9
+ function y(t) {
10
10
  return {
11
- showing: (e, t, d) => b(r.showing, { from: e, to: t, total: d }),
12
- rowsPerPage: r.rowsPerPage,
13
- first: r.first,
14
- last: r.last,
15
- prev: r.prev,
16
- next: r.next,
17
- page: (e) => b(r.page, { n: e }),
18
- perPage: (e) => b(r.perPage, { n: e }),
19
- nav: r.nav
11
+ showing: (e, r, c) => h(t.showing, { from: e, to: r, total: c }),
12
+ rowsPerPage: t.rowsPerPage,
13
+ first: t.first,
14
+ last: t.last,
15
+ prev: t.prev,
16
+ next: t.next,
17
+ page: (e) => h(t.page, { n: e }),
18
+ perPage: (e) => h(t.perPage, { n: e }),
19
+ nav: t.nav
20
20
  };
21
21
  }
22
22
  const ee = y(
23
23
  z.pagination
24
24
  );
25
- function Q(r, e, t = 7) {
26
- if (e <= t) return Array.from({ length: e }, (l, f) => f + 1);
27
- const d = 1, a = [], s = Math.max(2, r - d), u = Math.min(e - 1, r + d);
25
+ function Q(t, e, r = 7) {
26
+ if (e <= r) return Array.from({ length: e }, (l, f) => f + 1);
27
+ const c = 1, a = [], s = Math.max(2, t - c), u = Math.min(e - 1, t + c);
28
28
  a.push(1), s > 2 && a.push("gap");
29
29
  for (let l = s; l <= u; l++) a.push(l);
30
30
  return u < e - 1 && a.push("gap"), a.push(e), a;
31
31
  }
32
32
  const U = A(function({
33
33
  page: e,
34
- pageCount: t,
35
- onPageChange: d,
34
+ pageCount: r,
35
+ onPageChange: c,
36
36
  totalItems: a,
37
37
  pageSize: s,
38
38
  pageSizeOptions: u,
@@ -43,10 +43,10 @@ const U = A(function({
43
43
  "aria-label": C,
44
44
  ...L
45
45
  }, M) {
46
- const R = q(), o = { ...y(R.pagination), ...P }, v = B(), S = E(() => Q(e, t), [e, t]), x = !a || t <= 0, N = s === void 0 ? void 0 : x ? 0 : (e - 1) * s + 1, p = s === void 0 || a === void 0 ? void 0 : x ? 0 : Math.min(e * s, a), k = e <= 1 || t <= 0, w = e >= t, m = (n) => {
47
- n < 1 || n > t || n === e || d(n);
46
+ const R = q(), o = { ...y(R.pagination), ...P }, v = B(), S = E(() => Q(e, r), [e, r]), x = !a || r <= 0, N = s === void 0 ? void 0 : x ? 0 : (e - 1) * s + 1, p = s === void 0 || a === void 0 ? void 0 : x ? 0 : Math.min(e * s, a), k = e <= 1 || r <= 0, w = e >= r, m = (n) => {
47
+ n < 1 || n > r || n === e || c(n);
48
48
  };
49
- return /* @__PURE__ */ c(
49
+ return /* @__PURE__ */ d(
50
50
  "nav",
51
51
  {
52
52
  "data-slot": "pagination",
@@ -55,17 +55,17 @@ const U = A(function({
55
55
  className: g("flex flex-wrap items-center justify-between gap-3", j),
56
56
  ...L,
57
57
  children: [
58
- /* @__PURE__ */ c("div", { className: "text-foreground-muted flex items-center gap-3 text-sm", children: [
58
+ /* @__PURE__ */ d("div", { className: "text-foreground-muted flex items-center gap-3 text-sm", children: [
59
59
  a !== void 0 && s !== void 0 && N !== void 0 && p !== void 0 && /* @__PURE__ */ i("span", { className: "tabular", children: o.showing(N, p, a) }),
60
- u && l && s !== void 0 && /* @__PURE__ */ c("div", { className: "flex items-center gap-2", children: [
60
+ u && l && s !== void 0 && /* @__PURE__ */ d("div", { className: "flex items-center gap-2", children: [
61
61
  /* @__PURE__ */ i("label", { htmlFor: v, className: "sr-only", children: o.rowsPerPage }),
62
- /* @__PURE__ */ c(D, { value: String(s), onValueChange: (n) => l(Number(n)), children: [
62
+ /* @__PURE__ */ d(D, { value: String(s), onValueChange: (n) => l(Number(n)), children: [
63
63
  /* @__PURE__ */ i(G, { id: v, size: "sm", className: "w-[7.5rem] whitespace-nowrap" }),
64
64
  /* @__PURE__ */ i(H, { children: u.map((n) => /* @__PURE__ */ i(K, { value: String(n), children: o.perPage(n) }, n)) })
65
65
  ] })
66
66
  ] })
67
67
  ] }),
68
- /* @__PURE__ */ c("ul", { className: "flex items-center gap-1", children: [
68
+ /* @__PURE__ */ d("ul", { className: "flex items-center gap-1", children: [
69
69
  f && /* @__PURE__ */ i("li", { className: "hidden sm:block", children: /* @__PURE__ */ i(
70
70
  "button",
71
71
  {
@@ -73,7 +73,7 @@ const U = A(function({
73
73
  "aria-label": o.first,
74
74
  disabled: k,
75
75
  onClick: () => m(1),
76
- className: h,
76
+ className: b,
77
77
  children: /* @__PURE__ */ i(T, { className: "size-4", "aria-hidden": !0 })
78
78
  }
79
79
  ) }),
@@ -84,14 +84,14 @@ const U = A(function({
84
84
  "aria-label": o.prev,
85
85
  disabled: k,
86
86
  onClick: () => m(e - 1),
87
- className: h,
87
+ className: b,
88
88
  children: /* @__PURE__ */ i(V, { className: "size-4", "aria-hidden": !0 })
89
89
  }
90
90
  ) }),
91
- /* @__PURE__ */ c("li", { className: "tabular text-foreground-muted px-2 text-sm sm:hidden", "aria-current": "page", children: [
91
+ /* @__PURE__ */ d("li", { className: "tabular text-foreground-muted px-2 text-sm sm:hidden", "aria-current": "page", children: [
92
92
  e,
93
93
  " / ",
94
- t
94
+ r
95
95
  ] }),
96
96
  S.map(
97
97
  (n, F) => n === "gap" ? /* @__PURE__ */ i("li", { className: "text-foreground-subtle hidden px-2 sm:block", children: "…" }, `gap-${F}`) : /* @__PURE__ */ i("li", { className: "hidden sm:block", children: /* @__PURE__ */ i(
@@ -118,7 +118,7 @@ const U = A(function({
118
118
  "aria-label": o.next,
119
119
  disabled: w,
120
120
  onClick: () => m(e + 1),
121
- className: h,
121
+ className: b,
122
122
  children: /* @__PURE__ */ i(_, { className: "size-4", "aria-hidden": !0 })
123
123
  }
124
124
  ) }),
@@ -128,8 +128,8 @@ const U = A(function({
128
128
  type: "button",
129
129
  "aria-label": o.last,
130
130
  disabled: w,
131
- onClick: () => m(t),
132
- className: h,
131
+ onClick: () => m(r),
132
+ className: b,
133
133
  children: /* @__PURE__ */ i($, { className: "size-4", "aria-hidden": !0 })
134
134
  }
135
135
  ) })
@@ -139,8 +139,10 @@ const U = A(function({
139
139
  );
140
140
  });
141
141
  U.displayName = "Pagination";
142
- const h = g(
143
- "inline-flex size-8 items-center justify-center rounded-md text-foreground-muted",
142
+ const b = g(
143
+ "relative inline-flex size-8 items-center justify-center rounded-md text-foreground-muted",
144
+ // 32px visual, 44px hit area via an invisible halo (WCAG 2.5.8).
145
+ 'before:absolute before:-inset-1.5 before:content-[""]',
144
146
  "transition-colors duration-[var(--duration-fast)]",
145
147
  "hover:bg-background-muted hover:text-foreground",
146
148
  "disabled:opacity-50 disabled:pointer-events-none",