@nadicodeai/ui 12.1.72 → 12.1.73

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.
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  type NativeSelectProps = Omit<React.ComponentProps<"select">, "size"> & {
3
3
  size?: "sm" | "default";
4
4
  };
5
- declare function NativeSelect({ className, size, ...props }: NativeSelectProps): React.JSX.Element;
5
+ declare function NativeSelect({ className, size, ref, ...props }: NativeSelectProps): React.JSX.Element;
6
6
  declare function NativeSelectOption({ className, ...props }: React.ComponentProps<"option">): React.JSX.Element;
7
7
  declare function NativeSelectOptGroup({ className, ...props }: React.ComponentProps<"optgroup">): React.JSX.Element;
8
8
  export { NativeSelect, NativeSelectOptGroup, NativeSelectOption };
@@ -1 +1 @@
1
- {"version":3,"file":"native-select.d.ts","sourceRoot":"","sources":["../../src/components/native-select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,KAAK,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,GAAG;IACtE,IAAI,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;CACzB,CAAC;AAEF,iBAAS,YAAY,CAAC,EAAE,SAAS,EAAE,IAAgB,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,qBAuBjF;AAED,iBAAS,kBAAkB,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,qBAQlF;AAED,iBAAS,oBAAoB,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,qBAQtF;AAED,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"native-select.d.ts","sourceRoot":"","sources":["../../src/components/native-select.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,KAAK,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,GAAG;IACtE,IAAI,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;CACzB,CAAC;AAEF,iBAAS,YAAY,CAAC,EAAE,SAAS,EAAE,IAAgB,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,qBA4DtF;AAED,iBAAS,kBAAkB,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,qBAQlF;AAED,iBAAS,oBAAoB,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,qBAQtF;AAED,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,CAAC"}
@@ -1,8 +1,48 @@
1
+ "use client";
1
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
2
4
  import { cn } from "../lib/utils.js";
3
5
  import { ChevronDownIcon } from "lucide-react";
4
- function NativeSelect({ className, size = "default", ...props }) {
5
- return (_jsxs("div", { className: cn("group/native-select relative w-fit has-[select:disabled]:opacity-50", className), "data-slot": "native-select-wrapper", "data-size": size, children: [_jsx("select", { "data-slot": "native-select", "data-size": size, className: "h-control-height min-h-touch-target w-full min-w-0 appearance-none rounded-md border border-input bg-background py-1 pr-8 pl-control-padding-inline text-sm transition-colors select-none selection:bg-primary selection:text-primary-foreground placeholder:text-placeholder disabled:pointer-events-none disabled:cursor-not-allowed aria-invalid:border-destructive data-[size=sm]:h-7 data-[size=sm]:py-0.5 [@media(hover:hover)_and_(pointer:fine)]:min-h-0", ...props }), _jsx(ChevronDownIcon, { className: "pointer-events-none absolute top-1/2 right-2.5 size-4 -translate-y-1/2 text-muted-foreground select-none", "aria-hidden": "true", "data-slot": "native-select-icon" })] }));
6
+ function NativeSelect({ className, size = "default", ref, ...props }) {
7
+ const select = React.useRef(null);
8
+ const setRef = React.useCallback((node) => {
9
+ select.current = node;
10
+ const cleanup = typeof ref === "function" ? ref(node) : undefined;
11
+ if (ref && typeof ref !== "function")
12
+ ref.current = node;
13
+ return () => {
14
+ select.current = null;
15
+ if (typeof cleanup === "function")
16
+ cleanup();
17
+ else if (typeof ref === "function")
18
+ ref(null);
19
+ else if (ref)
20
+ ref.current = null;
21
+ };
22
+ }, [ref]);
23
+ // React sets an uncontrolled select's default only when it mounts, and resets
24
+ // a form to that default after its action returns, so a saved value would
25
+ // snap back to the one the page loaded with.
26
+ const defaultKey = props.defaultValue === undefined
27
+ ? undefined
28
+ : JSON.stringify([props.defaultValue].flat().map(String));
29
+ const appliedDefault = React.useRef(defaultKey);
30
+ React.useLayoutEffect(() => {
31
+ const node = select.current;
32
+ if (defaultKey === undefined || !node || defaultKey === appliedDefault.current)
33
+ return;
34
+ const options = [...node.options];
35
+ const shown = options.filter((option) => option.selected).map((option) => option.value);
36
+ const stillShowsOldDefault = JSON.stringify(shown) === appliedDefault.current;
37
+ const wanted = new Set(JSON.parse(defaultKey));
38
+ for (const option of options)
39
+ option.defaultSelected = wanted.has(option.value);
40
+ if (!stillShowsOldDefault)
41
+ for (const option of options)
42
+ option.selected = shown.includes(option.value);
43
+ appliedDefault.current = defaultKey;
44
+ }, [defaultKey]);
45
+ return (_jsxs("div", { className: cn("group/native-select relative w-fit has-[select:disabled]:opacity-50", className), "data-slot": "native-select-wrapper", "data-size": size, children: [_jsx("select", { ref: setRef, "data-slot": "native-select", "data-size": size, className: "h-control-height min-h-touch-target w-full min-w-0 appearance-none rounded-md border border-input bg-background py-1 pr-8 pl-control-padding-inline text-sm transition-colors select-none selection:bg-primary selection:text-primary-foreground placeholder:text-placeholder disabled:pointer-events-none disabled:cursor-not-allowed aria-invalid:border-destructive data-[size=sm]:h-7 data-[size=sm]:py-0.5 [@media(hover:hover)_and_(pointer:fine)]:min-h-0", ...props }), _jsx(ChevronDownIcon, { className: "pointer-events-none absolute top-1/2 right-2.5 size-4 -translate-y-1/2 text-muted-foreground select-none", "aria-hidden": "true", "data-slot": "native-select-icon" })] }));
6
46
  }
7
47
  function NativeSelectOption({ className, ...props }) {
8
48
  return (_jsx("option", { "data-slot": "native-select-option", className: cn("bg-[Canvas] text-[CanvasText]", className), ...props }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nadicodeai/ui",
3
- "version": "12.1.72",
3
+ "version": "12.1.73",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -75,7 +75,7 @@
75
75
  "@base-ui/react": "^1.8.0",
76
76
  "@iconify-icons/logos": "^2.0.2",
77
77
  "@iconify/react": "^6.0.2",
78
- "@nadicodeai/design-system": "12.1.72",
78
+ "@nadicodeai/design-system": "12.1.73",
79
79
  "@tanstack/react-table": "^9.2.4",
80
80
  "class-variance-authority": "^0.7.1",
81
81
  "clsx": "^2.1.1",