nish-ui 1.8.0 → 2.0.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.
Files changed (152) hide show
  1. package/README.md +223 -61
  2. package/dist/base-tailwind.css +1757 -0
  3. package/dist/base.css +1590 -1445
  4. package/dist/chart.d.ts +4 -1
  5. package/dist/chart.js +122 -49
  6. package/dist/elements-all.d.ts +8 -0
  7. package/dist/elements-all.js +178 -0
  8. package/dist/elements-charts.d.ts +124 -2
  9. package/dist/elements-charts.js +131 -1
  10. package/dist/elements-data.d.ts +166 -2
  11. package/dist/elements-data.js +46 -1
  12. package/dist/elements-forms.d.ts +71 -0
  13. package/dist/elements-forms.js +24 -25
  14. package/dist/elements.d.ts +71 -0
  15. package/dist/elements.js +4 -5
  16. package/dist/esm/chart-values.js +58 -0
  17. package/dist/esm/chart.js +10 -0
  18. package/dist/esm/cn.js +19 -0
  19. package/dist/esm/combobox-filter.js +13 -0
  20. package/dist/esm/components/accordion.js +166 -0
  21. package/dist/esm/components/app-shell.js +198 -0
  22. package/dist/esm/components/avatar-classes.js +28 -0
  23. package/dist/esm/components/avatar.js +113 -0
  24. package/dist/esm/components/breadcrumbs.js +154 -0
  25. package/dist/esm/components/canvas/follow-caption.js +32 -0
  26. package/dist/esm/components/canvas/follow.js +119 -0
  27. package/dist/esm/components/canvas/icons.js +70 -0
  28. package/dist/esm/components/canvas/index.js +10 -0
  29. package/dist/esm/components/canvas/layout.js +258 -0
  30. package/dist/esm/components/canvas/legend.js +93 -0
  31. package/dist/esm/components/canvas/minimap.js +127 -0
  32. package/dist/esm/components/canvas/node.js +87 -0
  33. package/dist/esm/components/canvas/route.js +262 -0
  34. package/dist/esm/components/canvas/system-canvas.js +837 -0
  35. package/dist/esm/components/canvas/types.js +10 -0
  36. package/dist/esm/components/canvas/view.js +47 -0
  37. package/dist/esm/components/chart-hooks.js +19 -0
  38. package/dist/esm/components/charts.js +467 -0
  39. package/dist/esm/components/client.js +24 -0
  40. package/dist/esm/components/combobox.js +343 -0
  41. package/dist/esm/components/command.js +403 -0
  42. package/dist/esm/components/data-classes.js +159 -0
  43. package/dist/esm/components/data.js +517 -0
  44. package/dist/esm/components/display-classes.js +130 -0
  45. package/dist/esm/components/display.js +755 -0
  46. package/dist/esm/components/error-boundary.js +64 -0
  47. package/dist/esm/components/feedback.js +136 -0
  48. package/dist/esm/components/file-dropzone.js +184 -0
  49. package/dist/esm/components/filters.js +108 -0
  50. package/dist/esm/components/flow.js +746 -0
  51. package/dist/esm/components/forms-classes.js +43 -0
  52. package/dist/esm/components/forms.js +581 -0
  53. package/dist/esm/components/hooks-classes.js +9 -0
  54. package/dist/esm/components/hooks.js +236 -0
  55. package/dist/esm/components/icons.js +96 -0
  56. package/dist/esm/components/inbox-classes.js +29 -0
  57. package/dist/esm/components/inbox.js +257 -0
  58. package/dist/esm/components/latest.js +13 -0
  59. package/dist/esm/components/layout-vars.js +96 -0
  60. package/dist/esm/components/layout.js +272 -0
  61. package/dist/esm/components/media.js +143 -0
  62. package/dist/esm/components/nav.js +614 -0
  63. package/dist/esm/components/overlay-classes.js +66 -0
  64. package/dist/esm/components/overlay.js +1447 -0
  65. package/dist/esm/components/pagination-classes.js +29 -0
  66. package/dist/esm/components/pagination.js +154 -0
  67. package/dist/esm/components/portal.js +16 -0
  68. package/dist/esm/components/primitives-classes.js +198 -0
  69. package/dist/esm/components/primitives.js +268 -0
  70. package/dist/esm/components/progress.js +77 -0
  71. package/dist/esm/components/provider.js +32 -0
  72. package/dist/esm/components/radio-group.js +186 -0
  73. package/dist/esm/components/resource-classes.js +133 -0
  74. package/dist/esm/components/resource.js +209 -0
  75. package/dist/esm/components/segmented.js +178 -0
  76. package/dist/esm/components/separator.js +38 -0
  77. package/dist/esm/components/service-tokens.js +221 -0
  78. package/dist/esm/components/settings.js +301 -0
  79. package/dist/esm/components/slider.js +262 -0
  80. package/dist/esm/components/split-classes.js +8 -0
  81. package/dist/esm/components/split.js +411 -0
  82. package/dist/esm/components/strings.js +119 -0
  83. package/dist/esm/components/table.js +144 -0
  84. package/dist/esm/components/tabs-classes.js +21 -0
  85. package/dist/esm/components/tabs.js +201 -0
  86. package/dist/esm/components/tag-input.js +257 -0
  87. package/dist/esm/components/theme-toggle.js +177 -0
  88. package/dist/esm/components/toast.js +361 -0
  89. package/dist/esm/components/url-state.js +118 -0
  90. package/dist/esm/components/visually-hidden.js +20 -0
  91. package/dist/esm/format.js +320 -0
  92. package/dist/esm/inbox-client.js +2 -0
  93. package/dist/esm/inbox-types.js +2 -0
  94. package/dist/esm/index.js +320 -0
  95. package/dist/esm/runtime.js +37 -0
  96. package/dist/esm/server/inbox/client.js +297 -0
  97. package/dist/esm/server/inbox/types.js +24 -0
  98. package/dist/esm/sparkline-path.js +59 -0
  99. package/dist/esm/split-layout.js +419 -0
  100. package/dist/esm/system-canvas.js +2 -0
  101. package/dist/esm/theme.js +804 -0
  102. package/dist/esm/tokens.mjs +425 -0
  103. package/dist/esm/url.js +20 -0
  104. package/dist/files.json +5 -1
  105. package/dist/fonts/LICENSE-Inter.txt +93 -0
  106. package/dist/format.d.ts +32 -18
  107. package/dist/format.js +227 -82
  108. package/dist/inbox-client.js +3 -1
  109. package/dist/index.d.ts +1689 -667
  110. package/dist/nish-components.css +4701 -3169
  111. package/dist/nish-components.min.css +1 -0
  112. package/dist/nish.css +1603 -1450
  113. package/dist/nish.min.css +1 -0
  114. package/dist/node/eslint.js +29 -14
  115. package/dist/node/th-check.js +29 -14
  116. package/dist/node/vite.d.ts +12 -0
  117. package/dist/node/vite.js +12 -2
  118. package/dist/server/hono.d.ts +15 -6
  119. package/dist/server/hono.js +30 -25
  120. package/dist/server/index.d.ts +3 -10
  121. package/dist/server/index.js +71 -38
  122. package/dist/{spa-DuVB5O7S.d.ts → spa-BLlMc0eI.d.ts} +38 -5
  123. package/dist/system-canvas-BLuWd69H.d.ts +183 -0
  124. package/dist/system-canvas.d.ts +2 -168
  125. package/dist/tailwind-core.css +114 -0
  126. package/dist/tailwind.css +3 -7
  127. package/dist/theme-init.js +23 -9
  128. package/dist/theme-init.sha256 +1 -0
  129. package/dist/theme.d.ts +246 -4
  130. package/dist/theme.global.js +357 -90
  131. package/dist/theme.js +338 -68
  132. package/dist/tokens.css +14 -6
  133. package/dist/tokens.dtcg.json +1513 -0
  134. package/dist/tokens.js +29 -14
  135. package/dist/tokens.json +512 -0
  136. package/package.json +51 -13
  137. package/dist/chart.js.map +0 -1
  138. package/dist/elements-charts.js.map +0 -1
  139. package/dist/elements-data.js.map +0 -1
  140. package/dist/elements-forms.js.map +0 -1
  141. package/dist/elements.js.map +0 -1
  142. package/dist/format.js.map +0 -1
  143. package/dist/inbox-client.js.map +0 -1
  144. package/dist/index.js +0 -10260
  145. package/dist/index.js.map +0 -1
  146. package/dist/server/hono.js.map +0 -1
  147. package/dist/server/index.js.map +0 -1
  148. package/dist/split-layout.js.map +0 -1
  149. package/dist/system-canvas.js +0 -2204
  150. package/dist/system-canvas.js.map +0 -1
  151. package/dist/theme.global.js.map +0 -1
  152. package/dist/theme.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ // src/components/forms-classes.ts
