@constructive-io/ui 0.14.2 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ai-B08ufcbD.cjs → ai-DpeOFEwx.cjs} +9 -10
- package/dist/ai-DpeOFEwx.cjs.map +1 -0
- package/dist/{ai-4JrVVL3q.js → ai-b5y3Iqy4.js} +9 -10
- package/dist/ai-b5y3Iqy4.js.map +1 -0
- package/dist/components/ai/index.cjs +1 -1
- package/dist/components/ai/index.js +1 -1
- package/dist/components/autocomplete.cjs +1 -1
- package/dist/components/autocomplete.js +1 -1
- package/dist/components/button.cjs +2 -2
- package/dist/components/button.cjs.map +1 -1
- package/dist/components/button.d.cts +1 -1
- package/dist/components/button.d.ts +1 -1
- package/dist/components/button.js +2 -2
- package/dist/components/button.js.map +1 -1
- package/dist/components/card.d.cts +1 -1
- package/dist/components/card.d.ts +1 -1
- package/dist/components/combobox.cjs +1 -1
- package/dist/components/combobox.js +1 -1
- package/dist/components/command.cjs +1 -1
- package/dist/components/command.js +1 -1
- package/dist/components/dropdown-menu.cjs +8 -7
- package/dist/components/dropdown-menu.cjs.map +1 -1
- package/dist/components/dropdown-menu.js +8 -7
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/input-group.cjs +2 -2
- package/dist/components/input-group.cjs.map +1 -1
- package/dist/components/input-group.js +2 -2
- package/dist/components/input-group.js.map +1 -1
- package/dist/components/input-otp.cjs +5 -2
- package/dist/components/input-otp.cjs.map +1 -1
- package/dist/components/input-otp.js +5 -2
- package/dist/components/input-otp.js.map +1 -1
- package/dist/components/multi-select.cjs +1 -1
- package/dist/components/multi-select.js +1 -1
- package/dist/components/select.cjs +5 -5
- package/dist/components/select.cjs.map +1 -1
- package/dist/components/select.js +5 -5
- package/dist/components/select.js.map +1 -1
- package/dist/components/sheet.cjs +1 -1
- package/dist/components/sheet.js +1 -1
- package/dist/components/sidebar.cjs +1 -1
- package/dist/components/sidebar.js +1 -1
- package/dist/components/toggle-group.cjs +6 -2
- package/dist/components/toggle-group.cjs.map +1 -1
- package/dist/components/toggle-group.js +6 -2
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/workspace-kit/index.cjs +1 -1
- package/dist/components/workspace-kit/index.js +1 -1
- package/dist/{fluid-highlight-YWFRZXsw.cjs → fluid-highlight-B8olepSM.cjs} +7 -5
- package/dist/fluid-highlight-B8olepSM.cjs.map +1 -0
- package/dist/{fluid-highlight-CNELHV8o.js → fluid-highlight-BXVfWNk9.js} +7 -5
- package/dist/fluid-highlight-BXVfWNk9.js.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.js +3 -3
- package/dist/{sheet-OxWlnT_G.cjs → sheet-CGFqOAoI.cjs} +2 -2
- package/dist/{sheet-OxWlnT_G.cjs.map → sheet-CGFqOAoI.cjs.map} +1 -1
- package/dist/{sheet-wPF_l9Cn.js → sheet-LOK_d8-K.js} +2 -2
- package/dist/{sheet-wPF_l9Cn.js.map → sheet-LOK_d8-K.js.map} +1 -1
- package/dist/{sidebar-DWl1Azyv.js → sidebar-BNZkdIvO.js} +2 -2
- package/dist/{sidebar-DWl1Azyv.js.map → sidebar-BNZkdIvO.js.map} +1 -1
- package/dist/{sidebar-BEEWmJwC.cjs → sidebar-Bt7qXsqo.cjs} +2 -2
- package/dist/{sidebar-BEEWmJwC.cjs.map → sidebar-Bt7qXsqo.cjs.map} +1 -1
- package/package.json +2 -2
- package/dist/ai-4JrVVL3q.js.map +0 -1
- package/dist/ai-B08ufcbD.cjs.map +0 -1
- package/dist/fluid-highlight-CNELHV8o.js.map +0 -1
- package/dist/fluid-highlight-YWFRZXsw.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-group.cjs","names":["cn","truncateTextRuns","Input","Textarea"],"sources":["../../src/components/input-group.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport * as React from \"react\";\n\nimport { truncateTextRuns } from \"../lib/text-runs\";\nimport { cn } from \"../lib/utils\";\nimport { Input, type InputProps } from \"./input\";\nimport { Textarea, type TextareaProps } from \"./textarea\";\n\nfunction InputGroup({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n className={cn(\n // Match aria-invalid=\"true\" only. aria-invalid=\"false\" must not paint as invalid.\n \"relative inline-flex w-full min-w-0 items-center overflow-x-clip rounded-md border border-input bg-background bg-clip-padding text-base transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-md)-1px)] not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid=true],textarea[aria-invalid=true]]:before:shadow-[0_1px_--theme(--color-black/4%)] has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:border-destructive/64 has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:ring-destructive/16 has-[textarea]:h-auto has-data-[align=block-end]:h-auto has-data-[align=block-start]:h-auto has-data-[align=block-end]:flex-col has-data-[align=block-start]:flex-col has-[input:focus-visible,textarea:focus-visible]:border-ring/60 has-[input[aria-invalid=true],textarea[aria-invalid=true]]:border-destructive/36 has-[input:disabled,textarea:disabled]:opacity-64 has-[input:disabled,textarea:disabled,input:focus-visible,textarea:focus-visible,input[aria-invalid=true],textarea[aria-invalid=true]]:shadow-none has-[input:focus-visible,textarea:focus-visible]:ring-[3px] has-[input:focus-visible,textarea:focus-visible]:ring-ring/35 sm:text-sm dark:bg-input/32 dark:bg-clip-border dark:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:ring-destructive/24 dark:not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid=true],textarea[aria-invalid=true]]:before:shadow-[0_-1px_--theme(--color-white/8%)] has-data-[align=inline-start]:**:[[data-size=sm]_input]:ps-1.5 has-data-[align=inline-end]:**:[[data-size=sm]_input]:pe-1.5 *:[[data-slot=input-control],[data-slot=textarea-control]]:contents *:[[data-slot=input-control],[data-slot=textarea-control]]:before:hidden has-[[data-align=block-start],[data-align=block-end]]:**:[input]:h-auto has-data-[align=inline-start]:**:[input]:ps-2 has-data-[align=inline-end]:**:[input]:pe-2 has-data-[align=block-end]:**:[input]:pt-1.5 has-data-[align=block-start]:**:[input]:pb-1.5 **:data-[slot=input]:min-w-[max(8ch,35%)] **:data-[slot=input]:flex-1 **:[textarea]:min-h-20.5 **:[textarea]:resize-none **:[textarea]:py-[calc(--spacing(3)-1px)] **:[textarea]:max-sm:min-h-23.5 **:[textarea_button]:rounded-[calc(var(--radius-md)-2px)]\",\n className,\n )}\n data-slot=\"input-group\"\n role=\"group\"\n {...props}\n />\n );\n}\n\nconst inputGroupAddonVariants = cva(\n \"[&_svg]:-mx-0.5 flex h-auto min-w-0 shrink-0 cursor-text select-none items-center justify-center gap-2 has-[[data-slot=input-group-text]]:shrink [&_svg]:shrink-0 [&>kbd]:rounded-[calc(var(--radius)-5px)] in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4.5 sm:in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4 not-has-[button]:**:[svg:not([class*='opacity-'])]:opacity-80\",\n {\n defaultVariants: {\n align: \"inline-start\",\n },\n variants: {\n align: {\n \"block-end\":\n \"order-last w-full justify-start px-[calc(--spacing(3)-1px)] pb-[calc(--spacing(3)-1px)] [.border-t]:pt-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]\",\n \"block-start\":\n \"order-first w-full justify-start px-[calc(--spacing(3)-1px)] pt-[calc(--spacing(3)-1px)] [.border-b]:pb-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]\",\n \"inline-end\":\n \"overflow-x-clip has-[>:last-child[data-slot=badge]]:-me-1.5 has-[>button]:-me-2 order-last pe-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:me-[-0.35rem] [[data-size=sm]+&]:pe-[calc(--spacing(2.5)-1px)]\",\n \"inline-start\":\n \"overflow-x-clip has-[>:last-child[data-slot=badge]]:-ms-1.5 has-[>button]:-ms-2 order-first ps-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:ms-[-0.35rem] [[data-size=sm]+&]:ps-[calc(--spacing(2.5)-1px)]\",\n },\n },\n },\n);\n\nfunction InputGroupAddon({\n className,\n align = \"inline-start\",\n ...props\n}: React.ComponentProps<\"div\"> & VariantProps<typeof inputGroupAddonVariants>) {\n return (\n <div\n className={cn(inputGroupAddonVariants({ align }), className)}\n data-align={align}\n data-slot=\"input-group-addon\"\n onMouseDown={(e) => {\n const target = e.target as HTMLElement;\n const isInteractive = target.closest(\"button, a\");\n if (isInteractive) return;\n e.preventDefault();\n const parent = e.currentTarget.parentElement;\n const input = parent?.querySelector<\n HTMLInputElement | HTMLTextAreaElement\n >(\"input, textarea\");\n if (input && !parent?.querySelector(\"input:focus, textarea:focus\")) {\n input.focus();\n }\n }}\n {...props}\n />\n );\n}\n\nfunction InputGroupText({ className, children, ...props }: React.ComponentProps<\"span\">) {\n return (\n <span\n data-slot=\"input-group-text\"\n className={cn(\n \"[&_svg]:-mx-0.5 flex min-w-0 items-center gap-2 text-subtle-foreground [&_svg]:shrink-0 in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4.5 sm:in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none\",\n className,\n )}\n {...props}\n >\n {truncateTextRuns(children).nodes}\n </span>\n );\n}\n\nfunction InputGroupInput({ className, ...props }: InputProps) {\n return <Input className={className} unstyled {...props} />;\n}\n\nfunction InputGroupTextarea({ className, ...props }: TextareaProps) {\n return <Textarea className={className} unstyled {...props} />;\n}\n\nexport {\n InputGroup,\n InputGroupAddon,\n InputGroupText,\n InputGroupInput,\n InputGroupTextarea,\n};\n"],"mappings":";;;;;;;;;;;;;;AAUA,SAAS,WAAW,EAAE,WAAW,GAAG,SAAsC;CACxE,OACE,2CAAC,OAAD;EACE,WAAWA,iBAET,u6EACA,SACF;EACA,aAAU;EACV,MAAK;EACL,GAAI;CACL;AAEL;AAEA,MAAM,4DACJ,8gBACA;CACE,iBAAiB,EACf,OAAO,eACT;CACA,UAAU,EACR,OAAO;EACL,aACE;EACF,eACE;
|
|
1
|
+
{"version":3,"file":"input-group.cjs","names":["cn","truncateTextRuns","Input","Textarea"],"sources":["../../src/components/input-group.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport * as React from \"react\";\n\nimport { truncateTextRuns } from \"../lib/text-runs\";\nimport { cn } from \"../lib/utils\";\nimport { Input, type InputProps } from \"./input\";\nimport { Textarea, type TextareaProps } from \"./textarea\";\n\nfunction InputGroup({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n className={cn(\n // Match aria-invalid=\"true\" only. aria-invalid=\"false\" must not paint as invalid.\n \"relative inline-flex w-full min-w-0 items-center overflow-x-clip rounded-md border border-input bg-background bg-clip-padding text-base transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-md)-1px)] not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid=true],textarea[aria-invalid=true]]:before:shadow-[0_1px_--theme(--color-black/4%)] has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:border-destructive/64 has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:ring-destructive/16 has-[textarea]:h-auto has-data-[align=block-end]:h-auto has-data-[align=block-start]:h-auto has-data-[align=block-end]:flex-col has-data-[align=block-start]:flex-col has-[input:focus-visible,textarea:focus-visible]:border-ring/60 has-[input[aria-invalid=true],textarea[aria-invalid=true]]:border-destructive/36 has-[input:disabled,textarea:disabled]:opacity-64 has-[input:disabled,textarea:disabled,input:focus-visible,textarea:focus-visible,input[aria-invalid=true],textarea[aria-invalid=true]]:shadow-none has-[input:focus-visible,textarea:focus-visible]:ring-[3px] has-[input:focus-visible,textarea:focus-visible]:ring-ring/35 sm:text-sm dark:bg-input/32 dark:bg-clip-border dark:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:ring-destructive/24 dark:not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid=true],textarea[aria-invalid=true]]:before:shadow-[0_-1px_--theme(--color-white/8%)] has-data-[align=inline-start]:**:[[data-size=sm]_input]:ps-1.5 has-data-[align=inline-end]:**:[[data-size=sm]_input]:pe-1.5 *:[[data-slot=input-control],[data-slot=textarea-control]]:contents *:[[data-slot=input-control],[data-slot=textarea-control]]:before:hidden has-[[data-align=block-start],[data-align=block-end]]:**:[input]:h-auto has-data-[align=inline-start]:**:[input]:ps-2 has-data-[align=inline-end]:**:[input]:pe-2 has-data-[align=block-end]:**:[input]:pt-1.5 has-data-[align=block-start]:**:[input]:pb-1.5 **:data-[slot=input]:min-w-[max(8ch,35%)] **:data-[slot=input]:flex-1 **:[textarea]:min-h-20.5 **:[textarea]:resize-none **:[textarea]:py-[calc(--spacing(3)-1px)] **:[textarea]:max-sm:min-h-23.5 **:[textarea_button]:rounded-[calc(var(--radius-md)-2px)]\",\n className,\n )}\n data-slot=\"input-group\"\n role=\"group\"\n {...props}\n />\n );\n}\n\nconst inputGroupAddonVariants = cva(\n \"[&_svg]:-mx-0.5 flex h-auto min-w-0 shrink-0 cursor-text select-none items-center justify-center gap-2 has-[[data-slot=input-group-text]]:shrink [&_svg]:shrink-0 [&>kbd]:rounded-[calc(var(--radius)-5px)] in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4.5 sm:in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4 not-has-[button]:**:[svg:not([class*='opacity-'])]:opacity-80\",\n {\n defaultVariants: {\n align: \"inline-start\",\n },\n variants: {\n align: {\n \"block-end\":\n \"order-last w-full justify-start px-[calc(--spacing(3)-1px)] pb-[calc(--spacing(3)-1px)] [.border-t]:pt-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]\",\n \"block-start\":\n \"order-first w-full justify-start px-[calc(--spacing(3)-1px)] pt-[calc(--spacing(3)-1px)] [.border-b]:pb-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]\",\n // `[&_svg]:-mx-0.5` lets an icon hang 2px past the addon's content box, and\n // `overflow-x-clip` cuts at the padding box, so the inner side gets 2px of\n // padding for the icon and a matching negative margin that keeps the input\n // where it was.\n \"inline-end\":\n \"overflow-x-clip ps-0.5 -ms-0.5 has-[>:last-child[data-slot=badge]]:-me-1.5 has-[>button]:-me-2 order-last pe-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:me-[-0.35rem] [[data-size=sm]+&]:pe-[calc(--spacing(2.5)-1px)]\",\n \"inline-start\":\n \"overflow-x-clip pe-0.5 -me-0.5 has-[>:last-child[data-slot=badge]]:-ms-1.5 has-[>button]:-ms-2 order-first ps-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:ms-[-0.35rem] [[data-size=sm]+&]:ps-[calc(--spacing(2.5)-1px)]\",\n },\n },\n },\n);\n\nfunction InputGroupAddon({\n className,\n align = \"inline-start\",\n ...props\n}: React.ComponentProps<\"div\"> & VariantProps<typeof inputGroupAddonVariants>) {\n return (\n <div\n className={cn(inputGroupAddonVariants({ align }), className)}\n data-align={align}\n data-slot=\"input-group-addon\"\n onMouseDown={(e) => {\n const target = e.target as HTMLElement;\n const isInteractive = target.closest(\"button, a\");\n if (isInteractive) return;\n e.preventDefault();\n const parent = e.currentTarget.parentElement;\n const input = parent?.querySelector<\n HTMLInputElement | HTMLTextAreaElement\n >(\"input, textarea\");\n if (input && !parent?.querySelector(\"input:focus, textarea:focus\")) {\n input.focus();\n }\n }}\n {...props}\n />\n );\n}\n\nfunction InputGroupText({ className, children, ...props }: React.ComponentProps<\"span\">) {\n return (\n <span\n data-slot=\"input-group-text\"\n className={cn(\n \"[&_svg]:-mx-0.5 flex min-w-0 items-center gap-2 text-subtle-foreground [&_svg]:shrink-0 in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4.5 sm:in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none\",\n className,\n )}\n {...props}\n >\n {truncateTextRuns(children).nodes}\n </span>\n );\n}\n\nfunction InputGroupInput({ className, ...props }: InputProps) {\n return <Input className={className} unstyled {...props} />;\n}\n\nfunction InputGroupTextarea({ className, ...props }: TextareaProps) {\n return <Textarea className={className} unstyled {...props} />;\n}\n\nexport {\n InputGroup,\n InputGroupAddon,\n InputGroupText,\n InputGroupInput,\n InputGroupTextarea,\n};\n"],"mappings":";;;;;;;;;;;;;;AAUA,SAAS,WAAW,EAAE,WAAW,GAAG,SAAsC;CACxE,OACE,2CAAC,OAAD;EACE,WAAWA,iBAET,u6EACA,SACF;EACA,aAAU;EACV,MAAK;EACL,GAAI;CACL;AAEL;AAEA,MAAM,4DACJ,8gBACA;CACE,iBAAiB,EACf,OAAO,eACT;CACA,UAAU,EACR,OAAO;EACL,aACE;EACF,eACE;EAKF,cACE;EACF,gBACE;CACJ,EACF;AACF,CACF;AAEA,SAAS,gBAAgB,EACvB,WACA,QAAQ,gBACR,GAAG,SAC0E;CAC7E,OACE,2CAAC,OAAD;EACE,WAAWA,iBAAG,wBAAwB,EAAE,MAAM,CAAC,GAAG,SAAS;EAC3D,cAAY;EACZ,aAAU;EACV,cAAc,MAAM;GAGlB,IAFe,EAAE,OACY,QAAQ,WACrB,GAAG;GACnB,EAAE,eAAe;GACjB,MAAM,SAAS,EAAE,cAAc;GAC/B,MAAM,QAAQ,QAAQ,cAEpB,iBAAiB;GACnB,IAAI,SAAS,CAAC,QAAQ,cAAc,6BAA6B,GAC/D,MAAM,MAAM;EAEhB;EACA,GAAI;CACL;AAEL;AAEA,SAAS,eAAe,EAAE,WAAW,UAAU,GAAG,SAAuC;CACvF,OACE,2CAAC,QAAD;EACE,aAAU;EACV,WAAWA,iBACT,wXACA,SACF;EACA,GAAI;YAEHC,mCAAiB,QAAQ,CAAC,CAAC;CACxB;AAEV;AAEA,SAAS,gBAAgB,EAAE,WAAW,GAAG,SAAqB;CAC5D,OAAO,2CAACC,gCAAD;EAAkB;EAAW;EAAS,GAAI;CAAQ;AAC3D;AAEA,SAAS,mBAAmB,EAAE,WAAW,GAAG,SAAwB;CAClE,OAAO,2CAACC,sCAAD;EAAqB;EAAW;EAAS,GAAI;CAAQ;AAC9D"}
|
|
@@ -22,8 +22,8 @@ const inputGroupAddonVariants = cva("[&_svg]:-mx-0.5 flex h-auto min-w-0 shrink-
|
|
|
22
22
|
variants: { align: {
|
|
23
23
|
"block-end": "order-last w-full justify-start px-[calc(--spacing(3)-1px)] pb-[calc(--spacing(3)-1px)] [.border-t]:pt-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]",
|
|
24
24
|
"block-start": "order-first w-full justify-start px-[calc(--spacing(3)-1px)] pt-[calc(--spacing(3)-1px)] [.border-b]:pb-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]",
|
|
25
|
-
"inline-end": "overflow-x-clip has-[>:last-child[data-slot=badge]]:-me-1.5 has-[>button]:-me-2 order-last pe-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:me-[-0.35rem] [[data-size=sm]+&]:pe-[calc(--spacing(2.5)-1px)]",
|
|
26
|
-
"inline-start": "overflow-x-clip has-[>:last-child[data-slot=badge]]:-ms-1.5 has-[>button]:-ms-2 order-first ps-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:ms-[-0.35rem] [[data-size=sm]+&]:ps-[calc(--spacing(2.5)-1px)]"
|
|
25
|
+
"inline-end": "overflow-x-clip ps-0.5 -ms-0.5 has-[>:last-child[data-slot=badge]]:-me-1.5 has-[>button]:-me-2 order-last pe-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:me-[-0.35rem] [[data-size=sm]+&]:pe-[calc(--spacing(2.5)-1px)]",
|
|
26
|
+
"inline-start": "overflow-x-clip pe-0.5 -me-0.5 has-[>:last-child[data-slot=badge]]:-ms-1.5 has-[>button]:-ms-2 order-first ps-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:ms-[-0.35rem] [[data-size=sm]+&]:ps-[calc(--spacing(2.5)-1px)]"
|
|
27
27
|
} }
|
|
28
28
|
});
|
|
29
29
|
function InputGroupAddon({ className, align = "inline-start", ...props }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-group.js","names":[],"sources":["../../src/components/input-group.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport * as React from \"react\";\n\nimport { truncateTextRuns } from \"../lib/text-runs\";\nimport { cn } from \"../lib/utils\";\nimport { Input, type InputProps } from \"./input\";\nimport { Textarea, type TextareaProps } from \"./textarea\";\n\nfunction InputGroup({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n className={cn(\n // Match aria-invalid=\"true\" only. aria-invalid=\"false\" must not paint as invalid.\n \"relative inline-flex w-full min-w-0 items-center overflow-x-clip rounded-md border border-input bg-background bg-clip-padding text-base transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-md)-1px)] not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid=true],textarea[aria-invalid=true]]:before:shadow-[0_1px_--theme(--color-black/4%)] has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:border-destructive/64 has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:ring-destructive/16 has-[textarea]:h-auto has-data-[align=block-end]:h-auto has-data-[align=block-start]:h-auto has-data-[align=block-end]:flex-col has-data-[align=block-start]:flex-col has-[input:focus-visible,textarea:focus-visible]:border-ring/60 has-[input[aria-invalid=true],textarea[aria-invalid=true]]:border-destructive/36 has-[input:disabled,textarea:disabled]:opacity-64 has-[input:disabled,textarea:disabled,input:focus-visible,textarea:focus-visible,input[aria-invalid=true],textarea[aria-invalid=true]]:shadow-none has-[input:focus-visible,textarea:focus-visible]:ring-[3px] has-[input:focus-visible,textarea:focus-visible]:ring-ring/35 sm:text-sm dark:bg-input/32 dark:bg-clip-border dark:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:ring-destructive/24 dark:not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid=true],textarea[aria-invalid=true]]:before:shadow-[0_-1px_--theme(--color-white/8%)] has-data-[align=inline-start]:**:[[data-size=sm]_input]:ps-1.5 has-data-[align=inline-end]:**:[[data-size=sm]_input]:pe-1.5 *:[[data-slot=input-control],[data-slot=textarea-control]]:contents *:[[data-slot=input-control],[data-slot=textarea-control]]:before:hidden has-[[data-align=block-start],[data-align=block-end]]:**:[input]:h-auto has-data-[align=inline-start]:**:[input]:ps-2 has-data-[align=inline-end]:**:[input]:pe-2 has-data-[align=block-end]:**:[input]:pt-1.5 has-data-[align=block-start]:**:[input]:pb-1.5 **:data-[slot=input]:min-w-[max(8ch,35%)] **:data-[slot=input]:flex-1 **:[textarea]:min-h-20.5 **:[textarea]:resize-none **:[textarea]:py-[calc(--spacing(3)-1px)] **:[textarea]:max-sm:min-h-23.5 **:[textarea_button]:rounded-[calc(var(--radius-md)-2px)]\",\n className,\n )}\n data-slot=\"input-group\"\n role=\"group\"\n {...props}\n />\n );\n}\n\nconst inputGroupAddonVariants = cva(\n \"[&_svg]:-mx-0.5 flex h-auto min-w-0 shrink-0 cursor-text select-none items-center justify-center gap-2 has-[[data-slot=input-group-text]]:shrink [&_svg]:shrink-0 [&>kbd]:rounded-[calc(var(--radius)-5px)] in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4.5 sm:in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4 not-has-[button]:**:[svg:not([class*='opacity-'])]:opacity-80\",\n {\n defaultVariants: {\n align: \"inline-start\",\n },\n variants: {\n align: {\n \"block-end\":\n \"order-last w-full justify-start px-[calc(--spacing(3)-1px)] pb-[calc(--spacing(3)-1px)] [.border-t]:pt-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]\",\n \"block-start\":\n \"order-first w-full justify-start px-[calc(--spacing(3)-1px)] pt-[calc(--spacing(3)-1px)] [.border-b]:pb-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]\",\n \"inline-end\":\n \"overflow-x-clip has-[>:last-child[data-slot=badge]]:-me-1.5 has-[>button]:-me-2 order-last pe-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:me-[-0.35rem] [[data-size=sm]+&]:pe-[calc(--spacing(2.5)-1px)]\",\n \"inline-start\":\n \"overflow-x-clip has-[>:last-child[data-slot=badge]]:-ms-1.5 has-[>button]:-ms-2 order-first ps-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:ms-[-0.35rem] [[data-size=sm]+&]:ps-[calc(--spacing(2.5)-1px)]\",\n },\n },\n },\n);\n\nfunction InputGroupAddon({\n className,\n align = \"inline-start\",\n ...props\n}: React.ComponentProps<\"div\"> & VariantProps<typeof inputGroupAddonVariants>) {\n return (\n <div\n className={cn(inputGroupAddonVariants({ align }), className)}\n data-align={align}\n data-slot=\"input-group-addon\"\n onMouseDown={(e) => {\n const target = e.target as HTMLElement;\n const isInteractive = target.closest(\"button, a\");\n if (isInteractive) return;\n e.preventDefault();\n const parent = e.currentTarget.parentElement;\n const input = parent?.querySelector<\n HTMLInputElement | HTMLTextAreaElement\n >(\"input, textarea\");\n if (input && !parent?.querySelector(\"input:focus, textarea:focus\")) {\n input.focus();\n }\n }}\n {...props}\n />\n );\n}\n\nfunction InputGroupText({ className, children, ...props }: React.ComponentProps<\"span\">) {\n return (\n <span\n data-slot=\"input-group-text\"\n className={cn(\n \"[&_svg]:-mx-0.5 flex min-w-0 items-center gap-2 text-subtle-foreground [&_svg]:shrink-0 in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4.5 sm:in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none\",\n className,\n )}\n {...props}\n >\n {truncateTextRuns(children).nodes}\n </span>\n );\n}\n\nfunction InputGroupInput({ className, ...props }: InputProps) {\n return <Input className={className} unstyled {...props} />;\n}\n\nfunction InputGroupTextarea({ className, ...props }: TextareaProps) {\n return <Textarea className={className} unstyled {...props} />;\n}\n\nexport {\n InputGroup,\n InputGroupAddon,\n InputGroupText,\n InputGroupInput,\n InputGroupTextarea,\n};\n"],"mappings":";;;;;;;;;;;AAUA,SAAS,WAAW,EAAE,WAAW,GAAG,SAAsC;CACxE,OACE,oBAAC,OAAD;EACE,WAAW,GAET,u6EACA,SACF;EACA,aAAU;EACV,MAAK;EACL,GAAI;CACL;AAEL;AAEA,MAAM,0BAA0B,IAC9B,8gBACA;CACE,iBAAiB,EACf,OAAO,eACT;CACA,UAAU,EACR,OAAO;EACL,aACE;EACF,eACE;
|
|
1
|
+
{"version":3,"file":"input-group.js","names":[],"sources":["../../src/components/input-group.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport * as React from \"react\";\n\nimport { truncateTextRuns } from \"../lib/text-runs\";\nimport { cn } from \"../lib/utils\";\nimport { Input, type InputProps } from \"./input\";\nimport { Textarea, type TextareaProps } from \"./textarea\";\n\nfunction InputGroup({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n className={cn(\n // Match aria-invalid=\"true\" only. aria-invalid=\"false\" must not paint as invalid.\n \"relative inline-flex w-full min-w-0 items-center overflow-x-clip rounded-md border border-input bg-background bg-clip-padding text-base transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-md)-1px)] not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid=true],textarea[aria-invalid=true]]:before:shadow-[0_1px_--theme(--color-black/4%)] has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:border-destructive/64 has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:ring-destructive/16 has-[textarea]:h-auto has-data-[align=block-end]:h-auto has-data-[align=block-start]:h-auto has-data-[align=block-end]:flex-col has-data-[align=block-start]:flex-col has-[input:focus-visible,textarea:focus-visible]:border-ring/60 has-[input[aria-invalid=true],textarea[aria-invalid=true]]:border-destructive/36 has-[input:disabled,textarea:disabled]:opacity-64 has-[input:disabled,textarea:disabled,input:focus-visible,textarea:focus-visible,input[aria-invalid=true],textarea[aria-invalid=true]]:shadow-none has-[input:focus-visible,textarea:focus-visible]:ring-[3px] has-[input:focus-visible,textarea:focus-visible]:ring-ring/35 sm:text-sm dark:bg-input/32 dark:bg-clip-border dark:has-[input[aria-invalid=true],textarea[aria-invalid=true]]:ring-destructive/24 dark:not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid=true],textarea[aria-invalid=true]]:before:shadow-[0_-1px_--theme(--color-white/8%)] has-data-[align=inline-start]:**:[[data-size=sm]_input]:ps-1.5 has-data-[align=inline-end]:**:[[data-size=sm]_input]:pe-1.5 *:[[data-slot=input-control],[data-slot=textarea-control]]:contents *:[[data-slot=input-control],[data-slot=textarea-control]]:before:hidden has-[[data-align=block-start],[data-align=block-end]]:**:[input]:h-auto has-data-[align=inline-start]:**:[input]:ps-2 has-data-[align=inline-end]:**:[input]:pe-2 has-data-[align=block-end]:**:[input]:pt-1.5 has-data-[align=block-start]:**:[input]:pb-1.5 **:data-[slot=input]:min-w-[max(8ch,35%)] **:data-[slot=input]:flex-1 **:[textarea]:min-h-20.5 **:[textarea]:resize-none **:[textarea]:py-[calc(--spacing(3)-1px)] **:[textarea]:max-sm:min-h-23.5 **:[textarea_button]:rounded-[calc(var(--radius-md)-2px)]\",\n className,\n )}\n data-slot=\"input-group\"\n role=\"group\"\n {...props}\n />\n );\n}\n\nconst inputGroupAddonVariants = cva(\n \"[&_svg]:-mx-0.5 flex h-auto min-w-0 shrink-0 cursor-text select-none items-center justify-center gap-2 has-[[data-slot=input-group-text]]:shrink [&_svg]:shrink-0 [&>kbd]:rounded-[calc(var(--radius)-5px)] in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4.5 sm:in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4 not-has-[button]:**:[svg:not([class*='opacity-'])]:opacity-80\",\n {\n defaultVariants: {\n align: \"inline-start\",\n },\n variants: {\n align: {\n \"block-end\":\n \"order-last w-full justify-start px-[calc(--spacing(3)-1px)] pb-[calc(--spacing(3)-1px)] [.border-t]:pt-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]\",\n \"block-start\":\n \"order-first w-full justify-start px-[calc(--spacing(3)-1px)] pt-[calc(--spacing(3)-1px)] [.border-b]:pb-[calc(--spacing(3)-1px)] [[data-size=sm]+&]:px-[calc(--spacing(2.5)-1px)]\",\n // `[&_svg]:-mx-0.5` lets an icon hang 2px past the addon's content box, and\n // `overflow-x-clip` cuts at the padding box, so the inner side gets 2px of\n // padding for the icon and a matching negative margin that keeps the input\n // where it was.\n \"inline-end\":\n \"overflow-x-clip ps-0.5 -ms-0.5 has-[>:last-child[data-slot=badge]]:-me-1.5 has-[>button]:-me-2 order-last pe-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:me-[-0.35rem] [[data-size=sm]+&]:pe-[calc(--spacing(2.5)-1px)]\",\n \"inline-start\":\n \"overflow-x-clip pe-0.5 -me-0.5 has-[>:last-child[data-slot=badge]]:-ms-1.5 has-[>button]:-ms-2 order-first ps-[calc(--spacing(3)-1px)] has-[>kbd:last-child]:ms-[-0.35rem] [[data-size=sm]+&]:ps-[calc(--spacing(2.5)-1px)]\",\n },\n },\n },\n);\n\nfunction InputGroupAddon({\n className,\n align = \"inline-start\",\n ...props\n}: React.ComponentProps<\"div\"> & VariantProps<typeof inputGroupAddonVariants>) {\n return (\n <div\n className={cn(inputGroupAddonVariants({ align }), className)}\n data-align={align}\n data-slot=\"input-group-addon\"\n onMouseDown={(e) => {\n const target = e.target as HTMLElement;\n const isInteractive = target.closest(\"button, a\");\n if (isInteractive) return;\n e.preventDefault();\n const parent = e.currentTarget.parentElement;\n const input = parent?.querySelector<\n HTMLInputElement | HTMLTextAreaElement\n >(\"input, textarea\");\n if (input && !parent?.querySelector(\"input:focus, textarea:focus\")) {\n input.focus();\n }\n }}\n {...props}\n />\n );\n}\n\nfunction InputGroupText({ className, children, ...props }: React.ComponentProps<\"span\">) {\n return (\n <span\n data-slot=\"input-group-text\"\n className={cn(\n \"[&_svg]:-mx-0.5 flex min-w-0 items-center gap-2 text-subtle-foreground [&_svg]:shrink-0 in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4.5 sm:in-[[data-slot=input-group]:has([data-slot=input-control],[data-slot=textarea-control])]:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none\",\n className,\n )}\n {...props}\n >\n {truncateTextRuns(children).nodes}\n </span>\n );\n}\n\nfunction InputGroupInput({ className, ...props }: InputProps) {\n return <Input className={className} unstyled {...props} />;\n}\n\nfunction InputGroupTextarea({ className, ...props }: TextareaProps) {\n return <Textarea className={className} unstyled {...props} />;\n}\n\nexport {\n InputGroup,\n InputGroupAddon,\n InputGroupText,\n InputGroupInput,\n InputGroupTextarea,\n};\n"],"mappings":";;;;;;;;;;;AAUA,SAAS,WAAW,EAAE,WAAW,GAAG,SAAsC;CACxE,OACE,oBAAC,OAAD;EACE,WAAW,GAET,u6EACA,SACF;EACA,aAAU;EACV,MAAK;EACL,GAAI;CACL;AAEL;AAEA,MAAM,0BAA0B,IAC9B,8gBACA;CACE,iBAAiB,EACf,OAAO,eACT;CACA,UAAU,EACR,OAAO;EACL,aACE;EACF,eACE;EAKF,cACE;EACF,gBACE;CACJ,EACF;AACF,CACF;AAEA,SAAS,gBAAgB,EACvB,WACA,QAAQ,gBACR,GAAG,SAC0E;CAC7E,OACE,oBAAC,OAAD;EACE,WAAW,GAAG,wBAAwB,EAAE,MAAM,CAAC,GAAG,SAAS;EAC3D,cAAY;EACZ,aAAU;EACV,cAAc,MAAM;GAGlB,IAFe,EAAE,OACY,QAAQ,WACrB,GAAG;GACnB,EAAE,eAAe;GACjB,MAAM,SAAS,EAAE,cAAc;GAC/B,MAAM,QAAQ,QAAQ,cAEpB,iBAAiB;GACnB,IAAI,SAAS,CAAC,QAAQ,cAAc,6BAA6B,GAC/D,MAAM,MAAM;EAEhB;EACA,GAAI;CACL;AAEL;AAEA,SAAS,eAAe,EAAE,WAAW,UAAU,GAAG,SAAuC;CACvF,OACE,oBAAC,QAAD;EACE,aAAU;EACV,WAAW,GACT,wXACA,SACF;EACA,GAAI;YAEH,iBAAiB,QAAQ,CAAC,CAAC;CACxB;AAEV;AAEA,SAAS,gBAAgB,EAAE,WAAW,GAAG,SAAqB;CAC5D,OAAO,oBAAC,OAAD;EAAkB;EAAW;EAAS,GAAI;CAAQ;AAC3D;AAEA,SAAS,mBAAmB,EAAE,WAAW,GAAG,SAAwB;CAClE,OAAO,oBAAC,UAAD;EAAqB;EAAW;EAAS,GAAI;CAAQ;AAC9D"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
const require_utils = require('../utils-CzTQ3-VI.cjs');
|
|
5
|
-
const require_fluid_highlight = require('../fluid-highlight-
|
|
5
|
+
const require_fluid_highlight = require('../fluid-highlight-B8olepSM.cjs');
|
|
6
6
|
let react = require("react");
|
|
7
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
8
|
let motion_react = require("motion/react");
|
|
@@ -222,7 +222,10 @@ function InputOtp({ length = 6, value, defaultValue = "", onChange, onComplete,
|
|
|
222
222
|
})]
|
|
223
223
|
}, index);
|
|
224
224
|
}),
|
|
225
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_fluid_highlight.FluidHighlight, {
|
|
225
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_fluid_highlight.FluidHighlight, {
|
|
226
|
+
travel: true,
|
|
227
|
+
className: require_utils.cn("z-10 border bg-transparent", size === "sm" ? "rounded-md" : "rounded-lg", isInvalid ? "border-destructive ring-[3px] ring-destructive/25" : "border-ring/60 ring-[3px] ring-ring/35")
|
|
228
|
+
}),
|
|
226
229
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
227
230
|
ref: inputRef,
|
|
228
231
|
type: "text",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-otp.cjs","names":["cn","motion","FluidHighlight"],"sources":["../../src/components/input-otp.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useState, type ChangeEvent, type ClipboardEvent, type FocusEvent, type Ref } from 'react';\nimport { motion, useAnimate, useReducedMotion, type Transition } from 'motion/react';\n\nimport { FluidHighlight } from '../lib/motion/fluid-highlight';\nimport { cn } from '../lib/utils';\n\n/**\n * One-time-code input: one slot per digit, side by side.\n *\n * The slots are drawn, not typed into. A single transparent `<input>` lies over the whole row and owns the value,\n * the caret, and the selection; the slots mirror it. That one-field model is what makes the code behave like text:\n *\n * type fills the selected slot and moves on\n * Backspace deletes like any text field; later digits close the gap\n * ⌘A / Shift selects across slots, so cut, copy, and paste work on the whole code or a slice of it\n * paste strips separators and inserts at the caret; a complete code replaces the value outright\n * autofill the OS hands the whole code to the one field, which is all `autoComplete=\"one-time-code\"` needs\n *\n * It also means one tab stop and one labelled field for assistive tech, rather than six \"digit N\" boxes.\n *\n * Because the real glyphs and caret are transparent, the slots can animate what the user sees: digits rise into\n * place, a drawn caret blinks in the empty active slot, the focus ring glides between slots, and the row shakes\n * once when the code turns invalid. All of it stands still under reduced motion.\n */\ninterface InputOtpProps {\n\t/** Number of digit slots. */\n\tlength?: number;\n\t/** Controlled value. Non-digits are dropped and longer strings are truncated to `length`. */\n\tvalue?: string;\n\tdefaultValue?: string;\n\tonChange?: (value: string) => void;\n\t/** Fires when an edit leaves every slot filled with a code that differs from the previous one. */\n\tonComplete?: (value: string) => void;\n\tisDisabled?: boolean;\n\tisInvalid?: boolean;\n\t/** Renders a gap between groups, e.g. `3` gives 000 000. */\n\tgroupEvery?: number;\n\t/** `sm` fits the code into an inline row (e.g. a settings list) instead of a dialog. */\n\tsize?: 'default' | 'sm';\n\t'aria-label'?: string;\n\t'aria-describedby'?: string;\n\tclassName?: string;\n\tref?: Ref<HTMLDivElement>;\n}\n\ninterface SlotSelection {\n\tstart: number;\n\tend: number;\n}\n\ntype SelectionDirection = 'forward' | 'backward' | 'none';\n\nconst DIGITS_ONLY = /\\D/g;\n// Arabic-Indic, Persian, Devanagari, Bengali, Thai and full-width digits come from native numeric keyboards and IMEs.\n// They map to ASCII before everything else is dropped, so a code typed or pasted in them is not silently discarded.\nconst NON_ASCII_DIGITS = /[\\u0660-\\u0669\\u06F0-\\u06F9\\u0966-\\u096F\\u09E6-\\u09EF\\u0E50-\\u0E59\\uFF10-\\uFF19]/g;\nconst ZERO_CODE_POINTS = [0x0660, 0x06f0, 0x0966, 0x09e6, 0x0e50, 0xff10];\nconst toAsciiDigits = (raw: string) =>\n\traw.replace(NON_ASCII_DIGITS, (char) => {\n\t\tconst code = char.charCodeAt(0);\n\t\tconst zero = ZERO_CODE_POINTS.find((start) => code >= start && code <= start + 9)!;\n\t\treturn String(code - zero);\n\t});\n// Chrome restores autofill styling and the caret position a beat after a value change, so the mirror re-reads them.\nconst RESYNC_DELAYS = [0, 10, 50];\n// A hard on/off blink, like a text caret, rather than a fade.\nconst CARET_BLINK = { opacity: [1, 1, 0, 0] };\nconst CARET_TIMING: Transition = { duration: 1, times: [0, 0.5, 0.5, 1], ease: 'linear', repeat: Infinity };\n\nconst toCode = (raw: string, length: number) => toAsciiDigits(raw).replace(DIGITS_ONLY, '').slice(0, length);\n\nfunction InputOtp({\n\tlength = 6,\n\tvalue,\n\tdefaultValue = '',\n\tonChange,\n\tonComplete,\n\tisDisabled = false,\n\tisInvalid = false,\n\tgroupEvery,\n\tsize = 'default',\n\t'aria-label': ariaLabel = 'One-time code',\n\t'aria-describedby': ariaDescribedBy,\n\tclassName,\n\tref,\n}: InputOtpProps) {\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\tconst previousSelection = useRef<[number | null, number | null, SelectionDirection]>([null, null, 'none']);\n\tconst wasInvalid = useRef(isInvalid);\n\tconst [rowRef, animate] = useAnimate<HTMLDivElement>();\n\tconst reduceMotion = useReducedMotion();\n\tconst [internal, setInternal] = useState(() => toCode(defaultValue, length));\n\tconst [isFocused, setIsFocused] = useState(false);\n\tconst [selection, setSelection] = useState<SlotSelection | null>(null);\n\n\tconst controlled = value !== undefined;\n\tconst code = toCode(controlled ? value : internal, length);\n\n\tconst mirror = (start: number, end: number) =>\n\t\tsetSelection((current) => (current?.start === start && current.end === end ? current : { start, end }));\n\n\tconst commit = (next: string) => {\n\t\tif (next === code) return;\n\t\tif (!controlled) setInternal(next);\n\t\tonChange?.(next);\n\t\t// Comparing against the previous code keeps a re-render or an identical paste from verifying twice, while\n\t\t// correcting one digit of a full code still counts as a new attempt.\n\t\tif (next.length === length) onComplete?.(next);\n\t};\n\n\tuseEffect(() => {\n\t\tconst input = inputRef.current;\n\t\tif (!input) return;\n\n\t\t// The native caret only ever sits between characters. Over a slot, that reads as nothing being selected, so\n\t\t// a collapsed caret inside a full run is widened to select the digit after it (or before it, when moving left).\n\t\tconst syncSelection = () => {\n\t\t\tif (document.activeElement !== input) {\n\t\t\t\tsetSelection(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { selectionStart, selectionEnd, selectionDirection, maxLength, value: current } = input;\n\t\t\tconst [, previousEnd] = previousSelection.current;\n\t\t\tlet start = -1;\n\t\t\tlet end = -1;\n\t\t\tlet direction: SelectionDirection | undefined;\n\n\t\t\tif (current.length !== 0 && selectionStart !== null && selectionEnd !== null) {\n\t\t\t\tconst isCaret = selectionStart === selectionEnd;\n\t\t\t\tconst isAppending = selectionStart === current.length && current.length < maxLength;\n\t\t\t\tif (isCaret && !isAppending) {\n\t\t\t\t\tconst caret = selectionStart;\n\t\t\t\t\tif (caret === 0) {\n\t\t\t\t\t\t[start, end, direction] = [0, 1, 'forward'];\n\t\t\t\t\t} else if (caret === maxLength) {\n\t\t\t\t\t\t[start, end, direction] = [caret - 1, caret, 'backward'];\n\t\t\t\t\t} else if (maxLength > 1 && current.length > 1) {\n\t\t\t\t\t\tlet offset = 0;\n\t\t\t\t\t\tconst [previousStart] = previousSelection.current;\n\t\t\t\t\t\tif (previousStart !== null && previousEnd !== null) {\n\t\t\t\t\t\t\tdirection = caret < previousEnd ? 'backward' : 'forward';\n\t\t\t\t\t\t\tconst wasAppending = previousStart === previousEnd && previousStart < maxLength;\n\t\t\t\t\t\t\tif (direction === 'backward' && !wasAppending) offset = -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstart = caret + offset;\n\t\t\t\t\t\tend = caret + offset + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (start !== -1 && end !== -1 && start !== end) input.setSelectionRange(start, end, direction);\n\t\t\t}\n\n\t\t\tconst nextStart = start !== -1 ? start : (selectionStart ?? 0);\n\t\t\tconst nextEnd = end !== -1 ? end : (selectionEnd ?? 0);\n\t\t\tmirror(nextStart, nextEnd);\n\t\t\tpreviousSelection.current = [nextStart, nextEnd, direction ?? selectionDirection ?? 'none'];\n\t\t};\n\n\t\tdocument.addEventListener('selectionchange', syncSelection, { capture: true });\n\t\tsyncSelection();\n\t\tif (document.activeElement === input) setIsFocused(true);\n\t\treturn () => document.removeEventListener('selectionchange', syncSelection, { capture: true });\n\t}, []);\n\n\tuseEffect(() => {\n\t\tconst timeouts = RESYNC_DELAYS.map((delay) =>\n\t\t\tsetTimeout(() => {\n\t\t\t\tconst input = inputRef.current;\n\t\t\t\tif (!input) return;\n\t\t\t\t// A non-bubbling `input` event clears Chrome's `:autofill` state without reaching React's onChange.\n\t\t\t\tinput.dispatchEvent(new Event('input'));\n\t\t\t\tif (document.activeElement !== input || input.selectionStart === null || input.selectionEnd === null) return;\n\t\t\t\tmirror(input.selectionStart, input.selectionEnd);\n\t\t\t\tpreviousSelection.current = [input.selectionStart, input.selectionEnd, input.selectionDirection ?? 'none'];\n\t\t\t}, delay),\n\t\t);\n\t\treturn () => timeouts.forEach(clearTimeout);\n\t}, [code, isFocused]);\n\n\tuseEffect(() => {\n\t\tconst turnedInvalid = isInvalid && !wasInvalid.current;\n\t\twasInvalid.current = isInvalid;\n\t\tif (!turnedInvalid || reduceMotion || !rowRef.current) return;\n\t\tanimate(rowRef.current, { x: [0, -6, 6, -4, 4, -2, 0] }, { duration: 0.4, ease: 'easeInOut' });\n\t}, [isInvalid, reduceMotion, animate, rowRef]);\n\n\tconst onInputChange = (event: ChangeEvent<HTMLInputElement>) => {\n\t\tconst next = toCode(event.target.value, length);\n\t\t// Deleting doesn't fire `selectionchange`, so the mirror is nudged by hand.\n\t\tif (next.length < code.length) document.dispatchEvent(new Event('selectionchange'));\n\t\tcommit(next);\n\t};\n\n\tconst onPaste = (event: ClipboardEvent<HTMLInputElement>) => {\n\t\t// Always handled here: a native paste of \"123 456\" would be cut to `maxLength` before the spaces were dropped,\n\t\t// and iOS pastes over the whole field rather than at the caret.\n\t\tevent.preventDefault();\n\t\tconst input = event.currentTarget;\n\t\tconst pasted = toAsciiDigits(event.clipboardData.getData('text/plain')).replace(DIGITS_ONLY, '');\n\t\tif (pasted === '') return;\n\t\tconst start = input.selectionStart ?? code.length;\n\t\tconst end = input.selectionEnd ?? start;\n\t\t// A complete code replaces the value even when the caret is mid-way; it's an autofill or a copied message.\n\t\tconst next =\n\t\t\tpasted.length >= length ? pasted.slice(0, length) : (code.slice(0, start) + pasted + code.slice(end)).slice(0, length);\n\t\tinput.value = next;\n\t\tcommit(next);\n\t\tconst caret = Math.min(next.length, length - 1);\n\t\tinput.setSelectionRange(caret, next.length);\n\t\tmirror(caret, next.length);\n\t};\n\n\tconst onFocus = (event: FocusEvent<HTMLInputElement>) => {\n\t\t// Focus lands on the first empty slot, or selects the last digit of a full code so typing replaces it.\n\t\tconst input = event.currentTarget;\n\t\tconst start = Math.min(input.value.length, length - 1);\n\t\tinput.setSelectionRange(start, input.value.length);\n\t\tmirror(start, input.value.length);\n\t\tsetIsFocused(true);\n\t};\n\n\tconst isSlotActive = (index: number) =>\n\t\tisFocused &&\n\t\tselection !== null &&\n\t\t(selection.start === selection.end ? index === selection.start : index >= selection.start && index < selection.end);\n\tconst isRange = selection !== null && selection.end - selection.start > 1;\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tdata-slot=\"input-otp\"\n\t\t\tdata-size={size}\n\t\t\t// Chrome Translate wraps text nodes in <font>, which breaks React's next update; a code is never translatable.\n\t\t\ttranslate=\"no\"\n\t\t\t// Digits read left to right in every script, so the row, the caret mirror, and the slot order stay LTR in RTL pages.\n\t\t\tdir=\"ltr\"\n\t\t\tclassName={cn('w-full', size === 'sm' ? 'max-w-[15.5rem]' : 'max-w-[21rem]', className)}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={rowRef}\n\t\t\t\t// Gaps are a share of the row, not rem, so they cannot eat the slots when the root font size is raised.\n\t\t\t\tclassName={cn(\n\t\t\t\t\t'group/otp relative flex w-full items-center',\n\t\t\t\t\tsize === 'sm' ? 'gap-[min(0.375rem,2.5%)]' : 'gap-[min(0.25rem,2.5%)] sm:gap-[min(0.5rem,2.5%)]',\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{Array.from({ length }, (_, index) => {\n\t\t\t\t\tconst digit = code[index];\n\t\t\t\t\tconst isActive = isSlotActive(index);\n\t\t\t\t\tconst gapBefore = groupEvery !== undefined && index > 0 && index % groupEvery === 0;\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\t\tdata-slot=\"input-otp-slot\"\n\t\t\t\t\t\t\tdata-active={isActive || undefined}\n\t\t\t\t\t\t\t// The single active slot is what the gliding ring tracks; a range is shown by the slots themselves.\n\t\t\t\t\t\t\tdata-highlighted={(isActive && !isRange) || undefined}\n\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t'relative flex min-w-0 flex-1 items-center justify-center overflow-hidden font-mono tabular-nums',\n\t\t\t\t\t\t\t\tsize === 'sm' ? 'h-9 max-w-9 rounded-md text-base' : 'h-11 max-w-10 rounded-lg text-lg sm:h-12 sm:max-w-12',\n\t\t\t\t\t\t\t\tgapBefore &&\n\t\t\t\t\t\t\t\t\t(size === 'sm' ? 'ms-[min(0.375rem,2.5%)]' : 'ms-[min(0.25rem,2.5%)] sm:ms-[min(0.5rem,2.5%)]'),\n\t\t\t\t\t\t\t\t'border border-input bg-background text-foreground shadow-xs dark:bg-input/32',\n\t\t\t\t\t\t\t\t'transition-[background-color,border-color] duration-150 ease-out motion-reduce:transition-none',\n\t\t\t\t\t\t\t\t!isDisabled && 'group-hover/otp:border-ring/50',\n\t\t\t\t\t\t\t\tisActive && isRange && 'bg-accent',\n\t\t\t\t\t\t\t\t// Keep the invalid state visible without relying on tint alone.\n\t\t\t\t\t\t\t\tisInvalid && 'border-destructive bg-destructive/5 text-destructive group-hover/otp:border-destructive',\n\t\t\t\t\t\t\t\tisDisabled && 'bg-muted text-muted-foreground shadow-none',\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{digit !== undefined && (\n\t\t\t\t\t\t\t\t// Keyed on the digit so each new one replays the rise, including a correction in place.\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tkey={digit}\n\t\t\t\t\t\t\t\t\tclassName=\"inline-block transition-[translate,opacity] duration-150 ease-out starting:translate-y-2 starting:opacity-0 motion-reduce:transition-none\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{digit}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t{isActive && digit === undefined && (\n\t\t\t\t\t\t\t\t// The real caret is transparent, so the empty active slot draws its own.\n\t\t\t\t\t\t\t\t<motion.span\n\t\t\t\t\t\t\t\t\tclassName={cn('pointer-events-none absolute w-px bg-foreground', size === 'sm' ? 'h-4' : 'h-5')}\n\t\t\t\t\t\t\t\t\tanimate={reduceMotion ? undefined : CARET_BLINK}\n\t\t\t\t\t\t\t\t\ttransition={CARET_TIMING}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t);\n\t\t\t\t})}\n\t\t\t\t<FluidHighlight\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t'z-10 border bg-transparent',\n\t\t\t\t\t\tsize === 'sm' ? 'rounded-md' : 'rounded-lg',\n\t\t\t\t\t\tisInvalid ? 'border-destructive ring-[3px] ring-destructive/25' : 'border-ring/60 ring-[3px] ring-ring/35',\n\t\t\t\t\t)}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tref={inputRef}\n\t\t\t\t\t// `text` with a numeric mode rather than `number`: a number input brings spinners, accepts `e`\n\t\t\t\t\t// and `-`, and reports an empty value for anything it considers malformed.\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tinputMode=\"numeric\"\n\t\t\t\t\tautoComplete=\"one-time-code\"\n\t\t\t\t\tspellCheck={false}\n\t\t\t\t\tmaxLength={length}\n\t\t\t\t\tdisabled={isDisabled}\n\t\t\t\t\taria-label={ariaLabel}\n\t\t\t\t\taria-describedby={ariaDescribedBy}\n\t\t\t\t\taria-invalid={isInvalid || undefined}\n\t\t\t\t\tdata-slot=\"input-otp-input\"\n\t\t\t\t\tvalue={code}\n\t\t\t\t\tonChange={onInputChange}\n\t\t\t\t\tonPaste={onPaste}\n\t\t\t\t\tonFocus={onFocus}\n\t\t\t\t\tonBlur={() => setIsFocused(false)}\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t// Present and hit-testable over the whole row, but invisible: transparent ink rather than opacity,\n\t\t\t\t\t\t// because iOS only offers paste on a press-and-hold over a visible field.\n\t\t\t\t\t\t'absolute inset-0 z-20 size-full cursor-text appearance-none border-0 bg-transparent p-0 font-mono leading-none',\n\t\t\t\t\t\t'text-transparent caret-transparent tracking-[-0.5em] tabular-nums shadow-none outline-none',\n\t\t\t\t\t\t// A font as tall as the row keeps every glyph under the slots, so a tap anywhere lands in the field.\n\t\t\t\t\t\tsize === 'sm' ? 'text-[36px]' : 'text-[44px] sm:text-[48px]',\n\t\t\t\t\t\t'selection:bg-transparent selection:text-transparent',\n\t\t\t\t\t\t'autofill:opacity-0! autofill:shadow-none! autofill:[-webkit-text-fill-color:transparent]!',\n\t\t\t\t\t\t// iOS lays the glyphs out wider and leaks the caret at the edge; squeeze them back under the slots.\n\t\t\t\t\t\t'supports-[-webkit-touch-callout:none]:-left-px supports-[-webkit-touch-callout:none]:right-px',\n\t\t\t\t\t\t'supports-[-webkit-touch-callout:none]:font-thin supports-[-webkit-touch-callout:none]:tracking-[-0.6em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ACD;AAEP"}
|
|
1
|
+
{"version":3,"file":"input-otp.cjs","names":["cn","motion","FluidHighlight"],"sources":["../../src/components/input-otp.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useState, type ChangeEvent, type ClipboardEvent, type FocusEvent, type Ref } from 'react';\nimport { motion, useAnimate, useReducedMotion, type Transition } from 'motion/react';\n\nimport { FluidHighlight } from '../lib/motion/fluid-highlight';\nimport { cn } from '../lib/utils';\n\n/**\n * One-time-code input: one slot per digit, side by side.\n *\n * The slots are drawn, not typed into. A single transparent `<input>` lies over the whole row and owns the value,\n * the caret, and the selection; the slots mirror it. That one-field model is what makes the code behave like text:\n *\n * type fills the selected slot and moves on\n * Backspace deletes like any text field; later digits close the gap\n * ⌘A / Shift selects across slots, so cut, copy, and paste work on the whole code or a slice of it\n * paste strips separators and inserts at the caret; a complete code replaces the value outright\n * autofill the OS hands the whole code to the one field, which is all `autoComplete=\"one-time-code\"` needs\n *\n * It also means one tab stop and one labelled field for assistive tech, rather than six \"digit N\" boxes.\n *\n * Because the real glyphs and caret are transparent, the slots can animate what the user sees: digits rise into\n * place, a drawn caret blinks in the empty active slot, the focus ring glides between slots, and the row shakes\n * once when the code turns invalid. All of it stands still under reduced motion.\n */\ninterface InputOtpProps {\n\t/** Number of digit slots. */\n\tlength?: number;\n\t/** Controlled value. Non-digits are dropped and longer strings are truncated to `length`. */\n\tvalue?: string;\n\tdefaultValue?: string;\n\tonChange?: (value: string) => void;\n\t/** Fires when an edit leaves every slot filled with a code that differs from the previous one. */\n\tonComplete?: (value: string) => void;\n\tisDisabled?: boolean;\n\tisInvalid?: boolean;\n\t/** Renders a gap between groups, e.g. `3` gives 000 000. */\n\tgroupEvery?: number;\n\t/** `sm` fits the code into an inline row (e.g. a settings list) instead of a dialog. */\n\tsize?: 'default' | 'sm';\n\t'aria-label'?: string;\n\t'aria-describedby'?: string;\n\tclassName?: string;\n\tref?: Ref<HTMLDivElement>;\n}\n\ninterface SlotSelection {\n\tstart: number;\n\tend: number;\n}\n\ntype SelectionDirection = 'forward' | 'backward' | 'none';\n\nconst DIGITS_ONLY = /\\D/g;\n// Arabic-Indic, Persian, Devanagari, Bengali, Thai and full-width digits come from native numeric keyboards and IMEs.\n// They map to ASCII before everything else is dropped, so a code typed or pasted in them is not silently discarded.\nconst NON_ASCII_DIGITS = /[\\u0660-\\u0669\\u06F0-\\u06F9\\u0966-\\u096F\\u09E6-\\u09EF\\u0E50-\\u0E59\\uFF10-\\uFF19]/g;\nconst ZERO_CODE_POINTS = [0x0660, 0x06f0, 0x0966, 0x09e6, 0x0e50, 0xff10];\nconst toAsciiDigits = (raw: string) =>\n\traw.replace(NON_ASCII_DIGITS, (char) => {\n\t\tconst code = char.charCodeAt(0);\n\t\tconst zero = ZERO_CODE_POINTS.find((start) => code >= start && code <= start + 9)!;\n\t\treturn String(code - zero);\n\t});\n// Chrome restores autofill styling and the caret position a beat after a value change, so the mirror re-reads them.\nconst RESYNC_DELAYS = [0, 10, 50];\n// A hard on/off blink, like a text caret, rather than a fade.\nconst CARET_BLINK = { opacity: [1, 1, 0, 0] };\nconst CARET_TIMING: Transition = { duration: 1, times: [0, 0.5, 0.5, 1], ease: 'linear', repeat: Infinity };\n\nconst toCode = (raw: string, length: number) => toAsciiDigits(raw).replace(DIGITS_ONLY, '').slice(0, length);\n\nfunction InputOtp({\n\tlength = 6,\n\tvalue,\n\tdefaultValue = '',\n\tonChange,\n\tonComplete,\n\tisDisabled = false,\n\tisInvalid = false,\n\tgroupEvery,\n\tsize = 'default',\n\t'aria-label': ariaLabel = 'One-time code',\n\t'aria-describedby': ariaDescribedBy,\n\tclassName,\n\tref,\n}: InputOtpProps) {\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\tconst previousSelection = useRef<[number | null, number | null, SelectionDirection]>([null, null, 'none']);\n\tconst wasInvalid = useRef(isInvalid);\n\tconst [rowRef, animate] = useAnimate<HTMLDivElement>();\n\tconst reduceMotion = useReducedMotion();\n\tconst [internal, setInternal] = useState(() => toCode(defaultValue, length));\n\tconst [isFocused, setIsFocused] = useState(false);\n\tconst [selection, setSelection] = useState<SlotSelection | null>(null);\n\n\tconst controlled = value !== undefined;\n\tconst code = toCode(controlled ? value : internal, length);\n\n\tconst mirror = (start: number, end: number) =>\n\t\tsetSelection((current) => (current?.start === start && current.end === end ? current : { start, end }));\n\n\tconst commit = (next: string) => {\n\t\tif (next === code) return;\n\t\tif (!controlled) setInternal(next);\n\t\tonChange?.(next);\n\t\t// Comparing against the previous code keeps a re-render or an identical paste from verifying twice, while\n\t\t// correcting one digit of a full code still counts as a new attempt.\n\t\tif (next.length === length) onComplete?.(next);\n\t};\n\n\tuseEffect(() => {\n\t\tconst input = inputRef.current;\n\t\tif (!input) return;\n\n\t\t// The native caret only ever sits between characters. Over a slot, that reads as nothing being selected, so\n\t\t// a collapsed caret inside a full run is widened to select the digit after it (or before it, when moving left).\n\t\tconst syncSelection = () => {\n\t\t\tif (document.activeElement !== input) {\n\t\t\t\tsetSelection(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { selectionStart, selectionEnd, selectionDirection, maxLength, value: current } = input;\n\t\t\tconst [, previousEnd] = previousSelection.current;\n\t\t\tlet start = -1;\n\t\t\tlet end = -1;\n\t\t\tlet direction: SelectionDirection | undefined;\n\n\t\t\tif (current.length !== 0 && selectionStart !== null && selectionEnd !== null) {\n\t\t\t\tconst isCaret = selectionStart === selectionEnd;\n\t\t\t\tconst isAppending = selectionStart === current.length && current.length < maxLength;\n\t\t\t\tif (isCaret && !isAppending) {\n\t\t\t\t\tconst caret = selectionStart;\n\t\t\t\t\tif (caret === 0) {\n\t\t\t\t\t\t[start, end, direction] = [0, 1, 'forward'];\n\t\t\t\t\t} else if (caret === maxLength) {\n\t\t\t\t\t\t[start, end, direction] = [caret - 1, caret, 'backward'];\n\t\t\t\t\t} else if (maxLength > 1 && current.length > 1) {\n\t\t\t\t\t\tlet offset = 0;\n\t\t\t\t\t\tconst [previousStart] = previousSelection.current;\n\t\t\t\t\t\tif (previousStart !== null && previousEnd !== null) {\n\t\t\t\t\t\t\tdirection = caret < previousEnd ? 'backward' : 'forward';\n\t\t\t\t\t\t\tconst wasAppending = previousStart === previousEnd && previousStart < maxLength;\n\t\t\t\t\t\t\tif (direction === 'backward' && !wasAppending) offset = -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstart = caret + offset;\n\t\t\t\t\t\tend = caret + offset + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (start !== -1 && end !== -1 && start !== end) input.setSelectionRange(start, end, direction);\n\t\t\t}\n\n\t\t\tconst nextStart = start !== -1 ? start : (selectionStart ?? 0);\n\t\t\tconst nextEnd = end !== -1 ? end : (selectionEnd ?? 0);\n\t\t\tmirror(nextStart, nextEnd);\n\t\t\tpreviousSelection.current = [nextStart, nextEnd, direction ?? selectionDirection ?? 'none'];\n\t\t};\n\n\t\tdocument.addEventListener('selectionchange', syncSelection, { capture: true });\n\t\tsyncSelection();\n\t\tif (document.activeElement === input) setIsFocused(true);\n\t\treturn () => document.removeEventListener('selectionchange', syncSelection, { capture: true });\n\t}, []);\n\n\tuseEffect(() => {\n\t\tconst timeouts = RESYNC_DELAYS.map((delay) =>\n\t\t\tsetTimeout(() => {\n\t\t\t\tconst input = inputRef.current;\n\t\t\t\tif (!input) return;\n\t\t\t\t// A non-bubbling `input` event clears Chrome's `:autofill` state without reaching React's onChange.\n\t\t\t\tinput.dispatchEvent(new Event('input'));\n\t\t\t\tif (document.activeElement !== input || input.selectionStart === null || input.selectionEnd === null) return;\n\t\t\t\tmirror(input.selectionStart, input.selectionEnd);\n\t\t\t\tpreviousSelection.current = [input.selectionStart, input.selectionEnd, input.selectionDirection ?? 'none'];\n\t\t\t}, delay),\n\t\t);\n\t\treturn () => timeouts.forEach(clearTimeout);\n\t}, [code, isFocused]);\n\n\tuseEffect(() => {\n\t\tconst turnedInvalid = isInvalid && !wasInvalid.current;\n\t\twasInvalid.current = isInvalid;\n\t\tif (!turnedInvalid || reduceMotion || !rowRef.current) return;\n\t\tanimate(rowRef.current, { x: [0, -6, 6, -4, 4, -2, 0] }, { duration: 0.4, ease: 'easeInOut' });\n\t}, [isInvalid, reduceMotion, animate, rowRef]);\n\n\tconst onInputChange = (event: ChangeEvent<HTMLInputElement>) => {\n\t\tconst next = toCode(event.target.value, length);\n\t\t// Deleting doesn't fire `selectionchange`, so the mirror is nudged by hand.\n\t\tif (next.length < code.length) document.dispatchEvent(new Event('selectionchange'));\n\t\tcommit(next);\n\t};\n\n\tconst onPaste = (event: ClipboardEvent<HTMLInputElement>) => {\n\t\t// Always handled here: a native paste of \"123 456\" would be cut to `maxLength` before the spaces were dropped,\n\t\t// and iOS pastes over the whole field rather than at the caret.\n\t\tevent.preventDefault();\n\t\tconst input = event.currentTarget;\n\t\tconst pasted = toAsciiDigits(event.clipboardData.getData('text/plain')).replace(DIGITS_ONLY, '');\n\t\tif (pasted === '') return;\n\t\tconst start = input.selectionStart ?? code.length;\n\t\tconst end = input.selectionEnd ?? start;\n\t\t// A complete code replaces the value even when the caret is mid-way; it's an autofill or a copied message.\n\t\tconst next =\n\t\t\tpasted.length >= length ? pasted.slice(0, length) : (code.slice(0, start) + pasted + code.slice(end)).slice(0, length);\n\t\tinput.value = next;\n\t\tcommit(next);\n\t\tconst caret = Math.min(next.length, length - 1);\n\t\tinput.setSelectionRange(caret, next.length);\n\t\tmirror(caret, next.length);\n\t};\n\n\tconst onFocus = (event: FocusEvent<HTMLInputElement>) => {\n\t\t// Focus lands on the first empty slot, or selects the last digit of a full code so typing replaces it.\n\t\tconst input = event.currentTarget;\n\t\tconst start = Math.min(input.value.length, length - 1);\n\t\tinput.setSelectionRange(start, input.value.length);\n\t\tmirror(start, input.value.length);\n\t\tsetIsFocused(true);\n\t};\n\n\tconst isSlotActive = (index: number) =>\n\t\tisFocused &&\n\t\tselection !== null &&\n\t\t(selection.start === selection.end ? index === selection.start : index >= selection.start && index < selection.end);\n\tconst isRange = selection !== null && selection.end - selection.start > 1;\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tdata-slot=\"input-otp\"\n\t\t\tdata-size={size}\n\t\t\t// Chrome Translate wraps text nodes in <font>, which breaks React's next update; a code is never translatable.\n\t\t\ttranslate=\"no\"\n\t\t\t// Digits read left to right in every script, so the row, the caret mirror, and the slot order stay LTR in RTL pages.\n\t\t\tdir=\"ltr\"\n\t\t\tclassName={cn('w-full', size === 'sm' ? 'max-w-[15.5rem]' : 'max-w-[21rem]', className)}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={rowRef}\n\t\t\t\t// Gaps are a share of the row, not rem, so they cannot eat the slots when the root font size is raised.\n\t\t\t\tclassName={cn(\n\t\t\t\t\t'group/otp relative flex w-full items-center',\n\t\t\t\t\tsize === 'sm' ? 'gap-[min(0.375rem,2.5%)]' : 'gap-[min(0.25rem,2.5%)] sm:gap-[min(0.5rem,2.5%)]',\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{Array.from({ length }, (_, index) => {\n\t\t\t\t\tconst digit = code[index];\n\t\t\t\t\tconst isActive = isSlotActive(index);\n\t\t\t\t\tconst gapBefore = groupEvery !== undefined && index > 0 && index % groupEvery === 0;\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\t\tdata-slot=\"input-otp-slot\"\n\t\t\t\t\t\t\tdata-active={isActive || undefined}\n\t\t\t\t\t\t\t// The single active slot is what the gliding ring tracks; a range is shown by the slots themselves.\n\t\t\t\t\t\t\tdata-highlighted={(isActive && !isRange) || undefined}\n\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t'relative flex min-w-0 flex-1 items-center justify-center overflow-hidden font-mono tabular-nums',\n\t\t\t\t\t\t\t\tsize === 'sm' ? 'h-9 max-w-9 rounded-md text-base' : 'h-11 max-w-10 rounded-lg text-lg sm:h-12 sm:max-w-12',\n\t\t\t\t\t\t\t\tgapBefore &&\n\t\t\t\t\t\t\t\t\t(size === 'sm' ? 'ms-[min(0.375rem,2.5%)]' : 'ms-[min(0.25rem,2.5%)] sm:ms-[min(0.5rem,2.5%)]'),\n\t\t\t\t\t\t\t\t'border border-input bg-background text-foreground shadow-xs dark:bg-input/32',\n\t\t\t\t\t\t\t\t'transition-[background-color,border-color] duration-150 ease-out motion-reduce:transition-none',\n\t\t\t\t\t\t\t\t!isDisabled && 'group-hover/otp:border-ring/50',\n\t\t\t\t\t\t\t\tisActive && isRange && 'bg-accent',\n\t\t\t\t\t\t\t\t// Keep the invalid state visible without relying on tint alone.\n\t\t\t\t\t\t\t\tisInvalid && 'border-destructive bg-destructive/5 text-destructive group-hover/otp:border-destructive',\n\t\t\t\t\t\t\t\tisDisabled && 'bg-muted text-muted-foreground shadow-none',\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{digit !== undefined && (\n\t\t\t\t\t\t\t\t// Keyed on the digit so each new one replays the rise, including a correction in place.\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tkey={digit}\n\t\t\t\t\t\t\t\t\tclassName=\"inline-block transition-[translate,opacity] duration-150 ease-out starting:translate-y-2 starting:opacity-0 motion-reduce:transition-none\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{digit}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t{isActive && digit === undefined && (\n\t\t\t\t\t\t\t\t// The real caret is transparent, so the empty active slot draws its own.\n\t\t\t\t\t\t\t\t<motion.span\n\t\t\t\t\t\t\t\t\tclassName={cn('pointer-events-none absolute w-px bg-foreground', size === 'sm' ? 'h-4' : 'h-5')}\n\t\t\t\t\t\t\t\t\tanimate={reduceMotion ? undefined : CARET_BLINK}\n\t\t\t\t\t\t\t\t\ttransition={CARET_TIMING}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t);\n\t\t\t\t})}\n\t\t\t\t<FluidHighlight\n\t\t\t\t\ttravel\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t'z-10 border bg-transparent',\n\t\t\t\t\t\tsize === 'sm' ? 'rounded-md' : 'rounded-lg',\n\t\t\t\t\t\tisInvalid ? 'border-destructive ring-[3px] ring-destructive/25' : 'border-ring/60 ring-[3px] ring-ring/35',\n\t\t\t\t\t)}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tref={inputRef}\n\t\t\t\t\t// `text` with a numeric mode rather than `number`: a number input brings spinners, accepts `e`\n\t\t\t\t\t// and `-`, and reports an empty value for anything it considers malformed.\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tinputMode=\"numeric\"\n\t\t\t\t\tautoComplete=\"one-time-code\"\n\t\t\t\t\tspellCheck={false}\n\t\t\t\t\tmaxLength={length}\n\t\t\t\t\tdisabled={isDisabled}\n\t\t\t\t\taria-label={ariaLabel}\n\t\t\t\t\taria-describedby={ariaDescribedBy}\n\t\t\t\t\taria-invalid={isInvalid || undefined}\n\t\t\t\t\tdata-slot=\"input-otp-input\"\n\t\t\t\t\tvalue={code}\n\t\t\t\t\tonChange={onInputChange}\n\t\t\t\t\tonPaste={onPaste}\n\t\t\t\t\tonFocus={onFocus}\n\t\t\t\t\tonBlur={() => setIsFocused(false)}\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t// Present and hit-testable over the whole row, but invisible: transparent ink rather than opacity,\n\t\t\t\t\t\t// because iOS only offers paste on a press-and-hold over a visible field.\n\t\t\t\t\t\t'absolute inset-0 z-20 size-full cursor-text appearance-none border-0 bg-transparent p-0 font-mono leading-none',\n\t\t\t\t\t\t'text-transparent caret-transparent tracking-[-0.5em] tabular-nums shadow-none outline-none',\n\t\t\t\t\t\t// A font as tall as the row keeps every glyph under the slots, so a tap anywhere lands in the field.\n\t\t\t\t\t\tsize === 'sm' ? 'text-[36px]' : 'text-[44px] sm:text-[48px]',\n\t\t\t\t\t\t'selection:bg-transparent selection:text-transparent',\n\t\t\t\t\t\t'autofill:opacity-0! autofill:shadow-none! autofill:[-webkit-text-fill-color:transparent]!',\n\t\t\t\t\t\t// iOS lays the glyphs out wider and leaks the caret at the edge; squeeze them back under the slots.\n\t\t\t\t\t\t'supports-[-webkit-touch-callout:none]:-left-px supports-[-webkit-touch-callout:none]:right-px',\n\t\t\t\t\t\t'supports-[-webkit-touch-callout:none]:font-thin supports-[-webkit-touch-callout:none]:tracking-[-0.6em]',\n\t\t\t\t\t\t'disabled:cursor-not-allowed',\n\t\t\t\t\t)}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport { InputOtp };\nexport type { InputOtpProps };\n"],"mappings":";;;;;;;;;;AAsDA,MAAM,cAAc;AAGpB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;CAAC;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;AAAM;AACxE,MAAM,iBAAiB,QACtB,IAAI,QAAQ,mBAAmB,SAAS;CACvC,MAAM,OAAO,KAAK,WAAW,CAAC;CAC9B,MAAM,OAAO,iBAAiB,MAAM,UAAU,QAAQ,SAAS,QAAQ,QAAQ,CAAC;CAChF,OAAO,OAAO,OAAO,IAAI;AAC1B,CAAC;AAEF,MAAM,gBAAgB;CAAC;CAAG;CAAI;AAAE;AAEhC,MAAM,cAAc,EAAE,SAAS;CAAC;CAAG;CAAG;CAAG;AAAC,EAAE;AAC5C,MAAM,eAA2B;CAAE,UAAU;CAAG,OAAO;EAAC;EAAG;EAAK;EAAK;CAAC;CAAG,MAAM;CAAU,QAAQ;AAAS;AAE1G,MAAM,UAAU,KAAa,WAAmB,cAAc,GAAG,CAAC,CAAC,QAAQ,aAAa,EAAE,CAAC,CAAC,MAAM,GAAG,MAAM;AAE3G,SAAS,SAAS,EACjB,SAAS,GACT,OACA,eAAe,IACf,UACA,YACA,aAAa,OACb,YAAY,OACZ,YACA,OAAO,WACP,cAAc,YAAY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sD,wCACnE;IACA;IACD,2CAAC,SAAD;KACC,KAAK;KAGL,MAAK;KACL,WAAU;KACV,cAAa;KACb,YAAY;KACZ,WAAW;KACX,UAAU;KACV,cAAY;KACZ,oBAAkB;KAClB,gBAAc,aAAa;KAC3B,aAAU;KACV,OAAO;KACP,UAAU;KACD;KACA;KACT,cAAc,aAAa,KAAK;KAChC,WAAWA,iBAGV,kHACA,8FAEA,SAAS,OAAO,gBAAgB,8BAChC,uDACA,6FAEA,iGACA,2GACA,6BACD;IACA;GACG;;CACD;AAEP"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { t as cn } from "../utils-BkMLyah9.js";
|
|
4
|
-
import { t as FluidHighlight } from "../fluid-highlight-
|
|
4
|
+
import { t as FluidHighlight } from "../fluid-highlight-BXVfWNk9.js";
|
|
5
5
|
import { useEffect, useRef, useState } from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { motion, useAnimate, useReducedMotion } from "motion/react";
|
|
@@ -221,7 +221,10 @@ function InputOtp({ length = 6, value, defaultValue = "", onChange, onComplete,
|
|
|
221
221
|
})]
|
|
222
222
|
}, index);
|
|
223
223
|
}),
|
|
224
|
-
/* @__PURE__ */ jsx(FluidHighlight, {
|
|
224
|
+
/* @__PURE__ */ jsx(FluidHighlight, {
|
|
225
|
+
travel: true,
|
|
226
|
+
className: cn("z-10 border bg-transparent", size === "sm" ? "rounded-md" : "rounded-lg", isInvalid ? "border-destructive ring-[3px] ring-destructive/25" : "border-ring/60 ring-[3px] ring-ring/35")
|
|
227
|
+
}),
|
|
225
228
|
/* @__PURE__ */ jsx("input", {
|
|
226
229
|
ref: inputRef,
|
|
227
230
|
type: "text",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-otp.js","names":[],"sources":["../../src/components/input-otp.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useState, type ChangeEvent, type ClipboardEvent, type FocusEvent, type Ref } from 'react';\nimport { motion, useAnimate, useReducedMotion, type Transition } from 'motion/react';\n\nimport { FluidHighlight } from '../lib/motion/fluid-highlight';\nimport { cn } from '../lib/utils';\n\n/**\n * One-time-code input: one slot per digit, side by side.\n *\n * The slots are drawn, not typed into. A single transparent `<input>` lies over the whole row and owns the value,\n * the caret, and the selection; the slots mirror it. That one-field model is what makes the code behave like text:\n *\n * type fills the selected slot and moves on\n * Backspace deletes like any text field; later digits close the gap\n * ⌘A / Shift selects across slots, so cut, copy, and paste work on the whole code or a slice of it\n * paste strips separators and inserts at the caret; a complete code replaces the value outright\n * autofill the OS hands the whole code to the one field, which is all `autoComplete=\"one-time-code\"` needs\n *\n * It also means one tab stop and one labelled field for assistive tech, rather than six \"digit N\" boxes.\n *\n * Because the real glyphs and caret are transparent, the slots can animate what the user sees: digits rise into\n * place, a drawn caret blinks in the empty active slot, the focus ring glides between slots, and the row shakes\n * once when the code turns invalid. All of it stands still under reduced motion.\n */\ninterface InputOtpProps {\n\t/** Number of digit slots. */\n\tlength?: number;\n\t/** Controlled value. Non-digits are dropped and longer strings are truncated to `length`. */\n\tvalue?: string;\n\tdefaultValue?: string;\n\tonChange?: (value: string) => void;\n\t/** Fires when an edit leaves every slot filled with a code that differs from the previous one. */\n\tonComplete?: (value: string) => void;\n\tisDisabled?: boolean;\n\tisInvalid?: boolean;\n\t/** Renders a gap between groups, e.g. `3` gives 000 000. */\n\tgroupEvery?: number;\n\t/** `sm` fits the code into an inline row (e.g. a settings list) instead of a dialog. */\n\tsize?: 'default' | 'sm';\n\t'aria-label'?: string;\n\t'aria-describedby'?: string;\n\tclassName?: string;\n\tref?: Ref<HTMLDivElement>;\n}\n\ninterface SlotSelection {\n\tstart: number;\n\tend: number;\n}\n\ntype SelectionDirection = 'forward' | 'backward' | 'none';\n\nconst DIGITS_ONLY = /\\D/g;\n// Arabic-Indic, Persian, Devanagari, Bengali, Thai and full-width digits come from native numeric keyboards and IMEs.\n// They map to ASCII before everything else is dropped, so a code typed or pasted in them is not silently discarded.\nconst NON_ASCII_DIGITS = /[\\u0660-\\u0669\\u06F0-\\u06F9\\u0966-\\u096F\\u09E6-\\u09EF\\u0E50-\\u0E59\\uFF10-\\uFF19]/g;\nconst ZERO_CODE_POINTS = [0x0660, 0x06f0, 0x0966, 0x09e6, 0x0e50, 0xff10];\nconst toAsciiDigits = (raw: string) =>\n\traw.replace(NON_ASCII_DIGITS, (char) => {\n\t\tconst code = char.charCodeAt(0);\n\t\tconst zero = ZERO_CODE_POINTS.find((start) => code >= start && code <= start + 9)!;\n\t\treturn String(code - zero);\n\t});\n// Chrome restores autofill styling and the caret position a beat after a value change, so the mirror re-reads them.\nconst RESYNC_DELAYS = [0, 10, 50];\n// A hard on/off blink, like a text caret, rather than a fade.\nconst CARET_BLINK = { opacity: [1, 1, 0, 0] };\nconst CARET_TIMING: Transition = { duration: 1, times: [0, 0.5, 0.5, 1], ease: 'linear', repeat: Infinity };\n\nconst toCode = (raw: string, length: number) => toAsciiDigits(raw).replace(DIGITS_ONLY, '').slice(0, length);\n\nfunction InputOtp({\n\tlength = 6,\n\tvalue,\n\tdefaultValue = '',\n\tonChange,\n\tonComplete,\n\tisDisabled = false,\n\tisInvalid = false,\n\tgroupEvery,\n\tsize = 'default',\n\t'aria-label': ariaLabel = 'One-time code',\n\t'aria-describedby': ariaDescribedBy,\n\tclassName,\n\tref,\n}: InputOtpProps) {\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\tconst previousSelection = useRef<[number | null, number | null, SelectionDirection]>([null, null, 'none']);\n\tconst wasInvalid = useRef(isInvalid);\n\tconst [rowRef, animate] = useAnimate<HTMLDivElement>();\n\tconst reduceMotion = useReducedMotion();\n\tconst [internal, setInternal] = useState(() => toCode(defaultValue, length));\n\tconst [isFocused, setIsFocused] = useState(false);\n\tconst [selection, setSelection] = useState<SlotSelection | null>(null);\n\n\tconst controlled = value !== undefined;\n\tconst code = toCode(controlled ? value : internal, length);\n\n\tconst mirror = (start: number, end: number) =>\n\t\tsetSelection((current) => (current?.start === start && current.end === end ? current : { start, end }));\n\n\tconst commit = (next: string) => {\n\t\tif (next === code) return;\n\t\tif (!controlled) setInternal(next);\n\t\tonChange?.(next);\n\t\t// Comparing against the previous code keeps a re-render or an identical paste from verifying twice, while\n\t\t// correcting one digit of a full code still counts as a new attempt.\n\t\tif (next.length === length) onComplete?.(next);\n\t};\n\n\tuseEffect(() => {\n\t\tconst input = inputRef.current;\n\t\tif (!input) return;\n\n\t\t// The native caret only ever sits between characters. Over a slot, that reads as nothing being selected, so\n\t\t// a collapsed caret inside a full run is widened to select the digit after it (or before it, when moving left).\n\t\tconst syncSelection = () => {\n\t\t\tif (document.activeElement !== input) {\n\t\t\t\tsetSelection(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { selectionStart, selectionEnd, selectionDirection, maxLength, value: current } = input;\n\t\t\tconst [, previousEnd] = previousSelection.current;\n\t\t\tlet start = -1;\n\t\t\tlet end = -1;\n\t\t\tlet direction: SelectionDirection | undefined;\n\n\t\t\tif (current.length !== 0 && selectionStart !== null && selectionEnd !== null) {\n\t\t\t\tconst isCaret = selectionStart === selectionEnd;\n\t\t\t\tconst isAppending = selectionStart === current.length && current.length < maxLength;\n\t\t\t\tif (isCaret && !isAppending) {\n\t\t\t\t\tconst caret = selectionStart;\n\t\t\t\t\tif (caret === 0) {\n\t\t\t\t\t\t[start, end, direction] = [0, 1, 'forward'];\n\t\t\t\t\t} else if (caret === maxLength) {\n\t\t\t\t\t\t[start, end, direction] = [caret - 1, caret, 'backward'];\n\t\t\t\t\t} else if (maxLength > 1 && current.length > 1) {\n\t\t\t\t\t\tlet offset = 0;\n\t\t\t\t\t\tconst [previousStart] = previousSelection.current;\n\t\t\t\t\t\tif (previousStart !== null && previousEnd !== null) {\n\t\t\t\t\t\t\tdirection = caret < previousEnd ? 'backward' : 'forward';\n\t\t\t\t\t\t\tconst wasAppending = previousStart === previousEnd && previousStart < maxLength;\n\t\t\t\t\t\t\tif (direction === 'backward' && !wasAppending) offset = -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstart = caret + offset;\n\t\t\t\t\t\tend = caret + offset + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (start !== -1 && end !== -1 && start !== end) input.setSelectionRange(start, end, direction);\n\t\t\t}\n\n\t\t\tconst nextStart = start !== -1 ? start : (selectionStart ?? 0);\n\t\t\tconst nextEnd = end !== -1 ? end : (selectionEnd ?? 0);\n\t\t\tmirror(nextStart, nextEnd);\n\t\t\tpreviousSelection.current = [nextStart, nextEnd, direction ?? selectionDirection ?? 'none'];\n\t\t};\n\n\t\tdocument.addEventListener('selectionchange', syncSelection, { capture: true });\n\t\tsyncSelection();\n\t\tif (document.activeElement === input) setIsFocused(true);\n\t\treturn () => document.removeEventListener('selectionchange', syncSelection, { capture: true });\n\t}, []);\n\n\tuseEffect(() => {\n\t\tconst timeouts = RESYNC_DELAYS.map((delay) =>\n\t\t\tsetTimeout(() => {\n\t\t\t\tconst input = inputRef.current;\n\t\t\t\tif (!input) return;\n\t\t\t\t// A non-bubbling `input` event clears Chrome's `:autofill` state without reaching React's onChange.\n\t\t\t\tinput.dispatchEvent(new Event('input'));\n\t\t\t\tif (document.activeElement !== input || input.selectionStart === null || input.selectionEnd === null) return;\n\t\t\t\tmirror(input.selectionStart, input.selectionEnd);\n\t\t\t\tpreviousSelection.current = [input.selectionStart, input.selectionEnd, input.selectionDirection ?? 'none'];\n\t\t\t}, delay),\n\t\t);\n\t\treturn () => timeouts.forEach(clearTimeout);\n\t}, [code, isFocused]);\n\n\tuseEffect(() => {\n\t\tconst turnedInvalid = isInvalid && !wasInvalid.current;\n\t\twasInvalid.current = isInvalid;\n\t\tif (!turnedInvalid || reduceMotion || !rowRef.current) return;\n\t\tanimate(rowRef.current, { x: [0, -6, 6, -4, 4, -2, 0] }, { duration: 0.4, ease: 'easeInOut' });\n\t}, [isInvalid, reduceMotion, animate, rowRef]);\n\n\tconst onInputChange = (event: ChangeEvent<HTMLInputElement>) => {\n\t\tconst next = toCode(event.target.value, length);\n\t\t// Deleting doesn't fire `selectionchange`, so the mirror is nudged by hand.\n\t\tif (next.length < code.length) document.dispatchEvent(new Event('selectionchange'));\n\t\tcommit(next);\n\t};\n\n\tconst onPaste = (event: ClipboardEvent<HTMLInputElement>) => {\n\t\t// Always handled here: a native paste of \"123 456\" would be cut to `maxLength` before the spaces were dropped,\n\t\t// and iOS pastes over the whole field rather than at the caret.\n\t\tevent.preventDefault();\n\t\tconst input = event.currentTarget;\n\t\tconst pasted = toAsciiDigits(event.clipboardData.getData('text/plain')).replace(DIGITS_ONLY, '');\n\t\tif (pasted === '') return;\n\t\tconst start = input.selectionStart ?? code.length;\n\t\tconst end = input.selectionEnd ?? start;\n\t\t// A complete code replaces the value even when the caret is mid-way; it's an autofill or a copied message.\n\t\tconst next =\n\t\t\tpasted.length >= length ? pasted.slice(0, length) : (code.slice(0, start) + pasted + code.slice(end)).slice(0, length);\n\t\tinput.value = next;\n\t\tcommit(next);\n\t\tconst caret = Math.min(next.length, length - 1);\n\t\tinput.setSelectionRange(caret, next.length);\n\t\tmirror(caret, next.length);\n\t};\n\n\tconst onFocus = (event: FocusEvent<HTMLInputElement>) => {\n\t\t// Focus lands on the first empty slot, or selects the last digit of a full code so typing replaces it.\n\t\tconst input = event.currentTarget;\n\t\tconst start = Math.min(input.value.length, length - 1);\n\t\tinput.setSelectionRange(start, input.value.length);\n\t\tmirror(start, input.value.length);\n\t\tsetIsFocused(true);\n\t};\n\n\tconst isSlotActive = (index: number) =>\n\t\tisFocused &&\n\t\tselection !== null &&\n\t\t(selection.start === selection.end ? index === selection.start : index >= selection.start && index < selection.end);\n\tconst isRange = selection !== null && selection.end - selection.start > 1;\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tdata-slot=\"input-otp\"\n\t\t\tdata-size={size}\n\t\t\t// Chrome Translate wraps text nodes in <font>, which breaks React's next update; a code is never translatable.\n\t\t\ttranslate=\"no\"\n\t\t\t// Digits read left to right in every script, so the row, the caret mirror, and the slot order stay LTR in RTL pages.\n\t\t\tdir=\"ltr\"\n\t\t\tclassName={cn('w-full', size === 'sm' ? 'max-w-[15.5rem]' : 'max-w-[21rem]', className)}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={rowRef}\n\t\t\t\t// Gaps are a share of the row, not rem, so they cannot eat the slots when the root font size is raised.\n\t\t\t\tclassName={cn(\n\t\t\t\t\t'group/otp relative flex w-full items-center',\n\t\t\t\t\tsize === 'sm' ? 'gap-[min(0.375rem,2.5%)]' : 'gap-[min(0.25rem,2.5%)] sm:gap-[min(0.5rem,2.5%)]',\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{Array.from({ length }, (_, index) => {\n\t\t\t\t\tconst digit = code[index];\n\t\t\t\t\tconst isActive = isSlotActive(index);\n\t\t\t\t\tconst gapBefore = groupEvery !== undefined && index > 0 && index % groupEvery === 0;\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\t\tdata-slot=\"input-otp-slot\"\n\t\t\t\t\t\t\tdata-active={isActive || undefined}\n\t\t\t\t\t\t\t// The single active slot is what the gliding ring tracks; a range is shown by the slots themselves.\n\t\t\t\t\t\t\tdata-highlighted={(isActive && !isRange) || undefined}\n\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t'relative flex min-w-0 flex-1 items-center justify-center overflow-hidden font-mono tabular-nums',\n\t\t\t\t\t\t\t\tsize === 'sm' ? 'h-9 max-w-9 rounded-md text-base' : 'h-11 max-w-10 rounded-lg text-lg sm:h-12 sm:max-w-12',\n\t\t\t\t\t\t\t\tgapBefore &&\n\t\t\t\t\t\t\t\t\t(size === 'sm' ? 'ms-[min(0.375rem,2.5%)]' : 'ms-[min(0.25rem,2.5%)] sm:ms-[min(0.5rem,2.5%)]'),\n\t\t\t\t\t\t\t\t'border border-input bg-background text-foreground shadow-xs dark:bg-input/32',\n\t\t\t\t\t\t\t\t'transition-[background-color,border-color] duration-150 ease-out motion-reduce:transition-none',\n\t\t\t\t\t\t\t\t!isDisabled && 'group-hover/otp:border-ring/50',\n\t\t\t\t\t\t\t\tisActive && isRange && 'bg-accent',\n\t\t\t\t\t\t\t\t// Keep the invalid state visible without relying on tint alone.\n\t\t\t\t\t\t\t\tisInvalid && 'border-destructive bg-destructive/5 text-destructive group-hover/otp:border-destructive',\n\t\t\t\t\t\t\t\tisDisabled && 'bg-muted text-muted-foreground shadow-none',\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{digit !== undefined && (\n\t\t\t\t\t\t\t\t// Keyed on the digit so each new one replays the rise, including a correction in place.\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tkey={digit}\n\t\t\t\t\t\t\t\t\tclassName=\"inline-block transition-[translate,opacity] duration-150 ease-out starting:translate-y-2 starting:opacity-0 motion-reduce:transition-none\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{digit}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t{isActive && digit === undefined && (\n\t\t\t\t\t\t\t\t// The real caret is transparent, so the empty active slot draws its own.\n\t\t\t\t\t\t\t\t<motion.span\n\t\t\t\t\t\t\t\t\tclassName={cn('pointer-events-none absolute w-px bg-foreground', size === 'sm' ? 'h-4' : 'h-5')}\n\t\t\t\t\t\t\t\t\tanimate={reduceMotion ? undefined : CARET_BLINK}\n\t\t\t\t\t\t\t\t\ttransition={CARET_TIMING}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t);\n\t\t\t\t})}\n\t\t\t\t<FluidHighlight\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t'z-10 border bg-transparent',\n\t\t\t\t\t\tsize === 'sm' ? 'rounded-md' : 'rounded-lg',\n\t\t\t\t\t\tisInvalid ? 'border-destructive ring-[3px] ring-destructive/25' : 'border-ring/60 ring-[3px] ring-ring/35',\n\t\t\t\t\t)}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tref={inputRef}\n\t\t\t\t\t// `text` with a numeric mode rather than `number`: a number input brings spinners, accepts `e`\n\t\t\t\t\t// and `-`, and reports an empty value for anything it considers malformed.\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tinputMode=\"numeric\"\n\t\t\t\t\tautoComplete=\"one-time-code\"\n\t\t\t\t\tspellCheck={false}\n\t\t\t\t\tmaxLength={length}\n\t\t\t\t\tdisabled={isDisabled}\n\t\t\t\t\taria-label={ariaLabel}\n\t\t\t\t\taria-describedby={ariaDescribedBy}\n\t\t\t\t\taria-invalid={isInvalid || undefined}\n\t\t\t\t\tdata-slot=\"input-otp-input\"\n\t\t\t\t\tvalue={code}\n\t\t\t\t\tonChange={onInputChange}\n\t\t\t\t\tonPaste={onPaste}\n\t\t\t\t\tonFocus={onFocus}\n\t\t\t\t\tonBlur={() => setIsFocused(false)}\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t// Present and hit-testable over the whole row, but invisible: transparent ink rather than opacity,\n\t\t\t\t\t\t// because iOS only offers paste on a press-and-hold over a visible field.\n\t\t\t\t\t\t'absolute inset-0 z-20 size-full cursor-text appearance-none border-0 bg-transparent p-0 font-mono leading-none',\n\t\t\t\t\t\t'text-transparent caret-transparent tracking-[-0.5em] tabular-nums shadow-none outline-none',\n\t\t\t\t\t\t// A font as tall as the row keeps every glyph under the slots, so a tap anywhere lands in the field.\n\t\t\t\t\t\tsize === 'sm' ? 'text-[36px]' : 'text-[44px] sm:text-[48px]',\n\t\t\t\t\t\t'selection:bg-transparent selection:text-transparent',\n\t\t\t\t\t\t'autofill:opacity-0! autofill:shadow-none! autofill:[-webkit-text-fill-color:transparent]!',\n\t\t\t\t\t\t// iOS lays the glyphs out wider and leaks the caret at the edge; squeeze them back under the slots.\n\t\t\t\t\t\t'supports-[-webkit-touch-callout:none]:-left-px supports-[-webkit-touch-callout:none]:right-px',\n\t\t\t\t\t\t'supports-[-webkit-touch-callout:none]:font-thin supports-[-webkit-touch-callout:none]:tracking-[-0.6em]',\n\t\t\t\t\t\t'disabled:cursor-not-allowed',\n\t\t\t\t\t)}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport { InputOtp };\nexport type { InputOtpProps };\n"],"mappings":";;;;;;;;;AAsDA,MAAM,cAAc;AAGpB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;CAAC;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;AAAM;AACxE,MAAM,iBAAiB,QACtB,IAAI,QAAQ,mBAAmB,SAAS;CACvC,MAAM,OAAO,KAAK,WAAW,CAAC;CAC9B,MAAM,OAAO,iBAAiB,MAAM,UAAU,QAAQ,SAAS,QAAQ,QAAQ,CAAC;CAChF,OAAO,OAAO,OAAO,IAAI;AAC1B,CAAC;AAEF,MAAM,gBAAgB;CAAC;CAAG;CAAI;AAAE;AAEhC,MAAM,cAAc,EAAE,SAAS;CAAC;CAAG;CAAG;CAAG;AAAC,EAAE;AAC5C,MAAM,eAA2B;CAAE,UAAU;CAAG,OAAO;EAAC;EAAG;EAAK;EAAK;CAAC;CAAG,MAAM;CAAU,QAAQ;AAAS;AAE1G,MAAM,UAAU,KAAa,WAAmB,cAAc,GAAG,CAAC,CAAC,QAAQ,aAAa,EAAE,CAAC,CAAC,MAAM,GAAG,MAAM;AAE3G,SAAS,SAAS,EACjB,SAAS,GACT,OACA,eAAe,IACf,UACA,YACA,aAAa,OACb,YAAY,OACZ,YACA,OAAO,WACP,cAAc,YAAY,iBAC1B,oBAAoB,iBACpB,WACA,OACiB;CACjB,MAAM,WAAW,OAAyB,IAAI;CAC9C,MAAM,oBAAoB,OAA2D;EAAC;EAAM;EAAM;CAAM,CAAC;CACzG,MAAM,aAAa,OAAO,SAAS;CACnC,MAAM,C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BAAc,aAAa;KAC3B,aAAU;KACV,OAAO;KACP,UAAU;KACD;KACA;KACT,cAAc,aAAa,KAAK;KAChC,WAAW,GAGV,kHACA,8FAEA,SAAS,OAAO,gBAAgB,8BAChC,uDACA,6FAEA,iGACA,2GACA,6BACD;IACA;GACG;;CACD;AAEP"}
|
|
1
|
+
{"version":3,"file":"input-otp.js","names":[],"sources":["../../src/components/input-otp.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useState, type ChangeEvent, type ClipboardEvent, type FocusEvent, type Ref } from 'react';\nimport { motion, useAnimate, useReducedMotion, type Transition } from 'motion/react';\n\nimport { FluidHighlight } from '../lib/motion/fluid-highlight';\nimport { cn } from '../lib/utils';\n\n/**\n * One-time-code input: one slot per digit, side by side.\n *\n * The slots are drawn, not typed into. A single transparent `<input>` lies over the whole row and owns the value,\n * the caret, and the selection; the slots mirror it. That one-field model is what makes the code behave like text:\n *\n * type fills the selected slot and moves on\n * Backspace deletes like any text field; later digits close the gap\n * ⌘A / Shift selects across slots, so cut, copy, and paste work on the whole code or a slice of it\n * paste strips separators and inserts at the caret; a complete code replaces the value outright\n * autofill the OS hands the whole code to the one field, which is all `autoComplete=\"one-time-code\"` needs\n *\n * It also means one tab stop and one labelled field for assistive tech, rather than six \"digit N\" boxes.\n *\n * Because the real glyphs and caret are transparent, the slots can animate what the user sees: digits rise into\n * place, a drawn caret blinks in the empty active slot, the focus ring glides between slots, and the row shakes\n * once when the code turns invalid. All of it stands still under reduced motion.\n */\ninterface InputOtpProps {\n\t/** Number of digit slots. */\n\tlength?: number;\n\t/** Controlled value. Non-digits are dropped and longer strings are truncated to `length`. */\n\tvalue?: string;\n\tdefaultValue?: string;\n\tonChange?: (value: string) => void;\n\t/** Fires when an edit leaves every slot filled with a code that differs from the previous one. */\n\tonComplete?: (value: string) => void;\n\tisDisabled?: boolean;\n\tisInvalid?: boolean;\n\t/** Renders a gap between groups, e.g. `3` gives 000 000. */\n\tgroupEvery?: number;\n\t/** `sm` fits the code into an inline row (e.g. a settings list) instead of a dialog. */\n\tsize?: 'default' | 'sm';\n\t'aria-label'?: string;\n\t'aria-describedby'?: string;\n\tclassName?: string;\n\tref?: Ref<HTMLDivElement>;\n}\n\ninterface SlotSelection {\n\tstart: number;\n\tend: number;\n}\n\ntype SelectionDirection = 'forward' | 'backward' | 'none';\n\nconst DIGITS_ONLY = /\\D/g;\n// Arabic-Indic, Persian, Devanagari, Bengali, Thai and full-width digits come from native numeric keyboards and IMEs.\n// They map to ASCII before everything else is dropped, so a code typed or pasted in them is not silently discarded.\nconst NON_ASCII_DIGITS = /[\\u0660-\\u0669\\u06F0-\\u06F9\\u0966-\\u096F\\u09E6-\\u09EF\\u0E50-\\u0E59\\uFF10-\\uFF19]/g;\nconst ZERO_CODE_POINTS = [0x0660, 0x06f0, 0x0966, 0x09e6, 0x0e50, 0xff10];\nconst toAsciiDigits = (raw: string) =>\n\traw.replace(NON_ASCII_DIGITS, (char) => {\n\t\tconst code = char.charCodeAt(0);\n\t\tconst zero = ZERO_CODE_POINTS.find((start) => code >= start && code <= start + 9)!;\n\t\treturn String(code - zero);\n\t});\n// Chrome restores autofill styling and the caret position a beat after a value change, so the mirror re-reads them.\nconst RESYNC_DELAYS = [0, 10, 50];\n// A hard on/off blink, like a text caret, rather than a fade.\nconst CARET_BLINK = { opacity: [1, 1, 0, 0] };\nconst CARET_TIMING: Transition = { duration: 1, times: [0, 0.5, 0.5, 1], ease: 'linear', repeat: Infinity };\n\nconst toCode = (raw: string, length: number) => toAsciiDigits(raw).replace(DIGITS_ONLY, '').slice(0, length);\n\nfunction InputOtp({\n\tlength = 6,\n\tvalue,\n\tdefaultValue = '',\n\tonChange,\n\tonComplete,\n\tisDisabled = false,\n\tisInvalid = false,\n\tgroupEvery,\n\tsize = 'default',\n\t'aria-label': ariaLabel = 'One-time code',\n\t'aria-describedby': ariaDescribedBy,\n\tclassName,\n\tref,\n}: InputOtpProps) {\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\tconst previousSelection = useRef<[number | null, number | null, SelectionDirection]>([null, null, 'none']);\n\tconst wasInvalid = useRef(isInvalid);\n\tconst [rowRef, animate] = useAnimate<HTMLDivElement>();\n\tconst reduceMotion = useReducedMotion();\n\tconst [internal, setInternal] = useState(() => toCode(defaultValue, length));\n\tconst [isFocused, setIsFocused] = useState(false);\n\tconst [selection, setSelection] = useState<SlotSelection | null>(null);\n\n\tconst controlled = value !== undefined;\n\tconst code = toCode(controlled ? value : internal, length);\n\n\tconst mirror = (start: number, end: number) =>\n\t\tsetSelection((current) => (current?.start === start && current.end === end ? current : { start, end }));\n\n\tconst commit = (next: string) => {\n\t\tif (next === code) return;\n\t\tif (!controlled) setInternal(next);\n\t\tonChange?.(next);\n\t\t// Comparing against the previous code keeps a re-render or an identical paste from verifying twice, while\n\t\t// correcting one digit of a full code still counts as a new attempt.\n\t\tif (next.length === length) onComplete?.(next);\n\t};\n\n\tuseEffect(() => {\n\t\tconst input = inputRef.current;\n\t\tif (!input) return;\n\n\t\t// The native caret only ever sits between characters. Over a slot, that reads as nothing being selected, so\n\t\t// a collapsed caret inside a full run is widened to select the digit after it (or before it, when moving left).\n\t\tconst syncSelection = () => {\n\t\t\tif (document.activeElement !== input) {\n\t\t\t\tsetSelection(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { selectionStart, selectionEnd, selectionDirection, maxLength, value: current } = input;\n\t\t\tconst [, previousEnd] = previousSelection.current;\n\t\t\tlet start = -1;\n\t\t\tlet end = -1;\n\t\t\tlet direction: SelectionDirection | undefined;\n\n\t\t\tif (current.length !== 0 && selectionStart !== null && selectionEnd !== null) {\n\t\t\t\tconst isCaret = selectionStart === selectionEnd;\n\t\t\t\tconst isAppending = selectionStart === current.length && current.length < maxLength;\n\t\t\t\tif (isCaret && !isAppending) {\n\t\t\t\t\tconst caret = selectionStart;\n\t\t\t\t\tif (caret === 0) {\n\t\t\t\t\t\t[start, end, direction] = [0, 1, 'forward'];\n\t\t\t\t\t} else if (caret === maxLength) {\n\t\t\t\t\t\t[start, end, direction] = [caret - 1, caret, 'backward'];\n\t\t\t\t\t} else if (maxLength > 1 && current.length > 1) {\n\t\t\t\t\t\tlet offset = 0;\n\t\t\t\t\t\tconst [previousStart] = previousSelection.current;\n\t\t\t\t\t\tif (previousStart !== null && previousEnd !== null) {\n\t\t\t\t\t\t\tdirection = caret < previousEnd ? 'backward' : 'forward';\n\t\t\t\t\t\t\tconst wasAppending = previousStart === previousEnd && previousStart < maxLength;\n\t\t\t\t\t\t\tif (direction === 'backward' && !wasAppending) offset = -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstart = caret + offset;\n\t\t\t\t\t\tend = caret + offset + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (start !== -1 && end !== -1 && start !== end) input.setSelectionRange(start, end, direction);\n\t\t\t}\n\n\t\t\tconst nextStart = start !== -1 ? start : (selectionStart ?? 0);\n\t\t\tconst nextEnd = end !== -1 ? end : (selectionEnd ?? 0);\n\t\t\tmirror(nextStart, nextEnd);\n\t\t\tpreviousSelection.current = [nextStart, nextEnd, direction ?? selectionDirection ?? 'none'];\n\t\t};\n\n\t\tdocument.addEventListener('selectionchange', syncSelection, { capture: true });\n\t\tsyncSelection();\n\t\tif (document.activeElement === input) setIsFocused(true);\n\t\treturn () => document.removeEventListener('selectionchange', syncSelection, { capture: true });\n\t}, []);\n\n\tuseEffect(() => {\n\t\tconst timeouts = RESYNC_DELAYS.map((delay) =>\n\t\t\tsetTimeout(() => {\n\t\t\t\tconst input = inputRef.current;\n\t\t\t\tif (!input) return;\n\t\t\t\t// A non-bubbling `input` event clears Chrome's `:autofill` state without reaching React's onChange.\n\t\t\t\tinput.dispatchEvent(new Event('input'));\n\t\t\t\tif (document.activeElement !== input || input.selectionStart === null || input.selectionEnd === null) return;\n\t\t\t\tmirror(input.selectionStart, input.selectionEnd);\n\t\t\t\tpreviousSelection.current = [input.selectionStart, input.selectionEnd, input.selectionDirection ?? 'none'];\n\t\t\t}, delay),\n\t\t);\n\t\treturn () => timeouts.forEach(clearTimeout);\n\t}, [code, isFocused]);\n\n\tuseEffect(() => {\n\t\tconst turnedInvalid = isInvalid && !wasInvalid.current;\n\t\twasInvalid.current = isInvalid;\n\t\tif (!turnedInvalid || reduceMotion || !rowRef.current) return;\n\t\tanimate(rowRef.current, { x: [0, -6, 6, -4, 4, -2, 0] }, { duration: 0.4, ease: 'easeInOut' });\n\t}, [isInvalid, reduceMotion, animate, rowRef]);\n\n\tconst onInputChange = (event: ChangeEvent<HTMLInputElement>) => {\n\t\tconst next = toCode(event.target.value, length);\n\t\t// Deleting doesn't fire `selectionchange`, so the mirror is nudged by hand.\n\t\tif (next.length < code.length) document.dispatchEvent(new Event('selectionchange'));\n\t\tcommit(next);\n\t};\n\n\tconst onPaste = (event: ClipboardEvent<HTMLInputElement>) => {\n\t\t// Always handled here: a native paste of \"123 456\" would be cut to `maxLength` before the spaces were dropped,\n\t\t// and iOS pastes over the whole field rather than at the caret.\n\t\tevent.preventDefault();\n\t\tconst input = event.currentTarget;\n\t\tconst pasted = toAsciiDigits(event.clipboardData.getData('text/plain')).replace(DIGITS_ONLY, '');\n\t\tif (pasted === '') return;\n\t\tconst start = input.selectionStart ?? code.length;\n\t\tconst end = input.selectionEnd ?? start;\n\t\t// A complete code replaces the value even when the caret is mid-way; it's an autofill or a copied message.\n\t\tconst next =\n\t\t\tpasted.length >= length ? pasted.slice(0, length) : (code.slice(0, start) + pasted + code.slice(end)).slice(0, length);\n\t\tinput.value = next;\n\t\tcommit(next);\n\t\tconst caret = Math.min(next.length, length - 1);\n\t\tinput.setSelectionRange(caret, next.length);\n\t\tmirror(caret, next.length);\n\t};\n\n\tconst onFocus = (event: FocusEvent<HTMLInputElement>) => {\n\t\t// Focus lands on the first empty slot, or selects the last digit of a full code so typing replaces it.\n\t\tconst input = event.currentTarget;\n\t\tconst start = Math.min(input.value.length, length - 1);\n\t\tinput.setSelectionRange(start, input.value.length);\n\t\tmirror(start, input.value.length);\n\t\tsetIsFocused(true);\n\t};\n\n\tconst isSlotActive = (index: number) =>\n\t\tisFocused &&\n\t\tselection !== null &&\n\t\t(selection.start === selection.end ? index === selection.start : index >= selection.start && index < selection.end);\n\tconst isRange = selection !== null && selection.end - selection.start > 1;\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tdata-slot=\"input-otp\"\n\t\t\tdata-size={size}\n\t\t\t// Chrome Translate wraps text nodes in <font>, which breaks React's next update; a code is never translatable.\n\t\t\ttranslate=\"no\"\n\t\t\t// Digits read left to right in every script, so the row, the caret mirror, and the slot order stay LTR in RTL pages.\n\t\t\tdir=\"ltr\"\n\t\t\tclassName={cn('w-full', size === 'sm' ? 'max-w-[15.5rem]' : 'max-w-[21rem]', className)}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={rowRef}\n\t\t\t\t// Gaps are a share of the row, not rem, so they cannot eat the slots when the root font size is raised.\n\t\t\t\tclassName={cn(\n\t\t\t\t\t'group/otp relative flex w-full items-center',\n\t\t\t\t\tsize === 'sm' ? 'gap-[min(0.375rem,2.5%)]' : 'gap-[min(0.25rem,2.5%)] sm:gap-[min(0.5rem,2.5%)]',\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{Array.from({ length }, (_, index) => {\n\t\t\t\t\tconst digit = code[index];\n\t\t\t\t\tconst isActive = isSlotActive(index);\n\t\t\t\t\tconst gapBefore = groupEvery !== undefined && index > 0 && index % groupEvery === 0;\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\t\tdata-slot=\"input-otp-slot\"\n\t\t\t\t\t\t\tdata-active={isActive || undefined}\n\t\t\t\t\t\t\t// The single active slot is what the gliding ring tracks; a range is shown by the slots themselves.\n\t\t\t\t\t\t\tdata-highlighted={(isActive && !isRange) || undefined}\n\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t'relative flex min-w-0 flex-1 items-center justify-center overflow-hidden font-mono tabular-nums',\n\t\t\t\t\t\t\t\tsize === 'sm' ? 'h-9 max-w-9 rounded-md text-base' : 'h-11 max-w-10 rounded-lg text-lg sm:h-12 sm:max-w-12',\n\t\t\t\t\t\t\t\tgapBefore &&\n\t\t\t\t\t\t\t\t\t(size === 'sm' ? 'ms-[min(0.375rem,2.5%)]' : 'ms-[min(0.25rem,2.5%)] sm:ms-[min(0.5rem,2.5%)]'),\n\t\t\t\t\t\t\t\t'border border-input bg-background text-foreground shadow-xs dark:bg-input/32',\n\t\t\t\t\t\t\t\t'transition-[background-color,border-color] duration-150 ease-out motion-reduce:transition-none',\n\t\t\t\t\t\t\t\t!isDisabled && 'group-hover/otp:border-ring/50',\n\t\t\t\t\t\t\t\tisActive && isRange && 'bg-accent',\n\t\t\t\t\t\t\t\t// Keep the invalid state visible without relying on tint alone.\n\t\t\t\t\t\t\t\tisInvalid && 'border-destructive bg-destructive/5 text-destructive group-hover/otp:border-destructive',\n\t\t\t\t\t\t\t\tisDisabled && 'bg-muted text-muted-foreground shadow-none',\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{digit !== undefined && (\n\t\t\t\t\t\t\t\t// Keyed on the digit so each new one replays the rise, including a correction in place.\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tkey={digit}\n\t\t\t\t\t\t\t\t\tclassName=\"inline-block transition-[translate,opacity] duration-150 ease-out starting:translate-y-2 starting:opacity-0 motion-reduce:transition-none\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{digit}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t{isActive && digit === undefined && (\n\t\t\t\t\t\t\t\t// The real caret is transparent, so the empty active slot draws its own.\n\t\t\t\t\t\t\t\t<motion.span\n\t\t\t\t\t\t\t\t\tclassName={cn('pointer-events-none absolute w-px bg-foreground', size === 'sm' ? 'h-4' : 'h-5')}\n\t\t\t\t\t\t\t\t\tanimate={reduceMotion ? undefined : CARET_BLINK}\n\t\t\t\t\t\t\t\t\ttransition={CARET_TIMING}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t);\n\t\t\t\t})}\n\t\t\t\t<FluidHighlight\n\t\t\t\t\ttravel\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t'z-10 border bg-transparent',\n\t\t\t\t\t\tsize === 'sm' ? 'rounded-md' : 'rounded-lg',\n\t\t\t\t\t\tisInvalid ? 'border-destructive ring-[3px] ring-destructive/25' : 'border-ring/60 ring-[3px] ring-ring/35',\n\t\t\t\t\t)}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tref={inputRef}\n\t\t\t\t\t// `text` with a numeric mode rather than `number`: a number input brings spinners, accepts `e`\n\t\t\t\t\t// and `-`, and reports an empty value for anything it considers malformed.\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tinputMode=\"numeric\"\n\t\t\t\t\tautoComplete=\"one-time-code\"\n\t\t\t\t\tspellCheck={false}\n\t\t\t\t\tmaxLength={length}\n\t\t\t\t\tdisabled={isDisabled}\n\t\t\t\t\taria-label={ariaLabel}\n\t\t\t\t\taria-describedby={ariaDescribedBy}\n\t\t\t\t\taria-invalid={isInvalid || undefined}\n\t\t\t\t\tdata-slot=\"input-otp-input\"\n\t\t\t\t\tvalue={code}\n\t\t\t\t\tonChange={onInputChange}\n\t\t\t\t\tonPaste={onPaste}\n\t\t\t\t\tonFocus={onFocus}\n\t\t\t\t\tonBlur={() => setIsFocused(false)}\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t// Present and hit-testable over the whole row, but invisible: transparent ink rather than opacity,\n\t\t\t\t\t\t// because iOS only offers paste on a press-and-hold over a visible field.\n\t\t\t\t\t\t'absolute inset-0 z-20 size-full cursor-text appearance-none border-0 bg-transparent p-0 font-mono leading-none',\n\t\t\t\t\t\t'text-transparent caret-transparent tracking-[-0.5em] tabular-nums shadow-none outline-none',\n\t\t\t\t\t\t// A font as tall as the row keeps every glyph under the slots, so a tap anywhere lands in the field.\n\t\t\t\t\t\tsize === 'sm' ? 'text-[36px]' : 'text-[44px] sm:text-[48px]',\n\t\t\t\t\t\t'selection:bg-transparent selection:text-transparent',\n\t\t\t\t\t\t'autofill:opacity-0! autofill:shadow-none! autofill:[-webkit-text-fill-color:transparent]!',\n\t\t\t\t\t\t// iOS lays the glyphs out wider and leaks the caret at the edge; squeeze them back under the slots.\n\t\t\t\t\t\t'supports-[-webkit-touch-callout:none]:-left-px supports-[-webkit-touch-callout:none]:right-px',\n\t\t\t\t\t\t'supports-[-webkit-touch-callout:none]:font-thin supports-[-webkit-touch-callout:none]:tracking-[-0.6em]',\n\t\t\t\t\t\t'disabled:cursor-not-allowed',\n\t\t\t\t\t)}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport { InputOtp };\nexport type { InputOtpProps };\n"],"mappings":";;;;;;;;;AAsDA,MAAM,cAAc;AAGpB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;CAAC;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;AAAM;AACxE,MAAM,iBAAiB,QACtB,IAAI,QAAQ,mBAAmB,SAAS;CACvC,MAAM,OAAO,KAAK,WAAW,CAAC;CAC9B,MAAM,OAAO,iBAAiB,MAAM,UAAU,QAAQ,SAAS,QAAQ,QAAQ,CAAC;CAChF,OAAO,OAAO,OAAO,IAAI;AAC1B,CAAC;AAEF,MAAM,gBAAgB;CAAC;CAAG;CAAI;AAAE;AAEhC,MAAM,cAAc,EAAE,SAAS;CAAC;CAAG;CAAG;CAAG;AAAC,EAAE;AAC5C,MAAM,eAA2B;CAAE,UAAU;CAAG,OAAO;EAAC;EAAG;EAAK;EAAK;CAAC;CAAG,MAAM;CAAU,QAAQ;AAAS;AAE1G,MAAM,UAAU,KAAa,WAAmB,cAAc,GAAG,CAAC,CAAC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,mDAAmD,SAAS,OAAO,QAAQ,KAAK;OAC9F,SAAS,eAAe,SAAY;OACpC,YAAY;MACZ,EAEE;QArCC,KAqCD;IAEP,CAAC;IACD,oBAAC,gBAAD;KACC;KACA,WAAW,GACV,8BACA,SAAS,OAAO,eAAe,cAC/B,YAAY,sDAAsD,wCACnE;IACA;IACD,oBAAC,SAAD;KACC,KAAK;KAGL,MAAK;KACL,WAAU;KACV,cAAa;KACb,YAAY;KACZ,WAAW;KACX,UAAU;KACV,cAAY;KACZ,oBAAkB;KAClB,gBAAc,aAAa;KAC3B,aAAU;KACV,OAAO;KACP,UAAU;KACD;KACA;KACT,cAAc,aAAa,KAAK;KAChC,WAAW,GAGV,kHACA,8FAEA,SAAS,OAAO,gBAAgB,8BAChC,uDACA,6FAEA,iGACA,2GACA,6BACD;IACA;GACG;;CACD;AAEP"}
|
|
@@ -5,7 +5,7 @@ const require_rolldown_runtime = require('../rolldown-runtime-D_qnwXdH.cjs');
|
|
|
5
5
|
const require_utils = require('../utils-CzTQ3-VI.cjs');
|
|
6
6
|
const require_components_separator = require('./separator.cjs');
|
|
7
7
|
const require_components_badge = require('./badge.cjs');
|
|
8
|
-
const require_fluid_highlight = require('../fluid-highlight-
|
|
8
|
+
const require_fluid_highlight = require('../fluid-highlight-B8olepSM.cjs');
|
|
9
9
|
const require_components_popover = require('./popover.cjs');
|
|
10
10
|
let react = require("react");
|
|
11
11
|
react = require_rolldown_runtime.__toESM(react, 1);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { t as cn } from "../utils-BkMLyah9.js";
|
|
4
4
|
import { Separator } from "./separator.js";
|
|
5
5
|
import { Badge } from "./badge.js";
|
|
6
|
-
import { t as FluidHighlight } from "../fluid-highlight-
|
|
6
|
+
import { t as FluidHighlight } from "../fluid-highlight-BXVfWNk9.js";
|
|
7
7
|
import { Popover, PopoverContent, PopoverTrigger } from "./popover.js";
|
|
8
8
|
import * as React$1 from "react";
|
|
9
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
const require_rolldown_runtime = require('../rolldown-runtime-D_qnwXdH.cjs');
|
|
5
5
|
const require_utils = require('../utils-CzTQ3-VI.cjs');
|
|
6
|
-
const require_fluid_highlight = require('../fluid-highlight-
|
|
6
|
+
const require_fluid_highlight = require('../fluid-highlight-B8olepSM.cjs');
|
|
7
7
|
let react = require("react");
|
|
8
8
|
react = require_rolldown_runtime.__toESM(react, 1);
|
|
9
9
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -120,7 +120,7 @@ function SelectPopup({ className, children, sideOffset = 4, alignItemWithTrigger
|
|
|
120
120
|
className: require_utils.cn("relative max-h-(--available-height) min-w-(--anchor-width) scroll-py-6 overflow-y-auto p-1 [&:not(:has([role=option]))>[data-slot=select-empty]]:block", className),
|
|
121
121
|
"data-slot": "select-list",
|
|
122
122
|
children: [
|
|
123
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_fluid_highlight.FluidHighlight, {}),
|
|
123
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_fluid_highlight.FluidHighlight, { className: "rounded-[calc(var(--radius-lg)-5px)]" }),
|
|
124
124
|
children,
|
|
125
125
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
126
126
|
className: "hidden px-2 py-1.5 text-center text-muted-foreground text-sm",
|
|
@@ -143,7 +143,7 @@ function SelectPopup({ className, children, sideOffset = 4, alignItemWithTrigger
|
|
|
143
143
|
}
|
|
144
144
|
function SelectItem({ className, children, ...props }) {
|
|
145
145
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_select.Select.Item, {
|
|
146
|
-
className: require_utils.cn("relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-
|
|
146
|
+
className: require_utils.cn("relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-[calc(var(--radius-lg)-5px)] py-1 ps-2 pe-4 text-base outline-none pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 data-disabled:pointer-events-none data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0", className),
|
|
147
147
|
"data-slot": "select-item",
|
|
148
148
|
...props,
|
|
149
149
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_select.Select.ItemIndicator, {
|
|
@@ -189,7 +189,7 @@ function SelectGroupLabel({ ...props }) {
|
|
|
189
189
|
}
|
|
190
190
|
function SelectRichItem({ className, children, label, description, icon, ...props }) {
|
|
191
191
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_select.Select.Item, {
|
|
192
|
-
className: require_utils.cn("relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-
|
|
192
|
+
className: require_utils.cn("relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-[calc(var(--radius-lg)-5px)] py-1.5 ps-2 pe-4 text-base outline-none pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 data-disabled:pointer-events-none data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0", className),
|
|
193
193
|
"data-slot": "select-rich-item",
|
|
194
194
|
...props,
|
|
195
195
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_select.Select.ItemIndicator, {
|
|
@@ -221,7 +221,7 @@ function SelectRichItem({ className, children, label, description, icon, ...prop
|
|
|
221
221
|
}
|
|
222
222
|
function SelectFieldItem({ className, name, type, ...props }) {
|
|
223
223
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_select.Select.Item, {
|
|
224
|
-
className: require_utils.cn("relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-
|
|
224
|
+
className: require_utils.cn("relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-[calc(var(--radius-lg)-5px)] py-1 ps-2 pe-4 text-base outline-none pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 data-disabled:pointer-events-none data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0", className),
|
|
225
225
|
"data-slot": "select-field-item",
|
|
226
226
|
...props,
|
|
227
227
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_select.Select.ItemIndicator, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.cjs","names":["React","SelectPrimitive","cn","ChevronsUpDownIcon","ChevronUpIcon","FluidHighlight","ChevronDownIcon"],"sources":["../../src/components/select.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Select as SelectPrimitive } from \"@base-ui/react/select\";\nimport {\n ChevronDownIcon,\n ChevronsUpDownIcon,\n ChevronUpIcon,\n} from \"lucide-react\";\n\nimport { useFloatingOverlayPortalProps } from \"@constructive-io/ui/portal\";\nimport { FluidHighlight } from \"../lib/motion/fluid-highlight\";\nimport { cn } from \"../lib/utils\";\n\ntype SelectProps = Omit<SelectPrimitive.Root.Props<string>, \"onValueChange\"> & {\n /** Callback when value changes */\n onValueChange?: (value: string) => void;\n};\n\ntype SelectLabels = Record<string, string>;\n\nconst NO_LABELS: SelectLabels = {};\n\n/** The text a node renders, so an item's label can stand in for its value in the trigger. */\nfunction textOf(node: React.ReactNode): string {\n if (typeof node === \"string\" || typeof node === \"number\") return String(node);\n if (Array.isArray(node)) return node.map(textOf).join(\"\");\n if (React.isValidElement<{ children?: React.ReactNode }>(node)) return textOf(node.props.children);\n return \"\";\n}\n\nfunction collectInto(children: React.ReactNode, labels: SelectLabels) {\n React.Children.forEach(children, (child) => {\n if (!React.isValidElement<{ value?: unknown; children?: React.ReactNode; label?: React.ReactNode; name?: string }>(child)) {\n return;\n }\n const { value, children: inner, label, name } = child.props;\n if (child.type === SelectItem || child.type === SelectRichItem || child.type === SelectFieldItem) {\n const text = child.type === SelectFieldItem ? (name ?? \"\") : textOf(child.type === SelectRichItem ? (label ?? inner) : inner).trim();\n if (typeof value === \"string\" && text) labels[value] = text;\n } else if (inner) {\n collectInto(inner, labels);\n }\n });\n}\n\n/** Reads `value -> label` from the <SelectItem>s declared in `children` (groups, fragments and nested markup included). */\nfunction collectItemLabels(children: React.ReactNode): SelectLabels {\n const labels: SelectLabels = {};\n collectInto(children, labels);\n return Object.keys(labels).length > 0 ? labels : NO_LABELS;\n}\n\nfunction sameLabels(a: SelectLabels, b: SelectLabels): boolean {\n if (a === b) return true;\n const keys = Object.keys(b);\n return keys.length === Object.keys(a).length && keys.every((key) => a[key] === b[key]);\n}\n\n/** Keeps the same object while the labels are unchanged, so Base UI is not handed a new `items` on every render. */\nfunction useStableLabels(next: SelectLabels): SelectLabels {\n const [stable, setStable] = React.useState(next);\n if (sameLabels(stable, next)) return stable;\n // Adjusting state while rendering: React re-renders at once, before anything is committed, and no ref is involved.\n setStable(next);\n return next;\n}\n\n/**\n * Base UI shows the raw `value` in the trigger unless it is given `items`. Pass `items` for full control (the children\n * are then not read at all); without it the labels are read from the <SelectItem>s declared in `children`, so\n * `defaultValue=\"editor\"` shows \"Editor\", not `editor`. Items rendered by a wrapper component are not visible from\n * here: pass `items` when the options come from one.\n */\nfunction Select({ onValueChange, items, children, ...props }: SelectProps) {\n const declared = useStableLabels(items != null ? NO_LABELS : collectItemLabels(children));\n\n return (\n <SelectPrimitive.Root<string>\n items={items ?? (declared === NO_LABELS ? undefined : declared)}\n onValueChange={\n onValueChange\n ? (value, _eventDetails) => {\n // Only call callback when there's an actual value (not null/undefined)\n if (value != null) {\n onValueChange(value);\n }\n }\n : undefined\n }\n {...props}\n >\n {children}\n </SelectPrimitive.Root>\n );\n}\n\ntype SelectTriggerProps = SelectPrimitive.Trigger.Props & {\n size?: \"sm\" | \"default\" | \"lg\";\n};\n\nconst SelectTrigger = React.forwardRef<HTMLButtonElement, SelectTriggerProps>(\n ({ className, size = \"default\", children, ...props }, ref) => {\n return (\n <SelectPrimitive.Trigger\n ref={ref}\n className={cn(\n \"relative inline-flex min-h-9 w-full min-w-[min(9rem,100%)] select-none items-center justify-between gap-2 rounded-md border border-input bg-background bg-clip-padding px-[calc(--spacing(3)-1px)] text-left text-base outline-none ring-ring/35 transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-md)-1px)] not-data-disabled:not-focus-visible:not-aria-invalid:not-data-pressed:before:shadow-[0_1px_--theme(--color-black/4%)] pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 focus-visible:border-ring/60 focus-visible:ring-[3px] aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/16 data-disabled:pointer-events-none data-disabled:opacity-64 sm:min-h-8 sm:text-sm dark:bg-input/32 dark:not-in-data-[slot=group]:bg-clip-border dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-focus-visible:not-aria-invalid:not-data-pressed:before:shadow-[0_-1px_--theme(--color-white/8%)] [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0 [[data-disabled],:focus-visible,[aria-invalid],[data-pressed]]:shadow-none\",\n size === \"sm\" &&\n \"min-h-8 gap-1.5 px-[calc(--spacing(2.5)-1px)] sm:min-h-7\",\n size === \"lg\" && \"min-h-10 sm:min-h-9\",\n className,\n )}\n data-slot=\"select-trigger\"\n {...props}\n >\n {children}\n <SelectPrimitive.Icon data-slot=\"select-icon\">\n <ChevronsUpDownIcon className=\"-me-1 size-4.5 opacity-80 sm:size-4\" />\n </SelectPrimitive.Icon>\n </SelectPrimitive.Trigger>\n );\n }\n);\nSelectTrigger.displayName = \"SelectTrigger\";\n\ntype SelectValueProps = React.ComponentProps<typeof SelectPrimitive.Value>;\n\nfunction SelectValue({ className, placeholder, children, onMouseEnter, title, ...props }: SelectValueProps) {\n return (\n <SelectPrimitive.Value\n className={cn(\n \"flex-1 truncate data-placeholder:text-subtle-foreground\",\n className,\n )}\n data-slot=\"select-value\"\n placeholder={placeholder}\n title={title}\n // A truncated value carries its full text as a tooltip and a value that fits carries none, unless the host set a\n // `title` of its own, which stays.\n onMouseEnter={(event) => {\n if (title === undefined) {\n const element = event.currentTarget;\n element.title = element.scrollWidth > element.clientWidth ? (element.textContent ?? \"\") : \"\";\n }\n onMouseEnter?.(event);\n }}\n {...props}\n >\n {children}\n </SelectPrimitive.Value>\n );\n}\n\ntype SelectPopupProps = SelectPrimitive.Popup.Props & {\n sideOffset?: SelectPrimitive.Positioner.Props[\"sideOffset\"];\n alignItemWithTrigger?: SelectPrimitive.Positioner.Props[\"alignItemWithTrigger\"];\n /** @deprecated Not used in Base UI. Kept for backward compatibility. */\n position?: \"item-aligned\" | \"popper\";\n /** Shown when the list has no items. */\n emptyMessage?: React.ReactNode;\n};\n\nfunction SelectPopup({\n className,\n children,\n sideOffset = 4,\n alignItemWithTrigger = false,\n position: _position,\n emptyMessage = \"No options\",\n ...props\n}: SelectPopupProps) {\n const { container, zIndexClass } = useFloatingOverlayPortalProps();\n\n return (\n <SelectPrimitive.Portal container={container}>\n <SelectPrimitive.Positioner\n alignItemWithTrigger={alignItemWithTrigger}\n className={cn(\"select-none\", zIndexClass)}\n data-slot=\"select-positioner\"\n sideOffset={sideOffset}\n >\n <SelectPrimitive.Popup\n className=\"origin-(--transform-origin) scale-100 opacity-100 transition-[scale,opacity] duration-(--duration-moderate) data-[side=none]:transition-none data-starting-style:scale-98 data-ending-style:scale-98 data-starting-style:opacity-0 data-ending-style:opacity-0 motion-reduce:transition-none\"\n data-slot=\"select-popup\"\n {...props}\n >\n <SelectPrimitive.ScrollUpArrow\n className=\"top-0 flex h-6 w-full cursor-default items-center justify-center before:pointer-events-none before:absolute before:inset-x-px before:top-px before:h-[200%] before:rounded-t-[calc(var(--radius-lg)-1px)] before:bg-linear-to-b before:from-50% before:from-popover\"\n data-slot=\"select-scroll-up-arrow\"\n >\n <ChevronUpIcon className=\"relative size-4.5 sm:size-4\" />\n </SelectPrimitive.ScrollUpArrow>\n <span className=\"relative block h-full rounded-lg border bg-popover bg-clip-padding before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-lg dark:not-in-data-[slot=group]:bg-clip-border\">\n <SelectPrimitive.List\n className={cn(\n // `scroll-py-6` keeps a scrolled-to item clear of the scroll arrows; the empty message only shows\n // while the list holds no option.\n \"relative max-h-(--available-height) min-w-(--anchor-width) scroll-py-6 overflow-y-auto p-1 [&:not(:has([role=option]))>[data-slot=select-empty]]:block\",\n className,\n )}\n data-slot=\"select-list\"\n >\n <FluidHighlight />\n {children}\n <div\n className=\"hidden px-2 py-1.5 text-center text-muted-foreground text-sm\"\n data-slot=\"select-empty\"\n role=\"presentation\"\n >\n {emptyMessage}\n </div>\n </SelectPrimitive.List>\n </span>\n <SelectPrimitive.ScrollDownArrow\n className=\"bottom-0 flex h-6 w-full cursor-default items-center justify-center before:pointer-events-none before:absolute before:inset-x-px before:bottom-px before:h-[200%] before:rounded-b-[calc(var(--radius-lg)-1px)] before:bg-linear-to-t before:from-50% before:from-popover\"\n data-slot=\"select-scroll-down-arrow\"\n >\n <ChevronDownIcon className=\"relative size-4.5 sm:size-4\" />\n </SelectPrimitive.ScrollDownArrow>\n </SelectPrimitive.Popup>\n </SelectPrimitive.Positioner>\n </SelectPrimitive.Portal>\n );\n}\n\nfunction SelectItem({\n className,\n children,\n ...props\n}: SelectPrimitive.Item.Props) {\n return (\n <SelectPrimitive.Item\n className={cn(\n \"relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-sm py-1 ps-2 pe-4 text-base outline-none pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 data-disabled:pointer-events-none data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n className,\n )}\n data-slot=\"select-item\"\n {...props}\n >\n\t\t<SelectPrimitive.ItemIndicator\n\t\t\tkeepMounted\n\t\t\tclassName={(state) =>\n\t\t\t\tcn(\n\t\t\t\t\t'col-start-1 transition-[opacity,scale,filter] duration-(--duration-slow) ease-out motion-reduce:transition-none',\n\t\t\t\t\tstate.selected ? 'scale-100 opacity-100 blur-0' : 'scale-[0.25] opacity-0 blur-[4px]',\n\t\t\t\t)\n\t\t\t}\n\t\t>\n <svg\n fill=\"none\"\n height=\"24\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n viewBox=\"0 0 24 24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/1500/svg\"\n >\n <path d=\"M5.252 12.7 10.2 18.63 18.748 5.37\" />\n </svg>\n </SelectPrimitive.ItemIndicator>\n <SelectPrimitive.ItemText className=\"col-start-2 min-w-0 [overflow-wrap:anywhere]\">\n {children}\n </SelectPrimitive.ItemText>\n </SelectPrimitive.Item>\n );\n}\n\nfunction SelectSeparator({\n className,\n ...props\n}: SelectPrimitive.Separator.Props) {\n return (\n <SelectPrimitive.Separator\n className={cn(\"mx-2 my-1 h-px bg-border\", className)}\n data-slot=\"select-separator\"\n {...props}\n />\n );\n}\n\nfunction SelectGroup({ ...props }: SelectPrimitive.Group.Props) {\n return <SelectPrimitive.Group data-slot=\"select-group\" {...props} />;\n}\n\nfunction SelectGroupLabel({ ...props }: SelectPrimitive.GroupLabel.Props) {\n return (\n <SelectPrimitive.GroupLabel\n className=\"px-2 py-1.5 font-medium text-muted-foreground text-xs\"\n data-slot=\"select-group-label\"\n {...props}\n />\n );\n}\n\ntype SelectRichItemProps = SelectPrimitive.Item.Props & {\n /** Main label text */\n label?: React.ReactNode;\n /** Optional description text below the label */\n description?: React.ReactNode;\n /** Optional icon element */\n icon?: React.ReactNode;\n};\n\nfunction SelectRichItem({\n className,\n children,\n label,\n description,\n icon,\n ...props\n}: SelectRichItemProps) {\n return (\n <SelectPrimitive.Item\n className={cn(\n \"relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-sm py-1.5 ps-2 pe-4 text-base outline-none pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 data-disabled:pointer-events-none data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n className,\n )}\n data-slot=\"select-rich-item\"\n {...props}\n >\n\t\t<SelectPrimitive.ItemIndicator\n\t\t\tkeepMounted\n\t\t\tclassName={(state) =>\n\t\t\t\tcn(\n\t\t\t\t\t'col-start-1 mt-0.5 self-start transition-[opacity,scale,filter] duration-(--duration-slow) ease-out motion-reduce:transition-none',\n\t\t\t\t\tstate.selected ? 'scale-100 opacity-100 blur-0' : 'scale-[0.25] opacity-0 blur-[4px]',\n\t\t\t\t)\n\t\t\t}\n\t\t>\n <svg\n fill=\"none\"\n height=\"24\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n viewBox=\"0 0 24 24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path d=\"M5.252 12.7 10.2 18.63 18.748 5.37\" />\n </svg>\n </SelectPrimitive.ItemIndicator>\n <SelectPrimitive.ItemText className=\"col-start-2 min-w-0 flex flex-col gap-0.5 [overflow-wrap:anywhere]\">\n <span className=\"flex items-center gap-2\">\n {icon}\n {label ?? children}\n </span>\n {description && (\n <span className=\"text-muted-foreground text-xs\">{description}</span>\n )}\n </SelectPrimitive.ItemText>\n </SelectPrimitive.Item>\n );\n}\n\ntype SelectFieldItemProps = SelectPrimitive.Item.Props & {\n /** Field name to display */\n name: string;\n /** Field type to display as muted text */\n type?: string;\n};\n\nfunction SelectFieldItem({\n className,\n name,\n type,\n ...props\n}: SelectFieldItemProps) {\n return (\n <SelectPrimitive.Item\n className={cn(\n \"relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-sm py-1 ps-2 pe-4 text-base outline-none pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 data-disabled:pointer-events-none data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n className,\n )}\n data-slot=\"select-field-item\"\n {...props}\n >\n\t\t<SelectPrimitive.ItemIndicator\n\t\t\tkeepMounted\n\t\t\tclassName={(state) =>\n\t\t\t\tcn(\n\t\t\t\t\t'col-start-1 transition-[opacity,scale,filter] duration-(--duration-slow) ease-out motion-reduce:transition-none',\n\t\t\t\t\tstate.selected ? 'scale-100 opacity-100 blur-0' : 'scale-[0.25] opacity-0 blur-[4px]',\n\t\t\t\t)\n\t\t\t}\n\t\t>\n <svg\n fill=\"none\"\n height=\"24\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n viewBox=\"0 0 24 24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path d=\"M5.252 12.7 10.2 18.63 18.748 5.37\" />\n </svg>\n </SelectPrimitive.ItemIndicator>\n <SelectPrimitive.ItemText className=\"col-start-2 min-w-0 flex items-center justify-between gap-2\">\n <span className=\"truncate\">{name}</span>\n {type && (\n <span className=\"text-muted-foreground text-xs shrink-0\">{type}</span>\n )}\n </SelectPrimitive.ItemText>\n </SelectPrimitive.Item>\n );\n}\n\nexport {\n Select,\n SelectTrigger,\n SelectValue,\n SelectPopup,\n SelectPopup as SelectContent,\n SelectItem,\n SelectRichItem,\n SelectFieldItem,\n SelectSeparator,\n SelectGroup,\n SelectGroupLabel,\n SelectGroupLabel as SelectLabel,\n};\n"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAM,YAA0B,CAAC;;AAGjC,SAAS,OAAO,MAA+B;CAC7C,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU,OAAO,OAAO,IAAI;CAC5E,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,KAAK,IAAI,MAAM,CAAC,CAAC,KAAK,EAAE;CACxD,IAAIA,MAAM,eAA+C,IAAI,GAAG,OAAO,OAAO,KAAK,MAAM,QAAQ;CACjG,OAAO;AACT;AAEA,SAAS,YAAY,UAA2B,QAAsB;CACpE,MAAM,SAAS,QAAQ,WAAW,UAAU;EAC1C,IAAI,CAACA,MAAM,eAAwG,KAAK,GACtH;EAEF,MAAM,EAAE,OAAO,UAAU,OAAO,OAAO,SAAS,MAAM;EACtD,IAAI,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IACP,eAAc;IACd,gBAAe;IACf,aAAY;IACZ,SAAQ;IACR,OAAM;IACN,OAAM;cAEN,2CAAC,QAAD,EAAM,GAAE,qCAAsC;GAC3C;EACwB,IAC/B,4CAACD,6BAAgB,UAAjB;GAA0B,WAAU;aAApC,CACE,4CAAC,QAAD;IAAM,WAAU;cAAhB,CACG,MACA,SAAS,QACN;OACL,eACC,2CAAC,QAAD;IAAM,WAAU;cAAiC;GAAkB,EAE7C;IACN;;AAE1B;AASA,SAAS,gBAAgB,EACvB,WACA,MACA,MACA,GAAG,SACoB;CACvB,OACE,4CAACA,6BAAgB,MAAjB;EACE,WAAWC,iBACT,ifACA,SACF;EACA,aAAU;EACV,GAAI;YANN,CAQF,2CAACD,6BAAgB,eAAjB;GACC;GACA,YAAY,UACXC,iBACC,mHACA,MAAM,WAAW,iCAAiC,mCACnD;aAGI,2CAAC,OAAD;IACE,MAAK;IACL,QAAO;IACP,QAAO;IACP,eAAc;IACd,gBAAe;IACf,aAAY;IACZ,SAAQ;IACR,OAAM;IACN,OAAM;cAEN,2CAAC,QAAD,EAAM,GAAE,qCAAsC;GAC3C;EACwB,IAC/B,4CAACD,6BAAgB,UAAjB;GAA0B,WAAU;aAApC,CACE,2CAAC,QAAD;IAAM,WAAU;cAAY;GAAW,IACtC,QACC,2CAAC,QAAD;IAAM,WAAU;cAA0C;GAAW,EAE/C;IACN;;AAE1B"}
|
|
1
|
+
{"version":3,"file":"select.cjs","names":["React","SelectPrimitive","cn","ChevronsUpDownIcon","ChevronUpIcon","FluidHighlight","ChevronDownIcon"],"sources":["../../src/components/select.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Select as SelectPrimitive } from \"@base-ui/react/select\";\nimport {\n ChevronDownIcon,\n ChevronsUpDownIcon,\n ChevronUpIcon,\n} from \"lucide-react\";\n\nimport { useFloatingOverlayPortalProps } from \"@constructive-io/ui/portal\";\nimport { FluidHighlight } from \"../lib/motion/fluid-highlight\";\nimport { cn } from \"../lib/utils\";\n\ntype SelectProps = Omit<SelectPrimitive.Root.Props<string>, \"onValueChange\"> & {\n /** Callback when value changes */\n onValueChange?: (value: string) => void;\n};\n\ntype SelectLabels = Record<string, string>;\n\nconst NO_LABELS: SelectLabels = {};\n\n/** The text a node renders, so an item's label can stand in for its value in the trigger. */\nfunction textOf(node: React.ReactNode): string {\n if (typeof node === \"string\" || typeof node === \"number\") return String(node);\n if (Array.isArray(node)) return node.map(textOf).join(\"\");\n if (React.isValidElement<{ children?: React.ReactNode }>(node)) return textOf(node.props.children);\n return \"\";\n}\n\nfunction collectInto(children: React.ReactNode, labels: SelectLabels) {\n React.Children.forEach(children, (child) => {\n if (!React.isValidElement<{ value?: unknown; children?: React.ReactNode; label?: React.ReactNode; name?: string }>(child)) {\n return;\n }\n const { value, children: inner, label, name } = child.props;\n if (child.type === SelectItem || child.type === SelectRichItem || child.type === SelectFieldItem) {\n const text = child.type === SelectFieldItem ? (name ?? \"\") : textOf(child.type === SelectRichItem ? (label ?? inner) : inner).trim();\n if (typeof value === \"string\" && text) labels[value] = text;\n } else if (inner) {\n collectInto(inner, labels);\n }\n });\n}\n\n/** Reads `value -> label` from the <SelectItem>s declared in `children` (groups, fragments and nested markup included). */\nfunction collectItemLabels(children: React.ReactNode): SelectLabels {\n const labels: SelectLabels = {};\n collectInto(children, labels);\n return Object.keys(labels).length > 0 ? labels : NO_LABELS;\n}\n\nfunction sameLabels(a: SelectLabels, b: SelectLabels): boolean {\n if (a === b) return true;\n const keys = Object.keys(b);\n return keys.length === Object.keys(a).length && keys.every((key) => a[key] === b[key]);\n}\n\n/** Keeps the same object while the labels are unchanged, so Base UI is not handed a new `items` on every render. */\nfunction useStableLabels(next: SelectLabels): SelectLabels {\n const [stable, setStable] = React.useState(next);\n if (sameLabels(stable, next)) return stable;\n // Adjusting state while rendering: React re-renders at once, before anything is committed, and no ref is involved.\n setStable(next);\n return next;\n}\n\n/**\n * Base UI shows the raw `value` in the trigger unless it is given `items`. Pass `items` for full control (the children\n * are then not read at all); without it the labels are read from the <SelectItem>s declared in `children`, so\n * `defaultValue=\"editor\"` shows \"Editor\", not `editor`. Items rendered by a wrapper component are not visible from\n * here: pass `items` when the options come from one.\n */\nfunction Select({ onValueChange, items, children, ...props }: SelectProps) {\n const declared = useStableLabels(items != null ? NO_LABELS : collectItemLabels(children));\n\n return (\n <SelectPrimitive.Root<string>\n items={items ?? (declared === NO_LABELS ? undefined : declared)}\n onValueChange={\n onValueChange\n ? (value, _eventDetails) => {\n // Only call callback when there's an actual value (not null/undefined)\n if (value != null) {\n onValueChange(value);\n }\n }\n : undefined\n }\n {...props}\n >\n {children}\n </SelectPrimitive.Root>\n );\n}\n\ntype SelectTriggerProps = SelectPrimitive.Trigger.Props & {\n size?: \"sm\" | \"default\" | \"lg\";\n};\n\nconst SelectTrigger = React.forwardRef<HTMLButtonElement, SelectTriggerProps>(\n ({ className, size = \"default\", children, ...props }, ref) => {\n return (\n <SelectPrimitive.Trigger\n ref={ref}\n className={cn(\n \"relative inline-flex min-h-9 w-full min-w-[min(9rem,100%)] select-none items-center justify-between gap-2 rounded-md border border-input bg-background bg-clip-padding px-[calc(--spacing(3)-1px)] text-left text-base outline-none ring-ring/35 transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-md)-1px)] not-data-disabled:not-focus-visible:not-aria-invalid:not-data-pressed:before:shadow-[0_1px_--theme(--color-black/4%)] pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 focus-visible:border-ring/60 focus-visible:ring-[3px] aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/16 data-disabled:pointer-events-none data-disabled:opacity-64 sm:min-h-8 sm:text-sm dark:bg-input/32 dark:not-in-data-[slot=group]:bg-clip-border dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-focus-visible:not-aria-invalid:not-data-pressed:before:shadow-[0_-1px_--theme(--color-white/8%)] [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0 [[data-disabled],:focus-visible,[aria-invalid],[data-pressed]]:shadow-none\",\n size === \"sm\" &&\n \"min-h-8 gap-1.5 px-[calc(--spacing(2.5)-1px)] sm:min-h-7\",\n size === \"lg\" && \"min-h-10 sm:min-h-9\",\n className,\n )}\n data-slot=\"select-trigger\"\n {...props}\n >\n {children}\n <SelectPrimitive.Icon data-slot=\"select-icon\">\n <ChevronsUpDownIcon className=\"-me-1 size-4.5 opacity-80 sm:size-4\" />\n </SelectPrimitive.Icon>\n </SelectPrimitive.Trigger>\n );\n }\n);\nSelectTrigger.displayName = \"SelectTrigger\";\n\ntype SelectValueProps = React.ComponentProps<typeof SelectPrimitive.Value>;\n\nfunction SelectValue({ className, placeholder, children, onMouseEnter, title, ...props }: SelectValueProps) {\n return (\n <SelectPrimitive.Value\n className={cn(\n \"flex-1 truncate data-placeholder:text-subtle-foreground\",\n className,\n )}\n data-slot=\"select-value\"\n placeholder={placeholder}\n title={title}\n // A truncated value carries its full text as a tooltip and a value that fits carries none, unless the host set a\n // `title` of its own, which stays.\n onMouseEnter={(event) => {\n if (title === undefined) {\n const element = event.currentTarget;\n element.title = element.scrollWidth > element.clientWidth ? (element.textContent ?? \"\") : \"\";\n }\n onMouseEnter?.(event);\n }}\n {...props}\n >\n {children}\n </SelectPrimitive.Value>\n );\n}\n\ntype SelectPopupProps = SelectPrimitive.Popup.Props & {\n sideOffset?: SelectPrimitive.Positioner.Props[\"sideOffset\"];\n alignItemWithTrigger?: SelectPrimitive.Positioner.Props[\"alignItemWithTrigger\"];\n /** @deprecated Not used in Base UI. Kept for backward compatibility. */\n position?: \"item-aligned\" | \"popper\";\n /** Shown when the list has no items. */\n emptyMessage?: React.ReactNode;\n};\n\nfunction SelectPopup({\n className,\n children,\n sideOffset = 4,\n alignItemWithTrigger = false,\n position: _position,\n emptyMessage = \"No options\",\n ...props\n}: SelectPopupProps) {\n const { container, zIndexClass } = useFloatingOverlayPortalProps();\n\n return (\n <SelectPrimitive.Portal container={container}>\n <SelectPrimitive.Positioner\n alignItemWithTrigger={alignItemWithTrigger}\n className={cn(\"select-none\", zIndexClass)}\n data-slot=\"select-positioner\"\n sideOffset={sideOffset}\n >\n <SelectPrimitive.Popup\n className=\"origin-(--transform-origin) scale-100 opacity-100 transition-[scale,opacity] duration-(--duration-moderate) data-[side=none]:transition-none data-starting-style:scale-98 data-ending-style:scale-98 data-starting-style:opacity-0 data-ending-style:opacity-0 motion-reduce:transition-none\"\n data-slot=\"select-popup\"\n {...props}\n >\n <SelectPrimitive.ScrollUpArrow\n className=\"top-0 flex h-6 w-full cursor-default items-center justify-center before:pointer-events-none before:absolute before:inset-x-px before:top-px before:h-[200%] before:rounded-t-[calc(var(--radius-lg)-1px)] before:bg-linear-to-b before:from-50% before:from-popover\"\n data-slot=\"select-scroll-up-arrow\"\n >\n <ChevronUpIcon className=\"relative size-4.5 sm:size-4\" />\n </SelectPrimitive.ScrollUpArrow>\n <span className=\"relative block h-full rounded-lg border bg-popover bg-clip-padding before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-lg dark:not-in-data-[slot=group]:bg-clip-border\">\n <SelectPrimitive.List\n className={cn(\n // `scroll-py-6` keeps a scrolled-to item clear of the scroll arrows; the empty message only shows\n // while the list holds no option.\n \"relative max-h-(--available-height) min-w-(--anchor-width) scroll-py-6 overflow-y-auto p-1 [&:not(:has([role=option]))>[data-slot=select-empty]]:block\",\n className,\n )}\n data-slot=\"select-list\"\n >\n {/* Items sit 5px inside the 10px popup (1px border + 4px padding), so they are 10px - 5px round. */}\n <FluidHighlight className=\"rounded-[calc(var(--radius-lg)-5px)]\" />\n {children}\n <div\n className=\"hidden px-2 py-1.5 text-center text-muted-foreground text-sm\"\n data-slot=\"select-empty\"\n role=\"presentation\"\n >\n {emptyMessage}\n </div>\n </SelectPrimitive.List>\n </span>\n <SelectPrimitive.ScrollDownArrow\n className=\"bottom-0 flex h-6 w-full cursor-default items-center justify-center before:pointer-events-none before:absolute before:inset-x-px before:bottom-px before:h-[200%] before:rounded-b-[calc(var(--radius-lg)-1px)] before:bg-linear-to-t before:from-50% before:from-popover\"\n data-slot=\"select-scroll-down-arrow\"\n >\n <ChevronDownIcon className=\"relative size-4.5 sm:size-4\" />\n </SelectPrimitive.ScrollDownArrow>\n </SelectPrimitive.Popup>\n </SelectPrimitive.Positioner>\n </SelectPrimitive.Portal>\n );\n}\n\nfunction SelectItem({\n className,\n children,\n ...props\n}: SelectPrimitive.Item.Props) {\n return (\n <SelectPrimitive.Item\n className={cn(\n \"relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-[calc(var(--radius-lg)-5px)] py-1 ps-2 pe-4 text-base outline-none pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 data-disabled:pointer-events-none data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n className,\n )}\n data-slot=\"select-item\"\n {...props}\n >\n\t\t<SelectPrimitive.ItemIndicator\n\t\t\tkeepMounted\n\t\t\tclassName={(state) =>\n\t\t\t\tcn(\n\t\t\t\t\t'col-start-1 transition-[opacity,scale,filter] duration-(--duration-slow) ease-out motion-reduce:transition-none',\n\t\t\t\t\tstate.selected ? 'scale-100 opacity-100 blur-0' : 'scale-[0.25] opacity-0 blur-[4px]',\n\t\t\t\t)\n\t\t\t}\n\t\t>\n <svg\n fill=\"none\"\n height=\"24\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n viewBox=\"0 0 24 24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/1500/svg\"\n >\n <path d=\"M5.252 12.7 10.2 18.63 18.748 5.37\" />\n </svg>\n </SelectPrimitive.ItemIndicator>\n <SelectPrimitive.ItemText className=\"col-start-2 min-w-0 [overflow-wrap:anywhere]\">\n {children}\n </SelectPrimitive.ItemText>\n </SelectPrimitive.Item>\n );\n}\n\nfunction SelectSeparator({\n className,\n ...props\n}: SelectPrimitive.Separator.Props) {\n return (\n <SelectPrimitive.Separator\n className={cn(\"mx-2 my-1 h-px bg-border\", className)}\n data-slot=\"select-separator\"\n {...props}\n />\n );\n}\n\nfunction SelectGroup({ ...props }: SelectPrimitive.Group.Props) {\n return <SelectPrimitive.Group data-slot=\"select-group\" {...props} />;\n}\n\nfunction SelectGroupLabel({ ...props }: SelectPrimitive.GroupLabel.Props) {\n return (\n <SelectPrimitive.GroupLabel\n className=\"px-2 py-1.5 font-medium text-muted-foreground text-xs\"\n data-slot=\"select-group-label\"\n {...props}\n />\n );\n}\n\ntype SelectRichItemProps = SelectPrimitive.Item.Props & {\n /** Main label text */\n label?: React.ReactNode;\n /** Optional description text below the label */\n description?: React.ReactNode;\n /** Optional icon element */\n icon?: React.ReactNode;\n};\n\nfunction SelectRichItem({\n className,\n children,\n label,\n description,\n icon,\n ...props\n}: SelectRichItemProps) {\n return (\n <SelectPrimitive.Item\n className={cn(\n \"relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-[calc(var(--radius-lg)-5px)] py-1.5 ps-2 pe-4 text-base outline-none pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 data-disabled:pointer-events-none data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n className,\n )}\n data-slot=\"select-rich-item\"\n {...props}\n >\n\t\t<SelectPrimitive.ItemIndicator\n\t\t\tkeepMounted\n\t\t\tclassName={(state) =>\n\t\t\t\tcn(\n\t\t\t\t\t'col-start-1 mt-0.5 self-start transition-[opacity,scale,filter] duration-(--duration-slow) ease-out motion-reduce:transition-none',\n\t\t\t\t\tstate.selected ? 'scale-100 opacity-100 blur-0' : 'scale-[0.25] opacity-0 blur-[4px]',\n\t\t\t\t)\n\t\t\t}\n\t\t>\n <svg\n fill=\"none\"\n height=\"24\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n viewBox=\"0 0 24 24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path d=\"M5.252 12.7 10.2 18.63 18.748 5.37\" />\n </svg>\n </SelectPrimitive.ItemIndicator>\n <SelectPrimitive.ItemText className=\"col-start-2 min-w-0 flex flex-col gap-0.5 [overflow-wrap:anywhere]\">\n <span className=\"flex items-center gap-2\">\n {icon}\n {label ?? children}\n </span>\n {description && (\n <span className=\"text-muted-foreground text-xs\">{description}</span>\n )}\n </SelectPrimitive.ItemText>\n </SelectPrimitive.Item>\n );\n}\n\ntype SelectFieldItemProps = SelectPrimitive.Item.Props & {\n /** Field name to display */\n name: string;\n /** Field type to display as muted text */\n type?: string;\n};\n\nfunction SelectFieldItem({\n className,\n name,\n type,\n ...props\n}: SelectFieldItemProps) {\n return (\n <SelectPrimitive.Item\n className={cn(\n \"relative grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 rounded-[calc(var(--radius-lg)-5px)] py-1 ps-2 pe-4 text-base outline-none pointer-coarse:min-h-11 sm:pointer-coarse:min-h-11 data-disabled:pointer-events-none data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n className,\n )}\n data-slot=\"select-field-item\"\n {...props}\n >\n\t\t<SelectPrimitive.ItemIndicator\n\t\t\tkeepMounted\n\t\t\tclassName={(state) =>\n\t\t\t\tcn(\n\t\t\t\t\t'col-start-1 transition-[opacity,scale,filter] duration-(--duration-slow) ease-out motion-reduce:transition-none',\n\t\t\t\t\tstate.selected ? 'scale-100 opacity-100 blur-0' : 'scale-[0.25] opacity-0 blur-[4px]',\n\t\t\t\t)\n\t\t\t}\n\t\t>\n <svg\n fill=\"none\"\n height=\"24\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n viewBox=\"0 0 24 24\"\n width=\"24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path d=\"M5.252 12.7 10.2 18.63 18.748 5.37\" />\n </svg>\n </SelectPrimitive.ItemIndicator>\n <SelectPrimitive.ItemText className=\"col-start-2 min-w-0 flex items-center justify-between gap-2\">\n <span className=\"truncate\">{name}</span>\n {type && (\n <span className=\"text-muted-foreground text-xs shrink-0\">{type}</span>\n )}\n </SelectPrimitive.ItemText>\n </SelectPrimitive.Item>\n );\n}\n\nexport {\n Select,\n SelectTrigger,\n SelectValue,\n SelectPopup,\n SelectPopup as SelectContent,\n SelectItem,\n SelectRichItem,\n SelectFieldItem,\n SelectSeparator,\n SelectGroup,\n SelectGroupLabel,\n SelectGroupLabel as SelectLabel,\n};\n"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAM,YAA0B,CAAC;;AAGjC,SAAS,OAAO,MAA+B;CAC7C,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU,OAAO,OAAO,IAAI;CAC5E,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,KAAK,IAAI,MAAM,CAAC,CAAC,KAAK,EAAE;CACxD,IAAIA,MAAM,eAA+C,IAAI,GAAG,OAAO,OAAO,KAAK,MAAM,QAAQ;CACjG,OAAO;AACT;AAEA,SAAS,YAAY,UAA2B,QAAsB;CACpE,MAAM,SAAS,QAAQ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