@cmdniels/uikit 1.4.6 → 1.4.7

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.
@@ -1,3 +1,2 @@
1
1
  import { Select as SelectPrimitive } from "@base-ui/react/select";
2
- export declare const SelectRegistryContext: import("react").Context<Map<unknown, string> | null>;
3
- export default function Select({ children, ...props }: SelectPrimitive.Root.Props<unknown, boolean | undefined>): import("react/jsx-runtime").JSX.Element;
2
+ export default function Select({ children, items, ...props }: SelectPrimitive.Root.Props<unknown, boolean | undefined>): import("react/jsx-runtime").JSX.Element;
@@ -12,10 +12,30 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { Select as SelectPrimitive } from "@base-ui/react/select";
15
- import { createContext, useRef } from "react";
16
- export const SelectRegistryContext = createContext(null);
15
+ import { useMemo, Children, isValidElement } from "react";
16
+ function extractItemsFromChildren(children, items) {
17
+ Children.forEach(children, (child) => {
18
+ if (isValidElement(child)) {
19
+ const props = child.props;
20
+ if (props.value !== undefined && props.children) {
21
+ items.push({ value: props.value, label: props.children });
22
+ }
23
+ if (props.children) {
24
+ extractItemsFromChildren(props.children, items);
25
+ }
26
+ }
27
+ });
28
+ }
17
29
  export default function Select(_a) {
18
- var { children } = _a, props = __rest(_a, ["children"]);
19
- const registryRef = useRef(new Map());
20
- return (_jsx(SelectRegistryContext.Provider, { value: registryRef.current, children: _jsx(SelectPrimitive.Root, Object.assign({}, props, { itemToStringLabel: (value) => { var _a; return (_a = registryRef.current.get(value)) !== null && _a !== void 0 ? _a : String(value); }, children: children })) }));
30
+ var { children, items } = _a, props = __rest(_a, ["children", "items"]);
31
+ const autoItems = useMemo(() => {
32
+ if (items) {
33
+ return items;
34
+ }
35
+ ;
36
+ const itemsArray = [];
37
+ extractItemsFromChildren(children, itemsArray);
38
+ return itemsArray;
39
+ }, [children, items]);
40
+ return (_jsx(SelectPrimitive.Root, Object.assign({}, props, { items: autoItems, children: children })));
21
41
  }
@@ -13,17 +13,8 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { Select as SelectPrimitive } from "@base-ui/react/select";
15
15
  import { IconCheck } from "@tabler/icons-react";
16
- import { useContext, useEffect } from "react";
17
16
  import cn from "../../cn";
18
- import { SelectRegistryContext } from "./Select";
19
17
  export default function SelectItem(_a) {
20
18
  var { className, children, value } = _a, props = __rest(_a, ["className", "children", "value"]);
21
- const registry = useContext(SelectRegistryContext);
22
- useEffect(() => {
23
- if (registry && value !== undefined) {
24
- const label = typeof children === "string" ? children : String(children);
25
- registry.set(value, label);
26
- }
27
- }, [registry, value, children]);
28
19
  return (_jsxs(SelectPrimitive.Item, Object.assign({ "data-slot": "select-item", className: cn("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2", className), value: value }, props, { children: [_jsx(SelectPrimitive.ItemText, { className: "flex flex-1 shrink-0 gap-2 whitespace-nowrap", children: children }), _jsx(SelectPrimitive.ItemIndicator, { render: _jsx("span", { className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center" }), children: _jsx(IconCheck, { className: "pointer-events-none" }) })] })));
29
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmdniels/uikit",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",