2
+ import { cn } from "../cn.js";
3
+ function setRef(ref, node) {
4
+ if (typeof ref === "function") ref(node);
5
+ else if (ref) ref.current = node;
6
+ }
7
+ var CHIP_BASE = "inline-flex shrink-0 select-none items-center gap-1.5 whitespace-nowrap rounded-full border font-medium transition-colors duration-150";
8
+ var CHIP_SIZE = { sm: "h-7 px-2.5 text-xs", md: "h-8 px-3 text-sm" };
9
+ var CHIP_LOOK = {
10
+ toggle: "border-th-line-control text-th-hi2 hover:bg-th-elevated hover:text-th-hi",
11
+ pressed: "border-th-accent/60 bg-th-accent-soft text-th-accent hover:bg-th-accent/20 forced-colors:border-[color:Highlight] forced-colors:forced-color-adjust-none forced-colors:bg-[color:Highlight] forced-colors:text-[color:HighlightText]",
12
+ suggestion: "border-dashed border-th-line-control text-th-hi3 hover:border-th-hi3 hover:text-th-hi",
13
+ tag: "border-th-line bg-th-elevated text-th-hi2"
14
+ };
15
+ function chipClass({ pressed = false, variant = "toggle", size = "md", className } = {}) {
16
+ return cn(
17
+ CHIP_BASE,
18
+ CHIP_SIZE[size],
19
+ variant !== "tag" && "pointer-coarse:min-h-11",
20
+ CHIP_LOOK[variant === "toggle" && pressed ? "pressed" : variant],
21
+ className
22
+ );
23
+ }
24
+ var SEGMENTED_SELECTED = {
25
+ accent: "bg-th-accent-soft text-th-accent ring-1 ring-th-accent/40 forced-colors:forced-color-adjust-none forced-colors:bg-[color:Highlight] forced-colors:text-[color:HighlightText]",
26
+ warn: "bg-th-warn-soft text-th-warn ring-1 ring-th-warn/40 forced-colors:forced-color-adjust-none forced-colors:bg-[color:Highlight] forced-colors:text-[color:HighlightText]",
27
+ loss: "bg-th-loss-soft text-th-loss ring-1 ring-th-loss/40 forced-colors:forced-color-adjust-none forced-colors:bg-[color:Highlight] forced-colors:text-[color:HighlightText]"
28
+ };
29
+ var SEGMENTED_SIZE = {
30
+ xs: "h-6 px-2 text-2xs",
31
+ sm: "h-7 px-2.5 text-xs",
32
+ md: "h-8 px-3 text-sm"
33
+ };
34
+ function indexComboboxOptions(options) {
35
+ return options.map((option) => ({ option, label: option.label.toLowerCase(), hint: option.hint?.toLowerCase() }));
36
+ }
37
+ export {
38
+ SEGMENTED_SELECTED,
39
+ SEGMENTED_SIZE,
40
+ chipClass,
41
+ indexComboboxOptions,
42
+ setRef
43
+ };
@@ -0,0 +1,581 @@
1
+ "use client";
2
+
3
+ // src/components/forms.tsx
4
+ import {
5
+ Children,
6
+ cloneElement,
7
+ isValidElement,
8
+ useCallback,
9
+ useEffect,
10
+ useId,
11
+ useRef,
12
+ useState
13
+ } from "react";
14
+ import { cn } from "../cn.js";
15
+ import { FIELD, IconButton, Input } from "./primitives.js";
16
+ import { XIcon } from "./icons.js";
17
+ import { isRtl, useIsoLayoutEffect } from "./client.js";
18
+ import { useNishStrings } from "./provider.js";
19
+ import { chipClass, setRef } from "./forms-classes.js";
20
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
21
+ function Svg({ size = 16, children, ...rest }) {
22
+ return /* @__PURE__ */ jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", ...rest, children });
23
+ }
24
+ var SearchIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
25
+ /* @__PURE__ */ jsx("circle", { cx: "11", cy: "11", r: "8" }),
26
+ /* @__PURE__ */ jsx("path", { d: "m21 21-4.3-4.3" })
27
+ ] });
28
+ var PlusIcon = (p) => /* @__PURE__ */ jsx(Svg, { ...p, children: /* @__PURE__ */ jsx("path", { d: "M5 12h14M12 5v14" }) });
29
+ var CheckIcon = (p) => /* @__PURE__ */ jsx(Svg, { strokeWidth: 3, ...p, children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" }) });
30
+ var MinusIcon = (p) => /* @__PURE__ */ jsx(Svg, { strokeWidth: 3, ...p, children: /* @__PURE__ */ jsx("path", { d: "M5 12h14" }) });
31
+ var noop = () => {
32
+ };
33
+ function useFormReset(ref, onReset) {
34
+ const latest = useRef(onReset);
35
+ useEffect(() => {
36
+ latest.current = onReset;
37
+ });
38
+ useEffect(() => {
39
+ const form = ref.current?.form;
40
+ if (!form) return;
41
+ const handler = () => latest.current();
42
+ form.addEventListener("reset", handler);
43
+ return () => form.removeEventListener("reset", handler);
44
+ }, [ref]);
45
+ }
46
+ function Textarea({ ref, invalid, size = "md", autoGrow = false, className, rows = 4, value, onInput, ...rest }) {
47
+ const inner = useRef(null);
48
+ const grow = autoGrow !== false;
49
+ const maxRows = typeof autoGrow === "object" ? autoGrow.maxRows : void 0;
50
+ const resize = useCallback(() => {
51
+ const el = inner.current;
52
+ if (!el || !grow) return;
53
+ el.style.height = "auto";
54
+ const cs = getComputedStyle(el);
55
+ const border = parseFloat(cs.borderTopWidth) + parseFloat(cs.borderBottomWidth);
56
+ let h = el.scrollHeight + border;
57
+ if (maxRows) {
58
+ const line = parseFloat(cs.lineHeight) || parseFloat(cs.fontSize) * 1.5;
59
+ const max = line * maxRows + parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom) + border;
60
+ el.style.overflowY = h > max ? "auto" : "hidden";
61
+ h = Math.min(h, max);
62
+ } else {
63
+ el.style.overflowY = "hidden";
64
+ }
65
+ el.style.height = `${h}px`;
66
+ }, [grow, maxRows]);
67
+ useIsoLayoutEffect(() => {
68
+ resize();
69
+ }, [resize, value]);
70
+ return /* @__PURE__ */ jsx(
71
+ "textarea",
72
+ {
73
+ ref: (node) => {
74
+ inner.current = node;
75
+ setRef(ref, node);
76
+ },
77
+ rows,
78
+ value,
79
+ "aria-invalid": invalid || void 0,
80
+ onInput: (e) => {
81
+ resize();
82
+ onInput?.(e);
83
+ },
84
+ className: cn(
85
+ FIELD,
86
+ "block leading-relaxed",
87
+ size === "sm" ? "px-2.5 py-1.5 text-xs" : "px-3 py-2 text-sm",
88
+ "pointer-coarse:text-base",
89
+ grow ? "resize-none" : "resize-y",
90
+ className
91
+ ),
92
+ ...rest
93
+ }
94
+ );
95
+ }
96
+ function Checkbox({ ref, label, hint, indeterminate = false, trailing, size = "md", invalid, className, id, disabled, onChange, ...rest }) {
97
+ const auto = useId();
98
+ const boxId = id ?? `${auto}-box`;
99
+ const labelId = `${auto}-label`;
100
+ const hintId = `${auto}-hint`;
101
+ const trailingId = `${auto}-trailing`;
102
+ const inner = useRef(null);
103
+ const [live, setLive] = useState(rest.defaultChecked ?? false);
104
+ const isChecked = rest.checked ?? live;
105
+ useFormReset(inner, () => setLive(rest.defaultChecked ?? false));
106
+ useEffect(() => {
107
+ if (inner.current) inner.current.indeterminate = indeterminate;
108
+ }, [indeterminate]);
109
+ const sm = size === "sm";
110
+ const describedBy = [rest["aria-describedby"], hint ? hintId : void 0, trailing != null ? trailingId : void 0].filter(Boolean).join(" ") || void 0;
111
+ const named = label != null && (hint || trailing != null) && !rest["aria-label"] && !rest["aria-labelledby"];
112
+ return /* @__PURE__ */ jsxs(
113
+ "label",
114
+ {
115
+ htmlFor: boxId,
116
+ "data-state": indeterminate ? "indeterminate" : isChecked ? "checked" : "unchecked",
117
+ "data-disabled": disabled ? "" : void 0,
118
+ className: cn(
119
+ "cursor-pointer items-start gap-2.5 text-th-hi pointer-coarse:min-h-11 pointer-coarse:py-2.5",
120
+ sm ? "gap-2 text-xs" : "text-sm",
121
+ trailing != null ? "flex w-full" : "inline-flex",
122
+ label == null && hint == null && "items-center pointer-coarse:min-w-11 pointer-coarse:justify-center",
123
+ disabled && "cursor-not-allowed opacity-50",
124
+ className
125
+ ),
126
+ children: [
127
+ /* @__PURE__ */ jsxs("span", { className: cn("relative inline-flex shrink-0", label != null && (sm ? "mt-px" : "mt-0.5")), children: [
128
+ /* @__PURE__ */ jsx(
129
+ "input",
130
+ {
131
+ ...rest,
132
+ ref: (node) => {
133
+ inner.current = node;
134
+ setRef(ref, node);
135
+ },
136
+ id: boxId,
137
+ type: "checkbox",
138
+ disabled,
139
+ onChange: (e) => {
140
+ setLive(e.target.checked);
141
+ onChange?.(e);
142
+ },
143
+ "aria-invalid": invalid || rest["aria-invalid"] || void 0,
144
+ "aria-labelledby": named ? labelId : rest["aria-labelledby"],
145
+ "aria-describedby": describedBy,
146
+ className: cn(
147
+ "peer m-0 shrink-0 cursor-[inherit] appearance-none rounded border border-th-line-control bg-th-surface transition-colors",
148
+ "checked:border-th-accent checked:bg-th-accent indeterminate:border-th-accent indeterminate:bg-th-accent",
149
+ "aria-[invalid=true]:border-th-loss",
150
+ "forced-colors:checked:border-[color:Highlight] forced-colors:checked:bg-[color:Highlight] forced-colors:indeterminate:border-[color:Highlight] forced-colors:indeterminate:bg-[color:Highlight]",
151
+ sm ? "size-3.5" : "size-4"
152
+ )
153
+ }
154
+ ),
155
+ /* @__PURE__ */ jsx(
156
+ CheckIcon,
157
+ {
158
+ size: sm ? 10 : 12,
159
+ className: "pointer-events-none absolute inset-0 m-auto hidden text-th-on-accent peer-checked:block peer-indeterminate:hidden forced-colors:text-[color:HighlightText]"
160
+ }
161
+ ),
162
+ /* @__PURE__ */ jsx(
163
+ MinusIcon,
164
+ {
165
+ size: sm ? 10 : 12,
166
+ className: "pointer-events-none absolute inset-0 m-auto hidden text-th-on-accent peer-indeterminate:block forced-colors:text-[color:HighlightText]"
167
+ }
168
+ )
169
+ ] }),
170
+ label != null || hint != null ? /* @__PURE__ */ jsxs("span", { className: "min-w-0", children: [
171
+ label != null ? /* @__PURE__ */ jsx("span", { id: labelId, className: "block leading-snug", children: label }) : null,
172
+ hint ? /* @__PURE__ */ jsx("span", { id: hintId, className: "mt-0.5 block text-xs text-th-hi3", children: hint }) : null
173
+ ] }) : null,
174
+ trailing != null ? /* @__PURE__ */ jsx("span", { id: trailingId, className: "ms-auto shrink-0 ps-2 text-th-hi2 tabular-nums", children: trailing }) : null
175
+ ]
176
+ }
177
+ );
178
+ }
179
+ function Switch({
180
+ ref,
181
+ checked: checkedProp,
182
+ defaultChecked = false,
183
+ onChange,
184
+ onCheckedChange,
185
+ name,
186
+ value = "on",
187
+ required,
188
+ form,
189
+ label,
190
+ description,
191
+ size = "md",
192
+ labelSide = "start",
193
+ disabled,
194
+ className,
195
+ id,
196
+ onClick,
197
+ ...rest
198
+ }) {
199
+ const auto = useId();
200
+ const btnId = id ?? `${auto}-switch`;
201
+ const labelId = `${auto}-label`;
202
+ const descId = `${auto}-desc`;
203
+ const sm = size === "sm";
204
+ const [inner, setInner] = useState(defaultChecked);
205
+ const controlled = checkedProp !== void 0;
206
+ const checked = controlled ? checkedProp : inner;
207
+ const hidden = useRef(null);
208
+ useFormReset(hidden, () => {
209
+ if (!controlled) setInner(defaultChecked);
210
+ });
211
+ const state = checked ? "checked" : "unchecked";
212
+ const button = /* @__PURE__ */ jsx(
213
+ "button",
214
+ {
215
+ ...rest,
216
+ ref,
217
+ id: btnId,
218
+ type: "button",
219
+ role: "switch",
220
+ "aria-checked": checked,
221
+ "aria-required": required || void 0,
222
+ "aria-labelledby": label != null ? labelId : rest["aria-labelledby"],
223
+ "aria-describedby": description != null ? descId : rest["aria-describedby"],
224
+ "data-state": state,
225
+ "data-disabled": disabled ? "" : void 0,
226
+ disabled,
227
+ onClick: (e) => {
228
+ onClick?.(e);
229
+ if (e.defaultPrevented) return;
230
+ const next = !checked;
231
+ if (!controlled) setInner(next);
232
+ onChange?.(next, e);
233
+ onCheckedChange?.(next);
234
+ },
235
+ className: cn(
236
+ "group relative inline-flex shrink-0 items-center justify-center rounded-full disabled:cursor-not-allowed disabled:opacity-50",
237
+ "pointer-coarse:min-h-11 pointer-coarse:min-w-11",
238
+ label == null && className
239
+ ),
240
+ children: /* @__PURE__ */ jsx(
241
+ "span",
242
+ {
243
+ "aria-hidden": "true",
244
+ "data-state": state,
245
+ className: cn(
246
+ "inline-flex items-center rounded-full p-0.5 transition-colors duration-150 forced-color-adjust-none",
247
+ "forced-colors:border forced-colors:border-[color:ButtonText] forced-colors:group-disabled:border-[color:GrayText]",
248
+ sm ? "h-4 w-7" : "h-5 w-9",
249
+ checked ? "bg-th-accent forced-colors:bg-[color:Highlight]" : "bg-th-line-control forced-colors:bg-[color:Canvas]"
250
+ ),
251
+ children: /* @__PURE__ */ jsx(
252
+ "span",
253
+ {
254
+ className: cn(
255
+ "rounded-full shadow-card transition-transform duration-150 motion-reduce:transition-none",
256
+ sm ? "size-3" : "size-4",
257
+ checked ? cn(sm ? "translate-x-3 rtl:-translate-x-3" : "translate-x-4 rtl:-translate-x-4", "bg-th-on-accent forced-colors:bg-[color:HighlightText]") : "translate-x-0 bg-th-surface forced-colors:bg-[color:ButtonText]"
258
+ )
259
+ }
260
+ )
261
+ }
262
+ )
263
+ }
264
+ );
265
+ const mirror = name != null ? /* @__PURE__ */ jsx(
266
+ "input",
267
+ {
268
+ ref: hidden,
269
+ type: "checkbox",
270
+ "aria-hidden": "true",
271
+ tabIndex: -1,
272
+ className: "sr-only pointer-events-none",
273
+ name,
274
+ value,
275
+ form,
276
+ required,
277
+ disabled,
278
+ checked,
279
+ onChange: noop
280
+ }
281
+ ) : null;
282
+ if (label == null)
283
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
284
+ button,
285
+ mirror
286
+ ] });
287
+ const text = /* @__PURE__ */ jsxs("span", { className: "min-w-0", children: [
288
+ /* @__PURE__ */ jsx("span", { id: labelId, className: cn("block leading-snug text-th-hi", sm ? "text-xs" : "text-sm"), children: label }),
289
+ description != null ? /* @__PURE__ */ jsx("span", { id: descId, className: "mt-0.5 block text-xs text-th-hi3", children: description }) : null
290
+ ] });
291
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
292
+ /* @__PURE__ */ jsxs(
293
+ "label",
294
+ {
295
+ htmlFor: btnId,
296
+ "data-state": state,
297
+ "data-disabled": disabled ? "" : void 0,
298
+ className: cn(
299
+ "flex cursor-pointer items-start gap-3 pointer-coarse:items-center",
300
+ labelSide === "start" && "justify-between",
301
+ disabled && "cursor-not-allowed",
302
+ className
303
+ ),
304
+ children: [
305
+ labelSide === "start" ? text : null,
306
+ /* @__PURE__ */ jsx("span", { className: cn("inline-flex", sm ? "pt-0" : "pt-px", "pointer-coarse:pt-0"), children: button }),
307
+ labelSide === "end" ? text : null
308
+ ]
309
+ }
310
+ ),
311
+ mirror
312
+ ] });
313
+ }
314
+ function Field({
315
+ ref,
316
+ label,
317
+ hint,
318
+ error,
319
+ optional = false,
320
+ required = false,
321
+ htmlFor,
322
+ layout = "stack",
323
+ labelWidth = "7rem",
324
+ children,
325
+ className,
326
+ style,
327
+ ...rest
328
+ }) {
329
+ const auto = useId();
330
+ const strings = useNishStrings();
331
+ const only = Children.count(children) === 1 && isValidElement(children) ? children : null;
332
+ const childId = only && typeof only.props.id === "string" ? only.props.id : void 0;
333
+ const controlId = htmlFor ?? childId ?? `${auto}-control`;
334
+ const hasError = error != null && error !== false && error !== "";
335
+ const hintId = `${auto}-hint`;
336
+ const errorId = `${auto}-error`;
337
+ const describedBy = [only?.props["aria-describedby"], hasError ? errorId : hint != null ? hintId : void 0].filter(Boolean).join(" ") || void 0;
338
+ const control = only ? cloneElement(only, {
339
+ id: htmlFor ?? childId ?? controlId,
340
+ "aria-describedby": describedBy,
341
+ ...hasError ? { "aria-invalid": true } : null,
342
+ ...required ? { required: true, "aria-required": true } : null
343
+ }) : children;
344
+ const inline = layout === "inline";
345
+ const labelEl = /* @__PURE__ */ jsxs(
346
+ "label",
347
+ {
348
+ htmlFor: controlId,
349
+ className: cn(
350
+ "flex flex-wrap items-baseline gap-x-1.5",
351
+ inline ? "text-xs text-th-hi3 pointer-coarse:min-h-11 pointer-coarse:items-center" : "text-sm font-medium text-th-hi"
352
+ ),
353
+ children: [
354
+ /* @__PURE__ */ jsxs("span", { children: [
355
+ label,
356
+ required ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", "data-nish-required": "", className: "ms-0.5 text-th-loss", children: "*" }) : null
357
+ ] }),
358
+ optional && !required ? /* @__PURE__ */ jsx("span", { className: "text-xs font-normal text-th-hi3", children: strings.optional }) : null
359
+ ]
360
+ }
361
+ );
362
+ const message = hasError ? /* @__PURE__ */ jsx("p", { id: errorId, role: "alert", className: "text-xs text-th-loss", children: error }) : hint != null ? /* @__PURE__ */ jsx("p", { id: hintId, className: "text-xs text-th-hi3", children: hint }) : null;
363
+ if (inline) {
364
+ return /* @__PURE__ */ jsxs(
365
+ "div",
366
+ {
367
+ ...rest,
368
+ ref,
369
+ className: cn("grid items-center gap-x-3 gap-y-1", className),
370
+ style: { ...style, gridTemplateColumns: `${labelWidth} minmax(0, 1fr)` },
371
+ children: [
372
+ labelEl,
373
+ /* @__PURE__ */ jsx("div", { className: "min-w-0", children: control }),
374
+ message ? /* @__PURE__ */ jsx("div", { className: "col-start-2", children: message }) : null
375
+ ]
376
+ }
377
+ );
378
+ }
379
+ return /* @__PURE__ */ jsxs("div", { ...rest, ref, style, className: cn("grid w-full gap-1.5", className), children: [
380
+ labelEl,
381
+ control,
382
+ message
383
+ ] });
384
+ }
385
+ function FieldGroup({ ref, label, hint, error, optional = false, className, children, ...rest }) {
386
+ const auto = useId();
387
+ const strings = useNishStrings();
388
+ const hasError = error != null && error !== false && error !== "";
389
+ const hintId = `${auto}-hint`;
390
+ const errorId = `${auto}-error`;
391
+ const describedBy = [rest["aria-describedby"], hasError ? errorId : hint != null ? hintId : void 0].filter(Boolean).join(" ") || void 0;
392
+ return /* @__PURE__ */ jsxs("fieldset", { ...rest, ref, "aria-describedby": describedBy, className: cn("m-0 grid min-w-0 gap-1.5 border-0 p-0", className), children: [
393
+ /* @__PURE__ */ jsxs("legend", { className: "mb-1.5 flex flex-wrap items-baseline gap-x-1.5 p-0 text-sm font-medium text-th-hi", children: [
394
+ /* @__PURE__ */ jsx("span", { children: label }),
395
+ optional ? /* @__PURE__ */ jsx("span", { className: "text-xs font-normal text-th-hi3", children: strings.optional }) : null
396
+ ] }),
397
+ children,
398
+ hasError ? /* @__PURE__ */ jsx("p", { id: errorId, role: "alert", className: "text-xs text-th-loss", children: error }) : hint != null ? /* @__PURE__ */ jsx("p", { id: hintId, className: "text-xs text-th-hi3", children: hint }) : null
399
+ ] });
400
+ }
401
+ var SEARCH_SIZE = {
402
+ xs: "h-7 text-2xs pointer-coarse:text-base",
403
+ sm: "h-8 text-xs pointer-coarse:text-base",
404
+ md: "h-9 text-sm pointer-coarse:text-base"
405
+ };
406
+ function SearchInput({
407
+ ref,
408
+ value: valueProp,
409
+ defaultValue = "",
410
+ onChange,
411
+ onClear,
412
+ size = "md",
413
+ variant = "field",
414
+ className,
415
+ inputClassName,
416
+ onKeyDown,
417
+ placeholder,
418
+ clearLabel,
419
+ disabled,
420
+ ...rest
421
+ }) {
422
+ const strings = useNishStrings();
423
+ const inner = useRef(null);
424
+ const [own, setOwn] = useState(defaultValue);
425
+ const controlled = valueProp !== void 0;
426
+ const value = controlled ? valueProp : own;
427
+ useFormReset(inner, () => {
428
+ if (!controlled) setOwn(defaultValue);
429
+ });
430
+ const set = (next, event) => {
431
+ if (!controlled) setOwn(next);
432
+ onChange?.(next, event);
433
+ };
434
+ const clear = () => {
435
+ set("");
436
+ onClear?.();
437
+ };
438
+ return /* @__PURE__ */ jsxs("div", { className: cn("relative w-full min-w-0", className), children: [
439
+ /* @__PURE__ */ jsx(
440
+ SearchIcon,
441
+ {
442
+ size: size === "md" ? 16 : 14,
443
+ className: cn("pointer-events-none absolute top-1/2 -translate-y-1/2 text-th-hi3", size === "xs" ? "start-2" : "start-2.5")
444
+ }
445
+ ),
446
+ /* @__PURE__ */ jsx(
447
+ Input,
448
+ {
449
+ ...rest,
450
+ ref: (node) => {
451
+ inner.current = node;
452
+ setRef(ref, node);
453
+ },
454
+ type: "search",
455
+ enterKeyHint: "search",
456
+ autoComplete: "off",
457
+ value,
458
+ placeholder: placeholder ?? strings.search,
459
+ disabled,
460
+ onChange: (e) => set(e.target.value, e),
461
+ onKeyDown: (e) => {
462
+ onKeyDown?.(e);
463
+ if (e.defaultPrevented) return;
464
+ if (e.key === "Escape" && value) {
465
+ e.preventDefault();
466
+ e.stopPropagation();
467
+ clear();
468
+ }
469
+ },
470
+ className: cn(
471
+ SEARCH_SIZE[size],
472
+ size === "xs" ? "ps-7" : size === "sm" ? "ps-8" : "ps-9",
473
+ value ? "pe-8 pointer-coarse:pe-11" : size === "xs" ? "pe-2" : "pe-3",
474
+ "[&::-webkit-search-cancel-button]:appearance-none [&::-webkit-search-decoration]:appearance-none",
475
+ variant === "bare" && "border-transparent bg-transparent hover:border-transparent focus:border-transparent",
476
+ inputClassName
477
+ )
478
+ }
479
+ ),
480
+ value && !disabled ? /* @__PURE__ */ jsx(
481
+ IconButton,
482
+ {
483
+ label: clearLabel ?? strings.clearSearch,
484
+ size: "xs",
485
+ onClick: () => {
486
+ clear();
487
+ inner.current?.focus();
488
+ },
489
+ className: "absolute end-1 top-1/2 -translate-y-1/2",
490
+ children: /* @__PURE__ */ jsx(XIcon, { size: 14 })
491
+ }
492
+ ) : null
493
+ ] });
494
+ }
495
+ function Chip({ ref, variant = "toggle", pressed, onRemove, removeLabel, icon, trailing, size = "md", className, children, type = "button", ...rest }) {
496
+ const strings = useNishStrings();
497
+ if (variant === "tag") {
498
+ const name = removeLabel ?? (typeof children === "string" ? strings.removeNamed(children) : strings.remove);
499
+ const spanProps = rest;
500
+ return /* @__PURE__ */ jsxs(
501
+ "span",
502
+ {
503
+ ...spanProps,
504
+ ref,
505
+ className: chipClass({ variant: "tag", size, className: cn(onRemove && (size === "sm" ? "pe-0.5" : "pe-1"), className) }),
506
+ children: [
507
+ icon,
508
+ children,
509
+ trailing,
510
+ onRemove ? /* @__PURE__ */ jsx(IconButton, { label: name, size: "xs", onClick: onRemove, className: "rounded-full", children: /* @__PURE__ */ jsx(XIcon, { size: 12 }) }) : null
511
+ ]
512
+ }
513
+ );
514
+ }
515
+ const suggestion = variant === "suggestion";
516
+ return /* @__PURE__ */ jsxs(
517
+ "button",
518
+ {
519
+ ...rest,
520
+ ref,
521
+ type,
522
+ "aria-pressed": suggestion ? void 0 : !!pressed,
523
+ "data-state": suggestion ? void 0 : pressed ? "active" : "inactive",
524
+ "data-disabled": rest.disabled ? "" : void 0,
525
+ className: chipClass({
526
+ variant: suggestion ? "suggestion" : "toggle",
527
+ pressed: !!pressed,
528
+ size,
529
+ className: cn("disabled:pointer-events-none disabled:opacity-50 forced-colors:disabled:text-[color:GrayText]", className)
530
+ }),
531
+ children: [
532
+ icon ?? (suggestion ? /* @__PURE__ */ jsx(PlusIcon, { size: size === "sm" ? 12 : 14 }) : null),
533
+ children,
534
+ trailing
535
+ ]
536
+ }
537
+ );
538
+ }
539
+ function ChipGroup({ ref, label, scroll = false, className, children, onKeyDown, ...rest }) {
540
+ return /* @__PURE__ */ jsx(
541
+ "div",
542
+ {
543
+ ...rest,
544
+ ref,
545
+ role: "group",
546
+ "aria-label": label,
547
+ onKeyDown: (e) => {
548
+ onKeyDown?.(e);
549
+ if (e.defaultPrevented) return;
550
+ const rtl = isRtl(e.currentTarget);
551
+ const next = e.key === (rtl ? "ArrowLeft" : "ArrowRight") ? 1 : e.key === (rtl ? "ArrowRight" : "ArrowLeft") ? -1 : 0;
552
+ const home = e.key === "Home";
553
+ const end = e.key === "End";
554
+ if (!next && !home && !end) return;
555
+ const chips = Array.from(e.currentTarget.querySelectorAll("button:not(:disabled)"));
556
+ const at = chips.indexOf(e.target);
557
+ if (at < 0) return;
558
+ e.preventDefault();
559
+ const to = home ? 0 : end ? chips.length - 1 : (at + next + chips.length) % chips.length;
560
+ chips[to]?.focus();
561
+ },
562
+ className: cn(
563
+ "flex flex-wrap items-center gap-2",
564
+ scroll && "max-sm:flex-nowrap max-sm:overflow-x-auto max-sm:py-1 scrollbar-none",
565
+ className
566
+ ),
567
+ children
568
+ }
569
+ );
570
+ }
571
+ export {
572
+ Checkbox,
573
+ Chip,
574
+ ChipGroup,
575
+ Field,
576
+ FieldGroup,
577
+ SearchInput,
578
+ Switch,
579
+ Textarea,
580
+ chipClass
581
+ };
@@ -0,0 +1,9 @@
1
+ // src/components/hooks-classes.ts
2
+ var BREAKPOINTS = { sm: 640, md: 768, lg: 1024, xl: 1280 };
3
+ var PHONE_QUERY = "(max-width: 639.98px)";
4
+ var NARROW_QUERY = "(max-width: 767.98px)";
5
+ export {
6
+ BREAKPOINTS,
7
+ NARROW_QUERY,
8
+ PHONE_QUERY
9
+ };