@sonamu-kit/react-components 0.4.10 → 0.5.1
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/_virtual/~icons/lucide/arrow-left.js +13 -10
- package/dist/_virtual/~icons/lucide/arrow-left.js.map +1 -1
- package/dist/_virtual/~icons/lucide/arrow-right.js +13 -10
- package/dist/_virtual/~icons/lucide/arrow-right.js.map +1 -1
- package/dist/_virtual/~icons/lucide/calendar.js +17 -14
- package/dist/_virtual/~icons/lucide/calendar.js.map +1 -1
- package/dist/_virtual/~icons/lucide/check.js +13 -10
- package/dist/_virtual/~icons/lucide/check.js.map +1 -1
- package/dist/_virtual/~icons/lucide/chevron-down.js +13 -10
- package/dist/_virtual/~icons/lucide/chevron-down.js.map +1 -1
- package/dist/_virtual/~icons/lucide/chevron-left.js +13 -10
- package/dist/_virtual/~icons/lucide/chevron-left.js.map +1 -1
- package/dist/_virtual/~icons/lucide/chevron-right.js +13 -10
- package/dist/_virtual/~icons/lucide/chevron-right.js.map +1 -1
- package/dist/_virtual/~icons/lucide/chevrons-up-down.js +13 -10
- package/dist/_virtual/~icons/lucide/chevrons-up-down.js.map +1 -1
- package/dist/_virtual/~icons/lucide/circle.js +13 -10
- package/dist/_virtual/~icons/lucide/circle.js.map +1 -1
- package/dist/_virtual/~icons/lucide/dot.js +15 -12
- package/dist/_virtual/~icons/lucide/dot.js.map +1 -1
- package/dist/_virtual/~icons/lucide/grip-vertical.js +19 -16
- package/dist/_virtual/~icons/lucide/grip-vertical.js.map +1 -1
- package/dist/_virtual/~icons/lucide/image.js +16 -13
- package/dist/_virtual/~icons/lucide/image.js.map +1 -1
- package/dist/_virtual/~icons/lucide/loader-2.js +13 -10
- package/dist/_virtual/~icons/lucide/loader-2.js.map +1 -1
- package/dist/_virtual/~icons/lucide/loader2.js +13 -10
- package/dist/_virtual/~icons/lucide/loader2.js.map +1 -1
- package/dist/_virtual/~icons/lucide/more-horizontal.js +16 -13
- package/dist/_virtual/~icons/lucide/more-horizontal.js.map +1 -1
- package/dist/_virtual/~icons/lucide/panel-left.js +15 -12
- package/dist/_virtual/~icons/lucide/panel-left.js.map +1 -1
- package/dist/_virtual/~icons/lucide/plus.js +13 -10
- package/dist/_virtual/~icons/lucide/plus.js.map +1 -1
- package/dist/_virtual/~icons/lucide/search.js +14 -11
- package/dist/_virtual/~icons/lucide/search.js.map +1 -1
- package/dist/_virtual/~icons/lucide/trash-2.js +13 -10
- package/dist/_virtual/~icons/lucide/trash-2.js.map +1 -1
- package/dist/_virtual/~icons/lucide/upload.js +13 -10
- package/dist/_virtual/~icons/lucide/upload.js.map +1 -1
- package/dist/_virtual/~icons/lucide/x-circle.js +15 -12
- package/dist/_virtual/~icons/lucide/x-circle.js.map +1 -1
- package/dist/_virtual/~icons/lucide/x.js +13 -10
- package/dist/_virtual/~icons/lucide/x.js.map +1 -1
- package/dist/components/ui/accordion.js +1 -2
- package/dist/components/ui/accordion.js.map +1 -1
- package/dist/components/ui/alert-dialog.d.ts +2 -2
- package/dist/components/ui/alert-dialog.js +1 -2
- package/dist/components/ui/alert-dialog.js.map +1 -1
- package/dist/components/ui/alert.js +15 -15
- package/dist/components/ui/alert.js.map +1 -1
- package/dist/components/ui/aspect-ratio.js +1 -2
- package/dist/components/ui/aspect-ratio.js.map +1 -1
- package/dist/components/ui/avatar.js +1 -2
- package/dist/components/ui/avatar.js.map +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/badge.js +11 -11
- package/dist/components/ui/badge.js.map +1 -1
- package/dist/components/ui/breadcrumb.d.ts +2 -2
- package/dist/components/ui/breadcrumb.js +1 -2
- package/dist/components/ui/breadcrumb.js.map +1 -1
- package/dist/components/ui/button.js +33 -33
- package/dist/components/ui/button.js.map +1 -1
- package/dist/components/ui/calendar.d.ts +1 -1
- package/dist/components/ui/calendar.js +41 -43
- package/dist/components/ui/calendar.js.map +1 -1
- package/dist/components/ui/card.d.ts +7 -7
- package/dist/components/ui/card.js +1 -2
- package/dist/components/ui/card.js.map +1 -1
- package/dist/components/ui/carousel.js +2 -3
- package/dist/components/ui/carousel.js.map +1 -1
- package/dist/components/ui/checkbox.js +2 -3
- package/dist/components/ui/checkbox.js.map +1 -1
- package/dist/components/ui/collapsible.js +1 -2
- package/dist/components/ui/collapsible.js.map +1 -1
- package/dist/components/ui/combobox.js +1 -2
- package/dist/components/ui/combobox.js.map +1 -1
- package/dist/components/ui/command.d.ts +2 -2
- package/dist/components/ui/command.js +1 -2
- package/dist/components/ui/command.js.map +1 -1
- package/dist/components/ui/common-modal.d.ts +1 -1
- package/dist/components/ui/common-modal.js +1 -2
- package/dist/components/ui/common-modal.js.map +1 -1
- package/dist/components/ui/context-menu.d.ts +1 -1
- package/dist/components/ui/context-menu.js +1 -2
- package/dist/components/ui/context-menu.js.map +1 -1
- package/dist/components/ui/date-input.d.ts +1 -1
- package/dist/components/ui/date-input.js +3 -3
- package/dist/components/ui/date-input.js.map +1 -1
- package/dist/components/ui/date-picker.d.ts +3 -3
- package/dist/components/ui/date-picker.js +3 -4
- package/dist/components/ui/date-picker.js.map +1 -1
- package/dist/components/ui/dialog.d.ts +2 -2
- package/dist/components/ui/dialog.js +1 -2
- package/dist/components/ui/dialog.js.map +1 -1
- package/dist/components/ui/drawer.d.ts +3 -3
- package/dist/components/ui/drawer.js +1 -2
- package/dist/components/ui/drawer.js.map +1 -1
- package/dist/components/ui/dropdown-menu.d.ts +1 -1
- package/dist/components/ui/dropdown-menu.js +1 -2
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/file-input.d.ts +1 -1
- package/dist/components/ui/file-input.js +20 -12
- package/dist/components/ui/file-input.js.map +1 -1
- package/dist/components/ui/form.d.ts +6 -4
- package/dist/components/ui/form.js +1 -2
- package/dist/components/ui/form.js.map +1 -1
- package/dist/components/ui/hover-card.js +1 -2
- package/dist/components/ui/hover-card.js.map +1 -1
- package/dist/components/ui/input-otp.d.ts +4 -2
- package/dist/components/ui/input-otp.js +1 -2
- package/dist/components/ui/input-otp.js.map +1 -1
- package/dist/components/ui/input.js +1 -2
- package/dist/components/ui/input.js.map +1 -1
- package/dist/components/ui/label.js +1 -2
- package/dist/components/ui/label.js.map +1 -1
- package/dist/components/ui/menubar.d.ts +6 -6
- package/dist/components/ui/menubar.js +1 -2
- package/dist/components/ui/menubar.js.map +1 -1
- package/dist/components/ui/month-picker-multiple.d.ts +1 -1
- package/dist/components/ui/month-picker-multiple.js +80 -79
- package/dist/components/ui/month-picker-multiple.js.map +1 -1
- package/dist/components/ui/navigation-menu.js +1 -2
- package/dist/components/ui/navigation-menu.js.map +1 -1
- package/dist/components/ui/pagination.js +3 -4
- package/dist/components/ui/pagination.js.map +1 -1
- package/dist/components/ui/popover.d.ts +4 -4
- package/dist/components/ui/popover.js +1 -2
- package/dist/components/ui/popover.js.map +1 -1
- package/dist/components/ui/progress.js +1 -2
- package/dist/components/ui/progress.js.map +1 -1
- package/dist/components/ui/radio-group.js +1 -2
- package/dist/components/ui/radio-group.js.map +1 -1
- package/dist/components/ui/range-number-input.d.ts +1 -1
- package/dist/components/ui/range-number-input.js +1 -2
- package/dist/components/ui/range-number-input.js.map +1 -1
- package/dist/components/ui/resizable.d.ts +4 -20
- package/dist/components/ui/resizable.js +5 -6
- package/dist/components/ui/resizable.js.map +1 -1
- package/dist/components/ui/scroll-area.js +1 -2
- package/dist/components/ui/scroll-area.js.map +1 -1
- package/dist/components/ui/select/enum-select.d.ts +2 -1
- package/dist/components/ui/select/enum-select.js +1 -2
- package/dist/components/ui/select/enum-select.js.map +1 -1
- package/dist/components/ui/select/id-async-select.js +60 -60
- package/dist/components/ui/select/id-async-select.js.map +1 -1
- package/dist/components/ui/select/select.js +11 -9
- package/dist/components/ui/select/select.js.map +1 -1
- package/dist/components/ui/separator.js +1 -2
- package/dist/components/ui/separator.js.map +1 -1
- package/dist/components/ui/sheet.d.ts +2 -2
- package/dist/components/ui/sheet.js +20 -21
- package/dist/components/ui/sheet.js.map +1 -1
- package/dist/components/ui/sidebar.d.ts +23 -23
- package/dist/components/ui/sidebar.js +1 -2
- package/dist/components/ui/sidebar.js.map +1 -1
- package/dist/components/ui/skeleton.d.ts +1 -1
- package/dist/components/ui/skeleton.js +1 -2
- package/dist/components/ui/skeleton.js.map +1 -1
- package/dist/components/ui/slider.js +1 -2
- package/dist/components/ui/slider.js.map +1 -1
- package/dist/components/ui/sonamu-filter/constants.js +1 -2
- package/dist/components/ui/sonamu-filter/constants.js.map +1 -1
- package/dist/components/ui/sonamu-filter/rule-row-input.d.ts +1 -1
- package/dist/components/ui/sonamu-filter/rule-row-input.js +1 -2
- package/dist/components/ui/sonamu-filter/rule-row-input.js.map +1 -1
- package/dist/components/ui/sonamu-filter/sonamu-filter-modal.d.ts +1 -1
- package/dist/components/ui/sonamu-filter/sonamu-filter-modal.js +2 -3
- package/dist/components/ui/sonamu-filter/sonamu-filter-modal.js.map +1 -1
- package/dist/components/ui/sonamu-filter/sonamu-filter-popover.d.ts +1 -1
- package/dist/components/ui/sonamu-filter/sonamu-filter-popover.js +1 -2
- package/dist/components/ui/sonamu-filter/sonamu-filter-popover.js.map +1 -1
- package/dist/components/ui/sonamu-filter/utils.js +2 -3
- package/dist/components/ui/sonamu-filter/utils.js.map +1 -1
- package/dist/components/ui/sonamu-filter/value-input.d.ts +1 -1
- package/dist/components/ui/sonamu-filter/value-input.js +1 -2
- package/dist/components/ui/sonamu-filter/value-input.js.map +1 -1
- package/dist/components/ui/sonner.d.ts +1 -1
- package/dist/components/ui/switch.js +1 -2
- package/dist/components/ui/switch.js.map +1 -1
- package/dist/components/ui/table.d.ts +8 -8
- package/dist/components/ui/table.js +1 -2
- package/dist/components/ui/table.js.map +1 -1
- package/dist/components/ui/tabs.js +1 -2
- package/dist/components/ui/tabs.js.map +1 -1
- package/dist/components/ui/tag-input.d.ts +1 -1
- package/dist/components/ui/tag-input.js +3 -12
- package/dist/components/ui/tag-input.js.map +1 -1
- package/dist/components/ui/textarea.js +1 -2
- package/dist/components/ui/textarea.js.map +1 -1
- package/dist/components/ui/toast.js +18 -19
- package/dist/components/ui/toast.js.map +1 -1
- package/dist/components/ui/toaster.d.ts +1 -1
- package/dist/components/ui/toaster.js +1 -2
- package/dist/components/ui/toaster.js.map +1 -1
- package/dist/components/ui/toggle-group.js +1 -2
- package/dist/components/ui/toggle-group.js.map +1 -1
- package/dist/components/ui/toggle.js +17 -17
- package/dist/components/ui/toggle.js.map +1 -1
- package/dist/components/ui/tooltip.js +1 -2
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/contexts/index.js +1 -2
- package/dist/contexts/sonamu-context.d.ts +1 -1
- package/dist/contexts/sonamu-context.js +1 -2
- package/dist/contexts/sonamu-context.js.map +1 -1
- package/dist/demo/App.d.ts +1 -1
- package/dist/demo/Layout.d.ts +1 -1
- package/dist/demo/components/FormDebugPanel.d.ts +1 -1
- package/dist/demo/routeTree.gen.d.ts +37 -37
- package/dist/demo/schemas/form-demo.schema.d.ts +8 -8
- package/dist/hooks/index.js +1 -2
- package/dist/hooks/use-toast.js +2 -3
- package/dist/hooks/use-toast.js.map +1 -1
- package/dist/i18n/rc-keys.js +1 -2
- package/dist/i18n/rc-keys.js.map +1 -1
- package/dist/lib/base-helpers.js +3 -3
- package/dist/lib/base-helpers.js.map +1 -1
- package/dist/lib/caster.d.ts +1 -1
- package/dist/lib/caster.js +1 -2
- package/dist/lib/caster.js.map +1 -1
- package/dist/lib/form-helpers.js +1 -2
- package/dist/lib/form-helpers.js.map +1 -1
- package/dist/lib/list-helpers.js +1 -2
- package/dist/lib/list-helpers.js.map +1 -1
- package/dist/lib/modal-helpers.js +1 -2
- package/dist/lib/modal-helpers.js.map +1 -1
- package/dist/lib/types.js +1 -2
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/use-mobile.js +7 -9
- package/dist/lib/use-mobile.js.map +1 -1
- package/dist/lib/utils.js +1 -2
- package/dist/lib/utils.js.map +1 -1
- package/dist/styles/globals.css +1 -7
- package/package.json +69 -67
|
@@ -6,7 +6,7 @@ import r from "../../_virtual/~icons/lucide/circle.js";
|
|
|
6
6
|
import * as i from "react";
|
|
7
7
|
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
8
8
|
import * as s from "@radix-ui/react-dropdown-menu";
|
|
9
|
-
|
|
9
|
+
// src/components/ui/dropdown-menu.tsx
|
|
10
10
|
var c = s.Root, l = s.Trigger, u = s.Group, d = s.Portal, f = s.Sub, p = s.RadioGroup, m = i.forwardRef(({ className: n, inset: r, children: i, ...c }, l) => /* @__PURE__ */ o(s.SubTrigger, {
|
|
11
11
|
ref: l,
|
|
12
12
|
className: e("flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", r && "pl-8", n),
|
|
@@ -71,7 +71,6 @@ var S = ({ className: t, ...n }) => /* @__PURE__ */ a("span", {
|
|
|
71
71
|
...n
|
|
72
72
|
});
|
|
73
73
|
S.displayName = "DropdownMenuShortcut";
|
|
74
|
-
//#endregion
|
|
75
74
|
export { c as DropdownMenu, v as DropdownMenuCheckboxItem, g as DropdownMenuContent, u as DropdownMenuGroup, _ as DropdownMenuItem, b as DropdownMenuLabel, d as DropdownMenuPortal, p as DropdownMenuRadioGroup, y as DropdownMenuRadioItem, x as DropdownMenuSeparator, S as DropdownMenuShortcut, f as DropdownMenuSub, h as DropdownMenuSubContent, m as DropdownMenuSubTrigger, l as DropdownMenuTrigger };
|
|
76
75
|
|
|
77
76
|
//# sourceMappingURL=dropdown-menu.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown-menu.js","names":[],"sources":["../../../src/components/ui/dropdown-menu.tsx"],"sourcesContent":["\"use client\";\n\nimport * as DropdownMenuPrimitive from \"@radix-ui/react-dropdown-menu\";\nimport * as React from \"react\";\nimport CheckIcon from \"~icons/lucide/check\";\nimport ChevronRightIcon from \"~icons/lucide/chevron-right\";\nimport CircleIcon from \"~icons/lucide/circle\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst DropdownMenu = DropdownMenuPrimitive.Root;\n\nconst DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;\n\nconst DropdownMenuGroup = DropdownMenuPrimitive.Group;\n\nconst DropdownMenuPortal = DropdownMenuPrimitive.Portal;\n\nconst DropdownMenuSub = DropdownMenuPrimitive.Sub;\n\nconst DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;\n\nconst DropdownMenuSubTrigger = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.SubTrigger>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {\n inset?: boolean;\n }\n>(({ className, inset, children, ...props }, ref) => (\n <DropdownMenuPrimitive.SubTrigger\n ref={ref}\n className={cn(\n \"flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0\",\n inset && \"pl-8\",\n className,\n )}\n {...props}\n >\n {children}\n <ChevronRightIcon className=\"ml-auto\" />\n </DropdownMenuPrimitive.SubTrigger>\n));\nDropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName;\n\nconst DropdownMenuSubContent = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.SubContent>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>\n>(({ className, ...props }, ref) => (\n <DropdownMenuPrimitive.SubContent\n ref={ref}\n className={cn(\n \"z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]\",\n className,\n )}\n {...props}\n />\n));\nDropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName;\n\nconst DropdownMenuContent = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>\n>(({ className, sideOffset = 4, ...props }, ref) => (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.Content\n ref={ref}\n sideOffset={sideOffset}\n className={cn(\n \"z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-32 overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]\",\n className,\n )}\n {...props}\n />\n </DropdownMenuPrimitive.Portal>\n));\nDropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;\n\nconst DropdownMenuItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Item>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {\n inset?: boolean;\n }\n>(({ className, inset, ...props }, ref) => (\n <DropdownMenuPrimitive.Item\n ref={ref}\n className={cn(\n \"relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0\",\n inset && \"pl-8\",\n className,\n )}\n {...props}\n />\n));\nDropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;\n\nconst DropdownMenuCheckboxItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.CheckboxItem>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>\n>(({ className, children, checked, ...props }, ref) => (\n <DropdownMenuPrimitive.CheckboxItem\n ref={ref}\n className={cn(\n \"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50\",\n className,\n )}\n checked={checked}\n {...props}\n >\n <span className=\"absolute left-2 flex h-3.5 w-3.5 items-center justify-center\">\n <DropdownMenuPrimitive.ItemIndicator>\n <CheckIcon className=\"h-4 w-4\" />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </DropdownMenuPrimitive.CheckboxItem>\n));\nDropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName;\n\nconst DropdownMenuRadioItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.RadioItem>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>\n>(({ className, children, ...props }, ref) => (\n <DropdownMenuPrimitive.RadioItem\n ref={ref}\n className={cn(\n \"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50\",\n className,\n )}\n {...props}\n >\n <span className=\"absolute left-2 flex h-3.5 w-3.5 items-center justify-center\">\n <DropdownMenuPrimitive.ItemIndicator>\n <CircleIcon className=\"h-2 w-2 fill-current\" />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </DropdownMenuPrimitive.RadioItem>\n));\nDropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;\n\nconst DropdownMenuLabel = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Label>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {\n inset?: boolean;\n }\n>(({ className, inset, ...props }, ref) => (\n <DropdownMenuPrimitive.Label\n ref={ref}\n className={cn(\"px-2 py-1.5 text-sm font-semibold\", inset && \"pl-8\", className)}\n {...props}\n />\n));\nDropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;\n\nconst DropdownMenuSeparator = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Separator>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>\n>(({ className, ...props }, ref) => (\n <DropdownMenuPrimitive.Separator\n ref={ref}\n className={cn(\"-mx-1 my-1 h-px bg-muted\", className)}\n {...props}\n />\n));\nDropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;\n\nconst DropdownMenuShortcut = ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) => {\n return (\n <span className={cn(\"ml-auto text-xs tracking-widest opacity-60\", className)} {...props} />\n );\n};\nDropdownMenuShortcut.displayName = \"DropdownMenuShortcut\";\n\nexport {\n DropdownMenu,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuCheckboxItem,\n DropdownMenuRadioItem,\n DropdownMenuLabel,\n DropdownMenuSeparator,\n DropdownMenuShortcut,\n DropdownMenuGroup,\n DropdownMenuPortal,\n DropdownMenuSub,\n DropdownMenuSubContent,\n DropdownMenuSubTrigger,\n DropdownMenuRadioGroup,\n};\n"],"mappings":";;;;;;;;;AAUA,IAAM,IAAe,EAAsB,MAErC,IAAsB,EAAsB,SAE5C,IAAoB,EAAsB,OAE1C,IAAqB,EAAsB,QAE3C,IAAkB,EAAsB,KAExC,IAAyB,EAAsB,YAE/C,IAAyB,EAAM,YAKlC,EAAE,cAAW,UAAO,aAAU,GAAG,KAAS,MAC3C,kBAAC,EAAsB,YAAvB;CACO;CACL,WAAW,EACT,0MACA,KAAS,QACT,CACF;CACA,GAAI;WAPN,CASG,GACD,kBAAC,GAAD,EAAkB,WAAU,UAAW,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A,EACX,CAAA;CACjC,CAAA,GACL,CAC8B;EAClC;AACD,EAAsB,cAAc,EAAsB,UAAU;AAEpE,IAAM,IAAoB,EAAM,YAK7B,EAAE,cAAW,UAAO,GAAG,KAAS,MACjC,kBAAC,EAAsB,OAAvB;CACO;CACL,WAAW,EAAG,qCAAqC,KAAS,QAAQ,CAAS;CAC7E,GAAI;AACL,CAAA,CACF;AACD,EAAkB,cAAc,EAAsB,MAAM;AAE5D,IAAM,IAAwB,EAAM,YAGjC,EAAE,cAAW,GAAG,KAAS,MAC1B,kBAAC,EAAsB,WAAvB;CACO;CACL,WAAW,EAAG,4BAA4B,CAAS;CACnD,GAAI;AACL,CAAA,CACF;AACD,EAAsB,cAAc,EAAsB,UAAU;AAEpE,IAAM,KAAwB,EAAE,cAAW,GAAG,QAE1C,kBAAC,QAAD;CAAM,WAAW,EAAG,8CAA8C,CAAS;CAAG,GAAI;AAAQ,CAAA;AAG9F,EAAqB,cAAc"}
|
|
1
|
+
{"version":3,"file":"dropdown-menu.js","names":["React","ChevronRightIcon","CheckIcon","CircleIcon","ForwardRef","ForwardRef$1","ForwardRef$2","React$1","DropdownMenuPrimitive","DropdownMenu","DropdownMenuTrigger","DropdownMenuGroup","DropdownMenuPortal","DropdownMenuSub","DropdownMenuRadioGroup","DropdownMenuSubTrigger","props","cn","inset","className","children","DropdownMenuSubContent","DropdownMenuContent","DropdownMenuItem","DropdownMenuCheckboxItem","DropdownMenuRadioItem","DropdownMenuLabel","DropdownMenuSeparator","DropdownMenuShortcut"],"sources":["../../../src/components/ui/dropdown-menu.tsx"],"sourcesContent":["\"use client\";\n\nimport * as DropdownMenuPrimitive from \"@radix-ui/react-dropdown-menu\";\nimport * as React from \"react\";\nimport CheckIcon from \"~icons/lucide/check\";\nimport ChevronRightIcon from \"~icons/lucide/chevron-right\";\nimport CircleIcon from \"~icons/lucide/circle\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst DropdownMenu = DropdownMenuPrimitive.Root;\n\nconst DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;\n\nconst DropdownMenuGroup = DropdownMenuPrimitive.Group;\n\nconst DropdownMenuPortal = DropdownMenuPrimitive.Portal;\n\nconst DropdownMenuSub = DropdownMenuPrimitive.Sub;\n\nconst DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;\n\nconst DropdownMenuSubTrigger = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.SubTrigger>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {\n inset?: boolean;\n }\n>(({ className, inset, children, ...props }, ref) => (\n <DropdownMenuPrimitive.SubTrigger\n ref={ref}\n className={cn(\n \"flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0\",\n inset && \"pl-8\",\n className,\n )}\n {...props}\n >\n {children}\n <ChevronRightIcon className=\"ml-auto\" />\n </DropdownMenuPrimitive.SubTrigger>\n));\nDropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName;\n\nconst DropdownMenuSubContent = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.SubContent>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>\n>(({ className, ...props }, ref) => (\n <DropdownMenuPrimitive.SubContent\n ref={ref}\n className={cn(\n \"z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]\",\n className,\n )}\n {...props}\n />\n));\nDropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName;\n\nconst DropdownMenuContent = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>\n>(({ className, sideOffset = 4, ...props }, ref) => (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.Content\n ref={ref}\n sideOffset={sideOffset}\n className={cn(\n \"z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-32 overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]\",\n className,\n )}\n {...props}\n />\n </DropdownMenuPrimitive.Portal>\n));\nDropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;\n\nconst DropdownMenuItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Item>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {\n inset?: boolean;\n }\n>(({ className, inset, ...props }, ref) => (\n <DropdownMenuPrimitive.Item\n ref={ref}\n className={cn(\n \"relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0\",\n inset && \"pl-8\",\n className,\n )}\n {...props}\n />\n));\nDropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;\n\nconst DropdownMenuCheckboxItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.CheckboxItem>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>\n>(({ className, children, checked, ...props }, ref) => (\n <DropdownMenuPrimitive.CheckboxItem\n ref={ref}\n className={cn(\n \"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50\",\n className,\n )}\n checked={checked}\n {...props}\n >\n <span className=\"absolute left-2 flex h-3.5 w-3.5 items-center justify-center\">\n <DropdownMenuPrimitive.ItemIndicator>\n <CheckIcon className=\"h-4 w-4\" />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </DropdownMenuPrimitive.CheckboxItem>\n));\nDropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName;\n\nconst DropdownMenuRadioItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.RadioItem>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>\n>(({ className, children, ...props }, ref) => (\n <DropdownMenuPrimitive.RadioItem\n ref={ref}\n className={cn(\n \"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50\",\n className,\n )}\n {...props}\n >\n <span className=\"absolute left-2 flex h-3.5 w-3.5 items-center justify-center\">\n <DropdownMenuPrimitive.ItemIndicator>\n <CircleIcon className=\"h-2 w-2 fill-current\" />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </DropdownMenuPrimitive.RadioItem>\n));\nDropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;\n\nconst DropdownMenuLabel = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Label>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {\n inset?: boolean;\n }\n>(({ className, inset, ...props }, ref) => (\n <DropdownMenuPrimitive.Label\n ref={ref}\n className={cn(\"px-2 py-1.5 text-sm font-semibold\", inset && \"pl-8\", className)}\n {...props}\n />\n));\nDropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;\n\nconst DropdownMenuSeparator = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Separator>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>\n>(({ className, ...props }, ref) => (\n <DropdownMenuPrimitive.Separator\n ref={ref}\n className={cn(\"-mx-1 my-1 h-px bg-muted\", className)}\n {...props}\n />\n));\nDropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;\n\nconst DropdownMenuShortcut = ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) => {\n return (\n <span className={cn(\"ml-auto text-xs tracking-widest opacity-60\", className)} {...props} />\n );\n};\nDropdownMenuShortcut.displayName = \"DropdownMenuShortcut\";\n\nexport {\n DropdownMenu,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuCheckboxItem,\n DropdownMenuRadioItem,\n DropdownMenuLabel,\n DropdownMenuSeparator,\n DropdownMenuShortcut,\n DropdownMenuGroup,\n DropdownMenuPortal,\n DropdownMenuSub,\n DropdownMenuSubContent,\n DropdownMenuSubTrigger,\n DropdownMenuRadioGroup,\n};\n"],"mappings":";;;;;;;;;AAUA,IAAMS,IAAeD,EAAsB,MAErCE,IAAsBF,EAAsB,SAE5CG,IAAoBH,EAAsB,OAE1CI,IAAqBJ,EAAsB,QAE3CK,IAAkBL,EAAsB,KAExCM,IAAyBN,EAAsB,YAE/CO,IAAyBf,EAAM,YAKlC,EAAE,cAAW,UAAO,aAAU,GAAGgB,KAAS,MAC3C,kBAACR,EAAsB,YAAvB;CACO;CACL,WAAWS,EACT,0MACAC,KAAS,QACTC,CACF;CACA,GAAIH;CAPN,UAAA,CASGI,GACD,kBAACnB,GAAD,EAAkB,WAAU,UAAW,CAAA,CACP;AACnC,CAAA,CAAA;AACD,EAAuB,cAAcO,EAAsB,WAAW;AAEtE,IAAMa,IAAyB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AD,EAAY,WAAU,uBAAwB,CAAA,EACX,CAAA;CACjC,CAAA,GACLiB,CAC8B;AAClC,CAAA,CAAA;AACD,EAAsB,cAAcZ,EAAsB,UAAU;AAEpE,IAAMkB,IAAoB1B,EAAM,YAK7B,EAAE,cAAW,UAAO,GAAGgB,KAAS,MACjC,kBAACR,EAAsB,OAAvB;CACO;CACL,WAAWS,EAAG,qCAAqCC,KAAS,QAAQC,CAAS;CAC7E,GAAIH;AACL,CAAA,CACF;AACD,EAAkB,cAAcR,EAAsB,MAAM;AAE5D,IAAMmB,IAAwB3B,EAAM,YAGjC,EAAE,cAAW,GAAGgB,KAAS,MAC1B,kBAACR,EAAsB,WAAvB;CACO;CACL,WAAWS,EAAG,4BAA4BE,CAAS;CACnD,GAAIH;AACL,CAAA,CACF;AACD,EAAsB,cAAcR,EAAsB,UAAU;AAEpE,IAAMoB,KAAwB,EAAE,cAAW,GAAGZ,QAE1C,kBAAC,QAAD;CAAM,WAAWC,EAAG,8CAA8CE,CAAS;CAAG,GAAIH;AAAQ,CAAA;AAG9F,EAAqB,cAAc"}
|
|
@@ -24,5 +24,5 @@ type MultipleModeProps = BaseProps & {
|
|
|
24
24
|
maxFiles?: number;
|
|
25
25
|
};
|
|
26
26
|
export type FileInputProps = SingleModeProps | MultipleModeProps;
|
|
27
|
-
export declare function FileInput(props: FileInputProps):
|
|
27
|
+
export declare function FileInput(props: FileInputProps): React.JSX.Element;
|
|
28
28
|
export {};
|
|
@@ -9,7 +9,7 @@ import { useCallback as c, useMemo as l, useRef as u, useState as d } from "reac
|
|
|
9
9
|
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
10
10
|
import { isFunction as h } from "radashi";
|
|
11
11
|
import { FileIcon as g, defaultStyles as _ } from "react-file-icon";
|
|
12
|
-
|
|
12
|
+
// src/components/ui/file-input.tsx
|
|
13
13
|
function v(e) {
|
|
14
14
|
return Object.prototype.toString.call(e) === "[object File]";
|
|
15
15
|
}
|
|
@@ -55,14 +55,20 @@ function T(g) {
|
|
|
55
55
|
return e ? [e] : [];
|
|
56
56
|
}
|
|
57
57
|
return g.value ?? [];
|
|
58
|
-
}, [g.multiple, g.value]), V = l(() => B.filter(v), [B]), H = t(V), U = B.map((e) =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
}, [g.multiple, g.value]), V = l(() => B.filter(v), [B]), H = t(V), U = B.map((e) => {
|
|
59
|
+
if (v(e)) {
|
|
60
|
+
let t = V.indexOf(e);
|
|
61
|
+
return {
|
|
62
|
+
url: H[t],
|
|
63
|
+
name: e.name,
|
|
64
|
+
isPending: !0
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
url: e.url,
|
|
69
|
+
name: e.name,
|
|
70
|
+
isPending: !1
|
|
71
|
+
};
|
|
66
72
|
}), W = g.multiple === !0 ? g.maxFiles ?? 10 : 1, G = B.length, K = G < W, q = c(async (e) => {
|
|
67
73
|
if (e.length === 0 || y) return;
|
|
68
74
|
let t = W - G;
|
|
@@ -100,9 +106,12 @@ function T(g) {
|
|
|
100
106
|
k,
|
|
101
107
|
A
|
|
102
108
|
]), J = c((e) => {
|
|
103
|
-
|
|
109
|
+
let t = Array.from(e.target.files || []);
|
|
110
|
+
q(t), P.current && (P.current.value = "");
|
|
104
111
|
}, [q]), Y = c((e) => {
|
|
105
|
-
e.preventDefault(), R(!1),
|
|
112
|
+
if (e.preventDefault(), R(!1), y || F) return;
|
|
113
|
+
let t = Array.from(e.dataTransfer.files);
|
|
114
|
+
q(t);
|
|
106
115
|
}, [
|
|
107
116
|
q,
|
|
108
117
|
y,
|
|
@@ -263,7 +272,6 @@ function T(g) {
|
|
|
263
272
|
]
|
|
264
273
|
});
|
|
265
274
|
}
|
|
266
|
-
//#endregion
|
|
267
275
|
export { T as FileInput };
|
|
268
276
|
|
|
269
277
|
//# sourceMappingURL=file-input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-input.js","names":[],"sources":["../../../src/components/ui/file-input.tsx"],"sourcesContent":["import { isFunction } from \"radashi\";\nimport type React from \"react\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport { FileIcon as ReactFileIcon, defaultStyles } from \"react-file-icon\";\nimport ImageIcon from \"~icons/lucide/image\";\nimport Loader2Icon from \"~icons/lucide/loader2\";\nimport UploadIcon from \"~icons/lucide/upload\";\nimport XIcon from \"~icons/lucide/x\";\n\nimport { type SonamuFile, type UploadParams } from \"@/contexts\";\nimport { useSonamuBaseContext } from \"@/contexts\";\nimport { type RCKeys } from \"@/i18n/rc-keys\";\nimport { cn, useObjectUrls } from \"@/lib/utils\";\n\nimport { Button } from \"./button\";\n\nexport type PreviewSize = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\nfunction isFile(value: SonamuFile | File): value is File {\n return Object.prototype.toString.call(value) === \"[object File]\";\n}\n\nfunction getFileExtension(filename: string): string {\n const parts = filename.split(\".\");\n if (parts.length < 2) return \"\";\n return parts[parts.length - 1].toLowerCase();\n}\n\nconst fileIconSizes = {\n sm: 14,\n md: 18,\n lg: 22,\n xl: 26,\n};\n\nconst fileIconStyles = new Map<string, Partial<React.ComponentProps<typeof ReactFileIcon>>>(\n Object.entries(defaultStyles),\n);\n\nfunction FileTypeIcon({ filename, size = \"md\" }: { filename: string; size?: PreviewSize }) {\n const ext = getFileExtension(filename);\n const styleProps = fileIconStyles.get(ext) ?? {};\n\n return (\n <div className=\"shrink-0 self-center\" style={{ width: fileIconSizes[size], marginTop: -2 }}>\n <ReactFileIcon extension={ext || undefined} {...styleProps} />\n </div>\n );\n}\n\n// 이미지용: 정사각형\nconst imageSizeClasses = {\n sm: \"w-20 h-20\",\n md: \"w-32 h-32\",\n lg: \"w-40 h-40\",\n xl: \"w-48 h-48\",\n};\n\n// 파일용: 가로로 긴 직사각형\nconst fileSizeClasses = {\n sm: \"w-48 h-12\",\n md: \"w-80 h-16\",\n lg: \"w-96 h-20\",\n xl: \"w-[28rem] h-24\",\n};\n\ntype BaseProps = {\n uploadMode: \"eager\" | \"lazy\";\n viewMode: \"image\" | \"file\";\n placeholder?: string;\n accept?: string;\n disabled?: boolean;\n className?: string;\n previewSize?: PreviewSize;\n uploadParams?: UploadParams;\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\n};\n\ntype SingleModeProps = BaseProps & {\n multiple?: false;\n value: SonamuFile | File | null;\n onValueChange?: (value: SonamuFile | File | null) => void;\n};\n\ntype MultipleModeProps = BaseProps & {\n multiple: true;\n value: (SonamuFile | File)[] | null;\n onValueChange?: (value: (SonamuFile | File)[]) => void;\n maxFiles?: number;\n};\n\nexport type FileInputProps = SingleModeProps | MultipleModeProps;\n\nexport function FileInput(props: FileInputProps) {\n const {\n placeholder,\n disabled = false,\n className,\n previewSize = \"md\",\n uploadMode,\n viewMode,\n uploadParams,\n onBlur,\n } = props;\n\n const { uploader, SD } = useSonamuBaseContext<RCKeys>();\n\n const isMultiple = props.multiple ?? false;\n const isImageView = viewMode === \"image\";\n\n // viewMode에 따라 accept 자동 설정\n const accept = props.accept ?? (isImageView ? \"image/*\" : \"*/*\");\n\n const inputRef = useRef<HTMLInputElement>(null);\n const [isUploading, setIsUploading] = useState(false);\n const [dragOver, setDragOver] = useState(false);\n\n // 기본 placeholder 설정\n const defaultPlaceholder =\n placeholder ??\n `${isImageView ? SD(\"rc.fileInput.imagePlaceholder\") : SD(\"rc.fileInput.filePlaceholder\")} URL${isMultiple ? \"S\" : \"\"}`;\n\n // 입력 정규화: 내부적으로 배열로 통일\n const values: Array<SonamuFile | File> = useMemo(() => {\n if (props.multiple !== true) {\n const singleValue = props.value;\n return singleValue ? [singleValue] : [];\n }\n return props.value ?? [];\n }, [props.multiple, props.value]);\n\n // File 객체만 추출\n const fileObjects = useMemo(() => values.filter(isFile), [values]);\n\n // File 객체는 useObjectUrls로 안전하게 blob URL 생성 (자동 메모리 해제)\n const blobUrls = useObjectUrls(fileObjects);\n\n // 최종 display 데이터: 원래 순서를 유지하면서 File은 blob URL로, SonamuFile은 그대로\n const displayItems = values.map((v) => {\n if (isFile(v)) {\n const index = fileObjects.indexOf(v);\n return {\n url: blobUrls[index],\n name: v.name,\n isPending: true,\n };\n }\n // SonamuFile\n return {\n url: v.url,\n name: v.name,\n isPending: false,\n };\n });\n\n const maxFiles = props.multiple === true ? (props.maxFiles ?? 10) : 1;\n const totalCount = values.length;\n const canAddMore = totalCount < maxFiles;\n\n const handleFilesChange = useCallback(\n async (files: File[]) => {\n if (files.length === 0 || disabled) return;\n\n // maxFiles 체크\n const remainingSlots = maxFiles - totalCount;\n if (remainingSlots <= 0) {\n const maxFilesTranslation = SD(\"rc.fileInput.maxFilesExceeded\");\n alert(\n isFunction(maxFilesTranslation) ? maxFilesTranslation(maxFiles) : maxFilesTranslation,\n );\n return;\n }\n\n const filesToAdd = files.slice(0, remainingSlots);\n\n // Eager 모드: 즉시 업로드\n if (uploadMode === \"eager\") {\n setIsUploading(true);\n try {\n const uploadedFiles = await uploader(filesToAdd, uploadParams);\n\n if (props.multiple === true) {\n // Multiple 파일 업로드\n const finalValues = [...values, ...uploadedFiles];\n props.onValueChange?.(finalValues);\n } else {\n // Single 파일 업로드\n props.onValueChange?.(uploadedFiles[0] ?? null);\n }\n } catch (error) {\n console.error(\"Upload failed:\", error);\n alert(SD(\"rc.fileInput.uploadFailed\"));\n } finally {\n setIsUploading(false);\n }\n } else {\n // Lazy 모드: File 객체 그대로 전달\n if (props.multiple === true) {\n const finalValues = [...values, ...filesToAdd];\n props.onValueChange?.(finalValues);\n } else {\n props.onValueChange?.(filesToAdd[0] ?? null);\n }\n }\n },\n [disabled, totalCount, maxFiles, uploadMode, uploadParams, values, props, uploader, SD],\n );\n\n const handleInputChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const files = Array.from(e.target.files || []);\n handleFilesChange(files);\n // input 초기화\n if (inputRef.current) {\n inputRef.current.value = \"\";\n }\n },\n [handleFilesChange],\n );\n\n const handleDrop = useCallback(\n (e: React.DragEvent) => {\n e.preventDefault();\n setDragOver(false);\n if (disabled || isUploading) return;\n\n const files = Array.from(e.dataTransfer.files);\n handleFilesChange(files);\n },\n [handleFilesChange, disabled, isUploading],\n );\n\n const handleRemove = useCallback(\n (index: number) => (e: React.MouseEvent) => {\n e.stopPropagation();\n\n if (props.multiple !== true) {\n props.onValueChange?.(null);\n } else {\n const newValue = values.filter((_, i) => i !== index);\n props.onValueChange?.(newValue);\n }\n },\n [values, props],\n );\n\n const handleClick = () => {\n if (!disabled && !isUploading) {\n inputRef.current?.click();\n }\n };\n\n // viewMode에 따라 적절한 사이즈 클래스 선택\n const sizeClasses = isImageView ? imageSizeClasses : fileSizeClasses;\n\n // Single 모드 렌더링\n if (!isMultiple && displayItems.length > 0) {\n const item = displayItems[0];\n return (\n <div className={cn(\"relative inline-block\", className)}>\n <input\n ref={inputRef}\n type=\"file\"\n accept={accept}\n onChange={handleInputChange}\n onBlur={onBlur}\n disabled={disabled || isUploading}\n className=\"sr-only\"\n />\n\n <div\n onClick={handleClick}\n onDrop={handleDrop}\n onDragOver={(e) => {\n e.preventDefault();\n !disabled && !isUploading && setDragOver(true);\n }}\n onDragLeave={(e) => {\n e.preventDefault();\n setDragOver(false);\n }}\n className={cn(\n \"relative flex items-center justify-center rounded-lg border-2 cursor-pointer transition-all\",\n sizeClasses[previewSize],\n isImageView\n ? \"border-transparent\"\n : \"border-dashed border-muted-foreground/25 hover:border-muted-foreground/50\",\n dragOver && \"border-primary bg-primary/5\",\n disabled && \"opacity-50 cursor-not-allowed\",\n isUploading && \"cursor-wait\",\n )}\n >\n {isUploading ? (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground\">\n <Loader2Icon className=\"h-6 w-6 animate-spin\" />\n <span className=\"text-xs\">{SD(\"rc.fileInput.uploading\")}</span>\n </div>\n ) : (\n <>\n {isImageView ? (\n <img\n src={item.url}\n alt=\"Preview\"\n className=\"h-full w-full object-cover rounded-lg overflow-hidden\"\n />\n ) : (\n <div className=\"flex items-center gap-2 px-3 h-full w-full min-w-0 overflow-hidden\">\n <FileTypeIcon filename={item.name} size={previewSize} />\n <span\n className={cn(\n \"text-xs truncate min-w-0\",\n item.isPending ? \"w-[140px] shrink-0\" : \"flex-1\",\n )}\n >\n {item.name}\n </span>\n {item.isPending && (\n <span className=\"px-2 py-0.5 bg-yellow-500/90 text-white text-xs rounded whitespace-nowrap shrink-0\">\n {SD(\"rc.fileInput.pending\")}\n </span>\n )}\n </div>\n )}\n {!disabled && (\n <Button\n type=\"button\"\n variant=\"destructive\"\n size=\"xs\"\n className=\"absolute -top-2 -right-2 h-6 w-6 rounded-full p-0\"\n onClick={handleRemove(0)}\n icon={<XIcon />}\n />\n )}\n {/* 이미지 모드일 때만 하단에 대기중 배지 표시 */}\n {isImageView && item.isPending && (\n <div className=\"absolute bottom-2 left-2 right-2 mx-auto max-w-[calc(100%-1rem)] px-2 py-1 bg-yellow-500/90 text-white text-xs rounded text-center truncate\">\n {SD(\"rc.fileInput.pending\")}\n </div>\n )}\n </>\n )}\n </div>\n </div>\n );\n }\n\n // Multiple 모드 또는 빈 Single 모드 렌더링\n return (\n <div className={cn(\"flex flex-wrap gap-3\", className)}>\n <input\n ref={inputRef}\n type=\"file\"\n accept={accept}\n multiple={isMultiple}\n onChange={handleInputChange}\n onBlur={onBlur}\n disabled={disabled || isUploading}\n className=\"sr-only\"\n />\n\n {/* 업로드된 파일들 */}\n {displayItems.map((item, index) => (\n <div key={`${item.url}-${index}`} className={cn(\"relative\", sizeClasses[previewSize])}>\n {isImageView ? (\n <div className=\"h-full w-full rounded-lg border overflow-hidden\">\n <img\n src={item.url}\n alt={`Uploaded ${index + 1}`}\n className=\"h-full w-full object-cover\"\n />\n </div>\n ) : (\n <div\n className={cn(\n \"relative flex items-center gap-2 px-3 rounded-lg border-2 min-w-0 overflow-hidden\",\n \"border-dashed border-muted-foreground/25\",\n \"h-full w-full\",\n )}\n >\n <FileTypeIcon filename={item.name} size={previewSize} />\n <span\n className={cn(\n \"text-xs truncate min-w-0\",\n item.isPending ? \"w-[140px] shrink-0\" : \"flex-1\",\n )}\n >\n {item.name}\n </span>\n {item.isPending && (\n <span className=\"px-2 py-0.5 bg-yellow-500/90 text-white text-xs rounded whitespace-nowrap shrink-0\">\n {SD(\"rc.fileInput.pending\")}\n </span>\n )}\n </div>\n )}\n {!disabled && (\n <Button\n type=\"button\"\n variant=\"destructive\"\n size=\"xs\"\n className=\"absolute -top-2 -right-2 h-6 w-6 rounded-full p-0\"\n onClick={handleRemove(index)}\n icon={<XIcon />}\n />\n )}\n {/* 이미지 모드일 때만 하단에 대기중 배지 표시 */}\n {isImageView && item.isPending && (\n <div className=\"absolute bottom-2 left-2 right-2 mx-auto max-w-[calc(100%-1rem)] px-2 py-1 bg-yellow-500/90 text-white text-xs rounded text-center truncate\">\n {SD(\"rc.fileInput.pending\")}\n </div>\n )}\n </div>\n ))}\n\n {/* 추가 버튼 */}\n {canAddMore && (\n <div\n onClick={handleClick}\n onDrop={handleDrop}\n onDragOver={(e) => {\n e.preventDefault();\n !disabled && !isUploading && setDragOver(true);\n }}\n onDragLeave={(e) => {\n e.preventDefault();\n setDragOver(false);\n }}\n className={cn(\n \"flex items-center justify-center rounded-lg border-2 border-dashed cursor-pointer transition-all\",\n sizeClasses[previewSize],\n dragOver\n ? \"border-primary bg-primary/5\"\n : \"border-muted-foreground/25 hover:border-muted-foreground/50\",\n disabled && \"opacity-50 cursor-not-allowed\",\n isUploading && \"cursor-wait\",\n )}\n >\n {isUploading ? (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground\">\n <Loader2Icon className=\"h-6 w-6 animate-spin\" />\n <span className=\"text-xs\">{SD(\"rc.fileInput.uploading\")}</span>\n </div>\n ) : (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground p-2\">\n {isImageView ? <ImageIcon className=\"h-6 w-6\" /> : <UploadIcon className=\"h-6 w-6\" />}\n <span className=\"text-xs text-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GACpF,kBAAC,QAAD;MAAM,WAAU;gBAAuB;KAAyB,CAAA,CAC7D;;GAEJ,CAAA;EAEJ;;AAET"}
|
|
1
|
+
{"version":3,"file":"file-input.js","names":["ReactFileIcon","Loader2Icon","_Fragment","XIcon","ImageIcon","UploadIcon","ForwardRef","ForwardRef$1","ForwardRef$2","ForwardRef$3","isFile","value","getFileExtension","parts","filename","fileIconSizes","fileIconStyles","defaultStyles","FileTypeIcon","ext","styleProps","size","FileIcon","imageSizeClasses","fileSizeClasses","FileInput","props","useSonamuBaseContext","isMultiple","isImageView","viewMode","accept","inputRef","useRef","isUploading","setIsUploading","useState","dragOver","setDragOver","defaultPlaceholder","placeholder","SD","values","useMemo","singleValue","fileObjects","blobUrls","useObjectUrls","displayItems","v","index","maxFiles","totalCount","canAddMore","handleFilesChange","useCallback","files","disabled","remainingSlots","maxFilesTranslation","isFunction","filesToAdd","uploadMode","uploadedFiles","uploader","uploadParams","finalValues","error","handleInputChange","handleDrop","handleRemove","e","newValue","i","handleClick","sizeClasses","item","cn","className","previewSize","Fragment","Button","jsx"],"sources":["../../../src/components/ui/file-input.tsx"],"sourcesContent":["import { isFunction } from \"radashi\";\nimport type React from \"react\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport { FileIcon as ReactFileIcon, defaultStyles } from \"react-file-icon\";\nimport ImageIcon from \"~icons/lucide/image\";\nimport Loader2Icon from \"~icons/lucide/loader2\";\nimport UploadIcon from \"~icons/lucide/upload\";\nimport XIcon from \"~icons/lucide/x\";\n\nimport { type SonamuFile, type UploadParams } from \"@/contexts\";\nimport { useSonamuBaseContext } from \"@/contexts\";\nimport { type RCKeys } from \"@/i18n/rc-keys\";\nimport { cn, useObjectUrls } from \"@/lib/utils\";\n\nimport { Button } from \"./button\";\n\nexport type PreviewSize = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\nfunction isFile(value: SonamuFile | File): value is File {\n return Object.prototype.toString.call(value) === \"[object File]\";\n}\n\nfunction getFileExtension(filename: string): string {\n const parts = filename.split(\".\");\n if (parts.length < 2) return \"\";\n return parts[parts.length - 1].toLowerCase();\n}\n\nconst fileIconSizes = {\n sm: 14,\n md: 18,\n lg: 22,\n xl: 26,\n};\n\nconst fileIconStyles = new Map<string, Partial<React.ComponentProps<typeof ReactFileIcon>>>(\n Object.entries(defaultStyles),\n);\n\nfunction FileTypeIcon({ filename, size = \"md\" }: { filename: string; size?: PreviewSize }) {\n const ext = getFileExtension(filename);\n const styleProps = fileIconStyles.get(ext) ?? {};\n\n return (\n <div className=\"shrink-0 self-center\" style={{ width: fileIconSizes[size], marginTop: -2 }}>\n <ReactFileIcon extension={ext || undefined} {...styleProps} />\n </div>\n );\n}\n\n// 이미지용: 정사각형\nconst imageSizeClasses = {\n sm: \"w-20 h-20\",\n md: \"w-32 h-32\",\n lg: \"w-40 h-40\",\n xl: \"w-48 h-48\",\n};\n\n// 파일용: 가로로 긴 직사각형\nconst fileSizeClasses = {\n sm: \"w-48 h-12\",\n md: \"w-80 h-16\",\n lg: \"w-96 h-20\",\n xl: \"w-[28rem] h-24\",\n};\n\ntype BaseProps = {\n uploadMode: \"eager\" | \"lazy\";\n viewMode: \"image\" | \"file\";\n placeholder?: string;\n accept?: string;\n disabled?: boolean;\n className?: string;\n previewSize?: PreviewSize;\n uploadParams?: UploadParams;\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\n};\n\ntype SingleModeProps = BaseProps & {\n multiple?: false;\n value: SonamuFile | File | null;\n onValueChange?: (value: SonamuFile | File | null) => void;\n};\n\ntype MultipleModeProps = BaseProps & {\n multiple: true;\n value: (SonamuFile | File)[] | null;\n onValueChange?: (value: (SonamuFile | File)[]) => void;\n maxFiles?: number;\n};\n\nexport type FileInputProps = SingleModeProps | MultipleModeProps;\n\nexport function FileInput(props: FileInputProps) {\n const {\n placeholder,\n disabled = false,\n className,\n previewSize = \"md\",\n uploadMode,\n viewMode,\n uploadParams,\n onBlur,\n } = props;\n\n const { uploader, SD } = useSonamuBaseContext<RCKeys>();\n\n const isMultiple = props.multiple ?? false;\n const isImageView = viewMode === \"image\";\n\n // viewMode에 따라 accept 자동 설정\n const accept = props.accept ?? (isImageView ? \"image/*\" : \"*/*\");\n\n const inputRef = useRef<HTMLInputElement>(null);\n const [isUploading, setIsUploading] = useState(false);\n const [dragOver, setDragOver] = useState(false);\n\n // 기본 placeholder 설정\n const defaultPlaceholder =\n placeholder ??\n `${isImageView ? SD(\"rc.fileInput.imagePlaceholder\") : SD(\"rc.fileInput.filePlaceholder\")} URL${isMultiple ? \"S\" : \"\"}`;\n\n // 입력 정규화: 내부적으로 배열로 통일\n const values: Array<SonamuFile | File> = useMemo(() => {\n if (props.multiple !== true) {\n const singleValue = props.value;\n return singleValue ? [singleValue] : [];\n }\n return props.value ?? [];\n }, [props.multiple, props.value]);\n\n // File 객체만 추출\n const fileObjects = useMemo(() => values.filter(isFile), [values]);\n\n // File 객체는 useObjectUrls로 안전하게 blob URL 생성 (자동 메모리 해제)\n const blobUrls = useObjectUrls(fileObjects);\n\n // 최종 display 데이터: 원래 순서를 유지하면서 File은 blob URL로, SonamuFile은 그대로\n const displayItems = values.map((v) => {\n if (isFile(v)) {\n const index = fileObjects.indexOf(v);\n return {\n url: blobUrls[index],\n name: v.name,\n isPending: true,\n };\n }\n // SonamuFile\n return {\n url: v.url,\n name: v.name,\n isPending: false,\n };\n });\n\n const maxFiles = props.multiple === true ? (props.maxFiles ?? 10) : 1;\n const totalCount = values.length;\n const canAddMore = totalCount < maxFiles;\n\n const handleFilesChange = useCallback(\n async (files: File[]) => {\n if (files.length === 0 || disabled) return;\n\n // maxFiles 체크\n const remainingSlots = maxFiles - totalCount;\n if (remainingSlots <= 0) {\n const maxFilesTranslation = SD(\"rc.fileInput.maxFilesExceeded\");\n alert(\n isFunction(maxFilesTranslation) ? maxFilesTranslation(maxFiles) : maxFilesTranslation,\n );\n return;\n }\n\n const filesToAdd = files.slice(0, remainingSlots);\n\n // Eager 모드: 즉시 업로드\n if (uploadMode === \"eager\") {\n setIsUploading(true);\n try {\n const uploadedFiles = await uploader(filesToAdd, uploadParams);\n\n if (props.multiple === true) {\n // Multiple 파일 업로드\n const finalValues = [...values, ...uploadedFiles];\n props.onValueChange?.(finalValues);\n } else {\n // Single 파일 업로드\n props.onValueChange?.(uploadedFiles[0] ?? null);\n }\n } catch (error) {\n console.error(\"Upload failed:\", error);\n alert(SD(\"rc.fileInput.uploadFailed\"));\n } finally {\n setIsUploading(false);\n }\n } else {\n // Lazy 모드: File 객체 그대로 전달\n if (props.multiple === true) {\n const finalValues = [...values, ...filesToAdd];\n props.onValueChange?.(finalValues);\n } else {\n props.onValueChange?.(filesToAdd[0] ?? null);\n }\n }\n },\n [disabled, totalCount, maxFiles, uploadMode, uploadParams, values, props, uploader, SD],\n );\n\n const handleInputChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const files = Array.from(e.target.files || []);\n handleFilesChange(files);\n // input 초기화\n if (inputRef.current) {\n inputRef.current.value = \"\";\n }\n },\n [handleFilesChange],\n );\n\n const handleDrop = useCallback(\n (e: React.DragEvent) => {\n e.preventDefault();\n setDragOver(false);\n if (disabled || isUploading) return;\n\n const files = Array.from(e.dataTransfer.files);\n handleFilesChange(files);\n },\n [handleFilesChange, disabled, isUploading],\n );\n\n const handleRemove = useCallback(\n (index: number) => (e: React.MouseEvent) => {\n e.stopPropagation();\n\n if (props.multiple !== true) {\n props.onValueChange?.(null);\n } else {\n const newValue = values.filter((_, i) => i !== index);\n props.onValueChange?.(newValue);\n }\n },\n [values, props],\n );\n\n const handleClick = () => {\n if (!disabled && !isUploading) {\n inputRef.current?.click();\n }\n };\n\n // viewMode에 따라 적절한 사이즈 클래스 선택\n const sizeClasses = isImageView ? imageSizeClasses : fileSizeClasses;\n\n // Single 모드 렌더링\n if (!isMultiple && displayItems.length > 0) {\n const item = displayItems[0];\n return (\n <div className={cn(\"relative inline-block\", className)}>\n <input\n ref={inputRef}\n type=\"file\"\n accept={accept}\n onChange={handleInputChange}\n onBlur={onBlur}\n disabled={disabled || isUploading}\n className=\"sr-only\"\n />\n\n <div\n onClick={handleClick}\n onDrop={handleDrop}\n onDragOver={(e) => {\n e.preventDefault();\n !disabled && !isUploading && setDragOver(true);\n }}\n onDragLeave={(e) => {\n e.preventDefault();\n setDragOver(false);\n }}\n className={cn(\n \"relative flex items-center justify-center rounded-lg border-2 cursor-pointer transition-all\",\n sizeClasses[previewSize],\n isImageView\n ? \"border-transparent\"\n : \"border-dashed border-muted-foreground/25 hover:border-muted-foreground/50\",\n dragOver && \"border-primary bg-primary/5\",\n disabled && \"opacity-50 cursor-not-allowed\",\n isUploading && \"cursor-wait\",\n )}\n >\n {isUploading ? (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground\">\n <Loader2Icon className=\"h-6 w-6 animate-spin\" />\n <span className=\"text-xs\">{SD(\"rc.fileInput.uploading\")}</span>\n </div>\n ) : (\n <>\n {isImageView ? (\n <img\n src={item.url}\n alt=\"Preview\"\n className=\"h-full w-full object-cover rounded-lg overflow-hidden\"\n />\n ) : (\n <div className=\"flex items-center gap-2 px-3 h-full w-full min-w-0 overflow-hidden\">\n <FileTypeIcon filename={item.name} size={previewSize} />\n <span\n className={cn(\n \"text-xs truncate min-w-0\",\n item.isPending ? \"w-[140px] shrink-0\" : \"flex-1\",\n )}\n >\n {item.name}\n </span>\n {item.isPending && (\n <span className=\"px-2 py-0.5 bg-yellow-500/90 text-white text-xs rounded whitespace-nowrap shrink-0\">\n {SD(\"rc.fileInput.pending\")}\n </span>\n )}\n </div>\n )}\n {!disabled && (\n <Button\n type=\"button\"\n variant=\"destructive\"\n size=\"xs\"\n className=\"absolute -top-2 -right-2 h-6 w-6 rounded-full p-0\"\n onClick={handleRemove(0)}\n icon={<XIcon />}\n />\n )}\n {/* 이미지 모드일 때만 하단에 대기중 배지 표시 */}\n {isImageView && item.isPending && (\n <div className=\"absolute bottom-2 left-2 right-2 mx-auto max-w-[calc(100%-1rem)] px-2 py-1 bg-yellow-500/90 text-white text-xs rounded text-center truncate\">\n {SD(\"rc.fileInput.pending\")}\n </div>\n )}\n </>\n )}\n </div>\n </div>\n );\n }\n\n // Multiple 모드 또는 빈 Single 모드 렌더링\n return (\n <div className={cn(\"flex flex-wrap gap-3\", className)}>\n <input\n ref={inputRef}\n type=\"file\"\n accept={accept}\n multiple={isMultiple}\n onChange={handleInputChange}\n onBlur={onBlur}\n disabled={disabled || isUploading}\n className=\"sr-only\"\n />\n\n {/* 업로드된 파일들 */}\n {displayItems.map((item, index) => (\n <div key={`${item.url}-${index}`} className={cn(\"relative\", sizeClasses[previewSize])}>\n {isImageView ? (\n <div className=\"h-full w-full rounded-lg border overflow-hidden\">\n <img\n src={item.url}\n alt={`Uploaded ${index + 1}`}\n className=\"h-full w-full object-cover\"\n />\n </div>\n ) : (\n <div\n className={cn(\n \"relative flex items-center gap-2 px-3 rounded-lg border-2 min-w-0 overflow-hidden\",\n \"border-dashed border-muted-foreground/25\",\n \"h-full w-full\",\n )}\n >\n <FileTypeIcon filename={item.name} size={previewSize} />\n <span\n className={cn(\n \"text-xs truncate min-w-0\",\n item.isPending ? \"w-[140px] shrink-0\" : \"flex-1\",\n )}\n >\n {item.name}\n </span>\n {item.isPending && (\n <span className=\"px-2 py-0.5 bg-yellow-500/90 text-white text-xs rounded whitespace-nowrap shrink-0\">\n {SD(\"rc.fileInput.pending\")}\n </span>\n )}\n </div>\n )}\n {!disabled && (\n <Button\n type=\"button\"\n variant=\"destructive\"\n size=\"xs\"\n className=\"absolute -top-2 -right-2 h-6 w-6 rounded-full p-0\"\n onClick={handleRemove(index)}\n icon={<XIcon />}\n />\n )}\n {/* 이미지 모드일 때만 하단에 대기중 배지 표시 */}\n {isImageView && item.isPending && (\n <div className=\"absolute bottom-2 left-2 right-2 mx-auto max-w-[calc(100%-1rem)] px-2 py-1 bg-yellow-500/90 text-white text-xs rounded text-center truncate\">\n {SD(\"rc.fileInput.pending\")}\n </div>\n )}\n </div>\n ))}\n\n {/* 추가 버튼 */}\n {canAddMore && (\n <div\n onClick={handleClick}\n onDrop={handleDrop}\n onDragOver={(e) => {\n e.preventDefault();\n !disabled && !isUploading && setDragOver(true);\n }}\n onDragLeave={(e) => {\n e.preventDefault();\n setDragOver(false);\n }}\n className={cn(\n \"flex items-center justify-center rounded-lg border-2 border-dashed cursor-pointer transition-all\",\n sizeClasses[previewSize],\n dragOver\n ? \"border-primary bg-primary/5\"\n : \"border-muted-foreground/25 hover:border-muted-foreground/50\",\n disabled && \"opacity-50 cursor-not-allowed\",\n isUploading && \"cursor-wait\",\n )}\n >\n {isUploading ? (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground\">\n <Loader2Icon className=\"h-6 w-6 animate-spin\" />\n <span className=\"text-xs\">{SD(\"rc.fileInput.uploading\")}</span>\n </div>\n ) : (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground p-2\">\n {isImageView ? <ImageIcon className=\"h-6 w-6\" /> : <UploadIcon className=\"h-6 w-6\" />}\n <span className=\"text-xs text-center\">{defaultPlaceholder}</span>\n </div>\n )}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,SAASU,EAAO,GAAyC;CACvD,OAAO,OAAO,UAAU,SAAS,KAAKC,CAAK,MAAM;AACnD;AAEA,SAASC,EAAiB,GAA0B;CAClD,IAAMC,IAAQC,EAAS,MAAM,GAAG;CAEhC,OADID,EAAM,SAAS,IAAU,KACtBA,EAAMA,EAAM,SAAS,EAAE,CAAC,YAAY;AAC7C;AAEA,IAAME,IAAgB;CACpB,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN,GAEMC,IAAiB,IAAI,IACzB,OAAO,QAAQC,CAAa,CAC9B;AAEA,SAASC,EAAa,EAAE,aAAU,UAAO,QAAkD;CACzF,IAAMC,IAAMP,EAAiBE,CAAQ,GAC/BM,IAAaJ,EAAe,IAAIG,CAAG,KAAK,CAAC;CAE/C,OACE,kBAAC,OAAD;EAAK,WAAU;EAAuB,OAAO;GAA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CC,GAArC,EAAW,WAAU,UAAW,CAAqC,GACpF,kBAAC,QAAD;MAAM,WAAU;MAAuB,UAAAkC;KAAyB,CAAA,CAC7D;;GAEJ,CAAA;EAEJ;;AAET"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ControllerProps, FieldPath, FieldValues } from 'react-hook-form';
|
|
2
2
|
import type * as LabelPrimitive from "@radix-ui/react-label";
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
declare const Form: <TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>(
|
|
5
|
-
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) =>
|
|
4
|
+
declare const Form: <TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>({ children, watch, getValues, getErrors, getFieldState, setError, clearErrors, setValue, setValues, trigger, formState, resetField, reset, resetDefaultValues, handleSubmit, unregister, control, register, setFocus, subscribe, }: import('react-hook-form').FormProviderProps<TFieldValues, TContext, TTransformedValues>) => React.JSX.Element;
|
|
5
|
+
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) => React.JSX.Element;
|
|
6
6
|
declare const useFormField: () => {
|
|
7
7
|
invalid: boolean;
|
|
8
8
|
isDirty: boolean;
|
|
9
9
|
isTouched: boolean;
|
|
10
10
|
isValidating: boolean;
|
|
11
|
-
error?: import('react-hook-form').FieldError;
|
|
11
|
+
error?: import('react-hook-form').FieldError | undefined;
|
|
12
12
|
id: string;
|
|
13
13
|
name: string;
|
|
14
14
|
formItemId: string;
|
|
@@ -17,7 +17,9 @@ declare const useFormField: () => {
|
|
|
17
17
|
};
|
|
18
18
|
declare const FormItem: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
19
19
|
declare const FormLabel: React.ForwardRefExoticComponent<Omit<LabelPrimitive.LabelProps & React.RefAttributes<HTMLLabelElement>, "ref"> & React.RefAttributes<HTMLLabelElement>>;
|
|
20
|
-
declare const FormControl: React.ForwardRefExoticComponent<Omit<
|
|
20
|
+
declare const FormControl: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLElement> & {
|
|
21
|
+
children?: React.ReactNode | undefined;
|
|
22
|
+
} & React.RefAttributes<HTMLElement>, "ref"> & React.RefAttributes<HTMLElement>>;
|
|
21
23
|
declare const FormDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
|
|
22
24
|
declare const FormMessage: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
|
|
23
25
|
export { useFormField, Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField, };
|
|
@@ -4,7 +4,7 @@ import * as n from "react";
|
|
|
4
4
|
import { jsx as r } from "react/jsx-runtime";
|
|
5
5
|
import { Slot as i } from "@radix-ui/react-slot";
|
|
6
6
|
import { Controller as a, FormProvider as o, useFormContext as s } from "react-hook-form";
|
|
7
|
-
|
|
7
|
+
// src/components/ui/form.tsx
|
|
8
8
|
var c = o, l = n.createContext(null), u = ({ ...e }) => /* @__PURE__ */ r(l.Provider, {
|
|
9
9
|
value: { name: e.name },
|
|
10
10
|
children: /* @__PURE__ */ r(a, { ...e })
|
|
@@ -75,7 +75,6 @@ var _ = n.forwardRef(({ className: t, children: n, ...i }, a) => {
|
|
|
75
75
|
}) : null;
|
|
76
76
|
});
|
|
77
77
|
_.displayName = "FormMessage";
|
|
78
|
-
//#endregion
|
|
79
78
|
export { c as Form, h as FormControl, g as FormDescription, u as FormField, p as FormItem, m as FormLabel, _ as FormMessage, d as useFormField };
|
|
80
79
|
|
|
81
80
|
//# sourceMappingURL=form.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.js","names":[],"sources":["../../../src/components/ui/form.tsx"],"sourcesContent":["import type * as LabelPrimitive from \"@radix-ui/react-label\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport * as React from \"react\";\nimport { Controller, FormProvider, useFormContext } from \"react-hook-form\";\nimport { type ControllerProps, type FieldPath, type FieldValues } from \"react-hook-form\";\n\nimport { cn } from \"../../lib/utils\";\nimport { Label } from \"./label\";\n\nconst Form = FormProvider;\n\ntype FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = {\n name: TName;\n};\n\nconst FormFieldContext = React.createContext<FormFieldContextValue | null>(null);\n\nconst FormField = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n ...props\n}: ControllerProps<TFieldValues, TName>) => {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n );\n};\n\nconst useFormField = () => {\n const fieldContext = React.useContext(FormFieldContext);\n const itemContext = React.useContext(FormItemContext);\n const { getFieldState, formState } = useFormContext();\n\n if (!fieldContext) {\n throw new Error(\"useFormField should be used within <FormField>\");\n }\n\n if (!itemContext) {\n throw new Error(\"useFormField should be used within <FormItem>\");\n }\n\n const fieldState = getFieldState(fieldContext.name, formState);\n\n const { id } = itemContext;\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-form-item`,\n formDescriptionId: `${id}-form-item-description`,\n formMessageId: `${id}-form-item-message`,\n ...fieldState,\n };\n};\n\ntype FormItemContextValue = {\n id: string;\n};\n\nconst FormItemContext = React.createContext<FormItemContextValue | null>(null);\n\nconst FormItem = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => {\n const id = React.useId();\n\n return (\n <FormItemContext.Provider value={{ id }}>\n <div ref={ref} className={cn(\"space-y-2\", className)} {...props} />\n </FormItemContext.Provider>\n );\n },\n);\nFormItem.displayName = \"FormItem\";\n\nconst FormLabel = React.forwardRef<\n React.ComponentRef<typeof LabelPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>\n>(({ className, ...props }, ref) => {\n const { error, formItemId } = useFormField();\n\n return (\n <Label\n ref={ref}\n className={cn(error && \"text-destructive\", className)}\n htmlFor={formItemId}\n {...props}\n />\n );\n});\nFormLabel.displayName = \"FormLabel\";\n\nconst FormControl = React.forwardRef<\n React.ComponentRef<typeof Slot>,\n React.ComponentPropsWithoutRef<typeof Slot>\n>(({ ...props }, ref) => {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField();\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`}\n aria-invalid={!!error}\n {...props}\n />\n );\n});\nFormControl.displayName = \"FormControl\";\n\nconst FormDescription = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\n const { formDescriptionId } = useFormField();\n\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn(\"text-sm text-muted-foreground\", className)}\n {...props}\n />\n );\n});\nFormDescription.displayName = \"FormDescription\";\n\nconst FormMessage = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, children, ...props }, ref) => {\n const { error, formMessageId } = useFormField();\n const body = error ? String(error?.message ?? \"\") : children;\n\n if (!body) {\n return null;\n }\n\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn(\"text-sm font-medium text-destructive\", className)}\n {...props}\n >\n {body}\n </p>\n );\n});\nFormMessage.displayName = \"FormMessage\";\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,\n FormDescription,\n FormMessage,\n FormField,\n};\n"],"mappings":";;;;;;;AASA,
|
|
1
|
+
{"version":3,"file":"form.js","names":["React","React$1","Form","FormProvider","FormFieldContext","FormField","props","Controller","useFormField","fieldContext","itemContext","FormItemContext","useFormContext","fieldState","getFieldState","formState","id","FormItem","cn","className","FormLabel","Label","error","formItemId","FormControl","Slot","formDescriptionId","formMessageId","FormDescription","FormMessage","body","children"],"sources":["../../../src/components/ui/form.tsx"],"sourcesContent":["import type * as LabelPrimitive from \"@radix-ui/react-label\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport * as React from \"react\";\nimport { Controller, FormProvider, useFormContext } from \"react-hook-form\";\nimport { type ControllerProps, type FieldPath, type FieldValues } from \"react-hook-form\";\n\nimport { cn } from \"../../lib/utils\";\nimport { Label } from \"./label\";\n\nconst Form = FormProvider;\n\ntype FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = {\n name: TName;\n};\n\nconst FormFieldContext = React.createContext<FormFieldContextValue | null>(null);\n\nconst FormField = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n ...props\n}: ControllerProps<TFieldValues, TName>) => {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n );\n};\n\nconst useFormField = () => {\n const fieldContext = React.useContext(FormFieldContext);\n const itemContext = React.useContext(FormItemContext);\n const { getFieldState, formState } = useFormContext();\n\n if (!fieldContext) {\n throw new Error(\"useFormField should be used within <FormField>\");\n }\n\n if (!itemContext) {\n throw new Error(\"useFormField should be used within <FormItem>\");\n }\n\n const fieldState = getFieldState(fieldContext.name, formState);\n\n const { id } = itemContext;\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-form-item`,\n formDescriptionId: `${id}-form-item-description`,\n formMessageId: `${id}-form-item-message`,\n ...fieldState,\n };\n};\n\ntype FormItemContextValue = {\n id: string;\n};\n\nconst FormItemContext = React.createContext<FormItemContextValue | null>(null);\n\nconst FormItem = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => {\n const id = React.useId();\n\n return (\n <FormItemContext.Provider value={{ id }}>\n <div ref={ref} className={cn(\"space-y-2\", className)} {...props} />\n </FormItemContext.Provider>\n );\n },\n);\nFormItem.displayName = \"FormItem\";\n\nconst FormLabel = React.forwardRef<\n React.ComponentRef<typeof LabelPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>\n>(({ className, ...props }, ref) => {\n const { error, formItemId } = useFormField();\n\n return (\n <Label\n ref={ref}\n className={cn(error && \"text-destructive\", className)}\n htmlFor={formItemId}\n {...props}\n />\n );\n});\nFormLabel.displayName = \"FormLabel\";\n\nconst FormControl = React.forwardRef<\n React.ComponentRef<typeof Slot>,\n React.ComponentPropsWithoutRef<typeof Slot>\n>(({ ...props }, ref) => {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField();\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`}\n aria-invalid={!!error}\n {...props}\n />\n );\n});\nFormControl.displayName = \"FormControl\";\n\nconst FormDescription = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\n const { formDescriptionId } = useFormField();\n\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn(\"text-sm text-muted-foreground\", className)}\n {...props}\n />\n );\n});\nFormDescription.displayName = \"FormDescription\";\n\nconst FormMessage = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, children, ...props }, ref) => {\n const { error, formMessageId } = useFormField();\n const body = error ? String(error?.message ?? \"\") : children;\n\n if (!body) {\n return null;\n }\n\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn(\"text-sm font-medium text-destructive\", className)}\n {...props}\n >\n {body}\n </p>\n );\n});\nFormMessage.displayName = \"FormMessage\";\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,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U,cAAc;AAExB,IAAMkB,IAAcxB,EAAM,YAGvB,EAAE,GAAGM,KAAS,MAAQ;CACvB,IAAM,EAAE,UAAO,eAAY,sBAAmB,qBAAkBE,EAAa;CAE7E,OACE,kBAACiB,GAAD;EACO;EACL,IAAIF;EACJ,oBAAmBD,IAAiC,GAAGI,EAAkB,GAAGC,MAAjD,GAAGD;EAC9B,gBAAc,CAAC,CAACJ;EAChB,GAAIhB;CACL,CAAA;AAEL,CAAC;AACD,EAAY,cAAc;AAE1B,IAAMsB,IAAkB5B,EAAM,YAG3B,EAAE,cAAW,GAAGM,KAAS,MAAQ;CAClC,IAAM,EAAE,yBAAsBE,EAAa;CAE3C,OACE,kBAAC,KAAD;EACO;EACL,IAAIkB;EACJ,WAAWR,EAAG,iCAAiCC,CAAS;EACxD,GAAIb;CACL,CAAA;AAEL,CAAC;AACD,EAAgB,cAAc;AAE9B,IAAMuB,IAAc7B,EAAM,YAGvB,EAAE,cAAW,aAAU,GAAGM,KAAS,MAAQ;CAC5C,IAAM,EAAE,UAAO,qBAAkBE,EAAa,GACxCsB,IAAOR,IAAQ,OAAOA,GAAO,WAAW,EAAE,IAAIS;CAMpD,OAJKD,IAKH,kBAAC,KAAD;EACO;EACL,IAAIH;EACJ,WAAWT,EAAG,wCAAwCC,CAAS;EAC/D,GAAIb;EAEH,UAAAwB;CACA,CAAA,IAXI;AAaX,CAAC;AACD,EAAY,cAAc"}
|
|
@@ -2,7 +2,7 @@ import { cn as e } from "../../lib/utils.js";
|
|
|
2
2
|
import * as t from "react";
|
|
3
3
|
import { jsx as n } from "react/jsx-runtime";
|
|
4
4
|
import * as r from "@radix-ui/react-hover-card";
|
|
5
|
-
|
|
5
|
+
// src/components/ui/hover-card.tsx
|
|
6
6
|
var i = r.Root, a = r.Trigger, o = t.forwardRef(({ className: t, align: i = "center", sideOffset: a = 4, ...o }, s) => /* @__PURE__ */ n(r.Content, {
|
|
7
7
|
ref: s,
|
|
8
8
|
align: i,
|
|
@@ -11,7 +11,6 @@ var i = r.Root, a = r.Trigger, o = t.forwardRef(({ className: t, align: i = "cen
|
|
|
11
11
|
...o
|
|
12
12
|
}));
|
|
13
13
|
o.displayName = r.Content.displayName;
|
|
14
|
-
//#endregion
|
|
15
14
|
export { i as HoverCard, o as HoverCardContent, a as HoverCardTrigger };
|
|
16
15
|
|
|
17
16
|
//# sourceMappingURL=hover-card.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hover-card.js","names":[],"sources":["../../../src/components/ui/hover-card.tsx"],"sourcesContent":["import * as HoverCardPrimitive from \"@radix-ui/react-hover-card\";\nimport * as React from \"react\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst HoverCard = HoverCardPrimitive.Root;\n\nconst HoverCardTrigger = HoverCardPrimitive.Trigger;\n\nconst HoverCardContent = React.forwardRef<\n React.ComponentRef<typeof HoverCardPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>\n>(({ className, align = \"center\", sideOffset = 4, ...props }, ref) => (\n <HoverCardPrimitive.Content\n ref={ref}\n align={align}\n sideOffset={sideOffset}\n className={cn(\n \"z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-hover-card-content-transform-origin]\",\n className,\n )}\n {...props}\n />\n));\nHoverCardContent.displayName = HoverCardPrimitive.Content.displayName;\n\nexport { HoverCard, HoverCardTrigger, HoverCardContent };\n"],"mappings":";;;;;AAKA,
|
|
1
|
+
{"version":3,"file":"hover-card.js","names":["React","React$1","HoverCardPrimitive","HoverCard","HoverCardTrigger","HoverCardContent","props","cn","className"],"sources":["../../../src/components/ui/hover-card.tsx"],"sourcesContent":["import * as HoverCardPrimitive from \"@radix-ui/react-hover-card\";\nimport * as React from \"react\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst HoverCard = HoverCardPrimitive.Root;\n\nconst HoverCardTrigger = HoverCardPrimitive.Trigger;\n\nconst HoverCardContent = React.forwardRef<\n React.ComponentRef<typeof HoverCardPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>\n>(({ className, align = \"center\", sideOffset = 4, ...props }, ref) => (\n <HoverCardPrimitive.Content\n ref={ref}\n align={align}\n sideOffset={sideOffset}\n className={cn(\n \"z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-hover-card-content-transform-origin]\",\n className,\n )}\n {...props}\n />\n));\nHoverCardContent.displayName = HoverCardPrimitive.Content.displayName;\n\nexport { HoverCard, HoverCardTrigger, HoverCardContent };\n"],"mappings":";;;;;AAKA,IAAMG,IAAYD,EAAmB,MAE/BE,IAAmBF,EAAmB,SAEtCG,IAAmBL,EAAM,YAG5B,EAAE,cAAW,WAAQ,UAAU,gBAAa,GAAG,GAAGM,KAAS,MAC5D,kBAACJ,EAAmB,SAApB;CACO;CACE;CACK;CACZ,WAAWK,EACT,meACAC,CACF;CACA,GAAIF;AACL,CAAA,CACF;AACD,EAAiB,cAAcJ,EAAmB,QAAQ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
declare const InputOTP: React.ForwardRefExoticComponent<(Omit<Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value" | "maxLength" | "textAlign" | "onComplete" | "pushPasswordManagerStrategy" | "pasteTransformer" | "containerClassName" | "noScriptCSSFallback"> & {
|
|
2
|
+
declare const InputOTP: React.ForwardRefExoticComponent<(Omit<Omit<React.InputHTMLAttributes<HTMLInputElement>, "nonce" | "onChange" | "value" | "maxLength" | "textAlign" | "onComplete" | "pushPasswordManagerStrategy" | "pasteTransformer" | "containerClassName" | "noScriptCSSFallback"> & {
|
|
3
3
|
value?: string;
|
|
4
4
|
onChange?: (newValue: string) => unknown;
|
|
5
5
|
maxLength: number;
|
|
@@ -9,10 +9,11 @@ declare const InputOTP: React.ForwardRefExoticComponent<(Omit<Omit<React.InputHT
|
|
|
9
9
|
pasteTransformer?: (pasted: string) => string;
|
|
10
10
|
containerClassName?: string;
|
|
11
11
|
noScriptCSSFallback?: string | null;
|
|
12
|
+
nonce?: string;
|
|
12
13
|
} & {
|
|
13
14
|
render: (props: import('input-otp').RenderProps) => React.ReactNode;
|
|
14
15
|
children?: never;
|
|
15
|
-
} & React.RefAttributes<HTMLInputElement>, "ref"> | Omit<Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value" | "maxLength" | "textAlign" | "onComplete" | "pushPasswordManagerStrategy" | "pasteTransformer" | "containerClassName" | "noScriptCSSFallback"> & {
|
|
16
|
+
} & React.RefAttributes<HTMLInputElement>, "ref"> | Omit<Omit<React.InputHTMLAttributes<HTMLInputElement>, "nonce" | "onChange" | "value" | "maxLength" | "textAlign" | "onComplete" | "pushPasswordManagerStrategy" | "pasteTransformer" | "containerClassName" | "noScriptCSSFallback"> & {
|
|
16
17
|
value?: string;
|
|
17
18
|
onChange?: (newValue: string) => unknown;
|
|
18
19
|
maxLength: number;
|
|
@@ -22,6 +23,7 @@ declare const InputOTP: React.ForwardRefExoticComponent<(Omit<Omit<React.InputHT
|
|
|
22
23
|
pasteTransformer?: (pasted: string) => string;
|
|
23
24
|
containerClassName?: string;
|
|
24
25
|
noScriptCSSFallback?: string | null;
|
|
26
|
+
nonce?: string;
|
|
25
27
|
} & {
|
|
26
28
|
render?: never;
|
|
27
29
|
children: React.ReactNode;
|
|
@@ -3,7 +3,7 @@ import t from "../../_virtual/~icons/lucide/dot.js";
|
|
|
3
3
|
import * as n from "react";
|
|
4
4
|
import { jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
5
5
|
import { OTPInput as a, OTPInputContext as o } from "input-otp";
|
|
6
|
-
|
|
6
|
+
// src/components/ui/input-otp.tsx
|
|
7
7
|
var s = n.forwardRef(({ className: t, containerClassName: n, ...i }, o) => /* @__PURE__ */ r(a, {
|
|
8
8
|
ref: o,
|
|
9
9
|
containerClassName: e("flex items-center gap-2 has-[:disabled]:opacity-50", n),
|
|
@@ -37,7 +37,6 @@ var u = n.forwardRef(({ ...e }, n) => /* @__PURE__ */ r("div", {
|
|
|
37
37
|
children: /* @__PURE__ */ r(t, {})
|
|
38
38
|
}));
|
|
39
39
|
u.displayName = "InputOTPSeparator";
|
|
40
|
-
//#endregion
|
|
41
40
|
export { s as InputOTP, c as InputOTPGroup, u as InputOTPSeparator, l as InputOTPSlot };
|
|
42
41
|
|
|
43
42
|
//# sourceMappingURL=input-otp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-otp.js","names":[],"sources":["../../../src/components/ui/input-otp.tsx"],"sourcesContent":["import { OTPInput, OTPInputContext } from \"input-otp\";\nimport * as React from \"react\";\nimport DotIcon from \"~icons/lucide/dot\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst InputOTP = React.forwardRef<\n React.ComponentRef<typeof OTPInput>,\n React.ComponentPropsWithoutRef<typeof OTPInput>\n>(({ className, containerClassName, ...props }, ref) => (\n <OTPInput\n ref={ref}\n containerClassName={cn(\n \"flex items-center gap-2 has-[:disabled]:opacity-50\",\n containerClassName,\n )}\n className={cn(\"disabled:cursor-not-allowed\", className)}\n {...props}\n />\n));\nInputOTP.displayName = \"InputOTP\";\n\nconst InputOTPGroup = React.forwardRef<\n React.ElementRef<\"div\">,\n React.ComponentPropsWithoutRef<\"div\">\n>(({ className, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex items-center\", className)} {...props} />\n));\nInputOTPGroup.displayName = \"InputOTPGroup\";\n\nconst InputOTPSlot = React.forwardRef<\n React.ElementRef<\"div\">,\n React.ComponentPropsWithoutRef<\"div\"> & { index: number }\n>(({ index, className, ...props }, ref) => {\n const inputOTPContext = React.useContext(OTPInputContext);\n const { char, hasFakeCaret, isActive } = inputOTPContext.slots[index];\n\n return (\n <div\n ref={ref}\n className={cn(\n \"relative flex h-10 w-10 items-center justify-center border-y border-r border-input text-sm transition-all first:rounded-l-md first:border-l last:rounded-r-md\",\n isActive && \"z-10 ring-2 ring-ring ring-offset-background\",\n className,\n )}\n {...props}\n >\n {char}\n {hasFakeCaret && (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center\">\n <div className=\"h-4 w-px animate-caret-blink bg-foreground duration-1000\" />\n </div>\n )}\n </div>\n );\n});\nInputOTPSlot.displayName = \"InputOTPSlot\";\n\nconst InputOTPSeparator = React.forwardRef<\n React.ElementRef<\"div\">,\n React.ComponentPropsWithoutRef<\"div\">\n>(({ ...props }, ref) => (\n <div ref={ref} role=\"separator\" {...props}>\n <DotIcon />\n </div>\n));\nInputOTPSeparator.displayName = \"InputOTPSeparator\";\n\nexport { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator };\n"],"mappings":";;;;;;AAMA,
|
|
1
|
+
{"version":3,"file":"input-otp.js","names":["React","DotIcon","ForwardRef","React$1","InputOTP","props","OTPInput","cn","containerClassName","className","InputOTPGroup","InputOTPSlot","OTPInputContext","index","isActive","char","hasFakeCaret","InputOTPSeparator"],"sources":["../../../src/components/ui/input-otp.tsx"],"sourcesContent":["import { OTPInput, OTPInputContext } from \"input-otp\";\nimport * as React from \"react\";\nimport DotIcon from \"~icons/lucide/dot\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst InputOTP = React.forwardRef<\n React.ComponentRef<typeof OTPInput>,\n React.ComponentPropsWithoutRef<typeof OTPInput>\n>(({ className, containerClassName, ...props }, ref) => (\n <OTPInput\n ref={ref}\n containerClassName={cn(\n \"flex items-center gap-2 has-[:disabled]:opacity-50\",\n containerClassName,\n )}\n className={cn(\"disabled:cursor-not-allowed\", className)}\n {...props}\n />\n));\nInputOTP.displayName = \"InputOTP\";\n\nconst InputOTPGroup = React.forwardRef<\n React.ElementRef<\"div\">,\n React.ComponentPropsWithoutRef<\"div\">\n>(({ className, ...props }, ref) => (\n <div ref={ref} className={cn(\"flex items-center\", className)} {...props} />\n));\nInputOTPGroup.displayName = \"InputOTPGroup\";\n\nconst InputOTPSlot = React.forwardRef<\n React.ElementRef<\"div\">,\n React.ComponentPropsWithoutRef<\"div\"> & { index: number }\n>(({ index, className, ...props }, ref) => {\n const inputOTPContext = React.useContext(OTPInputContext);\n const { char, hasFakeCaret, isActive } = inputOTPContext.slots[index];\n\n return (\n <div\n ref={ref}\n className={cn(\n \"relative flex h-10 w-10 items-center justify-center border-y border-r border-input text-sm transition-all first:rounded-l-md first:border-l last:rounded-r-md\",\n isActive && \"z-10 ring-2 ring-ring ring-offset-background\",\n className,\n )}\n {...props}\n >\n {char}\n {hasFakeCaret && (\n <div className=\"pointer-events-none absolute inset-0 flex items-center justify-center\">\n <div className=\"h-4 w-px animate-caret-blink bg-foreground duration-1000\" />\n </div>\n )}\n </div>\n );\n});\nInputOTPSlot.displayName = \"InputOTPSlot\";\n\nconst InputOTPSeparator = React.forwardRef<\n React.ElementRef<\"div\">,\n React.ComponentPropsWithoutRef<\"div\">\n>(({ ...props }, ref) => (\n <div ref={ref} role=\"separator\" {...props}>\n <DotIcon />\n </div>\n));\nInputOTPSeparator.displayName = \"InputOTPSeparator\";\n\nexport { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator };\n"],"mappings":";;;;;;AAMA,IAAMI,IAAWJ,EAAM,YAGpB,EAAE,cAAW,uBAAoB,GAAGK,KAAS,MAC9C,kBAACC,GAAD;CACO;CACL,oBAAoBC,EAClB,sDACAC,CACF;CACA,WAAWD,EAAG,+BAA+BE,CAAS;CACtD,GAAIJ;AACL,CAAA,CACF;AACD,EAAS,cAAc;AAEvB,IAAMK,IAAgBV,EAAM,YAGzB,EAAE,cAAW,GAAGK,KAAS,MAC1B,kBAAC,OAAD;CAAU;CAAK,WAAWE,EAAG,qBAAqBE,CAAS;CAAG,GAAIJ;AAAQ,CAAA,CAC3E;AACD,EAAc,cAAc;AAE5B,IAAMM,IAAeX,EAAM,YAGxB,EAAE,UAAO,cAAW,GAAGK,KAAS,MAAQ;CAEzC,IAAM,EAAE,SAAM,iBAAc,gBADJL,EAAM,WAAWY,CACA,CAAA,CAAgB,MAAMC;CAE/D,OACE,kBAAC,OAAD;EACO;EACL,WAAWN,EACT,iKACAO,KAAY,gDACZL,CACF;EACA,GAAIJ;EAPN,UAAA,CASGU,GACAC,KACC,kBAAC,OAAD;GAAK,WAAU;GACb,UAAA,kBAAC,OAAD,EAAK,WAAU,2DAA4D,CAAA;EACxE,CAAA,CAEJ;;AAET,CAAC;AACD,EAAa,cAAc;AAE3B,IAAMC,IAAoBjB,EAAM,YAG7B,EAAE,GAAGK,KAAS,MACf,kBAAC,OAAD;CAAU;CAAK,MAAK;CAAY,GAAIA;CAClC,UAAA,kBAACJ,GAAD,CAAU,CAAA;AACP,CAAA,CACN;AACD,EAAkB,cAAc"}
|
|
@@ -3,7 +3,7 @@ import t from "../../_virtual/~icons/lucide/x.js";
|
|
|
3
3
|
import * as n from "react";
|
|
4
4
|
import { jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
5
5
|
import { isFunction as a } from "radashi";
|
|
6
|
-
|
|
6
|
+
// src/components/ui/input.tsx
|
|
7
7
|
var o = n.forwardRef(({ className: o, type: s, onValueChange: c, onChange: l, clearable: u = !1, ...d }, f) => {
|
|
8
8
|
let p = n.useRef(null), m = n.useCallback((e) => {
|
|
9
9
|
p.current = e, a(f) ? f(e) : f && (f.current = e);
|
|
@@ -34,7 +34,6 @@ var o = n.forwardRef(({ className: o, type: s, onValueChange: c, onChange: l, cl
|
|
|
34
34
|
}) : S;
|
|
35
35
|
});
|
|
36
36
|
o.displayName = "Input";
|
|
37
|
-
//#endregion
|
|
38
37
|
export { o as Input };
|
|
39
38
|
|
|
40
39
|
//# sourceMappingURL=input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","names":[],"sources":["../../../src/components/ui/input.tsx"],"sourcesContent":["import { isFunction } from \"radashi\";\nimport * as React from \"react\";\nimport XIcon from \"~icons/lucide/x\";\n\nimport { type Override } from \"../../lib/types\";\nimport { cn } from \"../../lib/utils\";\n\nexport type InputProps = Override<\n React.ComponentProps<\"input\">,\n {\n onValueChange?: (value: string) => void;\n /**\n * 활성화 시 내용이 채워지면 오른쪽에 X 아이콘이 뜨고, 누르면 내용을 초기화한다.\n * controlled/uncontrolled 입력 모두 지원한다.\n */\n clearable?: boolean;\n }\n>;\n\nconst Input = React.forwardRef<HTMLInputElement, InputProps>(\n ({ className, type, onValueChange, onChange, clearable = false, ...props }, ref) => {\n const innerRef = React.useRef<HTMLInputElement>(null);\n\n // 전달된 ref와 내부 ref를 함께 채우는 콜백 ref\n const setRefs = React.useCallback(\n (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (isFunction(ref)) {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n },\n [ref],\n );\n\n // controlled면 value로, uncontrolled면 내부 상태로 내용 유무를 판단한다.\n const isControlled = props.value !== undefined;\n const [uncontrolledHasValue, setUncontrolledHasValue] = React.useState(\n () => String(props.defaultValue ?? \"\").length > 0,\n );\n const hasValue = isControlled ? String(props.value ?? \"\").length > 0 : uncontrolledHasValue;\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (!isControlled) {\n setUncontrolledHasValue(e.target.value.length > 0);\n }\n onValueChange?.(e.target.value);\n onChange?.(e);\n };\n\n const handleClear = () => {\n const node = innerRef.current;\n if (node) {\n // native value setter로 값을 비우고 input 이벤트를 dispatch하면\n // React의 value tracker가 변화를 인식해 controlled/uncontrolled 모두에서 onChange가 발화된다.\n const nativeInputValueSetter = Object.getOwnPropertyDescriptor(\n window.HTMLInputElement.prototype,\n \"value\",\n )?.set;\n nativeInputValueSetter?.call(node, \"\");\n node.dispatchEvent(new Event(\"input\", { bubbles: true }));\n node.focus();\n }\n if (!isControlled) {\n setUncontrolledHasValue(false);\n }\n };\n\n const showClear = clearable && hasValue && !props.disabled && !props.readOnly;\n\n const inputEl = (\n <input\n type={type}\n data-slot=\"input\"\n className={cn(\n \"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border px-3 py-1 text-base bg-input-background transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm\",\n \"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]\",\n \"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive\",\n clearable && \"pr-8\",\n className,\n )}\n ref={setRefs}\n {...props}\n onChange={handleChange}\n />\n );\n\n if (!clearable) {\n return inputEl;\n }\n\n return (\n <div className=\"relative w-full\">\n {inputEl}\n {showClear && (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label=\"Clear\"\n onMouseDown={(e) => e.preventDefault()}\n onClick={handleClear}\n className=\"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center text-muted-foreground opacity-60 hover:opacity-100 transition-opacity cursor-pointer\"\n >\n <XIcon className=\"h-4 w-4\" />\n </button>\n )}\n </div>\n );\n },\n);\nInput.displayName = \"Input\";\n\nexport { Input };\n"],"mappings":";;;;;;AAmBA,
|
|
1
|
+
{"version":3,"file":"input.js","names":["React","XIcon","ForwardRef","React$1","Input","props","innerRef","setRefs","node","isFunction","ref","isControlled","uncontrolledHasValue","setUncontrolledHasValue","hasValue","handleChange","onValueChange","onChange","handleClear","showClear","clearable","inputEl","cn","className"],"sources":["../../../src/components/ui/input.tsx"],"sourcesContent":["import { isFunction } from \"radashi\";\nimport * as React from \"react\";\nimport XIcon from \"~icons/lucide/x\";\n\nimport { type Override } from \"../../lib/types\";\nimport { cn } from \"../../lib/utils\";\n\nexport type InputProps = Override<\n React.ComponentProps<\"input\">,\n {\n onValueChange?: (value: string) => void;\n /**\n * 활성화 시 내용이 채워지면 오른쪽에 X 아이콘이 뜨고, 누르면 내용을 초기화한다.\n * controlled/uncontrolled 입력 모두 지원한다.\n */\n clearable?: boolean;\n }\n>;\n\nconst Input = React.forwardRef<HTMLInputElement, InputProps>(\n ({ className, type, onValueChange, onChange, clearable = false, ...props }, ref) => {\n const innerRef = React.useRef<HTMLInputElement>(null);\n\n // 전달된 ref와 내부 ref를 함께 채우는 콜백 ref\n const setRefs = React.useCallback(\n (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (isFunction(ref)) {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n },\n [ref],\n );\n\n // controlled면 value로, uncontrolled면 내부 상태로 내용 유무를 판단한다.\n const isControlled = props.value !== undefined;\n const [uncontrolledHasValue, setUncontrolledHasValue] = React.useState(\n () => String(props.defaultValue ?? \"\").length > 0,\n );\n const hasValue = isControlled ? String(props.value ?? \"\").length > 0 : uncontrolledHasValue;\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (!isControlled) {\n setUncontrolledHasValue(e.target.value.length > 0);\n }\n onValueChange?.(e.target.value);\n onChange?.(e);\n };\n\n const handleClear = () => {\n const node = innerRef.current;\n if (node) {\n // native value setter로 값을 비우고 input 이벤트를 dispatch하면\n // React의 value tracker가 변화를 인식해 controlled/uncontrolled 모두에서 onChange가 발화된다.\n const nativeInputValueSetter = Object.getOwnPropertyDescriptor(\n window.HTMLInputElement.prototype,\n \"value\",\n )?.set;\n nativeInputValueSetter?.call(node, \"\");\n node.dispatchEvent(new Event(\"input\", { bubbles: true }));\n node.focus();\n }\n if (!isControlled) {\n setUncontrolledHasValue(false);\n }\n };\n\n const showClear = clearable && hasValue && !props.disabled && !props.readOnly;\n\n const inputEl = (\n <input\n type={type}\n data-slot=\"input\"\n className={cn(\n \"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border px-3 py-1 text-base bg-input-background transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm\",\n \"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]\",\n \"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive\",\n clearable && \"pr-8\",\n className,\n )}\n ref={setRefs}\n {...props}\n onChange={handleChange}\n />\n );\n\n if (!clearable) {\n return inputEl;\n }\n\n return (\n <div className=\"relative w-full\">\n {inputEl}\n {showClear && (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label=\"Clear\"\n onMouseDown={(e) => e.preventDefault()}\n onClick={handleClear}\n className=\"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center text-muted-foreground opacity-60 hover:opacity-100 transition-opacity cursor-pointer\"\n >\n <XIcon className=\"h-4 w-4\" />\n </button>\n )}\n </div>\n );\n },\n);\nInput.displayName = \"Input\";\n\nexport { Input };\n"],"mappings":";;;;;;AAmBA,IAAMI,IAAQJ,EAAM,YACjB,EAAE,cAAW,SAAM,kBAAe,aAAU,eAAY,IAAO,GAAGK,KAAS,MAAQ;CAClF,IAAMC,IAAWN,EAAM,OAAyB,IAAI,GAG9CO,IAAUP,EAAM,aACnB,MAAkC;EAEjC,AADA,EAAS,UAAUQ,GACfC,EAAWC,CAAG,IAChBA,EAAIF,CAAI,IACCE,MACT,EAAI,UAAUF;CAElB,GACA,CAACE,CAAG,CACN,GAGMC,IAAeN,EAAM,UAAU,KAAA,GAC/B,CAACO,GAAsBC,KAA2Bb,EAAM,eACtD,OAAOK,EAAM,gBAAgB,EAAE,CAAC,CAAC,SAAS,CAClD,GACMS,IAAWH,IAAe,OAAON,EAAM,SAAS,EAAE,CAAC,CAAC,SAAS,IAAIO,GAEjEG,KAAgB,MAA2C;EAK/D,AAJKJ,KACHE,EAAwB,EAAE,OAAO,MAAM,SAAS,CAAC,GAEnDG,IAAgB,EAAE,OAAO,KAAK,GAC9BC,IAAW,CAAC;CACd,GAEMC,UAAoB;EACxB,IAAMV,IAAOF,EAAS;EAYtB,AAXIE,OAG6B,OAAO,yBACpC,OAAO,iBAAiB,WACxB,OACF,CAAC,EAAE,IAAA,EACqB,KAAKA,GAAM,EAAE,GACrCA,EAAK,cAAc,IAAI,MAAM,SAAS,EAAE,SAAS,GAAK,CAAC,CAAC,GACxDA,EAAK,MAAM,IAERG,KACHE,EAAwB,EAAK;CAEjC,GAEMM,IAAYC,KAAaN,KAAY,CAACT,EAAM,YAAY,CAACA,EAAM,UAE/DgB,IACJ,kBAAC,SAAD;EACQ;EACN,aAAU;EACV,WAAWC,EACT,8bACA,iFACA,0GACAF,KAAa,QACbG,CACF;EACA,KAAKhB;EACL,GAAIF;EACJ,UAAUU;CACX,CAAA;CAOH,OAJKK,IAKH,kBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACGC,GACAF,KACC,kBAAC,UAAD;GACE,MAAK;GACL,UAAU;GACV,cAAW;GACX,cAAc,MAAM,EAAE,eAAe;GACrC,SAASD;GACT,WAAU;GAEV,UAAA,kBAACjB,GAAD,EAAO,WAAU,UAAW,CAAA;EACtB,CAAA,CAEP;C,KAlBEoB;AAoBX,CACF;AACA,EAAM,cAAc"}
|
|
@@ -3,14 +3,13 @@ import * as t from "react";
|
|
|
3
3
|
import { jsx as n } from "react/jsx-runtime";
|
|
4
4
|
import { cva as r } from "class-variance-authority";
|
|
5
5
|
import * as i from "@radix-ui/react-label";
|
|
6
|
-
|
|
6
|
+
// src/components/ui/label.tsx
|
|
7
7
|
var a = r("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"), o = t.forwardRef(({ className: t, ...r }, o) => /* @__PURE__ */ n(i.Root, {
|
|
8
8
|
ref: o,
|
|
9
9
|
className: e(a(), t),
|
|
10
10
|
...r
|
|
11
11
|
}));
|
|
12
12
|
o.displayName = i.Root.displayName;
|
|
13
|
-
//#endregion
|
|
14
13
|
export { o as Label };
|
|
15
14
|
|
|
16
15
|
//# sourceMappingURL=label.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"label.js","names":[],"sources":["../../../src/components/ui/label.tsx"],"sourcesContent":["import * as LabelPrimitive from \"@radix-ui/react-label\";\nimport { cva } from \"class-variance-authority\";\nimport { type VariantProps } from \"class-variance-authority\";\nimport * as React from \"react\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst labelVariants = cva(\n \"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\",\n);\n\nconst Label = React.forwardRef<\n React.ComponentRef<typeof LabelPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants>\n>(({ className, ...props }, ref) => (\n <LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} />\n));\nLabel.displayName = LabelPrimitive.Root.displayName;\n\nexport { Label };\n"],"mappings":";;;;;;AAOA,
|
|
1
|
+
{"version":3,"file":"label.js","names":["React","React$1","LabelPrimitive","labelVariants","cva","Label","props","cn","className"],"sources":["../../../src/components/ui/label.tsx"],"sourcesContent":["import * as LabelPrimitive from \"@radix-ui/react-label\";\nimport { cva } from \"class-variance-authority\";\nimport { type VariantProps } from \"class-variance-authority\";\nimport * as React from \"react\";\n\nimport { cn } from \"../../lib/utils\";\n\nconst labelVariants = cva(\n \"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\",\n);\n\nconst Label = React.forwardRef<\n React.ComponentRef<typeof LabelPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants>\n>(({ className, ...props }, ref) => (\n <LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} />\n));\nLabel.displayName = LabelPrimitive.Root.displayName;\n\nexport { Label };\n"],"mappings":";;;;;;AAOA,IAAMG,IAAgBC,EACpB,4FACF,GAEMC,IAAQL,EAAM,YAGjB,EAAE,cAAW,GAAGM,KAAS,MAC1B,kBAACJ,EAAe,MAAhB;CAA0B;CAAK,WAAWK,EAAGJ,EAAc,GAAGK,CAAS;CAAG,GAAIF;AAAQ,CAAA,CACvF;AACD,EAAM,cAAcJ,EAAe,KAAK"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as MenubarPrimitive from "@radix-ui/react-menubar";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
declare function MenubarMenu({ ...props }: React.ComponentProps<typeof MenubarPrimitive.Menu>):
|
|
4
|
-
declare function MenubarGroup({ ...props }: React.ComponentProps<typeof MenubarPrimitive.Group>):
|
|
5
|
-
declare function MenubarPortal({ ...props }: React.ComponentProps<typeof MenubarPrimitive.Portal>):
|
|
6
|
-
declare function MenubarRadioGroup({ ...props }: React.ComponentProps<typeof MenubarPrimitive.RadioGroup>):
|
|
7
|
-
declare function MenubarSub({ ...props }: React.ComponentProps<typeof MenubarPrimitive.Sub>):
|
|
3
|
+
declare function MenubarMenu({ ...props }: React.ComponentProps<typeof MenubarPrimitive.Menu>): React.JSX.Element;
|
|
4
|
+
declare function MenubarGroup({ ...props }: React.ComponentProps<typeof MenubarPrimitive.Group>): React.JSX.Element;
|
|
5
|
+
declare function MenubarPortal({ ...props }: React.ComponentProps<typeof MenubarPrimitive.Portal>): React.JSX.Element;
|
|
6
|
+
declare function MenubarRadioGroup({ ...props }: React.ComponentProps<typeof MenubarPrimitive.RadioGroup>): React.JSX.Element;
|
|
7
|
+
declare function MenubarSub({ ...props }: React.ComponentProps<typeof MenubarPrimitive.Sub>): React.JSX.Element;
|
|
8
8
|
declare const Menubar: React.ForwardRefExoticComponent<Omit<MenubarPrimitive.MenubarProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
9
9
|
declare const MenubarTrigger: React.ForwardRefExoticComponent<Omit<MenubarPrimitive.MenubarTriggerProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
10
10
|
declare const MenubarSubTrigger: React.ForwardRefExoticComponent<Omit<MenubarPrimitive.MenubarSubTriggerProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
|
|
@@ -22,7 +22,7 @@ declare const MenubarLabel: React.ForwardRefExoticComponent<Omit<MenubarPrimitiv
|
|
|
22
22
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
23
23
|
declare const MenubarSeparator: React.ForwardRefExoticComponent<Omit<MenubarPrimitive.MenubarSeparatorProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
24
24
|
declare const MenubarShortcut: {
|
|
25
|
-
({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>):
|
|
25
|
+
({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>): React.JSX.Element;
|
|
26
26
|
displayname: string;
|
|
27
27
|
};
|
|
28
28
|
export { Menubar, MenubarMenu, MenubarTrigger, MenubarContent, MenubarItem, MenubarSeparator, MenubarLabel, MenubarCheckboxItem, MenubarRadioGroup, MenubarRadioItem, MenubarPortal, MenubarSubContent, MenubarSubTrigger, MenubarGroup, MenubarSub, MenubarShortcut, };
|
|
@@ -5,7 +5,7 @@ import r from "../../_virtual/~icons/lucide/circle.js";
|
|
|
5
5
|
import * as i from "react";
|
|
6
6
|
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
7
7
|
import * as s from "@radix-ui/react-menubar";
|
|
8
|
-
|
|
8
|
+
// src/components/ui/menubar.tsx
|
|
9
9
|
function c({ ...e }) {
|
|
10
10
|
return /* @__PURE__ */ a(s.Menu, { ...e });
|
|
11
11
|
}
|
|
@@ -102,7 +102,6 @@ var C = ({ className: t, ...n }) => /* @__PURE__ */ a("span", {
|
|
|
102
102
|
...n
|
|
103
103
|
});
|
|
104
104
|
C.displayname = "MenubarShortcut";
|
|
105
|
-
//#endregion
|
|
106
105
|
export { p as Menubar, y as MenubarCheckboxItem, _ as MenubarContent, l as MenubarGroup, v as MenubarItem, x as MenubarLabel, c as MenubarMenu, u as MenubarPortal, d as MenubarRadioGroup, b as MenubarRadioItem, S as MenubarSeparator, C as MenubarShortcut, f as MenubarSub, g as MenubarSubContent, h as MenubarSubTrigger, m as MenubarTrigger };
|
|
107
106
|
|
|
108
107
|
//# sourceMappingURL=menubar.js.map
|