@craftzbay/ui 0.11.3 → 0.11.4
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.
- package/dist-lib/_virtual/_rolldown/runtime.js +11 -0
- package/dist-lib/components/ui/Accordion.js +42 -67
- package/dist-lib/components/ui/Accordion.js.map +1 -1
- package/dist-lib/components/ui/Alert.js +71 -77
- package/dist-lib/components/ui/Alert.js.map +1 -1
- package/dist-lib/components/ui/Avatar.js +67 -92
- package/dist-lib/components/ui/Avatar.js.map +1 -1
- package/dist-lib/components/ui/Badge.js +119 -74
- package/dist-lib/components/ui/Badge.js.map +1 -1
- package/dist-lib/components/ui/Breadcrumbs.js +62 -50
- package/dist-lib/components/ui/Breadcrumbs.js.map +1 -1
- package/dist-lib/components/ui/Button.js +129 -131
- package/dist-lib/components/ui/Button.js.map +1 -1
- package/dist-lib/components/ui/Calendar.d.ts +1 -1
- package/dist-lib/components/ui/Calendar.js +99 -136
- package/dist-lib/components/ui/Calendar.js.map +1 -1
- package/dist-lib/components/ui/Card.js +88 -94
- package/dist-lib/components/ui/Card.js.map +1 -1
- package/dist-lib/components/ui/Carousel.js +125 -170
- package/dist-lib/components/ui/Carousel.js.map +1 -1
- package/dist-lib/components/ui/Chart.d.ts +3 -3
- package/dist-lib/components/ui/Chart.js +435 -464
- package/dist-lib/components/ui/Chart.js.map +1 -1
- package/dist-lib/components/ui/Checkbox.js +60 -69
- package/dist-lib/components/ui/Checkbox.js.map +1 -1
- package/dist-lib/components/ui/Combobox.js +179 -192
- package/dist-lib/components/ui/Combobox.js.map +1 -1
- package/dist-lib/components/ui/CommandPalette.d.ts +2 -2
- package/dist-lib/components/ui/CommandPalette.js +106 -167
- package/dist-lib/components/ui/CommandPalette.js.map +1 -1
- package/dist-lib/components/ui/ContextMenu.d.ts +1 -1
- package/dist-lib/components/ui/ContextMenu.js +89 -154
- package/dist-lib/components/ui/ContextMenu.js.map +1 -1
- package/dist-lib/components/ui/DataGrid.d.ts +1 -1
- package/dist-lib/components/ui/DataGrid.js +99 -96
- package/dist-lib/components/ui/DataGrid.js.map +1 -1
- package/dist-lib/components/ui/DatePicker.js +151 -188
- package/dist-lib/components/ui/DatePicker.js.map +1 -1
- package/dist-lib/components/ui/DesignSystemProvider.d.ts +1 -1
- package/dist-lib/components/ui/DesignSystemProvider.js +120 -130
- package/dist-lib/components/ui/DesignSystemProvider.js.map +1 -1
- package/dist-lib/components/ui/Dialog.d.ts +3 -3
- package/dist-lib/components/ui/Dialog.js +108 -156
- package/dist-lib/components/ui/Dialog.js.map +1 -1
- package/dist-lib/components/ui/Drawer.d.ts +3 -3
- package/dist-lib/components/ui/Drawer.js +90 -124
- package/dist-lib/components/ui/Drawer.js.map +1 -1
- package/dist-lib/components/ui/DropdownMenu.d.ts +1 -1
- package/dist-lib/components/ui/DropdownMenu.js +92 -158
- package/dist-lib/components/ui/DropdownMenu.js.map +1 -1
- package/dist-lib/components/ui/EmptyState.js +31 -44
- package/dist-lib/components/ui/EmptyState.js.map +1 -1
- package/dist-lib/components/ui/ErrorState.js +57 -67
- package/dist-lib/components/ui/ErrorState.js.map +1 -1
- package/dist-lib/components/ui/FileUpload.js +113 -107
- package/dist-lib/components/ui/FileUpload.js.map +1 -1
- package/dist-lib/components/ui/Form.d.ts +6 -4
- package/dist-lib/components/ui/Form.js +117 -122
- package/dist-lib/components/ui/Form.js.map +1 -1
- package/dist-lib/components/ui/Icon.d.ts +1 -1
- package/dist-lib/components/ui/Icon.js +30 -29
- package/dist-lib/components/ui/Icon.js.map +1 -1
- package/dist-lib/components/ui/IconButton.js +61 -63
- package/dist-lib/components/ui/IconButton.js.map +1 -1
- package/dist-lib/components/ui/Input.js +133 -156
- package/dist-lib/components/ui/Input.js.map +1 -1
- package/dist-lib/components/ui/Kbd.js +14 -21
- package/dist-lib/components/ui/Kbd.js.map +1 -1
- package/dist-lib/components/ui/MultiSelect.js +176 -208
- package/dist-lib/components/ui/MultiSelect.js.map +1 -1
- package/dist-lib/components/ui/Pagination.js +152 -149
- package/dist-lib/components/ui/Pagination.js.map +1 -1
- package/dist-lib/components/ui/Popover.js +18 -33
- package/dist-lib/components/ui/Popover.js.map +1 -1
- package/dist-lib/components/ui/Progress.js +77 -99
- package/dist-lib/components/ui/Progress.js.map +1 -1
- package/dist-lib/components/ui/RadioGroup.js +51 -80
- package/dist-lib/components/ui/RadioGroup.js.map +1 -1
- package/dist-lib/components/ui/RelativeTime.js +22 -29
- package/dist-lib/components/ui/RelativeTime.js.map +1 -1
- package/dist-lib/components/ui/ScrollArea.js +39 -58
- package/dist-lib/components/ui/ScrollArea.js.map +1 -1
- package/dist-lib/components/ui/Select.js +108 -131
- package/dist-lib/components/ui/Select.js.map +1 -1
- package/dist-lib/components/ui/Separator.js +18 -24
- package/dist-lib/components/ui/Separator.js.map +1 -1
- package/dist-lib/components/ui/Sheet.d.ts +2 -2
- package/dist-lib/components/ui/Sheet.js +77 -129
- package/dist-lib/components/ui/Sheet.js.map +1 -1
- package/dist-lib/components/ui/Sidebar.d.ts +1 -1
- package/dist-lib/components/ui/Sidebar.js +168 -207
- package/dist-lib/components/ui/Sidebar.js.map +1 -1
- package/dist-lib/components/ui/Skeleton.js +17 -27
- package/dist-lib/components/ui/Skeleton.js.map +1 -1
- package/dist-lib/components/ui/Slider.js +45 -62
- package/dist-lib/components/ui/Slider.js.map +1 -1
- package/dist-lib/components/ui/Snackbar.js +75 -55
- package/dist-lib/components/ui/Snackbar.js.map +1 -1
- package/dist-lib/components/ui/Spinner.js +45 -52
- package/dist-lib/components/ui/Spinner.js.map +1 -1
- package/dist-lib/components/ui/Stepper.js +56 -108
- package/dist-lib/components/ui/Stepper.js.map +1 -1
- package/dist-lib/components/ui/Switch.js +46 -79
- package/dist-lib/components/ui/Switch.js.map +1 -1
- package/dist-lib/components/ui/Table.js +108 -169
- package/dist-lib/components/ui/Table.js.map +1 -1
- package/dist-lib/components/ui/Tabs.js +57 -88
- package/dist-lib/components/ui/Tabs.js.map +1 -1
- package/dist-lib/components/ui/TagInput.js +76 -109
- package/dist-lib/components/ui/TagInput.js.map +1 -1
- package/dist-lib/components/ui/Textarea.js +74 -86
- package/dist-lib/components/ui/Textarea.js.map +1 -1
- package/dist-lib/components/ui/Timeline.d.ts +3 -3
- package/dist-lib/components/ui/Timeline.js +61 -49
- package/dist-lib/components/ui/Timeline.js.map +1 -1
- package/dist-lib/components/ui/Toast.d.ts +1 -1
- package/dist-lib/components/ui/Toast.js +136 -150
- package/dist-lib/components/ui/Toast.js.map +1 -1
- package/dist-lib/components/ui/Tooltip.d.ts +2 -2
- package/dist-lib/components/ui/Tooltip.js +35 -56
- package/dist-lib/components/ui/Tooltip.js.map +1 -1
- package/dist-lib/components/ui/TopNav.js +46 -66
- package/dist-lib/components/ui/TopNav.js.map +1 -1
- package/dist-lib/components/ui/Tree.js +134 -168
- package/dist-lib/components/ui/Tree.js.map +1 -1
- package/dist-lib/hooks/use-debounce.js +27 -33
- package/dist-lib/hooks/use-debounce.js.map +1 -1
- package/dist-lib/hooks/use-delayed-loading.js +19 -18
- package/dist-lib/hooks/use-delayed-loading.js.map +1 -1
- package/dist-lib/hooks/use-field-ids.js +14 -16
- package/dist-lib/hooks/use-field-ids.js.map +1 -1
- package/dist-lib/hooks/use-media-query.js +15 -19
- package/dist-lib/hooks/use-media-query.js.map +1 -1
- package/dist-lib/hooks/use-modifier-key.js +20 -15
- package/dist-lib/hooks/use-modifier-key.js.map +1 -1
- package/dist-lib/hooks/use-strings.js +10 -10
- package/dist-lib/hooks/use-strings.js.map +1 -1
- package/dist-lib/hooks/use-toast.js +73 -62
- package/dist-lib/hooks/use-toast.js.map +1 -1
- package/dist-lib/icon.js +2 -6
- package/dist-lib/icons/index.js +166 -163
- package/dist-lib/icons/index.js.map +1 -1
- package/dist-lib/illustrations/index.d.ts +7 -7
- package/dist-lib/illustrations/index.js +255 -106
- package/dist-lib/illustrations/index.js.map +1 -1
- package/dist-lib/index.js +69 -291
- package/dist-lib/lib/cva.js +2 -0
- package/dist-lib/lib/format.js +71 -87
- package/dist-lib/lib/format.js.map +1 -1
- package/dist-lib/lib/return-focus.js +11 -11
- package/dist-lib/lib/return-focus.js.map +1 -1
- package/dist-lib/lib/strings.js +167 -135
- package/dist-lib/lib/strings.js.map +1 -1
- package/dist-lib/lib/strings.mn.js +150 -113
- package/dist-lib/lib/strings.mn.js.map +1 -1
- package/dist-lib/lib/utils.js +9 -9
- package/dist-lib/lib/utils.js.map +1 -1
- package/dist-lib/styles.css +3 -1
- package/package.json +50 -50
- package/dist-lib/__tests__/helpers/color.d.ts +0 -9
- package/dist-lib/__tests__/helpers/theme.d.ts +0 -18
- package/dist-lib/icon.js.map +0 -1
- package/dist-lib/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.js","sources":["../../../src/components/ui/Form.tsx"],"sourcesContent":["'use client';\n\nimport {\n Children,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n useId,\n type HTMLAttributes,\n type ReactNode,\n} from 'react';\nimport * as LabelPrimitive from '@radix-ui/react-label';\nimport {\n Controller,\n FormProvider,\n useFormContext,\n type ControllerProps,\n type FieldErrors,\n type FieldPath,\n type FieldValues,\n type FormProviderProps,\n} from 'react-hook-form';\nimport { Slot } from '@radix-ui/react-slot';\nimport { cn } from '@/lib/utils';\n\n/* -----------------------------------------------------------------------------\n * react-hook-form bindings + accessible label / description / error wiring.\n *\n * Usage:\n * const form = useForm<Values>(…);\n * <Form {...form}>\n * <FormField\n * control={form.control}\n * name=\"email\"\n * render={({ field }) => (\n * <FormItem>\n * <FormLabel>Email</FormLabel>\n * <FormControl><Input type=\"email\" {...field} /></FormControl>\n * <FormDescription>We never share this.</FormDescription>\n * <FormError />\n * </FormItem>\n * )}\n * />\n * </Form>\n *\n * Ids: `<item>-item` (control), `<item>-desc`, `<item>-error` — the same\n * `-desc` / `-error` suffixes the standalone fields use (useFieldIds).\n * Invalid styling is driven purely by `aria-invalid` on the control; no\n * `aria-invalid` is set on the control; style from `aria-invalid:` (no `tone` injection).\n * --------------------------------------------------------------------------- */\n\nfunction collectMessages(errors: FieldErrors | undefined, out: string[] = []): string[] {\n if (!errors) return out;\n for (const value of Object.values(errors)) {\n if (!value || typeof value !== 'object') continue;\n const message = (value as { message?: unknown }).message;\n if (typeof message === 'string' && message) out.push(message);\n else if (!('type' in value)) collectMessages(value as FieldErrors, out);\n }\n return out;\n}\n\n/**\n * Single polite live region per form. Field-level `FormError` elements are\n * plain text wired via `aria-describedby`; this region announces the current\n * error set once instead of one `role=\"alert\"` per field firing in parallel.\n */\nfunction FormLiveRegion() {\n const { formState } = useFormContext();\n const messages = collectMessages(formState.errors);\n return (\n <div role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" className=\"sr-only\">\n {messages.join('. ')}\n </div>\n );\n}\n\n/**\n * Form context provider. Spread the `useForm()` return value into it, exactly\n * like react-hook-form's `FormProvider` — plus one shared live region for\n * validation announcements.\n */\nexport function Form<\n TFieldValues extends FieldValues = FieldValues,\n TContext = unknown,\n TTransformedValues = TFieldValues,\n>({ children, ...form }: FormProviderProps<TFieldValues, TContext, TTransformedValues>) {\n return (\n <FormProvider {...form}>\n {children}\n <FormLiveRegion />\n </FormProvider>\n );\n}\nForm.displayName = 'Form';\n\ninterface FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> {\n name: TName;\n}\n\nconst FormFieldContext = createContext<FormFieldContextValue | null>(null);\n\nexport function FormField<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>(props: ControllerProps<TFieldValues, TName>) {\n return (\n <FormFieldContext.Provider value={{ name: props.name as string }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n );\n}\n\ninterface FormItemContextValue {\n id: string;\n /** Whether a <FormDescription> is rendered — drives aria-describedby. */\n hasDescription: boolean;\n}\nconst FormItemContext = createContext<FormItemContextValue | null>(null);\n\nexport function useFormField() {\n const fieldContext = useContext(FormFieldContext);\n const itemContext = useContext(FormItemContext);\n const { getFieldState, formState } = useFormContext();\n if (!fieldContext) {\n throw new Error('useFormField must be used inside <FormField>');\n }\n const fieldState = getFieldState(fieldContext.name, formState);\n const id = itemContext?.id ?? '';\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-item`,\n formDescriptionId: `${id}-desc`,\n formMessageId: `${id}-error`,\n hasDescription: itemContext?.hasDescription ?? false,\n ...fieldState,\n };\n}\n\n/** Synchronous scan for a <FormDescription> among the item's children (through fragments / host elements). */\nfunction containsDescription(children: ReactNode): boolean {\n return Children.toArray(children).some((child) => {\n if (!isValidElement(child)) return false;\n if (child.type === FormDescription) return true;\n const nested = (child.props as { children?: ReactNode }).children;\n // Only descend into host elements / fragments — custom components own their subtree.\n return (typeof child.type === 'string' || typeof child.type === 'symbol') && nested\n ? containsDescription(nested)\n : false;\n });\n}\n\nexport const FormItem = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(\n function FormItem({ className, children, ...props }, ref) {\n const id = useId();\n // Derived during render (no effect → no second pass / hydration flip).\n const hasDescription = containsDescription(children);\n return (\n <FormItemContext.Provider value={{ id, hasDescription }}>\n <div ref={ref} className={cn('flex flex-col gap-1.5', className)} {...props}>\n {children}\n </div>\n </FormItemContext.Provider>\n );\n },\n);\nFormItem.displayName = 'FormItem';\n\nexport const FormLabel = forwardRef<\n React.ElementRef<typeof LabelPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>\n>(function FormLabel({ className, ...props }, ref) {\n const { formItemId, error } = useFormField();\n return (\n <LabelPrimitive.Root\n ref={ref}\n htmlFor={formItemId}\n className={cn('text-foreground text-sm font-medium', error && 'text-danger-text', className)}\n {...props}\n />\n );\n});\nFormLabel.displayName = 'FormLabel';\n\nexport const FormControl = forwardRef<HTMLElement, React.ComponentPropsWithoutRef<typeof Slot>>(\n function FormControl(props, ref) {\n const { error, formItemId, formDescriptionId, formMessageId, hasDescription } = useFormField();\n // Only reference ids that actually render: the description when mounted,\n // the message only while there is an error (FormError returns null otherwise).\n const describedBy =\n [hasDescription ? formDescriptionId : null, error ? formMessageId : null]\n .filter(Boolean)\n .join(' ') || undefined;\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={describedBy}\n aria-invalid={!!error}\n {...props}\n />\n );\n },\n);\nFormControl.displayName = 'FormControl';\n\nexport const FormDescription = forwardRef<\n HTMLParagraphElement,\n HTMLAttributes<HTMLParagraphElement>\n>(function FormDescription({ className, ...props }, ref) {\n const { formDescriptionId } = useFormField();\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn('text-foreground-subtle text-xs', className)}\n {...props}\n />\n );\n});\nFormDescription.displayName = 'FormDescription';\n\n/**\n * Field-level validation message. Not a live region on its own — it is\n * referenced from the control via `aria-describedby`, and the form's single\n * live region announces changes.\n */\nexport const FormError = forwardRef<HTMLParagraphElement, HTMLAttributes<HTMLParagraphElement>>(\n function FormError({ className, children, ...props }, ref) {\n const { error, formMessageId } = useFormField();\n const body = error ? String(error?.message ?? '') : children;\n if (!body) return null;\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn('text-danger-text text-xs', className)}\n {...props}\n >\n {body}\n </p>\n );\n },\n);\nFormError.displayName = 'FormError';\n"],"names":["collectMessages","errors","out","value","message","FormLiveRegion","formState","useFormContext","messages","jsx","Form","children","form","jsxs","FormProvider","FormFieldContext","createContext","FormField","props","Controller","FormItemContext","useFormField","fieldContext","useContext","itemContext","getFieldState","fieldState","id","containsDescription","Children","child","isValidElement","FormDescription","nested","FormItem","forwardRef","className","ref","useId","hasDescription","cn","FormLabel","formItemId","error","LabelPrimitive","FormControl","formDescriptionId","formMessageId","describedBy","Slot","FormError","body"],"mappings":";;;;;;;AAoDA,SAASA,EAAgBC,GAAiCC,IAAgB,IAAc;AACtF,MAAI,CAACD,EAAQ,QAAOC;AACpB,aAAWC,KAAS,OAAO,OAAOF,CAAM,GAAG;AAC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AAA,IARa;AAAA,EAWpB;AACF;AACAD,EAAU,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Form.js","names":[],"sources":["../../../src/components/ui/Form.tsx"],"sourcesContent":["'use client';\n\nimport {\n Children,\n createContext,\n forwardRef,\n isValidElement,\n useContext,\n useId,\n type HTMLAttributes,\n type ReactNode,\n} from 'react';\nimport * as LabelPrimitive from '@radix-ui/react-label';\nimport {\n Controller,\n FormProvider,\n useFormContext,\n type ControllerProps,\n type FieldErrors,\n type FieldPath,\n type FieldValues,\n type FormProviderProps,\n} from 'react-hook-form';\nimport { Slot } from '@radix-ui/react-slot';\nimport { cn } from '@/lib/utils';\n\n/* -----------------------------------------------------------------------------\n * react-hook-form bindings + accessible label / description / error wiring.\n *\n * Usage:\n * const form = useForm<Values>(…);\n * <Form {...form}>\n * <FormField\n * control={form.control}\n * name=\"email\"\n * render={({ field }) => (\n * <FormItem>\n * <FormLabel>Email</FormLabel>\n * <FormControl><Input type=\"email\" {...field} /></FormControl>\n * <FormDescription>We never share this.</FormDescription>\n * <FormError />\n * </FormItem>\n * )}\n * />\n * </Form>\n *\n * Ids: `<item>-item` (control), `<item>-desc`, `<item>-error` — the same\n * `-desc` / `-error` suffixes the standalone fields use (useFieldIds).\n * Invalid styling is driven purely by `aria-invalid` on the control; no\n * `aria-invalid` is set on the control; style from `aria-invalid:` (no `tone` injection).\n * --------------------------------------------------------------------------- */\n\nfunction collectMessages(errors: FieldErrors | undefined, out: string[] = []): string[] {\n if (!errors) return out;\n for (const value of Object.values(errors)) {\n if (!value || typeof value !== 'object') continue;\n const message = (value as { message?: unknown }).message;\n if (typeof message === 'string' && message) out.push(message);\n else if (!('type' in value)) collectMessages(value as FieldErrors, out);\n }\n return out;\n}\n\n/**\n * Single polite live region per form. Field-level `FormError` elements are\n * plain text wired via `aria-describedby`; this region announces the current\n * error set once instead of one `role=\"alert\"` per field firing in parallel.\n */\nfunction FormLiveRegion() {\n const { formState } = useFormContext();\n const messages = collectMessages(formState.errors);\n return (\n <div role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" className=\"sr-only\">\n {messages.join('. ')}\n </div>\n );\n}\n\n/**\n * Form context provider. Spread the `useForm()` return value into it, exactly\n * like react-hook-form's `FormProvider` — plus one shared live region for\n * validation announcements.\n */\nexport function Form<\n TFieldValues extends FieldValues = FieldValues,\n TContext = unknown,\n TTransformedValues = TFieldValues,\n>({ children, ...form }: FormProviderProps<TFieldValues, TContext, TTransformedValues>) {\n return (\n <FormProvider {...form}>\n {children}\n <FormLiveRegion />\n </FormProvider>\n );\n}\nForm.displayName = 'Form';\n\ninterface FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> {\n name: TName;\n}\n\nconst FormFieldContext = createContext<FormFieldContextValue | null>(null);\n\nexport function FormField<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>(props: ControllerProps<TFieldValues, TName>) {\n return (\n <FormFieldContext.Provider value={{ name: props.name as string }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n );\n}\n\ninterface FormItemContextValue {\n id: string;\n /** Whether a <FormDescription> is rendered — drives aria-describedby. */\n hasDescription: boolean;\n}\nconst FormItemContext = createContext<FormItemContextValue | null>(null);\n\nexport function useFormField() {\n const fieldContext = useContext(FormFieldContext);\n const itemContext = useContext(FormItemContext);\n const { getFieldState, formState } = useFormContext();\n if (!fieldContext) {\n throw new Error('useFormField must be used inside <FormField>');\n }\n const fieldState = getFieldState(fieldContext.name, formState);\n const id = itemContext?.id ?? '';\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-item`,\n formDescriptionId: `${id}-desc`,\n formMessageId: `${id}-error`,\n hasDescription: itemContext?.hasDescription ?? false,\n ...fieldState,\n };\n}\n\n/** Synchronous scan for a <FormDescription> among the item's children (through fragments / host elements). */\nfunction containsDescription(children: ReactNode): boolean {\n return Children.toArray(children).some((child) => {\n if (!isValidElement(child)) return false;\n if (child.type === FormDescription) return true;\n const nested = (child.props as { children?: ReactNode }).children;\n // Only descend into host elements / fragments — custom components own their subtree.\n return (typeof child.type === 'string' || typeof child.type === 'symbol') && nested\n ? containsDescription(nested)\n : false;\n });\n}\n\nexport const FormItem = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(\n function FormItem({ className, children, ...props }, ref) {\n const id = useId();\n // Derived during render (no effect → no second pass / hydration flip).\n const hasDescription = containsDescription(children);\n return (\n <FormItemContext.Provider value={{ id, hasDescription }}>\n <div ref={ref} className={cn('flex flex-col gap-1.5', className)} {...props}>\n {children}\n </div>\n </FormItemContext.Provider>\n );\n },\n);\nFormItem.displayName = 'FormItem';\n\nexport const FormLabel = forwardRef<\n React.ElementRef<typeof LabelPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>\n>(function FormLabel({ className, ...props }, ref) {\n const { formItemId, error } = useFormField();\n return (\n <LabelPrimitive.Root\n ref={ref}\n htmlFor={formItemId}\n className={cn('text-foreground text-sm font-medium', error && 'text-danger-text', className)}\n {...props}\n />\n );\n});\nFormLabel.displayName = 'FormLabel';\n\nexport const FormControl = forwardRef<HTMLElement, React.ComponentPropsWithoutRef<typeof Slot>>(\n function FormControl(props, ref) {\n const { error, formItemId, formDescriptionId, formMessageId, hasDescription } = useFormField();\n // Only reference ids that actually render: the description when mounted,\n // the message only while there is an error (FormError returns null otherwise).\n const describedBy =\n [hasDescription ? formDescriptionId : null, error ? formMessageId : null]\n .filter(Boolean)\n .join(' ') || undefined;\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={describedBy}\n aria-invalid={!!error}\n {...props}\n />\n );\n },\n);\nFormControl.displayName = 'FormControl';\n\nexport const FormDescription = forwardRef<\n HTMLParagraphElement,\n HTMLAttributes<HTMLParagraphElement>\n>(function FormDescription({ className, ...props }, ref) {\n const { formDescriptionId } = useFormField();\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn('text-foreground-subtle text-xs', className)}\n {...props}\n />\n );\n});\nFormDescription.displayName = 'FormDescription';\n\n/**\n * Field-level validation message. Not a live region on its own — it is\n * referenced from the control via `aria-describedby`, and the form's single\n * live region announces changes.\n */\nexport const FormError = forwardRef<HTMLParagraphElement, HTMLAttributes<HTMLParagraphElement>>(\n function FormError({ className, children, ...props }, ref) {\n const { error, formMessageId } = useFormField();\n const body = error ? String(error?.message ?? '') : children;\n if (!body) return null;\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn('text-danger-text text-xs', className)}\n {...props}\n >\n {body}\n </p>\n );\n },\n);\nFormError.displayName = 'FormError';\n"],"mappings":";;;;;;;;AAoDA,SAAS,EAAgB,GAAiC,IAAgB,CAAC,GAAa;CACtF,IAAI,CAAC,GAAQ,OAAO;CACpB,KAAK,IAAM,KAAS,OAAO,OAAO,CAAM,GAAG;EACzC,IAAI,CAAC,KAAS,OAAO,KAAU,UAAU;EACzC,IAAM,IAAW,EAAgC;EACjD,AAAI,OAAO,KAAY,YAAY,IAAS,EAAI,KAAK,CAAO,IACjD,UAAU,KAAQ,EAAgB,GAAsB,CAAG;CACxE;CACA,OAAO;AACT;AAOA,SAAS,IAAiB;CACxB,IAAM,EAAE,iBAAc,EAAe,GAC/B,IAAW,EAAgB,EAAU,MAAM;CACjD,OACE,kBAAC,OAAD;EAAK,MAAK;EAAS,aAAU;EAAS,eAAY;EAAO,WAAU;EAChE,UAAA,EAAS,KAAK,IAAI;CAChB,CAAA;AAET;AAOA,SAAgB,EAId,EAAE,aAAU,GAAG,KAAuE;CACtF,OACE,kBAAC,GAAD;EAAc,GAAI;EAAlB,UAAA,CACG,GACD,kBAAC,GAAD,CAAiB,CAAA,CACL;;AAElB;AACA,EAAK,cAAc;AASnB,IAAM,IAAmB,EAA4C,IAAI;AAEzE,SAAgB,EAGd,GAA6C;CAC7C,OACE,kBAAC,EAAiB,UAAlB;EAA2B,OAAO,EAAE,MAAM,EAAM,KAAe;EAC7D,UAAA,kBAA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ACT,WAAW,EAAG,uCAAuC,KAAS,oBAAoB,CAAS;EAC3F,GAAI;CACL,CAAA;AAEL,CAAC;AACD,EAAU,cAAc;AAExB,IAAa,IAAc,EACzB,SAAqB,GAAO,GAAK;CAC/B,IAAM,EAAE,UAAO,eAAY,sBAAmB,kBAAe,sBAAmB,EAAa,GAGvF,IACJ,CAAC,IAAiB,IAAoB,MAAM,IAAQ,IAAgB,IAAI,CAAC,CACtE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,KAAK,KAAA;CAClB,OACE,kBAAC,GAAD;EACO;EACL,IAAI;EACJ,oBAAkB;EAClB,gBAAc,CAAC,CAAC;EAChB,GAAI;CACL,CAAA;AAEL,CACF;AACA,EAAY,cAAc;AAE1B,IAAa,IAAkB,EAG7B,SAAyB,EAAE,cAAW,GAAG,KAAS,GAAK;CACvD,IAAM,EAAE,yBAAsB,EAAa;CAC3C,OACE,kBAAC,KAAD;EACO;EACL,IAAI;EACJ,WAAW,EAAG,kCAAkC,CAAS;EACzD,GAAI;CACL,CAAA;AAEL,CAAC;AACD,EAAgB,cAAc;AAO9B,IAAa,IAAY,EACvB,SAAmB,EAAE,cAAW,aAAU,GAAG,KAAS,GAAK;CACzD,IAAM,EAAE,UAAO,qBAAkB,EAAa,GACxC,IAAO,IAAQ,OAAO,GAAO,WAAW,EAAE,IAAI;CAEpD,OADK,IAEH,kBAAC,KAAD;EACO;EACL,IAAI;EACJ,WAAW,EAAG,4BAA4B,CAAS;EACnD,GAAI;EAEH,UAAA;CACA,CAAA,IATa;AAWpB,CACF;AACA,EAAU,cAAc"}
|
|
@@ -31,4 +31,4 @@ export interface IconProps extends Omit<LucideProps, 'ref'> {
|
|
|
31
31
|
* @dont Reach for this in hot lists with hundreds of distinct icons on first
|
|
32
32
|
* paint — statically imported icons from `Icons` skip the lazy hop.
|
|
33
33
|
*/
|
|
34
|
-
export declare function Icon({ name, fallback, ...props }: IconProps): import("react
|
|
34
|
+
export declare function Icon({ name, fallback, ...props }: IconProps): import("react").JSX.Element | null;
|
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const c = d(n);
|
|
15
|
-
return i.set(e, c), c;
|
|
2
|
+
import { Suspense as e, lazy as t, useMemo as n } from "react";
|
|
3
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
4
|
+
import i from "lucide-react/dynamicIconImports";
|
|
5
|
+
//#region src/components/ui/Icon.tsx
|
|
6
|
+
var a = Object.keys(i), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
|
|
7
|
+
function c(e) {
|
|
8
|
+
let n = o.get(e);
|
|
9
|
+
if (n) return n;
|
|
10
|
+
let r = i[e];
|
|
11
|
+
if (typeof r != "function") return process.env.NODE_ENV !== "production" && !s.has(e) && (s.add(e), console.warn(`[@craftzbay/ui] <Icon name="${e}"> is not a lucide icon; rendering nothing.`)), null;
|
|
12
|
+
let a = t(r);
|
|
13
|
+
return o.set(e, a), a;
|
|
16
14
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
function l({ name: t, fallback: i, ...a }) {
|
|
16
|
+
let o = n(() => c(t), [t]), s = i ?? /* @__PURE__ */ r("span", {
|
|
17
|
+
"aria-hidden": !0,
|
|
18
|
+
className: a.className,
|
|
19
|
+
style: {
|
|
20
|
+
display: "inline-block",
|
|
21
|
+
width: a.size ?? "1em",
|
|
22
|
+
height: a.size ?? "1em"
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return o ? /* @__PURE__ */ r(e, {
|
|
26
|
+
fallback: s,
|
|
27
|
+
children: /* @__PURE__ */ r(o, { ...a })
|
|
28
|
+
}) : null;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//# sourceMappingURL=Icon.js.map
|
|
30
|
+
//#endregion
|
|
31
|
+
export { l as Icon, a as iconNames };
|
|
32
|
+
|
|
33
|
+
//# 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 (process.env.NODE_ENV !== 'production' && !warned.has(name)) {\n warned.add(name);\n console.warn(\n `[@craftzbay/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"],"
|
|
1
|
+
{"version":3,"file":"Icon.js","names":[],"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 (process.env.NODE_ENV !== 'production' && !warned.has(name)) {\n warned.add(name);\n console.warn(\n `[@craftzbay/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"],"mappings":";;;;;AAUA,IAAa,IAAY,OAAO,KAAK,CAAkB,GAIjD,oBAAQ,IAAI,IAA+C,GAC3D,oBAAS,IAAI,IAAY;AAE/B,SAAS,EAAQ,GAAwD;CACvE,IAAM,IAAS,EAAM,IAAI,CAAI;CAC7B,IAAI,GAAQ,OAAO;CACnB,IAAM,IAAS,EAAmB;CAClC,IAAI,OAAO,KAAW,YAQpB,OANA,QAAA,IAAA,aAA6B,gBAAgB,CAAC,EAAO,I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
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
);
|
|
2
|
+
import { cn as e } from "../../lib/utils.js";
|
|
3
|
+
import { cva as t } from "../../lib/cva.js";
|
|
4
|
+
import { Loader2 as n } from "../../icons/index.js";
|
|
5
|
+
import { forwardRef as r } from "react";
|
|
6
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
7
|
+
//#region src/components/ui/IconButton.tsx
|
|
8
|
+
var a = t([
|
|
9
|
+
"inline-flex items-center justify-center shrink-0",
|
|
10
|
+
"rounded-md",
|
|
11
|
+
"transition-colors duration-[var(--duration-fast)] ease-[var(--ease-out)]",
|
|
12
|
+
"outline-none",
|
|
13
|
+
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
|
14
|
+
"focus-visible:ring-offset-background",
|
|
15
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
16
|
+
"aria-busy:pointer-events-none",
|
|
17
|
+
"[&_svg]:pointer-events-none"
|
|
18
|
+
], {
|
|
19
|
+
variants: {
|
|
20
|
+
variant: {
|
|
21
|
+
primary: "bg-accent text-on-accent hover:bg-accent-hover active:bg-accent-active",
|
|
22
|
+
secondary: "bg-background-muted text-foreground border border-border-strong hover:bg-surface-hover active:bg-surface-active",
|
|
23
|
+
outline: "border border-border-strong bg-transparent text-foreground hover:bg-background-muted",
|
|
24
|
+
ghost: "bg-transparent text-foreground-muted hover:bg-background-muted hover:text-foreground",
|
|
25
|
+
destructive: "bg-danger text-on-danger hover:bg-danger-hover active:bg-danger-active"
|
|
26
|
+
},
|
|
27
|
+
size: {
|
|
28
|
+
sm: "h-8 w-8 [&_svg]:size-4",
|
|
29
|
+
md: "h-9 w-9 [&_svg]:size-4",
|
|
30
|
+
lg: "h-10 w-10 [&_svg]:size-5",
|
|
31
|
+
xl: "h-11 w-11 [&_svg]:size-5"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
defaultVariants: {
|
|
35
|
+
variant: "ghost",
|
|
36
|
+
size: "md"
|
|
37
|
+
}
|
|
38
|
+
}), o = r(function({ className: t, variant: r, size: o, icon: c, loading: l, disabled: u, type: d = "button", onClick: f, ...p }, m) {
|
|
39
|
+
return /* @__PURE__ */ i("button", {
|
|
40
|
+
ref: m,
|
|
41
|
+
type: d,
|
|
42
|
+
"aria-busy": l || void 0,
|
|
43
|
+
"aria-disabled": l || void 0,
|
|
44
|
+
disabled: u,
|
|
45
|
+
className: e(a({
|
|
46
|
+
variant: r,
|
|
47
|
+
size: o
|
|
48
|
+
}), t),
|
|
49
|
+
onClick: l ? s : f,
|
|
50
|
+
...p,
|
|
51
|
+
children: l ? /* @__PURE__ */ i(n, {
|
|
52
|
+
className: "animate-spin",
|
|
53
|
+
"aria-hidden": "true"
|
|
54
|
+
}) : c
|
|
55
|
+
});
|
|
58
56
|
});
|
|
59
|
-
|
|
60
|
-
function
|
|
61
|
-
|
|
57
|
+
o.displayName = "IconButton";
|
|
58
|
+
function s(e) {
|
|
59
|
+
e.preventDefault(), e.stopPropagation();
|
|
62
60
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
//# sourceMappingURL=IconButton.js.map
|
|
61
|
+
//#endregion
|
|
62
|
+
export { o as IconButton };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=IconButton.js.map
|
|
@@ -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-none',\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 // Edge follows Button: the icon identifies the control, so the boundary\n // is not the 3:1 carrier (WCAG 1.4.11) — see Button.tsx.\n secondary:\n 'bg-background-muted text-foreground border border-border-strong hover:bg-surface-hover active:bg-surface-active',\n outline:\n 'border border-border-strong 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 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"],"
|
|
1
|
+
{"version":3,"file":"IconButton.js","names":[],"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-none',\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 // Edge follows Button: the icon identifies the control, so the boundary\n // is not the 3:1 carrier (WCAG 1.4.11) — see Button.tsx.\n secondary:\n 'bg-background-muted text-foreground border border-border-strong hover:bg-surface-hover active:bg-surface-active',\n outline:\n 'border border-border-strong 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 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"],"mappings":";;;;;;;AAOA,IAAM,IAAa,EACjB;CACE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GACA;CACE,UAAU;EACR,SAAS;GACP,SAAS;GAGT,WACE;GACF,SACE;GACF,OACE;GACF,aAAa;EACf;EACA,MAAM;GAEJ,IAAI;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;EACN;CACF;CACA,iBAAiB;EACf,SAAS;EACT,MAAM;CACR;AACF,CACF,GA8Ba,IAAa,EAA+C,SACvE,EAAE,cAAW,YAAS,SAAM,SAAM,YAAS,aAAU,UAAO,UAAU,YAAS,GAAG,KAClF,GACA;CACA,OACE,kBAAC,UAAD;EACO;EACC;EACN,aAAW,KAAW,KAAA;EACtB,iBAAe,KAAW,KAAA;EAChB;EACV,WAAW,EAAG,EAAW;GAAE;GAAS;EAAK,CAAC,GAAG,CAAS;EACtD,SAAS,IAAU,IAAa;EAChC,GAAI;EAEH,UAAA,IAAU,kBAAC,GAAD;GAAS,WAAU;GAAe,eAAY;EAAQ,CAAA,IAAI;CAC/D,CAAA;AAEZ,CAAC;AAED,EAAW,cAAc;AAEzB,SAAS,EAAW,GAAmB;CAErC,AADA,EAAE,eAAe,GACjB,EAAE,gBAAgB;AACpB"}
|