@hydrateless/react 0.4.0 → 0.6.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.
package/dist/index.js CHANGED
@@ -2,12 +2,18 @@
2
2
  import { useEffect, useRef } from "react";
3
3
  function useEnhancer(enhance, deps = []) {
4
4
  const ref = useRef(null);
5
+ const api = useRef(null);
5
6
  useEffect(() => {
6
7
  const el = ref.current;
7
8
  if (!el) return;
8
- return enhance(el);
9
+ const handle = enhance(el);
10
+ api.current = handle.api;
11
+ return () => {
12
+ api.current = null;
13
+ handle.destroy();
14
+ };
9
15
  }, deps);
10
- return ref;
16
+ return { ref, api };
11
17
  }
12
18
 
13
19
  // src/hooks.ts
@@ -32,422 +38,517 @@ var useTocEnhancer = (options) => useEnhancer(
32
38
  );
33
39
 
34
40
  // src/Accordion.tsx
35
- import { useEffect as useEffect2, useRef as useRef2 } from "react";
41
+ import { useEffect as useEffect2, useRef as useRef3 } from "react";
36
42
  import { enhanceAccordion as enhanceAccordion2 } from "@hydrateless/enhancers";
43
+
44
+ // src/util.ts
45
+ import { useRef as useRef2 } from "react";
46
+ function cx(...classes) {
47
+ return classes.filter(Boolean).join(" ");
48
+ }
49
+ function useLatest(value) {
50
+ const ref = useRef2(value);
51
+ ref.current = value;
52
+ return ref;
53
+ }
54
+
55
+ // src/Accordion.tsx
37
56
  import { jsx, jsxs } from "react/jsx-runtime";
38
- function Accordion({ allowMultiple = false, children, ...rest }) {
39
- const ref = useRef2(null);
57
+ function Accordion({
58
+ allowMultiple = false,
59
+ value,
60
+ defaultValue,
61
+ onValueChange,
62
+ children,
63
+ ...rest
64
+ }) {
65
+ const onValueChangeRef = useLatest(onValueChange);
66
+ const initialValueRef = useLatest(value ?? defaultValue);
67
+ const { ref, api } = useEnhancer(
68
+ (el) => enhanceAccordion2(el, {
69
+ allowMultiple,
70
+ defaultValue: initialValueRef.current,
71
+ onValueChange: (next) => onValueChangeRef.current?.(next)
72
+ }),
73
+ [allowMultiple]
74
+ );
40
75
  useEffect2(() => {
41
- if (!ref.current) return;
42
- return enhanceAccordion2(ref.current, { allowMultiple });
43
- }, [allowMultiple]);
76
+ if (value != null) api.current?.setValue(value);
77
+ }, [value, api]);
44
78
  return /* @__PURE__ */ jsx("div", { ...rest, "data-hl-accordion": true, ref, children });
45
79
  }
