@agentero/design-system 0.31.4 → 0.31.6

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,15 +1,16 @@
1
1
  "use client";
2
2
  import { cn as e } from "../../lib/utils.js";
3
3
  import { useMergeProps as t } from "../../lib/merge-props.js";
4
- import { InputContext as n } from "../input/context.js";
5
- import { inputRecipe as r } from "../input/input.js";
6
- import { IconCancel as i } from "./icons.js";
7
- import { tv as a } from "tailwind-variants";
8
- import { use as o } from "react";
9
- import { jsx as s, jsxs as c } from "react/jsx-runtime";
10
- import { Combobox as l } from "@base-ui/react/combobox";
4
+ import { useFieldContext as n } from "../field/context.js";
5
+ import { InputContext as r } from "../input/context.js";
6
+ import { inputRecipe as i } from "../input/input.js";
7
+ import { IconCancel as a, IconCheck as o } from "./icons.js";
8
+ import { tv as s } from "tailwind-variants";
9
+ import { createContext as c, use as l } from "react";
10
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
11
+ import { Combobox as f } from "@base-ui/react/combobox";
11
12
  //#region src/combobox/combobox.tsx
12
- var u = a({ slots: {
13
+ var p = s({ slots: {
13
14
  field: "relative",
14
15
  clear: [
15
16
  "absolute top-1/2 right-3 flex size-6 -translate-y-1/2 cursor-pointer items-center",
@@ -28,82 +29,115 @@ var u = a({ slots: {
28
29
  ],
29
30
  list: ["max-h-[min(10.25rem,var(--available-height))] overflow-y-auto scroll-py-2 py-2 outline-none", "data-empty:py-0"],
30
31
  item: [
31
- "mx-2 my-px flex cursor-pointer items-center rounded-[calc(var(--radius-md)-2px)]",
32
+ "group/item mx-2 my-px flex cursor-pointer items-center rounded-[calc(var(--radius-md)-2px)]",
32
33
  "px-3 py-2 text-sm text-text-default-base-primary select-none",
33
34
  "data-highlighted:bg-bg-default-base-primary-hover",
34
35
  "data-disabled:cursor-default data-disabled:text-text-default-base-tertiary"
35
36
  ],
37
+ indicator: [
38
+ "mr-2 flex size-4 shrink-0 items-center justify-center rounded-sm",
39
+ "border border-border-input-default bg-bg-input-normal",
40
+ "text-text-default-base-inverse-primary transition-colors duration-200 ease-in-out",
41
+ "data-selected:border-bg-checkbox-selected data-selected:bg-bg-checkbox-selected",
42
+ "[&>svg]:hidden data-selected:[&>svg]:block",
43
+ "group-data-disabled/item:border-border-checkbox-disabled",
44
+ "group-data-disabled/item:data-selected:border-bg-checkbox-disabled",
45
+ "group-data-disabled/item:data-selected:bg-bg-checkbox-disabled"
46
+ ],
36
47
  message: ["mx-2 my-px px-3 py-2 text-sm text-text-default-base-tertiary", "empty:m-0 empty:p-0"]
37
- } }), d = u(), f = (e) => /* @__PURE__ */ s(l.Root, { ...e });
38
- f.displayName = "Combobox.Root";
39
- var p = /* @__PURE__ */ new Set([
48
+ } }), m = p(), h = c(!1), g = ({ onOpenChange: e, ...t }) => {
49
+ let n = !!t.multiple;
50
+ return /* @__PURE__ */ u(h, {
51
+ value: n,
52
+ children: /* @__PURE__ */ u(f.Root, {
53
+ onOpenChange: (t, r) => {
54
+ e?.(t, r), n && !t && r.reason === "item-press" && r.cancel();
55
+ },
56
+ ...t
57
+ })
58
+ });
59
+ };
60
+ g.displayName = "Combobox.Root";
61
+ var _ = /* @__PURE__ */ new Set([
40
62
  "value",
41
63
  "defaultValue",
42
64
  "onChange"
43
- ]), m = (e) => {
44
- let r = o(n), i = r ? Object.fromEntries(Object.entries(r).filter(([e]) => !p.has(e))) : null;
45
- return t(i, e);
46
- }, h = ({ clearLabel: t = "Clear", ...n }) => {
47
- let { className: a, size: o = "md", ...u } = m(n);
48
- return /* @__PURE__ */ c("div", {
65
+ ]), v = (e) => {
66
+ let i = l(r), a = n(), o = i ? Object.fromEntries(Object.entries(i).filter(([e]) => !_.has(e))) : null, s = !("aria-label" in e || "aria-labelledby" in e) && a ? { "aria-labelledby": a.labelId } : null;
67
+ return t({
68
+ ...o,
69
+ ...s
70
+ }, e);
71
+ }, y = ({ clearLabel: t = "Clear", ...n }) => {
72
+ let { className: r, size: o = "md", ...s } = v(n), c = l(h);
73
+ return /* @__PURE__ */ d("div", {
49
74
  "data-slot": "combobox-field",
50
- className: d.field(),
51
- children: [/* @__PURE__ */ s(l.Input, {
75
+ className: m.field(),
76
+ children: [/* @__PURE__ */ u(f.Input, {
52
77
  "data-slot": "combobox-input",
53
78
  "data-size": o,
54
- className: e(r({ size: o }), "pr-11", a),
55
- ...u
56
- }), /* @__PURE__ */ s(l.Clear, {
79
+ className: e(i({ size: o }), "pr-11", r),
80
+ ...s
81
+ }), !c && /* @__PURE__ */ u(f.Clear, {
57
82
  "data-slot": "combobox-clear",
58
83
  "aria-label": t,
59
- className: d.clear(),
60
- children: /* @__PURE__ */ s(i, {})
84
+ className: m.clear(),
85
+ children: /* @__PURE__ */ u(a, {})
61
86
  })]
62
87
  });
63
88
  };
64
- h.displayName = "Combobox.Input";
65
- var g = ({ className: t, side: n = "bottom", align: r = "start", sideOffset: i = 12, alignOffset: a, anchor: o, collisionPadding: c = 8, ...u }) => /* @__PURE__ */ s(l.Portal, { children: /* @__PURE__ */ s(l.Positioner, {
89
+ y.displayName = "Combobox.Input";
90
+ var b = ({ className: t, side: n = "bottom", align: r = "start", sideOffset: i = 12, alignOffset: a, anchor: o, collisionPadding: s = 8, ...c }) => /* @__PURE__ */ u(f.Portal, { children: /* @__PURE__ */ u(f.Positioner, {
66
91
  side: n,
67
92
  align: r,
68
93
  sideOffset: i,
69
94
  alignOffset: a,
70
95
  anchor: o,
71
- collisionPadding: c,
96
+ collisionPadding: s,
72
97
  className: "isolate z-(--z-index-top-layer) pointer-events-auto",
73
- children: /* @__PURE__ */ s(l.Popup, {
98
+ children: /* @__PURE__ */ u(f.Popup, {
74
99
  "data-slot": "combobox-content",
75
- className: e(d.content(), t),
76
- ...u
100
+ className: e(m.content(), t),
101
+ ...c
77
102
  })
78
103
  }) });
79
- g.displayName = "Combobox.Content";
80
- var _ = ({ className: t, ...n }) => {
104
+ b.displayName = "Combobox.Content";
105
+ var x = ({ className: t, ...n }) => {
81
106
  let r = "aria-label" in n || "aria-labelledby" in n;
82
- return /* @__PURE__ */ s(l.List, {
107
+ return /* @__PURE__ */ u(f.List, {
83
108
  "data-slot": "combobox-list",
84
109
  "aria-label": r ? void 0 : "Suggestions",
85
- className: e(d.list(), t),
110
+ className: e(m.list(), t),
86
111
  ...n
87
112
  });
88
113
  };
89
- _.displayName = "Combobox.List";
90
- var v = ({ className: t, ...n }) => /* @__PURE__ */ s(l.Item, {
91
- "data-slot": "combobox-item",
92
- className: e(d.item(), t),
93
- ...n
94
- });
95
- v.displayName = "Combobox.Item";
96
- var y = ({ className: t, ...n }) => /* @__PURE__ */ s(l.Empty, {
114
+ x.displayName = "Combobox.List";
115
+ var S = ({ className: t, children: n, ...r }) => {
116
+ let i = l(h);
117
+ return /* @__PURE__ */ d(f.Item, {
118
+ "data-slot": "combobox-item",
119
+ className: e(m.item(), t),
120
+ ...r,
121
+ children: [i && /* @__PURE__ */ u(f.ItemIndicator, {
122
+ keepMounted: !0,
123
+ "data-slot": "combobox-item-indicator",
124
+ className: m.indicator(),
125
+ children: /* @__PURE__ */ u(o, { className: "size-3.5" })
126
+ }), n]
127
+ });
128
+ };
129
+ S.displayName = "Combobox.Item";
130
+ var C = ({ className: t, ...n }) => /* @__PURE__ */ u(f.Empty, {
97
131
  "data-slot": "combobox-empty",
98
- className: e(d.message(), t),
132
+ className: e(m.message(), t),
99
133
  ...n
100
134
  });
101
- y.displayName = "Combobox.Empty";
102
- var b = ({ className: t, ...n }) => /* @__PURE__ */ s(l.Status, {
135
+ C.displayName = "Combobox.Empty";
136
+ var w = ({ className: t, ...n }) => /* @__PURE__ */ u(f.Status, {
103
137
  "data-slot": "combobox-status",
104
- className: e(d.message(), t),
138
+ className: e(m.message(), t),
105
139
  ...n
106
140
  });
107
- b.displayName = "Combobox.Status";
141
+ w.displayName = "Combobox.Status";
108
142
  //#endregion
109
- export { g as Content, y as Empty, h as Input, v as Item, _ as List, f as Root, b as Status, u as comboboxRecipe };
143
+ export { b as Content, C as Empty, y as Input, S as Item, x as List, g as Root, w as Status, p as comboboxRecipe };
@@ -8,3 +8,11 @@ import { SVGProps } from 'react';
8
8
  * @summary 24px cancel icon used as the Combobox clear affordance
9
9
  */
10
10
  export declare const IconCancel: (props: SVGProps<SVGSVGElement>) => import("react/jsx-runtime").JSX.Element;
11
+ /**
12
+ * Material Sharp check drawn inside a selected row's indicator, the same glyph
13
+ * `Checkbox` uses, so a multi-select row reads as a ticked checkbox. Takes its
14
+ * color from the surrounding text.
15
+ *
16
+ * @summary 24px check used by the Combobox selection indicator
17
+ */
18
+ export declare const IconCheck: (props: SVGProps<SVGSVGElement>) => import("react/jsx-runtime").JSX.Element;
@@ -8,6 +8,16 @@ var t = (t) => /* @__PURE__ */ e("svg", {
8
8
  xmlns: "http://www.w3.org/2000/svg",
9
9
  ...t,
10
10
  children: /* @__PURE__ */ e("path", { d: "M12 13.0538L15.0731 16.1269C15.2115 16.2654 15.3856 16.3362 15.5952 16.3394C15.8048 16.3426 15.982 16.2718 16.1269 16.1269C16.2718 15.982 16.3442 15.8064 16.3442 15.6C16.3442 15.3936 16.2718 15.218 16.1269 15.0731L13.0538 12L16.1269 8.9269C16.2653 8.78845 16.3362 8.61442 16.3394 8.4048C16.3426 8.1952 16.2718 8.01797 16.1269 7.8731C15.982 7.72822 15.8064 7.65577 15.6 7.65577C15.3936 7.65577 15.2179 7.72822 15.0731 7.8731L12 10.9462L8.92688 7.8731C8.78842 7.73463 8.61439 7.6638 8.40478 7.6606C8.19518 7.65738 8.01794 7.72822 7.87308 7.8731C7.72819 8.01797 7.65575 8.1936 7.65575 8.4C7.65575 8.6064 7.72819 8.78203 7.87308 8.9269L10.9461 12L7.87308 15.0731C7.73461 15.2115 7.66378 15.3856 7.66058 15.5952C7.65736 15.8048 7.72819 15.982 7.87308 16.1269C8.01794 16.2718 8.19358 16.3442 8.39998 16.3442C8.60638 16.3442 8.78201 16.2718 8.92688 16.1269L12 13.0538ZM12.0016 21.5C10.6877 21.5 9.45268 21.2506 8.29655 20.752C7.1404 20.2533 6.13472 19.5766 5.2795 18.7217C4.42427 17.8669 3.74721 16.8616 3.24833 15.706C2.74944 14.5504 2.5 13.3156 2.5 12.0017C2.5 10.6877 2.74933 9.45271 3.248 8.29657C3.74667 7.14042 4.42342 6.13474 5.27825 5.27952C6.1331 4.42429 7.13834 3.74723 8.29398 3.24835C9.44959 2.74947 10.6844 2.50002 11.9983 2.50002C13.3122 2.50002 14.5473 2.74936 15.7034 3.24802C16.8596 3.74669 17.8652 4.42344 18.7205 5.27827C19.5757 6.13312 20.2527 7.13837 20.7516 8.294C21.2505 9.44962 21.5 10.6844 21.5 11.9983C21.5 13.3123 21.2506 14.5473 20.752 15.7034C20.2533 16.8596 19.5765 17.8653 18.7217 18.7205C17.8669 19.5757 16.8616 20.2528 15.706 20.7516C14.5504 21.2505 13.3156 21.5 12.0016 21.5ZM12 20C14.2333 20 16.125 19.225 17.675 17.675C19.225 16.125 20 14.2333 20 12C20 9.76667 19.225 7.875 17.675 6.325C16.125 4.775 14.2333 4 12 4C9.76664 4 7.87498 4.775 6.32498 6.325C4.77498 7.875 3.99998 9.76667 3.99998 12C3.99998 14.2333 4.77498 16.125 6.32498 17.675C7.87498 19.225 9.76664 20 12 20Z" })
11
+ }), n = (t) => /* @__PURE__ */ e("svg", {
12
+ width: "24",
13
+ height: "24",
14
+ viewBox: "0 0 24 24",
15
+ fill: "currentColor",
16
+ stroke: "currentColor",
17
+ "aria-hidden": "true",
18
+ xmlns: "http://www.w3.org/2000/svg",
19
+ ...t,
20
+ children: /* @__PURE__ */ e("path", { d: "M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z" })
11
21
  });
12
22
  //#endregion
13
- export { t as IconCancel };
23
+ export { t as IconCancel, n as IconCheck };
@@ -1,7 +1,7 @@
1
1
  export { comboboxRecipe } from './combobox';
2
2
  export declare const Combobox: {
3
3
  Root: {
4
- <Value, Multiple extends boolean | undefined = false, Item = Value>(props: import("@base-ui/react/combobox").ComboboxRoot.Props<Value, Multiple, Item>): import("react/jsx-runtime").JSX.Element;
4
+ <Value, Multiple extends boolean | undefined = false, Item = Value>({ onOpenChange, ...props }: import("@base-ui/react/combobox").ComboboxRoot.Props<Value, Multiple, Item>): import("react/jsx-runtime").JSX.Element;
5
5
  displayName: string;
6
6
  };
7
7
  Input: {
@@ -20,7 +20,7 @@ export declare const Combobox: {
20
20
  displayName: string;
21
21
  };
22
22
  Item: {
23
- ({ className, ...props }: Omit<import('@base-ui/react/combobox').ComboboxItemProps, "ref"> & import('react').RefAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
23
+ ({ className, children, ...props }: Omit<import('@base-ui/react/combobox').ComboboxItemProps, "ref"> & import('react').RefAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
24
24
  displayName: string;
25
25
  };
26
26
  Empty: {
@@ -1,5 +1,5 @@
1
1
  import { ComponentProps } from 'react';
2
- import { Command as CommandPrimitive } from 'cmdk';
2
+ import { Command as CommandPrimitive, useCommandState as useCommandStatePrimitive } from 'cmdk';
3
3
  export declare const commandRecipe: import('tailwind-variants').TVReturnType<{
4
4
  [key: string]: {
5
5
  [key: string]: import('tailwind-merge').ClassNameValue | {
@@ -85,6 +85,8 @@ type RootProps = ComponentProps<typeof CommandPrimitive>;
85
85
  * nothing to search.
86
86
  *
87
87
  * `label` names the search input — it is the only prop that can, see `Input`.
88
+ * A component rendered inside `Root` reads its search text and results with
89
+ * `useCommandState`, exported next to `Command`.
88
90
  *
89
91
  * @summary Filterable command palette container
90
92
  * @see {@link https://github.com/pacocoursey/cmdk|cmdk}
@@ -242,4 +244,38 @@ export declare const Item: {
242
244
  ({ className, ...props }: ItemProps): import("react/jsx-runtime").JSX.Element;
243
245
  displayName: string;
244
246
  };
247
+ /**
248
+ * Snapshot of the surrounding `Root` that `useCommandState` selects from.
249
+ *
250
+ * @property {string} search - Current text in `Input`.
251
+ * @property {string} value - Value of the active item.
252
+ * @property {string} [selectedItemId] - DOM id of the active item.
253
+ * @property {{ count: number; items: Map<string, number>; groups: Set<string> }} filtered -
254
+ * Result of the current search: how many items match, each matching item's score keyed by
255
+ * value, and the values of the groups that still hold a match.
256
+ */
257
+ export type CommandState = Parameters<Parameters<typeof useCommandStatePrimitive>[0]>[0];
258
+ /**
259
+ * Reads the state of the nearest `Command.Root`: the search text, the active
260
+ * value and the filtered results. The selector picks the slice a component
261
+ * needs, and the component re-renders only when that slice changes.
262
+ *
263
+ * Call it from a component rendered inside `Command.Root`. Import it from here,
264
+ * not from `cmdk`: this hook and `Root` resolve the same copy of `cmdk`, so it
265
+ * always finds the state, even when the app installs a different `cmdk` version.
266
+ *
267
+ * @summary Hook that reads the search text and results of the surrounding Command
268
+ *
269
+ * @example
270
+ * ```tsx
271
+ * import { Command, useCommandState } from '@agentero/design-system/command';
272
+ *
273
+ * const CreateItem = ({ onCreate }: { onCreate: (name: string) => void }) => {
274
+ * const search = useCommandState(state => state.search);
275
+ * if (!search) return null;
276
+ * return <Command.Item onSelect={() => onCreate(search)}>Create "{search}"</Command.Item>;
277
+ * };
278
+ * ```
279
+ */
280
+ export declare const useCommandState: <T>(selector: (state: CommandState) => T) => T;
245
281
  export {};
@@ -2,9 +2,9 @@
2
2
  import { IconSearch as e } from "./icons.js";
3
3
  import { tv as t } from "tailwind-variants";
4
4
  import { jsx as n, jsxs as r } from "react/jsx-runtime";
5
- import { Command as i } from "cmdk";
5
+ import { Command as i, useCommandState as a } from "cmdk";
6
6
  //#region src/command/command.tsx
7
- var a = t({ slots: {
7
+ var o = t({ slots: {
8
8
  root: ["overflow-hidden rounded-md bg-bg-default-base-primary shadow-xl", "border border-border-default-base-primary"],
9
9
  search: ["flex items-center gap-2 px-4 py-3", "border-b border-border-default-base-primary"],
10
10
  searchIcon: "shrink-0 pointer-events-none [&>path]:fill-icon-default-base-tertiary",
@@ -18,48 +18,49 @@ var a = t({ slots: {
18
18
  "data-[disabled=true]:cursor-default data-[disabled=true]:text-text-default-disable-primary",
19
19
  "data-[disabled=true]:hover:bg-transparent data-[disabled=true]:data-[selected=true]:bg-transparent"
20
20
  ]
21
- } }), o = a(), s = ({ className: e, ...t }) => /* @__PURE__ */ n(i, {
21
+ } }), s = o(), c = ({ className: e, ...t }) => /* @__PURE__ */ n(i, {
22
22
  "data-slot": "command-root",
23
- className: o.root({ className: e }),
23
+ className: s.root({ className: e }),
24
24
  ...t
25
25
  });
26
- s.displayName = "Command.Root";
27
- var c = ({ className: t, ...a }) => /* @__PURE__ */ r("div", {
26
+ c.displayName = "Command.Root";
27
+ var l = ({ className: t, ...a }) => /* @__PURE__ */ r("div", {
28
28
  "data-slot": "command-search",
29
- className: o.search({ className: t }),
29
+ className: s.search({ className: t }),
30
30
  children: [/* @__PURE__ */ n(e, {
31
31
  "data-slot": "command-search-icon",
32
- className: o.searchIcon(),
32
+ className: s.searchIcon(),
33
33
  "aria-hidden": !0
34
34
  }), /* @__PURE__ */ n(i.Input, {
35
35
  "data-slot": "command-input",
36
- className: o.input(),
36
+ className: s.input(),
37
37
  ...a
38
38
  })]
39
39
  });
40
- c.displayName = "Command.Input";
41
- var l = ({ className: e, ...t }) => /* @__PURE__ */ n(i.List, {
40
+ l.displayName = "Command.Input";
41
+ var u = ({ className: e, ...t }) => /* @__PURE__ */ n(i.List, {
42
42
  "data-slot": "command-list",
43
- className: o.list({ className: e }),
43
+ className: s.list({ className: e }),
44
44
  ...t
45
45
  });
46
- l.displayName = "Command.List";
47
- var u = ({ className: e, ...t }) => /* @__PURE__ */ n(i.Empty, {
46
+ u.displayName = "Command.List";
47
+ var d = ({ className: e, ...t }) => /* @__PURE__ */ n(i.Empty, {
48
48
  "data-slot": "command-empty",
49
- className: o.empty({ className: e }),
49
+ className: s.empty({ className: e }),
50
50
  ...t
51
51
  });
52
- u.displayName = "Command.Empty";
53
- var d = (e) => /* @__PURE__ */ n(i.Group, {
52
+ d.displayName = "Command.Empty";
53
+ var f = (e) => /* @__PURE__ */ n(i.Group, {
54
54
  "data-slot": "command-group",
55
55
  ...e
56
56
  });
57
- d.displayName = "Command.Group";
58
- var f = ({ className: e, ...t }) => /* @__PURE__ */ n(i.Item, {
57
+ f.displayName = "Command.Group";
58
+ var p = ({ className: e, ...t }) => /* @__PURE__ */ n(i.Item, {
59
59
  "data-slot": "command-item",
60
- className: o.item({ className: e }),
60
+ className: s.item({ className: e }),
61
61
  ...t
62
62
  });
63
- f.displayName = "Command.Item";
63
+ p.displayName = "Command.Item";
64
+ var m = (e) => a(e);
64
65
  //#endregion
65
- export { u as Empty, d as Group, c as Input, f as Item, l as List, s as Root, a as commandRecipe };
66
+ export { d as Empty, f as Group, l as Input, p as Item, u as List, c as Root, o as commandRecipe, m as useCommandState };
@@ -1,4 +1,5 @@
1
- export { commandRecipe } from './command';
1
+ export { commandRecipe, useCommandState } from './command';
2
+ export type { CommandState } from './command';
2
3
  export declare const Command: {
3
4
  Root: {
4
5
  ({ className, ...props }: {
@@ -1,6 +1,6 @@
1
- import { Empty as e, Group as t, Input as n, Item as r, List as i, Root as a, commandRecipe as o } from "./command.js";
1
+ import { Empty as e, Group as t, Input as n, Item as r, List as i, Root as a, commandRecipe as o, useCommandState as s } from "./command.js";
2
2
  //#region src/command/index.ts
3
- var s = {
3
+ var c = {
4
4
  Root: a,
5
5
  Input: n,
6
6
  List: i,
@@ -9,4 +9,4 @@ var s = {
9
9
  Item: r
10
10
  };
11
11
  //#endregion
12
- export { s as Command, o as commandRecipe };
12
+ export { c as Command, o as commandRecipe, s as useCommandState };
@@ -19,6 +19,13 @@ export type FieldErrorLike = {
19
19
  export type FieldContextValue = {
20
20
  /** `id` the control must carry so the label points at it. */
21
21
  controlId: string;
22
+ /**
23
+ * `id` the `Label` carries, for a control that names itself with
24
+ * `aria-labelledby` because a plain `<label for>` is not enough: a floating
25
+ * surface that hides the rest of the page from assistive technology hides
26
+ * the label with it, and only a direct reference survives that.
27
+ */
28
+ labelId: string;
22
29
  /** `id` the `Field.Description` takes by default. One description per field. */
23
30
  descriptionId: string;
24
31
  /** `id` the `Field.Error` takes by default. One error element per field. */
@@ -126,7 +126,9 @@ export type FieldRootProps = ComponentPropsWithRef<'div'> & {
126
126
  * `Field.Description` and `Field.Error` read `FieldContext` and register
127
127
  * themselves so the control's `aria-describedby` lists exactly the messages on
128
128
  * screen, and a `Field<X>` such as `FieldText` provides the control's context so
129
- * the control associates itself too. Nobody passes an `id` by hand.
129
+ * the control associates itself too. Nobody passes an `id` by hand. The label
130
+ * gets an id as well (`labelId` in `FieldContext`) for a control that must
131
+ * name itself with `aria-labelledby`, as `Combobox.Input` does.
130
132
  *
131
133
  * Presentational and form-library agnostic: pass `invalid` and the error
132
134
  * messages from whatever validates the form. Deliberately not a `role="group"`:
@@ -45,21 +45,23 @@ var m = s({
45
45
  });
46
46
  g.displayName = "Field.Group";
47
47
  var _ = ({ className: n, orientation: r = "vertical", invalid: a = !1, disabled: o = !1, readOnly: s = !1, required: u = !1, controlId: p, ...m }) => {
48
- let g = l(), _ = p ?? `${g}-control`, v = `${g}-description`, y = `${g}-error`, [b, x] = d([]), S = c((e) => (x((t) => t.includes(e) ? t : [...t, e]), () => x((t) => t.filter((t) => t !== e))), []), C = {
48
+ let g = l(), _ = p ?? `${g}-control`, v = `${g}-label`, y = `${g}-description`, b = `${g}-error`, [x, S] = d([]), C = c((e) => (S((t) => t.includes(e) ? t : [...t, e]), () => S((t) => t.filter((t) => t !== e))), []), w = {
49
49
  controlId: _,
50
- descriptionId: v,
51
- errorId: y,
52
- describedBy: [...[v, y].filter((e) => b.includes(e)), ...b.filter((e) => e !== v && e !== y)].join(" ") || void 0,
53
- registerMessage: S,
50
+ labelId: v,
51
+ descriptionId: y,
52
+ errorId: b,
53
+ describedBy: [...[y, b].filter((e) => x.includes(e)), ...x.filter((e) => e !== y && e !== b)].join(" ") || void 0,
54
+ registerMessage: C,
54
55
  invalid: a,
55
56
  disabled: o,
56
57
  readOnly: s,
57
58
  required: u
58
59
  };
59
60
  return /* @__PURE__ */ f(i, {
60
- value: C,
61
+ value: w,
61
62
  children: /* @__PURE__ */ f(t, {
62
63
  value: {
64
+ id: v,
63
65
  htmlFor: _,
64
66
  required: u || void 0
65
67
  },
@@ -1,11 +1,11 @@
1
1
  "use client";
2
- import { InputContext as e } from "../input/context.js";
3
- import { useFieldContext as t } from "../field/context.js";
4
- import { Field as n } from "../field/index.js";
2
+ import { useFieldContext as e } from "../field/context.js";
3
+ import { Field as t } from "../field/index.js";
4
+ import { InputContext as n } from "../input/context.js";
5
5
  import { jsx as r } from "react/jsx-runtime";
6
6
  //#region src/field-text/field-text.tsx
7
- var i = ({ children: n }) => {
8
- let i = t(), a = i && {
7
+ var i = ({ children: t }) => {
8
+ let i = e(), a = i && {
9
9
  id: i.controlId,
10
10
  "aria-describedby": i.describedBy,
11
11
  "aria-invalid": i.invalid || void 0,
@@ -13,12 +13,12 @@ var i = ({ children: n }) => {
13
13
  disabled: i.disabled || void 0,
14
14
  readOnly: i.readOnly || void 0
15
15
  };
16
- return /* @__PURE__ */ r(e, {
16
+ return /* @__PURE__ */ r(n, {
17
17
  value: a,
18
- children: n
18
+ children: t
19
19
  });
20
- }, a = ({ children: e, ...t }) => /* @__PURE__ */ r(n.Root, {
21
- ...t,
20
+ }, a = ({ children: e, ...n }) => /* @__PURE__ */ r(t.Root, {
21
+ ...n,
22
22
  children: /* @__PURE__ */ r(i, { children: e })
23
23
  });
24
24
  a.displayName = "FieldText";
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { mergeProps as e } from "../../lib/merge-props.js";
3
- import { Input as t } from "../input/input.js";
4
- import { Field as n } from "../field/index.js";
3
+ import { Field as t } from "../field/index.js";
4
+ import { Input as n } from "../input/input.js";
5
5
  import { FieldText as r } from "../field-text/field-text.js";
6
6
  import { jsx as i, jsxs as a } from "react/jsx-runtime";
7
7
  import { useController as o } from "react-hook-form";
@@ -23,15 +23,15 @@ var s = ({ name: s, control: c, rules: l, shouldUnregister: u, disabled: d, labe
23
23
  invalid: b.invalid,
24
24
  disabled: d || y.disabled,
25
25
  ...v,
26
- children: [/* @__PURE__ */ i(n.Label, {
26
+ children: [/* @__PURE__ */ i(t.Label, {
27
27
  tooltip: m,
28
28
  tooltipSide: h,
29
29
  optional: g,
30
30
  children: f
31
- }), /* @__PURE__ */ a(n.Content, { children: [
32
- /* @__PURE__ */ i(t, { ...e(x, _ ?? {}) }),
33
- p && /* @__PURE__ */ i(n.Description, { children: p }),
34
- /* @__PURE__ */ i(n.Error, { errors: b.error ? [b.error] : void 0 })
31
+ }), /* @__PURE__ */ a(t.Content, { children: [
32
+ /* @__PURE__ */ i(n, { ...e(x, _ ?? {}) }),
33
+ p && /* @__PURE__ */ i(t.Description, { children: p }),
34
+ /* @__PURE__ */ i(t.Error, { errors: b.error ? [b.error] : void 0 })
35
35
  ] })]
36
36
  });
37
37
  };