@yenio-pld/blocks 1.2.0-rc.11 → 1.2.0-rc.13
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/index.cjs +40 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +40 -10
- package/dist/index.js.map +1 -1
- package/dist/ui/dialog.d.ts +3 -1
- package/dist/ui/dialog.js +22 -4
- package/dist/ui/dialog.js.map +1 -1
- package/dist/ui/select.js +14 -5
- package/dist/ui/select.js.map +1 -1
- package/package.json +1 -1
package/dist/ui/dialog.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import * as React from 'react';
|
|
|
2
2
|
import { ComponentProps } from 'react';
|
|
3
3
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
4
4
|
|
|
5
|
+
/** Portal target for Base UI popups nested in this dialog (Select, Combobox, …). */
|
|
6
|
+
declare function useDialogPortalContainer(): HTMLElement | null;
|
|
5
7
|
declare function Dialog({ ...props }: ComponentProps<typeof DialogPrimitive.Root>): React.JSX.Element;
|
|
6
8
|
declare function DialogTrigger({ ...props }: ComponentProps<typeof DialogPrimitive.Trigger>): React.JSX.Element;
|
|
7
9
|
declare function DialogClose({ ...props }: ComponentProps<typeof DialogPrimitive.Close>): React.JSX.Element;
|
|
@@ -13,4 +15,4 @@ declare function DialogFooter({ className, ...props }: ComponentProps<"div">): R
|
|
|
13
15
|
declare function DialogTitle({ className, ...props }: ComponentProps<typeof DialogPrimitive.Title>): React.JSX.Element;
|
|
14
16
|
declare function DialogDescription({ className, ...props }: ComponentProps<typeof DialogPrimitive.Description>): React.JSX.Element;
|
|
15
17
|
|
|
16
|
-
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger };
|
|
18
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, useDialogPortalContainer };
|
package/dist/ui/dialog.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
3
3
|
import { XIcon } from 'lucide-react';
|
|
4
|
+
import { createContext, useContext, useState } from 'react';
|
|
4
5
|
import { clsx } from 'clsx';
|
|
5
6
|
import { twMerge } from 'tailwind-merge';
|
|
6
7
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
@@ -8,6 +9,10 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
8
9
|
function cn(...inputs) {
|
|
9
10
|
return twMerge(clsx(inputs));
|
|
10
11
|
}
|
|
12
|
+
var DialogPortalContainerContext = createContext(null);
|
|
13
|
+
function useDialogPortalContainer() {
|
|
14
|
+
return useContext(DialogPortalContainerContext);
|
|
15
|
+
}
|
|
11
16
|
function Dialog({ ...props }) {
|
|
12
17
|
return /* @__PURE__ */ jsx(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
|
|
13
18
|
}
|
|
@@ -46,7 +51,16 @@ function isPortaledOverlayTarget(target) {
|
|
|
46
51
|
if (!(target instanceof Element)) return false;
|
|
47
52
|
return Boolean(
|
|
48
53
|
target.closest(
|
|
49
|
-
|
|
54
|
+
[
|
|
55
|
+
'[data-slot="select-positioner"]',
|
|
56
|
+
'[data-slot="select-popup"]',
|
|
57
|
+
'[data-slot="combobox-positioner"]',
|
|
58
|
+
'[role="listbox"]',
|
|
59
|
+
'[role="option"]',
|
|
60
|
+
"[data-base-ui-portal]",
|
|
61
|
+
"[data-base-ui-focus-guard]",
|
|
62
|
+
"[data-base-ui-inert]"
|
|
63
|
+
].join(", ")
|
|
50
64
|
)
|
|
51
65
|
);
|
|
52
66
|
}
|
|
@@ -59,9 +73,12 @@ function DialogContent({
|
|
|
59
73
|
onFocusOutside,
|
|
60
74
|
...props
|
|
61
75
|
}) {
|
|
76
|
+
const [portalContainer, setPortalContainer] = useState(
|
|
77
|
+
null
|
|
78
|
+
);
|
|
62
79
|
return /* @__PURE__ */ jsxs(DialogPortal, { children: [
|
|
63
80
|
/* @__PURE__ */ jsx(DialogOverlay, {}),
|
|
64
|
-
/* @__PURE__ */ jsxs(
|
|
81
|
+
/* @__PURE__ */ jsx(DialogPortalContainerContext.Provider, { value: portalContainer, children: /* @__PURE__ */ jsxs(
|
|
65
82
|
DialogPrimitive.Content,
|
|
66
83
|
{
|
|
67
84
|
"data-slot": "dialog-content",
|
|
@@ -73,6 +90,7 @@ function DialogContent({
|
|
|
73
90
|
className
|
|
74
91
|
),
|
|
75
92
|
...props,
|
|
93
|
+
ref: setPortalContainer,
|
|
76
94
|
onPointerDownOutside: (event) => {
|
|
77
95
|
if (isPortaledOverlayTarget(event.target)) event.preventDefault();
|
|
78
96
|
onPointerDownOutside?.(event);
|
|
@@ -93,7 +111,7 @@ function DialogContent({
|
|
|
93
111
|
] }) : null
|
|
94
112
|
]
|
|
95
113
|
}
|
|
96
|
-
)
|
|
114
|
+
) })
|
|
97
115
|
] });
|
|
98
116
|
}
|
|
99
117
|
function DialogHeader({ className, ...props }) {
|
|
@@ -146,6 +164,6 @@ function DialogDescription({
|
|
|
146
164
|
);
|
|
147
165
|
}
|
|
148
166
|
|
|
149
|
-
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger };
|
|
167
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, useDialogPortalContainer };
|
|
150
168
|
//# sourceMappingURL=dialog.js.map
|
|
151
169
|
//# sourceMappingURL=dialog.js.map
|
package/dist/ui/dialog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/utils.ts","../../src/ui/dialog.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/lib/utils.ts","../../src/ui/dialog.tsx"],"names":[],"mappings":";;;;;;;AAGO,SAAS,MAAM,MAA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AAA;AAAA,IAAiB,eAAA,CAAA,KAAA;AAAA,IAAhB;AAAA,MACA,WAAA,EAAU,cAAA;AAAA,MACV,SAAA,EAAW,EAAA,CAAG,oCAAA,EAAsC,SAAS,CAAA;AAAA,MAC5D,GAAG;AAAA;AAAA,GACL;AAEF;AAEA,SAAS,iBAAA,CAAkB;AAAA,EAC1B,SAAA;AAAA,EACA,GAAG;AACJ,CAAA,EAAuD;AACtD,EAAA,uBACC,GAAA;AAAA,IAAiB,eAAA,CAAA,WAAA;AAAA,IAAhB;AAAA,MACA,WAAA,EAAU,oBAAA;AAAA,MACV,SAAA,EAAW,EAAA,CAAG,+BAAA,EAAiC,SAAS,CAAA;AAAA,MACvD,GAAG;AAAA;AAAA,GACL;AAEF","file":"dialog.js","sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n\treturn twMerge(clsx(inputs));\n}\n","\"use client\";\n\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\nimport { XIcon } from \"lucide-react\";\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseState,\n\ttype ComponentProps,\n} from \"react\";\nimport { cn } from \"../lib/utils\";\n\nconst DialogPortalContainerContext = createContext<HTMLElement | null>(null);\n\n/** Portal target for Base UI popups nested in this dialog (Select, Combobox, …). */\nfunction useDialogPortalContainer(): HTMLElement | null {\n\treturn useContext(DialogPortalContainerContext);\n}\n\nfunction Dialog({ ...props }: ComponentProps<typeof DialogPrimitive.Root>) {\n\treturn <DialogPrimitive.Root data-slot=\"dialog\" {...props} />;\n}\n\nfunction DialogTrigger({\n\t...props\n}: ComponentProps<typeof DialogPrimitive.Trigger>) {\n\treturn <DialogPrimitive.Trigger data-slot=\"dialog-trigger\" {...props} />;\n}\n\nfunction DialogPortal({\n\t...props\n}: ComponentProps<typeof DialogPrimitive.Portal>) {\n\treturn <DialogPrimitive.Portal data-slot=\"dialog-portal\" {...props} />;\n}\n\nfunction DialogClose({\n\t...props\n}: ComponentProps<typeof DialogPrimitive.Close>) {\n\treturn <DialogPrimitive.Close data-slot=\"dialog-close\" {...props} />;\n}\n\nfunction DialogOverlay({\n\tclassName,\n\t...props\n}: ComponentProps<typeof DialogPrimitive.Overlay>) {\n\treturn (\n\t\t<DialogPrimitive.Overlay\n\t\t\tdata-slot=\"dialog-overlay\"\n\t\t\tclassName={cn(\n\t\t\t\t\"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\n/**\n * Portaled Base UI Select / Combobox popups (and their focus guards / inert\n * backdrops) sit outside Dialog Content in the DOM when not using the dialog\n * portal container. Treat those nodes as inside the dialog for dismiss/focus.\n */\nfunction isPortaledOverlayTarget(target: EventTarget | null): boolean {\n\tif (!(target instanceof Element)) return false;\n\treturn Boolean(\n\t\ttarget.closest(\n\t\t\t[\n\t\t\t\t'[data-slot=\"select-positioner\"]',\n\t\t\t\t'[data-slot=\"select-popup\"]',\n\t\t\t\t'[data-slot=\"combobox-positioner\"]',\n\t\t\t\t'[role=\"listbox\"]',\n\t\t\t\t'[role=\"option\"]',\n\t\t\t\t\"[data-base-ui-portal]\",\n\t\t\t\t\"[data-base-ui-focus-guard]\",\n\t\t\t\t\"[data-base-ui-inert]\",\n\t\t\t].join(\", \"),\n\t\t),\n\t);\n}\n\nfunction DialogContent({\n\tclassName,\n\tchildren,\n\tshowCloseButton = true,\n\tonPointerDownOutside,\n\tonInteractOutside,\n\tonFocusOutside,\n\t...props\n}: ComponentProps<typeof DialogPrimitive.Content> & {\n\tshowCloseButton?: boolean;\n}) {\n\tconst [portalContainer, setPortalContainer] = useState<HTMLElement | null>(\n\t\tnull,\n\t);\n\n\treturn (\n\t\t<DialogPortal>\n\t\t\t<DialogOverlay />\n\t\t\t<DialogPortalContainerContext.Provider value={portalContainer}>\n\t\t\t\t<DialogPrimitive.Content\n\t\t\t\t\tdata-slot=\"dialog-content\"\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t// Center with inset + margin, not translate. Translate (and zoom\n\t\t\t\t\t\t// scale) create a containing block that misaligns Google Places\n\t\t\t\t\t\t// PlaceAutocompleteElement prediction lists and other fixed UI.\n\t\t\t\t\t\t\"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 m-auto grid h-fit w-full max-w-[calc(100%-2rem)] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg\",\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t)}\n\t\t\t\t\t{...props}\n\t\t\t\t\tref={setPortalContainer}\n\t\t\t\t\tonPointerDownOutside={(event) => {\n\t\t\t\t\t\tif (isPortaledOverlayTarget(event.target)) event.preventDefault();\n\t\t\t\t\t\tonPointerDownOutside?.(event);\n\t\t\t\t\t}}\n\t\t\t\t\tonInteractOutside={(event) => {\n\t\t\t\t\t\tif (isPortaledOverlayTarget(event.target)) event.preventDefault();\n\t\t\t\t\t\tonInteractOutside?.(event);\n\t\t\t\t\t}}\n\t\t\t\t\tonFocusOutside={(event) => {\n\t\t\t\t\t\tif (isPortaledOverlayTarget(event.target)) event.preventDefault();\n\t\t\t\t\t\tonFocusOutside?.(event);\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t\t{showCloseButton ? (\n\t\t\t\t\t\t<DialogPrimitive.Close className=\"ring-offset-background focus:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none\">\n\t\t\t\t\t\t\t<XIcon className=\"size-4\" />\n\t\t\t\t\t\t\t<span className=\"sr-only\">Close</span>\n\t\t\t\t\t\t</DialogPrimitive.Close>\n\t\t\t\t\t) : null}\n\t\t\t\t</DialogPrimitive.Content>\n\t\t\t</DialogPortalContainerContext.Provider>\n\t\t</DialogPortal>\n\t);\n}\n\nfunction DialogHeader({ className, ...props }: ComponentProps<\"div\">) {\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"dialog-header\"\n\t\t\tclassName={cn(\"flex flex-col gap-2 text-center sm:text-left\", className)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction DialogFooter({ className, ...props }: ComponentProps<\"div\">) {\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"dialog-footer\"\n\t\t\tclassName={cn(\n\t\t\t\t\"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction DialogTitle({\n\tclassName,\n\t...props\n}: ComponentProps<typeof DialogPrimitive.Title>) {\n\treturn (\n\t\t<DialogPrimitive.Title\n\t\t\tdata-slot=\"dialog-title\"\n\t\t\tclassName={cn(\"text-lg leading-none font-semibold\", className)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction DialogDescription({\n\tclassName,\n\t...props\n}: ComponentProps<typeof DialogPrimitive.Description>) {\n\treturn (\n\t\t<DialogPrimitive.Description\n\t\t\tdata-slot=\"dialog-description\"\n\t\t\tclassName={cn(\"text-muted-foreground text-sm\", className)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nexport {\n\tDialog,\n\tDialogClose,\n\tDialogContent,\n\tDialogDescription,\n\tDialogFooter,\n\tDialogHeader,\n\tDialogTitle,\n\tDialogTrigger,\n\tuseDialogPortalContainer,\n};\n"]}
|
package/dist/ui/select.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Select as Select$1 } from '@base-ui/react/select';
|
|
|
4
4
|
import { ChevronDownIcon, CheckIcon } from 'lucide-react';
|
|
5
5
|
import { clsx } from 'clsx';
|
|
6
6
|
import { twMerge } from 'tailwind-merge';
|
|
7
|
+
import { useDialogPortalContainer } from './dialog.js';
|
|
7
8
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
8
9
|
|
|
9
10
|
function cn(...inputs) {
|
|
@@ -26,6 +27,11 @@ function parseOptionChildren(children) {
|
|
|
26
27
|
var triggerClassName = "flex h-8 w-full min-w-0 items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40";
|
|
27
28
|
var popupClassName = "pointer-events-auto z-[100] max-h-(--available-height) min-w-(--anchor-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95";
|
|
28
29
|
var itemClassName = "relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none pointer-events-auto data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-accent data-highlighted:text-accent-foreground data-selected:bg-accent/50";
|
|
30
|
+
function optionsSignature(options) {
|
|
31
|
+
return options.map(
|
|
32
|
+
(option) => `${option.value}\0${option.disabled ? "1" : "0"}\0${typeof option.label === "string" ? option.label : ""}`
|
|
33
|
+
).join("\n");
|
|
34
|
+
}
|
|
29
35
|
function Select({
|
|
30
36
|
className,
|
|
31
37
|
children,
|
|
@@ -43,10 +49,13 @@ function Select({
|
|
|
43
49
|
"aria-describedby": ariaDescribedby,
|
|
44
50
|
"aria-invalid": ariaInvalid
|
|
45
51
|
}) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
)
|
|
52
|
+
const dialogPortalContainer = useDialogPortalContainer();
|
|
53
|
+
const optionsRef = React.useRef([]);
|
|
54
|
+
const nextOptions = parseOptionChildren(children);
|
|
55
|
+
if (optionsSignature(optionsRef.current) !== optionsSignature(nextOptions)) {
|
|
56
|
+
optionsRef.current = nextOptions;
|
|
57
|
+
}
|
|
58
|
+
const options = optionsRef.current;
|
|
50
59
|
const items = React.useMemo(
|
|
51
60
|
() => options.map((option) => ({ value: option.value, label: option.label })),
|
|
52
61
|
[options]
|
|
@@ -103,7 +112,7 @@ function Select({
|
|
|
103
112
|
]
|
|
104
113
|
}
|
|
105
114
|
),
|
|
106
|
-
/* @__PURE__ */ jsx(Select$1.Portal, { children: /* @__PURE__ */ jsx(
|
|
115
|
+
/* @__PURE__ */ jsx(Select$1.Portal, { container: dialogPortalContainer ?? void 0, children: /* @__PURE__ */ jsx(
|
|
107
116
|
Select$1.Positioner,
|
|
108
117
|
{
|
|
109
118
|
"data-slot": "select-positioner",
|
package/dist/ui/select.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/utils.ts","../../src/ui/select.tsx"],"names":["SelectPrimitive"],"mappings":";;;;;;;AAGO,SAAS,MAAM,MAAA,EAAsB;AAC3C,EAAA,OAAO,OAAA,CAAQ,IAAA,CAAK,MAAM,CAAC,CAAA;AAC5B;ACSA,SAAS,oBAAoB,QAAA,EAA2C;AACvE,EAAA,MAAM,UAA0B,EAAC;AACjC,EAAM,KAAA,CAAA,QAAA,CAAS,OAAA,CAAQ,QAAA,EAAU,CAAC,KAAA,KAAU;AAC3C,IAAA,IAAI,CAAO,KAAA,CAAA,cAAA,CAAe,KAAK,CAAA,IAAK,KAAA,CA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U,MAAA,CAAO,QAAA;AAAA,oBACjB,SAAA,EAAW,aAAA;AAAA,oBAEX,QAAA,EAAA;AAAA,sCAAA,GAAA,CAACA,QAAA,CAAgB,QAAA,EAAhB,EACC,QAAA,EAAA,MAAA,CAAO,KAAA,EACT,CAAA;AAAA,sCACA,GAAA,CAACA,QAAA,CAAgB,aAAA,EAAhB,EAA8B,SAAA,EAAU,kFACxC,QAAA,kBAAA,GAAA,CAAC,SAAA,EAAA,EAAU,SAAA,EAAU,QAAA,EAAS,CAAA,EAC/B;AAAA;AAAA,mBAAA;AAAA,kBAfK,MAAA,CAAO;AAAA,iBAiBb,CAAA,EACF;AAAA;AAAA;AACD;AAAA,SACD,EACD;AAAA;AAAA;AAAA,GACD;AAEF","file":"select.js","sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n\treturn twMerge(clsx(inputs));\n}\n","\"use client\";\n\nimport * as React from \"react\";\nimport { Select as SelectPrimitive } from \"@base-ui/react/select\";\nimport { CheckIcon, ChevronDownIcon } from \"lucide-react\";\n\nimport { cn } from \"../lib/utils\";\n\ntype ParsedOption = {\n\tvalue: string;\n\tlabel: React.ReactNode;\n\tdisabled?: boolean;\n};\n\nfunction parseOptionChildren(children: React.ReactNode): ParsedOption[] {\n\tconst options: ParsedOption[] = [];\n\tReact.Children.forEach(children, (child) => {\n\t\tif (!React.isValidElement(child) || child.type !== \"option\") return;\n\t\tconst props = child.props as React.OptionHTMLAttributes<HTMLOptionElement>;\n\t\tif (props.value === undefined || props.value === null) return;\n\t\toptions.push({\n\t\t\tvalue: String(props.value),\n\t\t\tlabel: props.children ?? String(props.value),\n\t\t\tdisabled: props.disabled,\n\t\t});\n\t});\n\treturn options;\n}\n\nconst triggerClassName =\n\t\"flex h-8 w-full min-w-0 items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40\";\n\nconst popupClassName =\n\t\"pointer-events-auto z-[100] max-h-(--available-height) min-w-(--anchor-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95\";\n\nconst itemClassName =\n\t\"relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none pointer-events-auto data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-accent data-highlighted:text-accent-foreground data-selected:bg-accent/50\";\n\ntype SelectProps = Omit<\n\tReact.ComponentProps<\"select\">,\n\t\"onChange\" | \"children\" | \"size\" | \"multiple\"\n> & {\n\tonChange?: React.ChangeEventHandler<HTMLSelectElement>;\n\tchildren?: React.ReactNode;\n};\n\nfunction Select({\n\tclassName,\n\tchildren,\n\tvalue,\n\tdefaultValue,\n\tonChange,\n\tdisabled,\n\trequired,\n\tname,\n\tid,\n\tautoFocus,\n\ttabIndex,\n\t\"aria-label\": ariaLabel,\n\t\"aria-labelledby\": ariaLabelledby,\n\t\"aria-describedby\": ariaDescribedby,\n\t\"aria-invalid\": ariaInvalid,\n}: SelectProps) {\n\tconst options = React.useMemo(\n\t\t() => parseOptionChildren(children),\n\t\t[children],\n\t);\n\tconst items = React.useMemo(\n\t\t() =>\n\t\t\toptions.map((option) => ({ value: option.value, label: option.label })),\n\t\t[options],\n\t);\n\n\tconst handleValueChange = React.useCallback(\n\t\t(next: string | null) => {\n\t\t\tif (!onChange) return;\n\t\t\tconst nextValue = next ?? \"\";\n\t\t\tonChange({\n\t\t\t\ttarget: { value: nextValue },\n\t\t\t\tcurrentTarget: { value: nextValue },\n\t\t\t} as React.ChangeEvent<HTMLSelectElement>);\n\t\t},\n\t\t[onChange],\n\t);\n\n\t// Base UI rejects \"\" as a controlled value (throws → workspace error boundary).\n\tconst controlledValue =\n\t\tvalue === undefined || value === null || value === \"\"\n\t\t\t? null\n\t\t\t: String(value);\n\tconst uncontrolledDefault =\n\t\tdefaultValue === undefined || defaultValue === null || defaultValue === \"\"\n\t\t\t? undefined\n\t\t\t: String(defaultValue);\n\n\tif (options.length === 0) {\n\t\treturn (\n\t\t\t<select\n\t\t\t\tdata-slot=\"select\"\n\t\t\t\tclassName={cn(triggerClassName, className)}\n\t\t\t\tdisabled\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<SelectPrimitive.Root\n\t\t\tname={name}\n\t\t\trequired={required}\n\t\t\tdisabled={disabled}\n\t\t\t// Keep the Base UI default (modal). `modal={false}` leaves the popup under\n\t\t\t// Radix Dialog's body `pointer-events: none`, so options cannot be clicked\n\t\t\t// and the list appears to blur/collapse immediately.\n\t\t\titems={items}\n\t\t\tvalue={controlledValue}\n\t\t\tdefaultValue={uncontrolledDefault}\n\t\t\tonValueChange={handleValueChange}\n\t\t>\n\t\t\t<SelectPrimitive.Trigger\n\t\t\t\tdata-slot=\"select\"\n\t\t\t\tid={id}\n\t\t\t\tautoFocus={autoFocus}\n\t\t\t\ttabIndex={tabIndex}\n\t\t\t\taria-label={ariaLabel}\n\t\t\t\taria-labelledby={ariaLabelledby}\n\t\t\t\taria-describedby={ariaDescribedby}\n\t\t\t\taria-invalid={ariaInvalid}\n\t\t\t\tclassName={cn(triggerClassName, className)}\n\t\t\t>\n\t\t\t\t<SelectPrimitive.Value className=\"truncate text-left\" />\n\t\t\t\t<SelectPrimitive.Icon className=\"pointer-events-none shrink-0 text-muted-foreground\">\n\t\t\t\t\t<ChevronDownIcon className=\"size-4\" />\n\t\t\t\t</SelectPrimitive.Icon>\n\t\t\t</SelectPrimitive.Trigger>\n\t\t\t<SelectPrimitive.Portal>\n\t\t\t\t{/* pointer-events-auto + high z: Radix Dialog overlay otherwise steals\n\t\t\t\t clicks/focus from this portaled popup (same pattern as CountryPicker). */}\n\t\t\t\t<SelectPrimitive.Positioner\n\t\t\t\t\tdata-slot=\"select-positioner\"\n\t\t\t\t\tclassName=\"pointer-events-auto isolate z-[100] outline-none\"\n\t\t\t\t\tsideOffset={4}\n\t\t\t\t>\n\t\t\t\t\t<SelectPrimitive.Popup\n\t\t\t\t\t\tdata-slot=\"select-popup\"\n\t\t\t\t\t\tclassName={popupClassName}\n\t\t\t\t\t>\n\t\t\t\t\t\t<SelectPrimitive.List onWheel={(event) => event.stopPropagation()}>\n\t\t\t\t\t\t\t{options.map((option) => (\n\t\t\t\t\t\t\t\t<SelectPrimitive.Item\n\t\t\t\t\t\t\t\t\tkey={option.value}\n\t\t\t\t\t\t\t\t\tvalue={option.value}\n\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\ttypeof option.label === \"string\"\n\t\t\t\t\t\t\t\t\t\t\t? option.label\n\t\t\t\t\t\t\t\t\t\t\t: option.value\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdisabled={option.disabled}\n\t\t\t\t\t\t\t\t\tclassName={itemClassName}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<SelectPrimitive.ItemText>\n\t\t\t\t\t\t\t\t\t\t{option.label}\n\t\t\t\t\t\t\t\t\t</SelectPrimitive.ItemText>\n\t\t\t\t\t\t\t\t\t<SelectPrimitive.ItemIndicator className=\"pointer-events-none absolute right-1.5 flex size-4 items-center justify-center\">\n\t\t\t\t\t\t\t\t\t\t<CheckIcon className=\"size-4\" />\n\t\t\t\t\t\t\t\t\t</SelectPrimitive.ItemIndicator>\n\t\t\t\t\t\t\t\t</SelectPrimitive.Item>\n\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t</SelectPrimitive.List>\n\t\t\t\t\t</SelectPrimitive.Popup>\n\t\t\t\t</SelectPrimitive.Positioner>\n\t\t\t</SelectPrimitive.Portal>\n\t\t</SelectPrimitive.Root>\n\t);\n}\n\nexport { Select };\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/lib/utils.ts","../../src/ui/select.tsx"],"names":["SelectPrimitive"],"mappings":";;;;;;;;AAGO,SAAS,MAAM,MAAA,EAAsB;AAC3C,EAAA,OAAO,OAAA,CAAQ,IAAA,CAAK,MAAM,CAAC,CAAA;AAC5B;ACUA,SAAS,oBAAoB,QAAA,EAA2C;AACvE,EAAA,MAAM,UAA0B,EAAC;AACjC,EAAM,KAAA,CAAA,QAAA,CAAS,OAAA,CAAQ,QAAA,EAAU,CAAC,KAAA,KAAU;AAC3C,IAAA,IAAI,CAAO,KAAA,CAAA,cAAA,CAAe,KAAK,CAAA,IAAK,KAAA,CAAM,SAAS,QAAA,EAAU;AAC7D,IAAA,MAAM,QAAQ,KAAA,CAAM,KAAA;AACpB,IAAA,IAAI,KAAA,CAAM,KAAA,KAAU,MAAA,IAAa,KAAA,CAAM,UAAU,IAAA,EAAM;AACvD,IAAA,OAAA,CAAQ,IAAA,CAAK;AAAA,MACZ,KAAA,EAAO,MAAA,CAAO,KAAA,CAAM,KAAK,CAAA;AAAA,MACzB,KAAA,EAAO,KAAA,CAAM,QAAA,IAAY,MAAA,CAAO,MAAM,KAAK,CAAA;AAAA,MAC3C,UAAU,KAAA,CAAM;AAAA,KAChB,CAAA;AAAA,EACF,CAAC,CAAA;AACD,EAAA,OAAO,OAAA;AACR;AAEA,IAAM,gBAAA,GACL,oiBAAA;AAED,IAAM,cAAA,GACL,qpBAAA;AAED,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,CAAO,QACP,MAAA,CAAO,KAAA;AAAA,oBAEX,UAAU,MAAA,CAAO,QAAA;AAAA,oBACjB,SAAA,EAAW,aAAA;AAAA,oBAEX,QAAA,EAAA;AAAA,sCAAA,GAAA,CAACA,QAAA,CAAgB,QAAA,EAAhB,EACC,QAAA,EAAA,MAAA,CAAO,KAAA,EACT,CAAA;AAAA,sCACA,GAAA,CAACA,QAAA,CAAgB,aAAA,EAAhB,EAA8B,SAAA,EAAU,kFACxC,QAAA,kBAAA,GAAA,CAAC,SAAA,EAAA,EAAU,SAAA,EAAU,QAAA,EAAS,CAAA,EAC/B;AAAA;AAAA,mBAAA;AAAA,kBAfK,MAAA,CAAO;AAAA,iBAiBb,CAAA,EACF;AAAA;AAAA;AACD;AAAA,SACD,EACD;AAAA;AAAA;AAAA,GACD;AAEF","file":"select.js","sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n\treturn twMerge(clsx(inputs));\n}\n","\"use client\";\n\nimport * as React from \"react\";\nimport { Select as SelectPrimitive } from \"@base-ui/react/select\";\nimport { CheckIcon, ChevronDownIcon } from \"lucide-react\";\n\nimport { cn } from \"../lib/utils\";\nimport { useDialogPortalContainer } from \"./dialog\";\n\ntype ParsedOption = {\n\tvalue: string;\n\tlabel: React.ReactNode;\n\tdisabled?: boolean;\n};\n\nfunction parseOptionChildren(children: React.ReactNode): ParsedOption[] {\n\tconst options: ParsedOption[] = [];\n\tReact.Children.forEach(children, (child) => {\n\t\tif (!React.isValidElement(child) || child.type !== \"option\") return;\n\t\tconst props = child.props as React.OptionHTMLAttributes<HTMLOptionElement>;\n\t\tif (props.value === undefined || props.value === null) return;\n\t\toptions.push({\n\t\t\tvalue: String(props.value),\n\t\t\tlabel: props.children ?? String(props.value),\n\t\t\tdisabled: props.disabled,\n\t\t});\n\t});\n\treturn options;\n}\n\nconst triggerClassName =\n\t\"flex h-8 w-full min-w-0 items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40\";\n\nconst popupClassName =\n\t\"pointer-events-auto z-[100] max-h-(--available-height) min-w-(--anchor-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95\";\n\nconst itemClassName =\n\t\"relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none pointer-events-auto data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-accent data-highlighted:text-accent-foreground data-selected:bg-accent/50\";\n\ntype SelectProps = Omit<\n\tReact.ComponentProps<\"select\">,\n\t\"onChange\" | \"children\" | \"size\" | \"multiple\"\n> & {\n\tonChange?: React.ChangeEventHandler<HTMLSelectElement>;\n\tchildren?: React.ReactNode;\n};\n\nfunction optionsSignature(options: ParsedOption[]): string {\n\treturn options\n\t\t.map(\n\t\t\t(option) =>\n\t\t\t\t`${option.value}\\0${option.disabled ? \"1\" : \"0\"}\\0${\n\t\t\t\t\ttypeof option.label === \"string\" ? option.label : \"\"\n\t\t\t\t}`,\n\t\t)\n\t\t.join(\"\\n\");\n}\n\nfunction Select({\n\tclassName,\n\tchildren,\n\tvalue,\n\tdefaultValue,\n\tonChange,\n\tdisabled,\n\trequired,\n\tname,\n\tid,\n\tautoFocus,\n\ttabIndex,\n\t\"aria-label\": ariaLabel,\n\t\"aria-labelledby\": ariaLabelledby,\n\t\"aria-describedby\": ariaDescribedby,\n\t\"aria-invalid\": ariaInvalid,\n}: SelectProps) {\n\tconst dialogPortalContainer = useDialogPortalContainer();\n\t// `children` is a new element tree every parent render; keep the same options\n\t// array when value/label/disabled are unchanged so an open list does not remount.\n\tconst optionsRef = React.useRef<ParsedOption[]>([]);\n\tconst nextOptions = parseOptionChildren(children);\n\tif (optionsSignature(optionsRef.current) !== optionsSignature(nextOptions)) {\n\t\toptionsRef.current = nextOptions;\n\t}\n\tconst options = optionsRef.current;\n\tconst items = React.useMemo(\n\t\t() =>\n\t\t\toptions.map((option) => ({ value: option.value, label: option.label })),\n\t\t[options],\n\t);\n\n\tconst handleValueChange = React.useCallback(\n\t\t(next: string | null) => {\n\t\t\tif (!onChange) return;\n\t\t\tconst nextValue = next ?? \"\";\n\t\t\tonChange({\n\t\t\t\ttarget: { value: nextValue },\n\t\t\t\tcurrentTarget: { value: nextValue },\n\t\t\t} as React.ChangeEvent<HTMLSelectElement>);\n\t\t},\n\t\t[onChange],\n\t);\n\n\t// Base UI rejects \"\" as a controlled value (throws → workspace error boundary).\n\tconst controlledValue =\n\t\tvalue === undefined || value === null || value === \"\"\n\t\t\t? null\n\t\t\t: String(value);\n\tconst uncontrolledDefault =\n\t\tdefaultValue === undefined || defaultValue === null || defaultValue === \"\"\n\t\t\t? undefined\n\t\t\t: String(defaultValue);\n\n\tif (options.length === 0) {\n\t\treturn (\n\t\t\t<select\n\t\t\t\tdata-slot=\"select\"\n\t\t\t\tclassName={cn(triggerClassName, className)}\n\t\t\t\tdisabled\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<SelectPrimitive.Root\n\t\t\tname={name}\n\t\t\trequired={required}\n\t\t\tdisabled={disabled}\n\t\t\t// Keep the Base UI default (modal). `modal={false}` leaves the popup under\n\t\t\t// Radix Dialog's body `pointer-events: none`, so options cannot be clicked\n\t\t\t// and the list appears to blur/collapse immediately.\n\t\t\titems={items}\n\t\t\tvalue={controlledValue}\n\t\t\tdefaultValue={uncontrolledDefault}\n\t\t\tonValueChange={handleValueChange}\n\t\t>\n\t\t\t<SelectPrimitive.Trigger\n\t\t\t\tdata-slot=\"select\"\n\t\t\t\tid={id}\n\t\t\t\tautoFocus={autoFocus}\n\t\t\t\ttabIndex={tabIndex}\n\t\t\t\taria-label={ariaLabel}\n\t\t\t\taria-labelledby={ariaLabelledby}\n\t\t\t\taria-describedby={ariaDescribedby}\n\t\t\t\taria-invalid={ariaInvalid}\n\t\t\t\tclassName={cn(triggerClassName, className)}\n\t\t\t>\n\t\t\t\t<SelectPrimitive.Value className=\"truncate text-left\" />\n\t\t\t\t<SelectPrimitive.Icon className=\"pointer-events-none shrink-0 text-muted-foreground\">\n\t\t\t\t\t<ChevronDownIcon className=\"size-4\" />\n\t\t\t\t</SelectPrimitive.Icon>\n\t\t\t</SelectPrimitive.Trigger>\n\t\t\t{/* Prefer Dialog content as portal root so Radix focus trap keeps the list\n\t\t\t open; fall back to body with pointer-events/z overrides. */}\n\t\t\t<SelectPrimitive.Portal container={dialogPortalContainer ?? undefined}>\n\t\t\t\t<SelectPrimitive.Positioner\n\t\t\t\t\tdata-slot=\"select-positioner\"\n\t\t\t\t\tclassName=\"pointer-events-auto isolate z-[100] outline-none\"\n\t\t\t\t\tsideOffset={4}\n\t\t\t\t>\n\t\t\t\t\t<SelectPrimitive.Popup\n\t\t\t\t\t\tdata-slot=\"select-popup\"\n\t\t\t\t\t\tclassName={popupClassName}\n\t\t\t\t\t>\n\t\t\t\t\t\t<SelectPrimitive.List onWheel={(event) => event.stopPropagation()}>\n\t\t\t\t\t\t\t{options.map((option) => (\n\t\t\t\t\t\t\t\t<SelectPrimitive.Item\n\t\t\t\t\t\t\t\t\tkey={option.value}\n\t\t\t\t\t\t\t\t\tvalue={option.value}\n\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\ttypeof option.label === \"string\"\n\t\t\t\t\t\t\t\t\t\t\t? option.label\n\t\t\t\t\t\t\t\t\t\t\t: option.value\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdisabled={option.disabled}\n\t\t\t\t\t\t\t\t\tclassName={itemClassName}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<SelectPrimitive.ItemText>\n\t\t\t\t\t\t\t\t\t\t{option.label}\n\t\t\t\t\t\t\t\t\t</SelectPrimitive.ItemText>\n\t\t\t\t\t\t\t\t\t<SelectPrimitive.ItemIndicator className=\"pointer-events-none absolute right-1.5 flex size-4 items-center justify-center\">\n\t\t\t\t\t\t\t\t\t\t<CheckIcon className=\"size-4\" />\n\t\t\t\t\t\t\t\t\t</SelectPrimitive.ItemIndicator>\n\t\t\t\t\t\t\t\t</SelectPrimitive.Item>\n\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t</SelectPrimitive.List>\n\t\t\t\t\t</SelectPrimitive.Popup>\n\t\t\t\t</SelectPrimitive.Positioner>\n\t\t\t</SelectPrimitive.Portal>\n\t\t</SelectPrimitive.Root>\n\t);\n}\n\nexport { Select };\n"]}
|