46
80
  function AccordionItem({
47
81
  summary,
82
+ value,
48
83
  defaultOpen = false,
49
84
  children,
50
85
  ...rest
51
86
  }) {
52
- const ref = useRef2(null);
87
+ const ref = useRef3(null);
53
88
  useEffect2(() => {
54
89
  if (ref.current && defaultOpen) ref.current.open = true;
55
90
  }, [defaultOpen]);
56
- return /* @__PURE__ */ jsxs("details", { ...rest, ref, children: [
91
+ return /* @__PURE__ */ jsxs("details", { ...rest, "data-hl-value": value, ref, children: [
57
92
  /* @__PURE__ */ jsx("summary", { children: summary }),
58
- /* @__PURE__ */ jsx("div", { className: "accordion-panel", children })
93
+ /* @__PURE__ */ jsx("div", { className: "hl-accordion-panel", children })
59
94
  ] });
60
95
  }
61
96
 
62
97
  // src/Disclosure.tsx
63
- import { useEffect as useEffect3, useRef as useRef3 } from "react";
98
+ import { useEffect as useEffect3, useRef as useRef4 } from "react";
64
99
  import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
65
- function Disclosure({ summary, defaultOpen = false, children, ...rest }) {
66
- const ref = useRef3(null);
100
+ function Disclosure({
101
+ summary,
102
+ defaultOpen = false,
103
+ className,
104
+ children,
105
+ ...rest
106
+ }) {
107
+ const ref = useRef4(null);
67
108
  useEffect3(() => {
68
109
  if (ref.current && defaultOpen) ref.current.open = true;
69
110
  }, [defaultOpen]);
70
- return /* @__PURE__ */ jsxs2("details", { ...rest, className: "hydrateless-disclosure", "data-hl-disclosure": true, ref, children: [
111
+ return /* @__PURE__ */ jsxs2("details", { ...rest, className: cx("hl-disclosure", className), "data-hl-disclosure": true, ref, children: [
71
112
  /* @__PURE__ */ jsx2("summary", { children: summary }),
72
- /* @__PURE__ */ jsx2("div", { className: "disclosure-panel", children })
113
+ /* @__PURE__ */ jsx2("div", { className: "hl-disclosure-panel", children })
73
114
  ] });
74
115
  }
75
116
 
76
117
  // src/Tabs.tsx
77
- import { useEffect as useEffect4, useRef as useRef4 } from "react";
118
+ import { useEffect as useEffect4 } from "react";
78
119
  import { enhanceTabs as enhanceTabs2 } from "@hydrateless/enhancers";
79
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
80
- function Tabs({ items, ...rest }) {
81
- const ref = useRef4(null);
120
+ import { jsx as jsx3 } from "react/jsx-runtime";
121
+ function Tabs({
122
+ activation,
123
+ orientation,
124
+ value,
125
+ defaultValue,
126
+ onValueChange,
127
+ children,
128
+ ...rest
129
+ }) {
130
+ const onValueChangeRef = useLatest(onValueChange);
131
+ const initialValueRef = useLatest(value ?? defaultValue);
132
+ const { ref, api } = useEnhancer(
133
+ (el) => enhanceTabs2(el, {
134
+ activation,
135
+ orientation,
136
+ defaultValue: initialValueRef.current,
137
+ onValueChange: (next) => onValueChangeRef.current?.(next)
138
+ }),
139
+ [activation, orientation]
140
+ );
82
141
  useEffect4(() => {
83
- if (!ref.current) return;
84
- return enhanceTabs2(ref.current);
85
- }, [items.length]);
86
- return /* @__PURE__ */ jsxs3("div", { ...rest, "data-hl-tabs": true, ref, children: [
87
- /* @__PURE__ */ jsx3("div", { role: "tablist", children: items.map((item, i) => /* @__PURE__ */ jsx3("button", { type: "button", role: "tab", children: item.label }, i)) }),
88
- items.map((item, i) => /* @__PURE__ */ jsx3("div", { role: "tabpanel", children: item.content }, i))
89
- ] });
142
+ if (value != null) api.current?.setValue(value);
143
+ }, [value, api]);
144
+ return /* @__PURE__ */ jsx3("div", { ...rest, "data-hl-tabs": true, ref, children });
145
+ }
146
+ function TabList({ children, ...rest }) {
147
+ return /* @__PURE__ */ jsx3("div", { ...rest, role: "tablist", children });
148
+ }
149
+ function Tab({ children, type, value, ...rest }) {
150
+ return /* @__PURE__ */ jsx3("button", { ...rest, type: type ?? "button", role: "tab", "data-hl-value": value, children });
151
+ }
152
+ function TabPanel({ children, ...rest }) {
153
+ return /* @__PURE__ */ jsx3("div", { ...rest, role: "tabpanel", children });
90
154
  }
91
155
 
92
156
  // src/Dropdown.tsx
93
- import { useEffect as useEffect5, useRef as useRef5 } from "react";
94
- import { enhanceDropdown as enhanceDropdown2 } from "@hydrateless/enhancers";
95
- import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
96
- function Dropdown({ trigger, items, ...rest }) {
97
- const ref = useRef5(null);
157
+ import {
158
+ useEffect as useEffect5
159
+ } from "react";
160
+ import {
161
+ enhanceDropdown as enhanceDropdown2
162
+ } from "@hydrateless/enhancers";
163
+ import { jsx as jsx4 } from "react/jsx-runtime";
164
+ function Dropdown({
165
+ placement,
166
+ open,
167
+ defaultOpen,
168
+ onOpenChange,
169
+ children,
170
+ ...rest
171
+ }) {
172
+ const onOpenChangeRef = useLatest(onOpenChange);
173
+ const initialOpenRef = useLatest(open ?? defaultOpen);
174
+ const { ref, api } = useEnhancer(
175
+ (el) => enhanceDropdown2(el, {
176
+ placement,
177
+ defaultOpen: initialOpenRef.current,
178
+ onOpenChange: (next) => onOpenChangeRef.current?.(next)
179
+ }),
180
+ [placement]
181
+ );
98
182
  useEffect5(() => {
183
+ if (open != null) api.current?.setOpen(open);
184
+ }, [open, api]);
185
+ return /* @__PURE__ */ jsx4("div", { ...rest, "data-hl-dropdown": true, ref, children });
186
+ }
187
+ function DropdownTrigger({ children, type, ...rest }) {
188
+ return /* @__PURE__ */ jsx4("button", { ...rest, type: type ?? "button", "data-hl-dropdown-trigger": true, children });
189
+ }
190
+ function DropdownMenu({ children, ...rest }) {
191
+ return /* @__PURE__ */ jsx4("ul", { ...rest, "data-hl-dropdown-menu": true, children });
192
+ }
193
+ function DropdownItem({ children, onSelect, onClick, type, ...rest }) {
194
+ return /* @__PURE__ */ jsx4("li", { children: /* @__PURE__ */ jsx4(
195
+ "button",
196
+ {
197
+ ...rest,
198
+ type: type ?? "button",
199
+ role: "menuitem",
200
+ onClick: (e) => {
201
+ onSelect?.();
202
+ onClick?.(e);
203
+ },
204
+ children
205
+ }
206
+ ) });
207
+ }
208
+ function DropdownSeparator(props) {
209
+ return /* @__PURE__ */ jsx4("li", { ...props, role: "separator" });
210
+ }
211
+
212
+ // src/Menu.tsx
213
+ import {
214
+ useEffect as useEffect6,
215
+ useRef as useRef5
216
+ } from "react";
217
+ import { enhanceMenu } from "@hydrateless/enhancers";
218
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
219
+ function Menu({ orientation = "horizontal", children, ...rest }) {
220
+ const ref = useRef5(null);
221
+ useEffect6(() => {
99
222
  if (!ref.current) return;
100
- return enhanceDropdown2(ref.current);
101
- }, [items.length]);
102
- return /* @__PURE__ */ jsxs4("div", { ...rest, "data-hl-dropdown": true, ref, children: [
103
- /* @__PURE__ */ jsx4("button", { type: "button", "data-hl-dropdown-trigger": true, children: trigger }),
104
- /* @__PURE__ */ jsx4("ul", { "data-hl-dropdown-menu": true, children: items.map(
105
- (item, i) => item.separator ? /* @__PURE__ */ jsx4("li", { role: "separator" }, i) : /* @__PURE__ */ jsx4("li", { children: /* @__PURE__ */ jsx4(
106
- "button",
107
- {
108
- type: "button",
109
- role: "menuitem",
110
- onClick: item.onSelect,
111
- disabled: item.disabled,
112
- children: item.label
113
- }
114
- ) }, i)
115
- ) })
223
+ return enhanceMenu(ref.current, { orientation }).destroy;
224
+ }, [orientation]);
225
+ return /* @__PURE__ */ jsx5(
226
+ "ul",
227
+ {
228
+ ...rest,
229
+ ref,
230
+ "data-hl-menu": true,
231
+ role: orientation === "vertical" ? "menu" : "menubar",
232
+ "aria-orientation": orientation,
233
+ children
234
+ }
235
+ );
236
+ }
237
+ function MenuItem({
238
+ href,
239
+ onSelect,
240
+ onClick,
241
+ submenu,
242
+ anchorProps,
243
+ children,
244
+ ...rest
245
+ }) {
246
+ const hasSubmenu = submenu != null;
247
+ return /* @__PURE__ */ jsxs3("li", { role: "none", children: [
248
+ href && !hasSubmenu ? /* @__PURE__ */ jsx5("a", { ...anchorProps, role: "menuitem", href, children }) : /* @__PURE__ */ jsx5(
249
+ "button",
250
+ {
251
+ ...rest,
252
+ type: "button",
253
+ role: "menuitem",
254
+ onClick: (e) => {
255
+ onSelect?.();
256
+ onClick?.(e);
257
+ },
258
+ children
259
+ }
260
+ ),
261
+ hasSubmenu && /* @__PURE__ */ jsx5("ul", { role: "menu", "data-hl-menu-submenu": true, hidden: true, children: submenu })
116
262
  ] });
117
263
  }
118
264
 
119
265
  // src/Modal.tsx
120
- import { useEffect as useEffect6, useRef as useRef6 } from "react";
121
- import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
266
+ import { useEffect as useEffect7 } from "react";
267
+ import { enhanceModal as enhanceModal2 } from "@hydrateless/enhancers";
268
+ import { jsx as jsx6 } from "react/jsx-runtime";
122
269
  function Modal({
123
270
  open,
124
- onClose,
125
- title,
126
- footer,
271
+ onOpenChange,
127
272
  closeOnBackdrop = true,
128
273
  className,
129
274
  children,
130
275
  ...rest
131
276
  }) {
132
- const ref = useRef6(null);
133
- useEffect6(() => {
134
- const dialog = ref.current;
135
- if (!dialog) return;
136
- if (open && !dialog.open) dialog.showModal();
137
- else if (!open && dialog.open) dialog.close();
138
- }, [open]);
139
- useEffect6(() => {
140
- const dialog = ref.current;
141
- if (!dialog) return;
142
- const handleClose = () => onClose?.();
143
- dialog.addEventListener("close", handleClose);
144
- return () => dialog.removeEventListener("close", handleClose);
145
- }, [onClose]);
146
- const handleClick = (e) => {
147
- if (closeOnBackdrop && e.target === ref.current) onClose?.();
148
- };
149
- return /* @__PURE__ */ jsxs5(
150
- "dialog",
151
- {
152
- ...rest,
153
- ref,
154
- className: ["hydrateless-modal", className].filter(Boolean).join(" "),
155
- onClick: handleClick,
156
- children: [
157
- title != null && /* @__PURE__ */ jsx5("div", { className: "hl-modal-header", children: title }),
158
- /* @__PURE__ */ jsx5("div", { className: "hl-modal-body", children }),
159
- footer != null && /* @__PURE__ */ jsx5("div", { className: "hl-modal-footer", children: footer })
160
- ]
161
- }
277
+ const onOpenChangeRef = useLatest(onOpenChange);
278
+ const { ref, api } = useEnhancer(
279
+ (el) => enhanceModal2(el, {
280
+ closeOnBackdrop,
281
+ onOpenChange: (next) => onOpenChangeRef.current?.(next)
282
+ }),
283
+ [closeOnBackdrop]
162
284
  );
285
+ useEffect7(() => {
286
+ api.current?.setOpen(open);
287
+ }, [open, api]);
288
+ return /* @__PURE__ */ jsx6("dialog", { ...rest, ref, "data-hl-modal": true, className: cx("hl-modal", className), children });
289
+ }
290
+ function ModalHeader({ className, ...rest }) {
291
+ return /* @__PURE__ */ jsx6("div", { ...rest, className: cx("hl-modal-header", className) });
292
+ }
293
+ function ModalBody({ className, ...rest }) {
294
+ return /* @__PURE__ */ jsx6("div", { ...rest, className: cx("hl-modal-body", className) });
295
+ }
296
+ function ModalFooter({ className, ...rest }) {
297
+ return /* @__PURE__ */ jsx6("div", { ...rest, className: cx("hl-modal-footer", className) });
163
298
  }
164
299
 
165
300
  // src/Drawer.tsx
166
- import { useEffect as useEffect7, useRef as useRef7 } from "react";
167
- import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
301
+ import { useEffect as useEffect8 } from "react";
302
+ import { enhanceDrawer } from "@hydrateless/enhancers";
303
+ import { jsx as jsx7 } from "react/jsx-runtime";
168
304
  function Drawer({
169
305
  open,
170
- onClose,
306
+ onOpenChange,
171
307
  side = "right",
172
- title,
173
- footer,
174
308
  closeOnBackdrop = true,
175
309
  className,
176
310
  children,
177
311
  ...rest
178
312
  }) {
179
- const ref = useRef7(null);
180
- useEffect7(() => {
181
- const dialog = ref.current;
182
- if (!dialog) return;
183
- if (open && !dialog.open) dialog.showModal();
184
- else if (!open && dialog.open) dialog.close();
185
- }, [open]);
186
- useEffect7(() => {
187
- const dialog = ref.current;
188
- if (!dialog) return;
189
- const handleClose = () => onClose?.();
190
- dialog.addEventListener("close", handleClose);
191
- return () => dialog.removeEventListener("close", handleClose);
192
- }, [onClose]);
193
- const handleClick = (e) => {
194
- if (closeOnBackdrop && e.target === ref.current) onClose?.();
195
- };
196
- return /* @__PURE__ */ jsxs6(
313
+ const onOpenChangeRef = useLatest(onOpenChange);
314
+ const { ref, api } = useEnhancer(
315
+ (el) => enhanceDrawer(el, {
316
+ closeOnBackdrop,
317
+ onOpenChange: (next) => onOpenChangeRef.current?.(next)
318
+ }),
319
+ [closeOnBackdrop]
320
+ );
321
+ useEffect8(() => {
322
+ api.current?.setOpen(open);
323
+ }, [open, api]);
324
+ return /* @__PURE__ */ jsx7(
197
325
  "dialog",
198
326
  {
199
327
  ...rest,
200
328
  ref,
329
+ "data-hl-drawer": true,
201
330
  "data-side": side,
202
- className: ["hydrateless-drawer", className].filter(Boolean).join(" "),
203
- onClick: handleClick,
204
- children: [
205
- title != null && /* @__PURE__ */ jsx6("div", { className: "hl-drawer-header", children: title }),
206
- /* @__PURE__ */ jsx6("div", { className: "hl-drawer-body", children }),
207
- footer != null && /* @__PURE__ */ jsx6("div", { className: "hl-drawer-footer", children: footer })
208
- ]
331
+ className: cx("hl-drawer", className),
332
+ children
209
333
  }
210
334
  );
211
335
  }
336
+ function DrawerHeader({ className, ...rest }) {
337
+ return /* @__PURE__ */ jsx7("div", { ...rest, className: cx("hl-drawer-header", className) });
338
+ }
339
+ function DrawerBody({ className, ...rest }) {
340
+ return /* @__PURE__ */ jsx7("div", { ...rest, className: cx("hl-drawer-body", className) });
341
+ }
342
+ function DrawerFooter({ className, ...rest }) {
343
+ return /* @__PURE__ */ jsx7("div", { ...rest, className: cx("hl-drawer-footer", className) });
344
+ }
212
345
 
213
346
  // src/Popover.tsx
214
- import { jsx as jsx7 } from "react/jsx-runtime";
215
- function Popover({ open, children, ...rest }) {
216
- return /* @__PURE__ */ jsx7("div", { ...rest, "data-hl-popover": true, role: "dialog", hidden: !open, children });
347
+ import { useEffect as useEffect9, useRef as useRef6 } from "react";
348
+ import { onClickOutside, onEscape, combine } from "@hydrateless/enhancers";
349
+ import { jsx as jsx8 } from "react/jsx-runtime";
350
+ function Popover({ open, onOpenChange, children, ...rest }) {
351
+ const ref = useRef6(null);
352
+ const onOpenChangeRef = useLatest(onOpenChange);
353
+ useEffect9(() => {
354
+ const el = ref.current;
355
+ if (!el || !open) return;
356
+ const dismiss = () => onOpenChangeRef.current?.(false);
357
+ return combine([onClickOutside(el, dismiss), onEscape(dismiss, el.ownerDocument)]);
358
+ }, [open, onOpenChangeRef]);
359
+ return /* @__PURE__ */ jsx8("div", { ...rest, ref, "data-hl-popover": true, role: "dialog", hidden: !open, children });
217
360
  }
218
361
 
219
362
  // src/Tooltip.tsx
220
363
  import {
221
364
  cloneElement,
222
365
  isValidElement,
223
- useEffect as useEffect8,
366
+ useEffect as useEffect10,
224
367
  useId,
225
- useRef as useRef8
368
+ useRef as useRef7
226
369
  } from "react";
227
370
  import { enhanceTooltip as enhanceTooltip2 } from "@hydrateless/enhancers";
228
- import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
371
+ import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
229
372
  function Tooltip({ label, children, id }) {
230
373
  const generatedId = useId().replace(/:/g, "");
231
374
  const tipId = id ?? `hl-tip-${generatedId}`;
232
- const ref = useRef8(null);
233
- useEffect8(() => {
375
+ const ref = useRef7(null);
376
+ useEffect10(() => {
234
377
  if (!ref.current) return;
235
- return enhanceTooltip2(ref.current);
378
+ return enhanceTooltip2(ref.current).destroy;
236
379
  }, [tipId]);
237
380
  const trigger = isValidElement(children) ? cloneElement(children, {
238
381
  "data-hl-tooltip": tipId,
239
382
  "aria-describedby": tipId
240
383
  }) : children;
241
- return /* @__PURE__ */ jsxs7("span", { ref, style: { position: "relative", display: "inline-block" }, children: [
384
+ return /* @__PURE__ */ jsxs4("span", { ref, style: { position: "relative", display: "inline-block" }, children: [
242
385
  trigger,
243
- /* @__PURE__ */ jsx8("span", { id: tipId, role: "tooltip", hidden: true, children: label })
386
+ /* @__PURE__ */ jsx9("span", { id: tipId, role: "tooltip", hidden: true, children: label })
244
387
  ] });
245
388
  }
246
389
 
247
390
  // src/Breadcrumb.tsx
248
- import { jsx as jsx9 } from "react/jsx-runtime";
249
- function Breadcrumb({ items, ...rest }) {
250
- return /* @__PURE__ */ jsx9("nav", { ...rest, "data-hl-breadcrumb": true, "aria-label": rest["aria-label"] ?? "Breadcrumb", children: /* @__PURE__ */ jsx9("ol", { children: items.map((item, i) => /* @__PURE__ */ jsx9("li", { children: item.current || !item.href ? /* @__PURE__ */ jsx9("span", { "aria-current": item.current ? "page" : void 0, children: item.label }) : /* @__PURE__ */ jsx9("a", { href: item.href, children: item.label }) }, i)) }) });
391
+ import { jsx as jsx10 } from "react/jsx-runtime";
392
+ function Breadcrumb({ children, ...rest }) {
393
+ return /* @__PURE__ */ jsx10("nav", { ...rest, "data-hl-breadcrumb": true, "aria-label": rest["aria-label"] ?? "Breadcrumb", children: /* @__PURE__ */ jsx10("ol", { children }) });
394
+ }
395
+ function BreadcrumbItem({
396
+ href,
397
+ current,
398
+ anchorProps,
399
+ children,
400
+ ...rest
401
+ }) {
402
+ return /* @__PURE__ */ jsx10("li", { ...rest, children: current || !href ? /* @__PURE__ */ jsx10("span", { "aria-current": current ? "page" : void 0, children }) : /* @__PURE__ */ jsx10("a", { ...anchorProps, href, children }) });
251
403
  }
252
404
 
253
405
  // src/Switch.tsx
254
- import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
406
+ import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
255
407
  function Switch({ children, className, ...rest }) {
256
- return /* @__PURE__ */ jsxs8("label", { "data-hl-switch": true, className, children: [
257
- /* @__PURE__ */ jsx10("input", { type: "checkbox", role: "switch", ...rest }),
408
+ return /* @__PURE__ */ jsxs5("label", { "data-hl-switch": true, className, children: [
409
+ /* @__PURE__ */ jsx11("input", { type: "checkbox", role: "switch", ...rest }),
258
410
  children
259
411
  ] });
260
412
  }
261
413
 
262
414
  // src/SkipLink.tsx
263
- import { jsx as jsx11 } from "react/jsx-runtime";
415
+ import { jsx as jsx12 } from "react/jsx-runtime";
264
416
  function SkipLink({ children = "Skip to content", className, ...rest }) {
265
- return /* @__PURE__ */ jsx11("a", { ...rest, className: ["a11y-skip-link", className].filter(Boolean).join(" "), children });
417
+ return /* @__PURE__ */ jsx12("a", { ...rest, className: cx("hl-skip-link", className), children });
266
418
  }
267
419
 
268
420
  // src/Toc.tsx
269
- import { useEffect as useEffect9, useRef as useRef9 } from "react";
421
+ import { useEffect as useEffect11, useRef as useRef8 } from "react";
270
422
  import { enhanceToc as enhanceToc2 } from "@hydrateless/enhancers";
271
- import { jsx as jsx12 } from "react/jsx-runtime";
423
+ import { jsx as jsx13 } from "react/jsx-runtime";
272
424
  function Toc({ contentSelector, headings, scrollSpy, ...rest }) {
273
- const ref = useRef9(null);
274
- useEffect9(() => {
425
+ const ref = useRef8(null);
426
+ useEffect11(() => {
275
427
  if (!ref.current) return;
276
- return enhanceToc2(ref.current.ownerDocument, { contentSelector, headings, scrollSpy });
428
+ return enhanceToc2(ref.current.ownerDocument, { contentSelector, headings, scrollSpy }).destroy;
277
429
  }, [contentSelector, headings, scrollSpy]);
278
- return /* @__PURE__ */ jsx12("nav", { ...rest, "data-hl-toc": true, ref });
430
+ return /* @__PURE__ */ jsx13("nav", { ...rest, "data-hl-toc": true, ref });
279
431
  }
280
432
 
281
433
  // src/Toast.tsx
282
- import { createContext, useContext, useEffect as useEffect10, useRef as useRef10 } from "react";
434
+ import { useEffect as useEffect12, useRef as useRef9 } from "react";
283
435
  import { enhanceToast } from "@hydrateless/enhancers";
284
- import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
285
- var ToastContext = createContext(null);
286
- function ToastProvider({ children }) {
287
- const apiRef = useRef10(null);
288
- const facade = useRef10({
289
- show: (message, options) => apiRef.current ? apiRef.current.show(message, options) : document.createElement("div"),
290
- dismiss: (toast) => apiRef.current?.dismiss(toast),
291
- destroy: () => apiRef.current?.destroy()
292
- });
293
- const regionRef = useRef10(null);
294
- useEffect10(() => {
295
- const region = regionRef.current;
296
- if (!region) return;
297
- const api = enhanceToast(region.ownerDocument);
298
- apiRef.current = api;
436
+ import { jsx as jsx14 } from "react/jsx-runtime";
437
+ var sharedApi = null;
438
+ function ensureApi() {
439
+ if (!sharedApi) {
440
+ const handle = enhanceToast(document);
441
+ sharedApi = handle.api;
442
+ }
443
+ return sharedApi;
444
+ }
445
+ var facade = {
446
+ show: (message, options) => ensureApi().show(message, options),
447
+ dismiss: (toast) => ensureApi().dismiss(toast)
448
+ };
449
+ function ToastRegion(props) {
450
+ const ref = useRef9(null);
451
+ useEffect12(() => {
452
+ if (!ref.current) return;
453
+ const handle = enhanceToast(ref.current.ownerDocument);
454
+ sharedApi = handle.api;
299
455
  return () => {
300
- api.destroy();
301
- apiRef.current = null;
456
+ handle.destroy();
457
+ sharedApi = null;
302
458
  };
303
459
  }, []);
304
- return /* @__PURE__ */ jsxs9(ToastContext.Provider, { value: facade.current, children: [
305
- children,
306
- /* @__PURE__ */ jsx13("div", { "data-hl-toast-region": true, ref: regionRef })
307
- ] });
460
+ return /* @__PURE__ */ jsx14("div", { ...props, "data-hl-toast-region": true, ref });
308
461
  }
309
462
  function useToast() {
310
- const ctx = useContext(ToastContext);
311
- if (!ctx) {
312
- throw new Error("useToast must be used within a <ToastProvider>");
313
- }
314
- return ctx;
315
- }
316
-
317
- // src/Menu.tsx
318
- import { useEffect as useEffect11, useRef as useRef11 } from "react";
319
- import { enhanceMenu } from "@hydrateless/enhancers";
320
- import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
321
- function renderItems(items) {
322
- return items.map((item, i) => /* @__PURE__ */ jsxs10("li", { role: "none", children: [
323
- item.href && !item.items ? /* @__PURE__ */ jsx14("a", { role: "menuitem", href: item.href, children: item.label }) : /* @__PURE__ */ jsx14("button", { type: "button", role: "menuitem", onClick: item.onSelect, disabled: item.disabled, children: item.label }),
324
- item.items && /* @__PURE__ */ jsx14("ul", { role: "menu", "data-hl-menu-submenu": true, hidden: true, children: renderItems(item.items) })
325
- ] }, i));
326
- }
327
- function Menu({ items, orientation = "horizontal", ...rest }) {
328
- const ref = useRef11(null);
329
- useEffect11(() => {
330
- if (!ref.current) return;
331
- return enhanceMenu(ref.current, { orientation });
332
- }, [items, orientation]);
333
- return /* @__PURE__ */ jsx14(
334
- "ul",
335
- {
336
- ...rest,
337
- ref,
338
- "data-hl-menu": true,
339
- role: orientation === "vertical" ? "menu" : "menubar",
340
- "aria-orientation": orientation,
341
- children: renderItems(items)
342
- }
343
- );
463
+ return facade;
344
464
  }
345
465
 
346
466
  // src/Combobox.tsx
347
467
  import {
348
- useEffect as useEffect12,
349
- useRef as useRef12
468
+ useEffect as useEffect13
350
469
  } from "react";
351
- import { enhanceCombobox } from "@hydrateless/enhancers";
352
- import { jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
470
+ import {
471
+ enhanceCombobox
472
+ } from "@hydrateless/enhancers";
473
+ import { jsx as jsx15 } from "react/jsx-runtime";
353
474
  function Combobox({
354
- options,
475
+ filter,
476
+ autoHighlight,
477
+ value,
355
478
  defaultValue,
356
- placeholder,
357
479
  onValueChange,
358
- inputProps,
480
+ children,
359
481
  ...rest
360
482
  }) {
361
- const ref = useRef12(null);
362
- const onChangeRef = useRef12(onValueChange);
363
- onChangeRef.current = onValueChange;
364
- useEffect12(() => {
365
- const el = ref.current;
366
- if (!el) return;
367
- const dispose = enhanceCombobox(el);
368
- const handler = (e) => onChangeRef.current?.(e.detail.value);
369
- el.addEventListener("hl:select", handler);
370
- return () => {
371
- el.removeEventListener("hl:select", handler);
372
- dispose();
373
- };
374
- }, [options.length]);
375
- return /* @__PURE__ */ jsxs11("div", { ...rest, ref, "data-hl-combobox": true, children: [
376
- /* @__PURE__ */ jsx15(
377
- "input",
378
- {
379
- ...inputProps,
380
- className: ["hl-input", inputProps?.className].filter(Boolean).join(" "),
381
- placeholder,
382
- defaultValue
383
- }
384
- ),
385
- /* @__PURE__ */ jsx15("ul", { role: "listbox", hidden: true, children: options.map((option) => /* @__PURE__ */ jsx15("li", { role: "option", "data-hl-value": option.value, children: option.label ?? option.value }, option.value)) })
386
- ] });
483
+ const onValueChangeRef = useLatest(onValueChange);
484
+ const initialValueRef = useLatest(value ?? defaultValue);
485
+ const { ref, api } = useEnhancer(
486
+ (el) => enhanceCombobox(el, {
487
+ filter,
488
+ autoHighlight,
489
+ defaultValue: initialValueRef.current,
490
+ onValueChange: (next) => onValueChangeRef.current?.(next)
491
+ }),
492
+ [filter, autoHighlight]
493
+ );
494
+ useEffect13(() => {
495
+ if (value != null) api.current?.setValue(value);
496
+ }, [value, api]);
497
+ return /* @__PURE__ */ jsx15("div", { ...rest, ref, "data-hl-combobox": true, children });
498
+ }
499
+ function ComboboxInput({ styled = true, className, ...rest }) {
500
+ return /* @__PURE__ */ jsx15("input", { ...rest, className: cx(styled && "hl-input", className) });
501
+ }
502
+ function ComboboxList({ children, ...rest }) {
503
+ return /* @__PURE__ */ jsx15("ul", { ...rest, role: "listbox", hidden: true, children });
504
+ }
505
+ function ComboboxOption({ value, children, ...rest }) {
506
+ return /* @__PURE__ */ jsx15("li", { ...rest, role: "option", "data-hl-value": value, children: children ?? value });
387
507
  }
388
508
 
389
509
  // src/Command.tsx
390
- import { useEffect as useEffect13, useRef as useRef13 } from "react";
510
+ import {
511
+ useEffect as useEffect14,
512
+ useRef as useRef10
513
+ } from "react";
391
514
  import { enhanceCommand } from "@hydrateless/enhancers";
392
- import { jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
393
- function groupItems(items) {
394
- const groups = /* @__PURE__ */ new Map();
395
- for (const item of items) {
396
- const key = item.group ?? "";
397
- const bucket = groups.get(key) ?? [];
398
- bucket.push(item);
399
- groups.set(key, bucket);
400
- }
401
- return [...groups.entries()];
402
- }
403
- function Command({
404
- items,
405
- placeholder = "Type a command\u2026",
406
- emptyLabel = "No results found.",
407
- hotkey,
408
- onSelect,
409
- ...rest
410
- }) {
411
- const ref = useRef13(null);
412
- const onSelectRef = useRef13(onSelect);
515
+ import { jsx as jsx16, jsxs as jsxs6 } from "react/jsx-runtime";
516
+ function Command({ hotkey, onSelect, children, ...rest }) {
517
+ const ref = useRef10(null);
518
+ const onSelectRef = useRef10(onSelect);
413
519
  onSelectRef.current = onSelect;
414
- useEffect13(() => {
520
+ useEffect14(() => {
415
521
  const el = ref.current;
416
522
  if (!el) return;
417
- const dispose = enhanceCommand(el);
418
- const handler = (e) => {
419
- const { value, item } = e.detail;
420
- const def = items.find((entry) => entry.value === (item.dataset.hlValue ?? value));
421
- def?.onSelect?.();
422
- onSelectRef.current?.(def?.value ?? value);
423
- };
424
- el.addEventListener("hl:command", handler);
425
- return () => {
426
- el.removeEventListener("hl:command", handler);
427
- dispose();
428
- };
429
- }, [items]);
430
- return /* @__PURE__ */ jsxs12("div", { ...rest, ref, "data-hl-command": true, "data-hl-command-hotkey": hotkey, children: [
431
- /* @__PURE__ */ jsx16("input", { className: "hl-input", "data-hl-command-input": true, placeholder }),
432
- /* @__PURE__ */ jsx16("div", { "data-hl-command-empty": true, hidden: true, children: emptyLabel }),
433
- /* @__PURE__ */ jsx16("div", { "data-hl-command-list": true, role: "listbox", children: groupItems(items).map(([group, groupEntries]) => /* @__PURE__ */ jsxs12("div", { "data-hl-command-group": true, children: [
434
- group && /* @__PURE__ */ jsx16("div", { className: "hl-command-group-label", role: "presentation", children: group }),
435
- groupEntries.map((item) => /* @__PURE__ */ jsxs12(
436
- "div",
437
- {
438
- role: "option",
439
- "data-hl-value": item.value,
440
- "data-hl-keywords": item.keywords,
441
- children: [
442
- item.icon,
443
- /* @__PURE__ */ jsx16("span", { children: item.label })
444
- ]
445
- },
446
- item.value
447
- ))
448
- ] }, group || "_")) })
523
+ const handle = enhanceCommand(el, {
524
+ hotkey,
525
+ onCommand: (value) => onSelectRef.current?.(value)
526
+ });
527
+ return handle.destroy;
528
+ }, [hotkey]);
529
+ return /* @__PURE__ */ jsx16("div", { ...rest, ref, "data-hl-command": true, "data-hl-command-hotkey": hotkey, children });
530
+ }
531
+ function CommandInput({ styled = true, className, ...rest }) {
532
+ return /* @__PURE__ */ jsx16("input", { ...rest, className: cx(styled && "hl-input", className), "data-hl-command-input": true });
533
+ }
534
+ function CommandList({ children, ...rest }) {
535
+ return /* @__PURE__ */ jsx16("div", { ...rest, "data-hl-command-list": true, role: "listbox", children });
536
+ }
537
+ function CommandGroup({ label, children, ...rest }) {
538
+ return /* @__PURE__ */ jsxs6("div", { ...rest, "data-hl-command-group": true, children: [
539
+ label != null && /* @__PURE__ */ jsx16("div", { className: "hl-command-group-label", role: "presentation", children: label }),
540
+ children
541
+ ] });
542
+ }
543
+ function CommandItem({ value, keywords, icon, children, ...rest }) {
544
+ return /* @__PURE__ */ jsxs6("div", { ...rest, role: "option", "data-hl-value": value, "data-hl-keywords": keywords, children: [
545
+ icon,
546
+ /* @__PURE__ */ jsx16("span", { children })
449
547
  ] });
450
548
  }
549
+ function CommandEmpty({ children = "No results found.", ...rest }) {
550
+ return /* @__PURE__ */ jsx16("div", { ...rest, "data-hl-command-empty": true, hidden: true, children });
551
+ }
451
552
 
452
553
  // src/Input.tsx
453
554
  import { forwardRef } from "react";
@@ -502,9 +603,9 @@ var Select = forwardRef3(function Select2({ size, invalid, options, className, c
502
603
 
503
604
  // src/Checkbox.tsx
504
605
  import { forwardRef as forwardRef4 } from "react";
505
- import { jsx as jsx20, jsxs as jsxs13 } from "react/jsx-runtime";
606
+ import { jsx as jsx20, jsxs as jsxs7 } from "react/jsx-runtime";
506
607
  var Checkbox = forwardRef4(function Checkbox2({ children, className, ...rest }, ref) {
507
- return /* @__PURE__ */ jsxs13("label", { className: ["hl-checkbox", className].filter(Boolean).join(" "), children: [
608
+ return /* @__PURE__ */ jsxs7("label", { className: ["hl-checkbox", className].filter(Boolean).join(" "), children: [
508
609
  /* @__PURE__ */ jsx20("input", { ...rest, ref, type: "checkbox" }),
509
610
  children != null && /* @__PURE__ */ jsx20("span", { children })
510
611
  ] });
@@ -512,16 +613,16 @@ var Checkbox = forwardRef4(function Checkbox2({ children, className, ...rest },
512
613
 
513
614
  // src/Radio.tsx
514
615
  import {
515
- createContext as createContext2,
616
+ createContext,
516
617
  forwardRef as forwardRef5,
517
- useContext as useContext2
618
+ useContext
518
619
  } from "react";
519
- import { jsx as jsx21, jsxs as jsxs14 } from "react/jsx-runtime";
520
- var RadioGroupContext = createContext2(null);
620
+ import { jsx as jsx21, jsxs as jsxs8 } from "react/jsx-runtime";
621
+ var RadioGroupContext = createContext(null);
521
622
  var Radio = forwardRef5(function Radio2({ children, className, value, ...rest }, ref) {
522
- const group = useContext2(RadioGroupContext);
623
+ const group = useContext(RadioGroupContext);
523
624
  const checked = group ? group.value === value : rest.checked;
524
- return /* @__PURE__ */ jsxs14("label", { className: ["hl-radio", className].filter(Boolean).join(" "), children: [
625
+ return /* @__PURE__ */ jsxs8("label", { className: ["hl-radio", className].filter(Boolean).join(" "), children: [
525
626
  /* @__PURE__ */ jsx21(
526
627
  "input",
527
628
  {
@@ -561,12 +662,12 @@ function RadioGroup({
561
662
 
562
663
  // src/Field.tsx
563
664
  import {
564
- createContext as createContext3,
565
- useContext as useContext3,
665
+ createContext as createContext2,
666
+ useContext as useContext2,
566
667
  useId as useId2
567
668
  } from "react";
568
- import { jsx as jsx22, jsxs as jsxs15 } from "react/jsx-runtime";
569
- var FieldContext = createContext3(null);
669
+ import { jsx as jsx22, jsxs as jsxs9 } from "react/jsx-runtime";
670
+ var FieldContext = createContext2(null);
570
671
  function Field({
571
672
  id,
572
673
  invalid = false,
@@ -597,7 +698,7 @@ function Field({
597
698
  ) });
598
699
  }
599
700
  function useFieldContext(component) {
600
- const ctx = useContext3(FieldContext);
701
+ const ctx = useContext2(FieldContext);
601
702
  if (!ctx) throw new Error(`<${component}> must be used within a <Field>`);
602
703
  return ctx;
603
704
  }
@@ -610,8 +711,8 @@ function useField() {
610
711
  "aria-invalid": ctx.invalid || void 0
611
712
  };
612
713
  }
613
- function Label({ className, children, ...rest }) {
614
- const ctx = useFieldContext("Label");
714
+ function FieldLabel({ className, children, ...rest }) {
715
+ const ctx = useFieldContext("FieldLabel");
615
716
  return /* @__PURE__ */ jsx22(
616
717
  "label",
617
718
  {
@@ -623,8 +724,8 @@ function Label({ className, children, ...rest }) {
623
724
  }
624
725
  );
625
726
  }
626
- function Help({ className, children, ...rest }) {
627
- const ctx = useFieldContext("Help");
727
+ function FieldHelp({ className, children, ...rest }) {
728
+ const ctx = useFieldContext("FieldHelp");
628
729
  return /* @__PURE__ */ jsx22("p", { ...rest, id: ctx.helpId, className: ["hl-help", className].filter(Boolean).join(" "), children });
629
730
  }
630
731
  function FieldError({ className, children, ...rest }) {
@@ -642,7 +743,7 @@ function FieldError({ className, children, ...rest }) {
642
743
  );
643
744
  }
644
745
  function Fieldset({ legend, className, children, ...rest }) {
645
- return /* @__PURE__ */ jsxs15("fieldset", { ...rest, className: ["hl-fieldset", className].filter(Boolean).join(" "), children: [
746
+ return /* @__PURE__ */ jsxs9("fieldset", { ...rest, className: ["hl-fieldset", className].filter(Boolean).join(" "), children: [
646
747
  legend != null && /* @__PURE__ */ jsx22("legend", { className: "hl-legend", children: legend }),
647
748
  children
648
749
  ] });
@@ -650,7 +751,7 @@ function Fieldset({ legend, className, children, ...rest }) {
650
751
 
651
752
  // src/SegmentedControl.tsx
652
753
  import { useId as useId3, useState } from "react";
653
- import { jsx as jsx23, jsxs as jsxs16 } from "react/jsx-runtime";
754
+ import { jsx as jsx23, jsxs as jsxs10 } from "react/jsx-runtime";
654
755
  function SegmentedControl({
655
756
  options,
656
757
  value,
@@ -676,7 +777,7 @@ function SegmentedControl({
676
777
  role: "radiogroup",
677
778
  className: ["hl-segmented", className].filter(Boolean).join(" "),
678
779
  "data-hl-size": size,
679
- children: options.map((option) => /* @__PURE__ */ jsxs16("label", { className: "hl-segmented-item", children: [
780
+ children: options.map((option) => /* @__PURE__ */ jsxs10("label", { className: "hl-segmented-item", children: [
680
781
  /* @__PURE__ */ jsx23(
681
782
  "input",
682
783
  {
@@ -735,9 +836,9 @@ var Button = forwardRef7(function Button2({ variant, intent, size, block, icon,
735
836
 
736
837
  // src/Alert.tsx
737
838
  import { forwardRef as forwardRef8 } from "react";
738
- import { jsx as jsx26, jsxs as jsxs17 } from "react/jsx-runtime";
839
+ import { jsx as jsx26, jsxs as jsxs11 } from "react/jsx-runtime";
739
840
  var Alert = forwardRef8(function Alert2({ intent, title, icon, className, children, ...rest }, ref) {
740
- return /* @__PURE__ */ jsxs17(
841
+ return /* @__PURE__ */ jsxs11(
741
842
  "div",
742
843
  {
743
844
  ...rest,
@@ -747,7 +848,7 @@ var Alert = forwardRef8(function Alert2({ intent, title, icon, className, childr
747
848
  "data-hl-intent": intent,
748
849
  children: [
749
850
  icon,
750
- /* @__PURE__ */ jsxs17("div", { className: "hl-alert-body", children: [
851
+ /* @__PURE__ */ jsxs11("div", { className: "hl-alert-body", children: [
751
852
  title != null && /* @__PURE__ */ jsx26("p", { className: "hl-alert-title", children: title }),
752
853
  children
753
854
  ] })
@@ -894,7 +995,7 @@ var Skeleton = forwardRef14(function Skeleton2({ variant, width, height, classNa
894
995
  });
895
996
 
896
997
  // src/Pagination.tsx
897
- import { jsx as jsx33, jsxs as jsxs18 } from "react/jsx-runtime";
998
+ import { jsx as jsx33, jsxs as jsxs12 } from "react/jsx-runtime";
898
999
  var ELLIPSIS = "ellipsis";
899
1000
  function range(start, end) {
900
1001
  return Array.from({ length: end - start + 1 }, (_, i) => start + i);
@@ -935,7 +1036,7 @@ function Pagination({
935
1036
  ...rest,
936
1037
  className: ["hl-pagination", className].filter(Boolean).join(" "),
937
1038
  "aria-label": rest["aria-label"] ?? "Pagination",
938
- children: /* @__PURE__ */ jsxs18("ul", { children: [
1039
+ children: /* @__PURE__ */ jsxs12("ul", { children: [
939
1040
  showControls && /* @__PURE__ */ jsx33("li", { children: /* @__PURE__ */ jsx33(
940
1041
  "button",
941
1042
  {
@@ -1007,6 +1108,7 @@ export {
1007
1108
  AvatarGroup,
1008
1109
  Badge,
1009
1110
  Breadcrumb,
1111
+ BreadcrumbItem,
1010
1112
  Button,
1011
1113
  Card,
1012
1114
  CardBody,
@@ -1016,19 +1118,38 @@ export {
1016
1118
  CardTitle,
1017
1119
  Checkbox,
1018
1120
  Combobox,
1121
+ ComboboxInput,
1122
+ ComboboxList,
1123
+ ComboboxOption,
1019
1124
  Command,
1125
+ CommandEmpty,
1126
+ CommandGroup,
1127
+ CommandInput,
1128
+ CommandItem,
1129
+ CommandList,
1020
1130
  Disclosure,
1021
1131
  Drawer,
1132
+ DrawerBody,
1133
+ DrawerFooter,
1134
+ DrawerHeader,
1022
1135
  Dropdown,
1136
+ DropdownItem,
1137
+ DropdownMenu,
1138
+ DropdownSeparator,
1139
+ DropdownTrigger,
1023
1140
  Field,
1024
1141
  FieldError,
1142
+ FieldHelp,
1143
+ FieldLabel,
1025
1144
  Fieldset,
1026
- Help,
1027
1145
  Input,
1028
1146
  Kbd,
1029
- Label,
1030
1147
  Menu,
1148
+ MenuItem,
1031
1149
  Modal,
1150
+ ModalBody,
1151
+ ModalFooter,
1152
+ ModalHeader,
1032
1153
  Pagination,
1033
1154
  Popover,
1034
1155
  Progress,
@@ -1042,11 +1163,15 @@ export {
1042
1163
  Slider,
1043
1164
  Spinner,
1044
1165
  Switch,
1166
+ Tab,
1167
+ TabList,
1168
+ TabPanel,
1045
1169
  Tabs,
1046
1170
  Textarea,
1047
- ToastProvider,
1171
+ ToastRegion,
1048
1172
  Toc,
1049
1173
  Tooltip,
1174
+ cx,
1050
1175
  useAccordion,
1051
1176
  useDisclosureGroup,
1052
1177
  useDropdown,