@hydrateless/react 0.10.0 → 0.11.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/README.md +20 -15
- package/dist/client.d.ts +760 -0
- package/dist/client.js +1121 -0
- package/dist/index.d.ts +2 -939
- package/dist/index.js +2 -1422
- package/dist/server.d.ts +216 -0
- package/dist/server.js +244 -0
- package/package.json +10 -2
package/dist/client.js
ADDED
|
@@ -0,0 +1,1121 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createContext, forwardRef, useContext, isValidElement, cloneElement, useState, useRef, useCallback, useReducer, useEffect, Children, createElement, useId } from 'react';
|
|
3
|
+
import { enhanceAccordion, enhanceTabs, enhanceDropdown, enhanceMenu, enhanceModal, enhanceDrawer, enhancePopover, enhanceTooltip, enhanceToc, enhanceToast, enhanceCombobox, enhanceCommand, enhanceDisclosure } from '@hydrateless/enhancers';
|
|
4
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/useEnhancer.ts
|
|
7
|
+
function useLatest(value) {
|
|
8
|
+
const ref = useRef(value);
|
|
9
|
+
ref.current = value;
|
|
10
|
+
return ref;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/useEnhancer.ts
|
|
14
|
+
function useEnhancer(ref, enhancer, options, deps = []) {
|
|
15
|
+
const api = useRef(null);
|
|
16
|
+
const handleRef = useRef(null);
|
|
17
|
+
const skipUpdate = useRef(false);
|
|
18
|
+
const latest = useLatest(options);
|
|
19
|
+
const latestEnhancer = useLatest(enhancer);
|
|
20
|
+
const buildOptions = () => {
|
|
21
|
+
const live = {};
|
|
22
|
+
for (const [key, value] of Object.entries(latest.current ?? {})) {
|
|
23
|
+
live[key] = typeof value === "function" ? (...args) => {
|
|
24
|
+
const fn = latest.current?.[key];
|
|
25
|
+
return typeof fn === "function" ? fn(...args) : void 0;
|
|
26
|
+
} : value;
|
|
27
|
+
}
|
|
28
|
+
return live;
|
|
29
|
+
};
|
|
30
|
+
const attach = () => {
|
|
31
|
+
const el = ref.current;
|
|
32
|
+
if (!el) return;
|
|
33
|
+
const handle = latestEnhancer.current(el, buildOptions());
|
|
34
|
+
handleRef.current = handle;
|
|
35
|
+
api.current = handle.api;
|
|
36
|
+
skipUpdate.current = true;
|
|
37
|
+
};
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
attach();
|
|
40
|
+
return () => {
|
|
41
|
+
const handle = handleRef.current;
|
|
42
|
+
handleRef.current = null;
|
|
43
|
+
api.current = null;
|
|
44
|
+
handle?.destroy();
|
|
45
|
+
};
|
|
46
|
+
}, [ref]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const handle = handleRef.current;
|
|
49
|
+
if (!handle) {
|
|
50
|
+
attach();
|
|
51
|
+
skipUpdate.current = false;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (skipUpdate.current) {
|
|
55
|
+
skipUpdate.current = false;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
handle.update(buildOptions());
|
|
59
|
+
}, deps);
|
|
60
|
+
return api;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/util.ts
|
|
64
|
+
function cx(...classes) {
|
|
65
|
+
return classes.filter(Boolean).join(" ");
|
|
66
|
+
}
|
|
67
|
+
function useControlled(controlled, defaultValue, onChange) {
|
|
68
|
+
const [internal, setInternal] = useState(defaultValue);
|
|
69
|
+
const [syncTick, bumpSync] = useReducer((n) => n + 1, 0);
|
|
70
|
+
const isControlled = useLatest(controlled !== void 0);
|
|
71
|
+
const onChangeRef = useLatest(onChange);
|
|
72
|
+
const setValue = useCallback(
|
|
73
|
+
(next) => {
|
|
74
|
+
if (isControlled.current) bumpSync();
|
|
75
|
+
else setInternal(next);
|
|
76
|
+
onChangeRef.current?.(next);
|
|
77
|
+
},
|
|
78
|
+
[isControlled, onChangeRef]
|
|
79
|
+
);
|
|
80
|
+
return [controlled !== void 0 ? controlled : internal, setValue, syncTick];
|
|
81
|
+
}
|
|
82
|
+
function useSyncApi(api, value, sync, syncTick = 0) {
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (value !== void 0 && api.current) sync(api.current, value);
|
|
85
|
+
}, [value, api, syncTick]);
|
|
86
|
+
}
|
|
87
|
+
function useForwardedRef(forwarded) {
|
|
88
|
+
const inner = useRef(null);
|
|
89
|
+
const forwardedRef = useRef(forwarded);
|
|
90
|
+
forwardedRef.current = forwarded;
|
|
91
|
+
const callback = useCallback((node) => {
|
|
92
|
+
inner.current = node;
|
|
93
|
+
const target = forwardedRef.current;
|
|
94
|
+
if (typeof target === "function") target(node);
|
|
95
|
+
else if (target) target.current = node;
|
|
96
|
+
}, []);
|
|
97
|
+
const ref = callback;
|
|
98
|
+
Object.defineProperty(ref, "current", {
|
|
99
|
+
configurable: true,
|
|
100
|
+
get: () => inner.current,
|
|
101
|
+
set: (node) => {
|
|
102
|
+
inner.current = node;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return ref;
|
|
106
|
+
}
|
|
107
|
+
var IndexContext = createContext(0);
|
|
108
|
+
function indexChildren(children, type) {
|
|
109
|
+
let index = 0;
|
|
110
|
+
return Children.map(children, (child) => {
|
|
111
|
+
if (!isValidElement(child) || child.type !== type) return child;
|
|
112
|
+
return createElement(IndexContext.Provider, { value: index++, key: child.key }, child);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
var AccordionContext = createContext([]);
|
|
116
|
+
var Accordion = forwardRef(function Accordion2({
|
|
117
|
+
allowMultiple = false,
|
|
118
|
+
value: valueProp,
|
|
119
|
+
defaultValue,
|
|
120
|
+
onValueChange,
|
|
121
|
+
className,
|
|
122
|
+
children,
|
|
123
|
+
...rest
|
|
124
|
+
}, forwardedRef) {
|
|
125
|
+
const ref = useForwardedRef(forwardedRef);
|
|
126
|
+
const [value = [], setValue, syncTick] = useControlled(valueProp, defaultValue, onValueChange);
|
|
127
|
+
const api = useEnhancer(
|
|
128
|
+
ref,
|
|
129
|
+
enhanceAccordion,
|
|
130
|
+
{ allowMultiple, defaultValue: value, onValueChange: setValue },
|
|
131
|
+
[allowMultiple]
|
|
132
|
+
);
|
|
133
|
+
useSyncApi(
|
|
134
|
+
api,
|
|
135
|
+
valueProp,
|
|
136
|
+
(api2, next) => {
|
|
137
|
+
api2.setValue(next, { silent: true });
|
|
138
|
+
},
|
|
139
|
+
syncTick
|
|
140
|
+
);
|
|
141
|
+
return /* @__PURE__ */ jsx(AccordionContext.Provider, { value, children: /* @__PURE__ */ jsx("div", { ...rest, ref, className: cx("hl-accordion", className), "data-hl-accordion": true, children: indexChildren(children, AccordionItem) }) });
|
|
142
|
+
});
|
|
143
|
+
var AccordionItem = forwardRef(
|
|
144
|
+
function AccordionItem2({ summary, value, children, ...rest }, ref) {
|
|
145
|
+
const open = useContext(AccordionContext);
|
|
146
|
+
const index = useContext(IndexContext);
|
|
147
|
+
return /* @__PURE__ */ jsxs(
|
|
148
|
+
"details",
|
|
149
|
+
{
|
|
150
|
+
...rest,
|
|
151
|
+
ref,
|
|
152
|
+
"data-hl-value": value,
|
|
153
|
+
open: open.includes(value ?? String(index)),
|
|
154
|
+
children: [
|
|
155
|
+
/* @__PURE__ */ jsx("summary", { children: summary }),
|
|
156
|
+
/* @__PURE__ */ jsx("div", { className: "hl-accordion-panel", children })
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
var Disclosure = forwardRef(function Disclosure2({ summary, open: openProp, defaultOpen, onOpenChange, name, className, children, ...rest }, forwardedRef) {
|
|
163
|
+
const ref = useForwardedRef(forwardedRef);
|
|
164
|
+
const [open, setOpen, syncTick] = useControlled(openProp, defaultOpen ?? false, onOpenChange);
|
|
165
|
+
const api = useEnhancer(ref, enhanceDisclosure, {
|
|
166
|
+
defaultOpen: open,
|
|
167
|
+
onOpenChange: setOpen
|
|
168
|
+
});
|
|
169
|
+
useSyncApi(
|
|
170
|
+
api,
|
|
171
|
+
openProp,
|
|
172
|
+
(api2, open2) => {
|
|
173
|
+
api2.setOpen(open2, { silent: true });
|
|
174
|
+
},
|
|
175
|
+
syncTick
|
|
176
|
+
);
|
|
177
|
+
return /* @__PURE__ */ jsxs(
|
|
178
|
+
"details",
|
|
179
|
+
{
|
|
180
|
+
...rest,
|
|
181
|
+
ref,
|
|
182
|
+
name,
|
|
183
|
+
open,
|
|
184
|
+
className: cx("hl-disclosure", className),
|
|
185
|
+
"data-hl-disclosure": true,
|
|
186
|
+
children: [
|
|
187
|
+
/* @__PURE__ */ jsx("summary", { children: summary }),
|
|
188
|
+
/* @__PURE__ */ jsx("div", { className: "hl-disclosure-panel", children })
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
var TabsContext = createContext({ selected: void 0, selectedIndex: 0 });
|
|
194
|
+
function tabValues(children) {
|
|
195
|
+
const list = Children.toArray(children).find((c) => isValidElement(c) && c.type === TabList);
|
|
196
|
+
if (!isValidElement(list)) return null;
|
|
197
|
+
return Children.toArray(list.props.children).filter((c) => isValidElement(c) && c.type === Tab).map((tab, i) => tab.props.value ?? String(i));
|
|
198
|
+
}
|
|
199
|
+
function useSelected(value) {
|
|
200
|
+
const { selected, selectedIndex } = useContext(TabsContext);
|
|
201
|
+
const index = useContext(IndexContext);
|
|
202
|
+
return value != null && selected != null ? value === selected : index === selectedIndex;
|
|
203
|
+
}
|
|
204
|
+
var Tabs = forwardRef(function Tabs2({
|
|
205
|
+
activation,
|
|
206
|
+
orientation,
|
|
207
|
+
value: valueProp,
|
|
208
|
+
defaultValue,
|
|
209
|
+
onValueChange,
|
|
210
|
+
className,
|
|
211
|
+
children,
|
|
212
|
+
...rest
|
|
213
|
+
}, forwardedRef) {
|
|
214
|
+
const ref = useForwardedRef(forwardedRef);
|
|
215
|
+
const [selected, setValue, syncTick] = useControlled(valueProp, defaultValue, onValueChange);
|
|
216
|
+
const api = useEnhancer(
|
|
217
|
+
ref,
|
|
218
|
+
enhanceTabs,
|
|
219
|
+
{ activation, orientation, defaultValue: selected, onValueChange: setValue },
|
|
220
|
+
[activation, orientation]
|
|
221
|
+
);
|
|
222
|
+
useSyncApi(
|
|
223
|
+
api,
|
|
224
|
+
valueProp,
|
|
225
|
+
(api2, value) => {
|
|
226
|
+
if (api2.value !== value) api2.setValue(value, { silent: true });
|
|
227
|
+
},
|
|
228
|
+
syncTick
|
|
229
|
+
);
|
|
230
|
+
const values = tabValues(children);
|
|
231
|
+
const selectedIndex = selected == null ? 0 : values ? values.indexOf(selected) : Number(selected);
|
|
232
|
+
return /* @__PURE__ */ jsx(TabsContext.Provider, { value: { selected, selectedIndex }, children: /* @__PURE__ */ jsx("div", { ...rest, ref, className: cx("hl-tabs", className), "data-hl-tabs": true, children: indexChildren(children, TabPanel) }) });
|
|
233
|
+
});
|
|
234
|
+
var TabList = forwardRef(function TabList2({ children, ...rest }, ref) {
|
|
235
|
+
return /* @__PURE__ */ jsx("div", { ...rest, ref, role: "tablist", children: indexChildren(children, Tab) });
|
|
236
|
+
});
|
|
237
|
+
var Tab = forwardRef(function Tab2({ children, type, value, ...rest }, ref) {
|
|
238
|
+
const selected = useSelected(value);
|
|
239
|
+
return /* @__PURE__ */ jsx(
|
|
240
|
+
"button",
|
|
241
|
+
{
|
|
242
|
+
...rest,
|
|
243
|
+
ref,
|
|
244
|
+
type: type ?? "button",
|
|
245
|
+
role: "tab",
|
|
246
|
+
"aria-selected": selected,
|
|
247
|
+
tabIndex: selected ? 0 : -1,
|
|
248
|
+
"data-hl-value": value,
|
|
249
|
+
children
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
var TabPanel = forwardRef(function TabPanel2({ children, ...rest }, ref) {
|
|
254
|
+
const selected = useSelected(void 0);
|
|
255
|
+
return /* @__PURE__ */ jsx("div", { ...rest, ref, role: "tabpanel", hidden: !selected, children });
|
|
256
|
+
});
|
|
257
|
+
function useHlId(prefix, id) {
|
|
258
|
+
const generated = useId();
|
|
259
|
+
return id ?? `hl-${prefix}-${generated.replace(/[^\w-]/g, "")}`;
|
|
260
|
+
}
|
|
261
|
+
var DropdownContext = createContext(void 0);
|
|
262
|
+
var Dropdown = forwardRef(function Dropdown2({
|
|
263
|
+
placement,
|
|
264
|
+
closeOnSelect,
|
|
265
|
+
open: openProp,
|
|
266
|
+
defaultOpen,
|
|
267
|
+
onOpenChange,
|
|
268
|
+
onSelect,
|
|
269
|
+
className,
|
|
270
|
+
children,
|
|
271
|
+
...rest
|
|
272
|
+
}, forwardedRef) {
|
|
273
|
+
const ref = useForwardedRef(forwardedRef);
|
|
274
|
+
const menuId = useHlId("dropdown-menu");
|
|
275
|
+
const [open, setOpen, syncTick] = useControlled(openProp, defaultOpen ?? false, onOpenChange);
|
|
276
|
+
const api = useEnhancer(
|
|
277
|
+
ref,
|
|
278
|
+
enhanceDropdown,
|
|
279
|
+
{ placement, closeOnSelect, defaultOpen: open, onOpenChange: setOpen, onSelect },
|
|
280
|
+
[placement, closeOnSelect]
|
|
281
|
+
);
|
|
282
|
+
useSyncApi(
|
|
283
|
+
api,
|
|
284
|
+
openProp,
|
|
285
|
+
(api2, open2) => {
|
|
286
|
+
if (api2.open !== open2) api2.setOpen(open2, { silent: true });
|
|
287
|
+
},
|
|
288
|
+
syncTick
|
|
289
|
+
);
|
|
290
|
+
return /* @__PURE__ */ jsx(DropdownContext.Provider, { value: menuId, children: /* @__PURE__ */ jsx("div", { ...rest, ref, className: cx("hl-dropdown", className), "data-hl-dropdown": true, children }) });
|
|
291
|
+
});
|
|
292
|
+
var DropdownTrigger = forwardRef(
|
|
293
|
+
function DropdownTrigger2({ children, type, ...rest }, ref) {
|
|
294
|
+
const menuId = useContext(DropdownContext);
|
|
295
|
+
const target = { popovertarget: rest.popoverTarget ?? menuId };
|
|
296
|
+
return /* @__PURE__ */ jsx(
|
|
297
|
+
"button",
|
|
298
|
+
{
|
|
299
|
+
...rest,
|
|
300
|
+
...target,
|
|
301
|
+
popoverTarget: void 0,
|
|
302
|
+
ref,
|
|
303
|
+
type: type ?? "button",
|
|
304
|
+
"data-hl-dropdown-trigger": true,
|
|
305
|
+
children
|
|
306
|
+
}
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
var DropdownMenu = forwardRef(function DropdownMenu2({ id, className, children, ...rest }, ref) {
|
|
311
|
+
const menuId = useContext(DropdownContext);
|
|
312
|
+
return /* @__PURE__ */ jsx(
|
|
313
|
+
"ul",
|
|
314
|
+
{
|
|
315
|
+
...rest,
|
|
316
|
+
ref,
|
|
317
|
+
id: id ?? menuId,
|
|
318
|
+
className: cx("hl-dropdown-menu", className),
|
|
319
|
+
popover: "auto",
|
|
320
|
+
"data-hl-dropdown-menu": true,
|
|
321
|
+
children
|
|
322
|
+
}
|
|
323
|
+
);
|
|
324
|
+
});
|
|
325
|
+
var DropdownItem = forwardRef(function DropdownItem2({ children, value, role = "menuitem", checked, disabled, type, ...rest }, ref) {
|
|
326
|
+
return /* @__PURE__ */ jsx("li", { role: "none", children: /* @__PURE__ */ jsx(
|
|
327
|
+
"button",
|
|
328
|
+
{
|
|
329
|
+
...rest,
|
|
330
|
+
ref,
|
|
331
|
+
type: type ?? "button",
|
|
332
|
+
role,
|
|
333
|
+
"aria-checked": role === "menuitem" ? void 0 : checked ?? false,
|
|
334
|
+
"aria-disabled": disabled || void 0,
|
|
335
|
+
disabled,
|
|
336
|
+
"data-hl-value": value,
|
|
337
|
+
children
|
|
338
|
+
}
|
|
339
|
+
) });
|
|
340
|
+
});
|
|
341
|
+
var DropdownGroup = forwardRef(
|
|
342
|
+
function DropdownGroup2({ label, children, ...rest }, ref) {
|
|
343
|
+
return /* @__PURE__ */ jsx("li", { role: "none", children: /* @__PURE__ */ jsx("ul", { ...rest, ref, role: "group", "aria-label": label, children }) });
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
var DropdownSeparator = forwardRef(
|
|
347
|
+
function DropdownSeparator2({ className, ...rest }, ref) {
|
|
348
|
+
return /* @__PURE__ */ jsx("li", { ...rest, ref, role: "separator", className: cx("hl-dropdown-separator", className) });
|
|
349
|
+
}
|
|
350
|
+
);
|
|
351
|
+
var Menu = forwardRef(function Menu2({
|
|
352
|
+
orientation = "horizontal",
|
|
353
|
+
value: valueProp,
|
|
354
|
+
defaultValue,
|
|
355
|
+
onValueChange,
|
|
356
|
+
onSelect,
|
|
357
|
+
className,
|
|
358
|
+
children,
|
|
359
|
+
...rest
|
|
360
|
+
}, forwardedRef) {
|
|
361
|
+
const ref = useForwardedRef(forwardedRef);
|
|
362
|
+
const [value, setValue, syncTick] = useControlled(
|
|
363
|
+
valueProp,
|
|
364
|
+
defaultValue ?? null,
|
|
365
|
+
onValueChange
|
|
366
|
+
);
|
|
367
|
+
const api = useEnhancer(
|
|
368
|
+
ref,
|
|
369
|
+
enhanceMenu,
|
|
370
|
+
{ orientation, defaultValue: value, onValueChange: setValue, onSelect },
|
|
371
|
+
[orientation]
|
|
372
|
+
);
|
|
373
|
+
useSyncApi(
|
|
374
|
+
api,
|
|
375
|
+
valueProp,
|
|
376
|
+
(api2, value2) => {
|
|
377
|
+
if (api2.value !== value2) api2.setValue(value2, { silent: true });
|
|
378
|
+
},
|
|
379
|
+
syncTick
|
|
380
|
+
);
|
|
381
|
+
return /* @__PURE__ */ jsx(
|
|
382
|
+
"ul",
|
|
383
|
+
{
|
|
384
|
+
...rest,
|
|
385
|
+
ref,
|
|
386
|
+
className: cx("hl-menu", className),
|
|
387
|
+
"data-hl-menu": true,
|
|
388
|
+
role: orientation === "vertical" ? "menu" : "menubar",
|
|
389
|
+
"aria-orientation": orientation,
|
|
390
|
+
children
|
|
391
|
+
}
|
|
392
|
+
);
|
|
393
|
+
});
|
|
394
|
+
var MenuItem = forwardRef(function MenuItem2({ href, value, role = "menuitem", checked, disabled, anchorProps, children, ...rest }, ref) {
|
|
395
|
+
const shared = {
|
|
396
|
+
role,
|
|
397
|
+
"aria-checked": role === "menuitem" ? void 0 : checked ?? false,
|
|
398
|
+
"aria-disabled": disabled || void 0,
|
|
399
|
+
"data-hl-value": value
|
|
400
|
+
};
|
|
401
|
+
return /* @__PURE__ */ jsx("li", { role: "none", children: href ? /* @__PURE__ */ jsx("a", { ...anchorProps, ...shared, ref, href, children }) : /* @__PURE__ */ jsx(
|
|
402
|
+
"button",
|
|
403
|
+
{
|
|
404
|
+
...rest,
|
|
405
|
+
...shared,
|
|
406
|
+
ref,
|
|
407
|
+
type: "button",
|
|
408
|
+
disabled,
|
|
409
|
+
children
|
|
410
|
+
}
|
|
411
|
+
) });
|
|
412
|
+
});
|
|
413
|
+
var MenuSubmenu = forwardRef(function MenuSubmenu2({ label, value, disabled, triggerProps, children, ...rest }, ref) {
|
|
414
|
+
return /* @__PURE__ */ jsxs("li", { role: "none", children: [
|
|
415
|
+
/* @__PURE__ */ jsx(
|
|
416
|
+
"button",
|
|
417
|
+
{
|
|
418
|
+
...triggerProps,
|
|
419
|
+
type: "button",
|
|
420
|
+
role: "menuitem",
|
|
421
|
+
"aria-disabled": disabled || void 0,
|
|
422
|
+
disabled,
|
|
423
|
+
"data-hl-value": value,
|
|
424
|
+
children: label
|
|
425
|
+
}
|
|
426
|
+
),
|
|
427
|
+
/* @__PURE__ */ jsx("ul", { ...rest, ref, role: "menu", "data-hl-submenu": true, children })
|
|
428
|
+
] });
|
|
429
|
+
});
|
|
430
|
+
var Modal = forwardRef(function Modal2({
|
|
431
|
+
open: openProp,
|
|
432
|
+
defaultOpen,
|
|
433
|
+
onOpenChange,
|
|
434
|
+
closeOnBackdrop = true,
|
|
435
|
+
className,
|
|
436
|
+
children,
|
|
437
|
+
...rest
|
|
438
|
+
}, forwardedRef) {
|
|
439
|
+
const ref = useForwardedRef(forwardedRef);
|
|
440
|
+
const [open, setOpen, syncTick] = useControlled(openProp, defaultOpen ?? false, onOpenChange);
|
|
441
|
+
const api = useEnhancer(
|
|
442
|
+
ref,
|
|
443
|
+
enhanceModal,
|
|
444
|
+
{ closeOnBackdrop, defaultOpen: open, onOpenChange: setOpen },
|
|
445
|
+
[closeOnBackdrop]
|
|
446
|
+
);
|
|
447
|
+
useSyncApi(
|
|
448
|
+
api,
|
|
449
|
+
openProp,
|
|
450
|
+
(api2, open2) => {
|
|
451
|
+
if (api2.open !== open2) api2.setOpen(open2, { silent: true });
|
|
452
|
+
},
|
|
453
|
+
syncTick
|
|
454
|
+
);
|
|
455
|
+
return /* @__PURE__ */ jsx("dialog", { ...rest, ref, "data-hl-modal": true, className: cx("hl-modal", className), children });
|
|
456
|
+
});
|
|
457
|
+
var Drawer = forwardRef(function Drawer2({
|
|
458
|
+
open: openProp,
|
|
459
|
+
defaultOpen,
|
|
460
|
+
onOpenChange,
|
|
461
|
+
side = "end",
|
|
462
|
+
closeOnBackdrop = true,
|
|
463
|
+
className,
|
|
464
|
+
children,
|
|
465
|
+
...rest
|
|
466
|
+
}, forwardedRef) {
|
|
467
|
+
const ref = useForwardedRef(forwardedRef);
|
|
468
|
+
const [open, setOpen, syncTick] = useControlled(openProp, defaultOpen ?? false, onOpenChange);
|
|
469
|
+
const api = useEnhancer(
|
|
470
|
+
ref,
|
|
471
|
+
enhanceDrawer,
|
|
472
|
+
{ closeOnBackdrop, defaultOpen: open, onOpenChange: setOpen },
|
|
473
|
+
[closeOnBackdrop]
|
|
474
|
+
);
|
|
475
|
+
useSyncApi(
|
|
476
|
+
api,
|
|
477
|
+
openProp,
|
|
478
|
+
(api2, open2) => {
|
|
479
|
+
if (api2.open !== open2) api2.setOpen(open2, { silent: true });
|
|
480
|
+
},
|
|
481
|
+
syncTick
|
|
482
|
+
);
|
|
483
|
+
return /* @__PURE__ */ jsx(
|
|
484
|
+
"dialog",
|
|
485
|
+
{
|
|
486
|
+
...rest,
|
|
487
|
+
ref,
|
|
488
|
+
"data-hl-drawer": true,
|
|
489
|
+
"data-hl-side": side,
|
|
490
|
+
className: cx("hl-drawer", className),
|
|
491
|
+
children
|
|
492
|
+
}
|
|
493
|
+
);
|
|
494
|
+
});
|
|
495
|
+
var Popover = forwardRef(function Popover2({ open: openProp, defaultOpen, onOpenChange, placement, hover, className, children, ...rest }, forwardedRef) {
|
|
496
|
+
const ref = useForwardedRef(forwardedRef);
|
|
497
|
+
const [open, setOpen, syncTick] = useControlled(openProp, defaultOpen ?? false, onOpenChange);
|
|
498
|
+
const api = useEnhancer(
|
|
499
|
+
ref,
|
|
500
|
+
enhancePopover,
|
|
501
|
+
{
|
|
502
|
+
placement,
|
|
503
|
+
triggerEvent: hover ? "hover" : "click",
|
|
504
|
+
defaultOpen: open,
|
|
505
|
+
onOpenChange: setOpen
|
|
506
|
+
},
|
|
507
|
+
[placement, hover]
|
|
508
|
+
);
|
|
509
|
+
useSyncApi(
|
|
510
|
+
api,
|
|
511
|
+
openProp,
|
|
512
|
+
(api2, open2) => {
|
|
513
|
+
if (api2.open !== open2) api2.setOpen(open2, { silent: true });
|
|
514
|
+
},
|
|
515
|
+
syncTick
|
|
516
|
+
);
|
|
517
|
+
return /* @__PURE__ */ jsx(
|
|
518
|
+
"div",
|
|
519
|
+
{
|
|
520
|
+
...rest,
|
|
521
|
+
ref,
|
|
522
|
+
className: cx("hl-popover", className),
|
|
523
|
+
"data-hl-popover": true,
|
|
524
|
+
popover: "auto",
|
|
525
|
+
role: "dialog",
|
|
526
|
+
children
|
|
527
|
+
}
|
|
528
|
+
);
|
|
529
|
+
});
|
|
530
|
+
var Tooltip = forwardRef(function Tooltip2({
|
|
531
|
+
content,
|
|
532
|
+
children,
|
|
533
|
+
placement,
|
|
534
|
+
showDelay,
|
|
535
|
+
hideDelay,
|
|
536
|
+
open: openProp,
|
|
537
|
+
onOpenChange,
|
|
538
|
+
id,
|
|
539
|
+
style,
|
|
540
|
+
...rest
|
|
541
|
+
}, forwardedRef) {
|
|
542
|
+
const ref = useForwardedRef(forwardedRef);
|
|
543
|
+
const tipId = useHlId("tip");
|
|
544
|
+
const [, setOpen, syncTick] = useControlled(openProp, false, onOpenChange);
|
|
545
|
+
const api = useEnhancer(
|
|
546
|
+
ref,
|
|
547
|
+
enhanceTooltip,
|
|
548
|
+
{ placement, showDelay, hideDelay, onOpenChange: setOpen },
|
|
549
|
+
[placement, showDelay, hideDelay]
|
|
550
|
+
);
|
|
551
|
+
useSyncApi(
|
|
552
|
+
api,
|
|
553
|
+
openProp,
|
|
554
|
+
(api2, open) => {
|
|
555
|
+
if (api2.open !== open) api2.setOpen(open, { silent: true });
|
|
556
|
+
},
|
|
557
|
+
syncTick
|
|
558
|
+
);
|
|
559
|
+
const trigger = isValidElement(children) ? cloneElement(children, {
|
|
560
|
+
"data-hl-tooltip": tipId,
|
|
561
|
+
"aria-describedby": tipId
|
|
562
|
+
}) : children;
|
|
563
|
+
return /* @__PURE__ */ jsxs(
|
|
564
|
+
"span",
|
|
565
|
+
{
|
|
566
|
+
...rest,
|
|
567
|
+
ref,
|
|
568
|
+
id,
|
|
569
|
+
style: { position: "relative", display: "inline-block", ...style },
|
|
570
|
+
children: [
|
|
571
|
+
trigger,
|
|
572
|
+
/* @__PURE__ */ jsx("span", { id: tipId, className: "hl-tooltip", role: "tooltip", children: content })
|
|
573
|
+
]
|
|
574
|
+
}
|
|
575
|
+
);
|
|
576
|
+
});
|
|
577
|
+
var FieldContext = createContext(null);
|
|
578
|
+
function useField() {
|
|
579
|
+
const ctx = useContext(FieldContext);
|
|
580
|
+
if (!ctx) return null;
|
|
581
|
+
const describedBy = [ctx.helpId, ctx.invalid ? ctx.errorId : null].filter(Boolean).join(" ");
|
|
582
|
+
return {
|
|
583
|
+
id: ctx.id,
|
|
584
|
+
describedBy: describedBy || void 0,
|
|
585
|
+
invalid: ctx.invalid,
|
|
586
|
+
required: ctx.required
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
var Field = forwardRef(function Field2({
|
|
590
|
+
id,
|
|
591
|
+
label,
|
|
592
|
+
description,
|
|
593
|
+
error,
|
|
594
|
+
invalid = false,
|
|
595
|
+
required = false,
|
|
596
|
+
className,
|
|
597
|
+
children,
|
|
598
|
+
...rest
|
|
599
|
+
}, ref) {
|
|
600
|
+
const baseId = useHlId("field", id);
|
|
601
|
+
const hasError = error != null && error !== false;
|
|
602
|
+
const value = {
|
|
603
|
+
id: baseId,
|
|
604
|
+
helpId: `${baseId}-help`,
|
|
605
|
+
errorId: `${baseId}-error`,
|
|
606
|
+
invalid: invalid || hasError,
|
|
607
|
+
required
|
|
608
|
+
};
|
|
609
|
+
return /* @__PURE__ */ jsx(FieldContext.Provider, { value, children: /* @__PURE__ */ jsxs(
|
|
610
|
+
"div",
|
|
611
|
+
{
|
|
612
|
+
...rest,
|
|
613
|
+
ref,
|
|
614
|
+
className: cx("hl-field", className),
|
|
615
|
+
"data-hl-invalid": value.invalid || void 0,
|
|
616
|
+
children: [
|
|
617
|
+
label != null && /* @__PURE__ */ jsx(FieldLabel, { children: label }),
|
|
618
|
+
children,
|
|
619
|
+
description != null && /* @__PURE__ */ jsx(FieldHelp, { children: description }),
|
|
620
|
+
hasError && /* @__PURE__ */ jsx(FieldError, { children: error })
|
|
621
|
+
]
|
|
622
|
+
}
|
|
623
|
+
) });
|
|
624
|
+
});
|
|
625
|
+
var FieldLabel = forwardRef(function FieldLabel2({ className, children, ...rest }, ref) {
|
|
626
|
+
const ctx = useContext(FieldContext);
|
|
627
|
+
return /* @__PURE__ */ jsx(
|
|
628
|
+
"label",
|
|
629
|
+
{
|
|
630
|
+
...rest,
|
|
631
|
+
ref,
|
|
632
|
+
htmlFor: rest.htmlFor ?? ctx?.id,
|
|
633
|
+
className: cx("hl-label", className),
|
|
634
|
+
"data-hl-required": ctx?.required || void 0,
|
|
635
|
+
children
|
|
636
|
+
}
|
|
637
|
+
);
|
|
638
|
+
});
|
|
639
|
+
var FieldHelp = forwardRef(function FieldHelp2({ className, children, ...rest }, ref) {
|
|
640
|
+
const ctx = useContext(FieldContext);
|
|
641
|
+
return /* @__PURE__ */ jsx("p", { ...rest, ref, id: rest.id ?? ctx?.helpId, className: cx("hl-help", className), children });
|
|
642
|
+
});
|
|
643
|
+
var FieldError = forwardRef(function FieldError2({ className, children, ...rest }, ref) {
|
|
644
|
+
const ctx = useContext(FieldContext);
|
|
645
|
+
if (children == null || children === false) return null;
|
|
646
|
+
return /* @__PURE__ */ jsx(
|
|
647
|
+
"p",
|
|
648
|
+
{
|
|
649
|
+
...rest,
|
|
650
|
+
ref,
|
|
651
|
+
id: rest.id ?? ctx?.errorId,
|
|
652
|
+
role: "alert",
|
|
653
|
+
className: cx("hl-error", className),
|
|
654
|
+
children
|
|
655
|
+
}
|
|
656
|
+
);
|
|
657
|
+
});
|
|
658
|
+
var Fieldset = forwardRef(function Fieldset2({ legend, className, children, ...rest }, ref) {
|
|
659
|
+
return /* @__PURE__ */ jsxs("fieldset", { ...rest, ref, className: cx("hl-fieldset", className), children: [
|
|
660
|
+
legend != null && /* @__PURE__ */ jsx("legend", { className: "hl-legend", children: legend }),
|
|
661
|
+
children
|
|
662
|
+
] });
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
// src/internal/useFieldControl.ts
|
|
666
|
+
function useFieldControl(props, invalid) {
|
|
667
|
+
const field = useField();
|
|
668
|
+
const isInvalid = invalid || props["aria-invalid"] || field?.invalid || void 0;
|
|
669
|
+
return {
|
|
670
|
+
...props,
|
|
671
|
+
id: props.id ?? field?.id,
|
|
672
|
+
required: props.required ?? field?.required,
|
|
673
|
+
"aria-describedby": props["aria-describedby"] ?? field?.describedBy,
|
|
674
|
+
"aria-invalid": isInvalid
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
var Switch = forwardRef(function Switch2({ children, className, ...rest }, ref) {
|
|
678
|
+
const props = useFieldControl(rest);
|
|
679
|
+
return /* @__PURE__ */ jsxs("label", { className: cx("hl-switch", className), children: [
|
|
680
|
+
/* @__PURE__ */ jsx("input", { ...props, ref, type: "checkbox", role: "switch" }),
|
|
681
|
+
children
|
|
682
|
+
] });
|
|
683
|
+
});
|
|
684
|
+
var Toc = forwardRef(function Toc2({ contentSelector, headings, scrollSpy, className, ...rest }, forwardedRef) {
|
|
685
|
+
const ref = useForwardedRef(forwardedRef);
|
|
686
|
+
useEnhancer(
|
|
687
|
+
ref,
|
|
688
|
+
// The content lives outside the nav, so scan from the document.
|
|
689
|
+
(nav, options) => enhanceToc(nav.ownerDocument, options),
|
|
690
|
+
{ contentSelector, headings, scrollSpy },
|
|
691
|
+
[contentSelector, headings, scrollSpy]
|
|
692
|
+
);
|
|
693
|
+
return /* @__PURE__ */ jsx("nav", { ...rest, ref, className: cx("hl-toc", className), "data-hl-toc": true });
|
|
694
|
+
});
|
|
695
|
+
var sharedApi = null;
|
|
696
|
+
function ensureApi() {
|
|
697
|
+
if (!sharedApi) {
|
|
698
|
+
const handle = enhanceToast(document);
|
|
699
|
+
sharedApi = handle.api;
|
|
700
|
+
}
|
|
701
|
+
return sharedApi;
|
|
702
|
+
}
|
|
703
|
+
var facade = {
|
|
704
|
+
show: (message, options) => ensureApi().show(message, options),
|
|
705
|
+
dismiss: (toast) => ensureApi().dismiss(toast),
|
|
706
|
+
dismissAll: () => ensureApi().dismissAll()
|
|
707
|
+
};
|
|
708
|
+
var ToastRegion = forwardRef(function ToastRegion2({ duration, onOpenChange, className, ...props }, forwardedRef) {
|
|
709
|
+
const ref = useForwardedRef(forwardedRef);
|
|
710
|
+
useEnhancer(
|
|
711
|
+
ref,
|
|
712
|
+
(region, options) => {
|
|
713
|
+
const handle = enhanceToast(region.ownerDocument, options);
|
|
714
|
+
sharedApi = handle.api;
|
|
715
|
+
return {
|
|
716
|
+
...handle,
|
|
717
|
+
destroy: () => {
|
|
718
|
+
handle.destroy();
|
|
719
|
+
sharedApi = null;
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
},
|
|
723
|
+
{ duration, onOpenChange },
|
|
724
|
+
[duration]
|
|
725
|
+
);
|
|
726
|
+
return /* @__PURE__ */ jsx("div", { ...props, ref, className: cx("hl-toast-region", className), "data-hl-toast-region": true });
|
|
727
|
+
});
|
|
728
|
+
function useToast() {
|
|
729
|
+
return facade;
|
|
730
|
+
}
|
|
731
|
+
var Combobox = forwardRef(function Combobox2({
|
|
732
|
+
filter,
|
|
733
|
+
autoHighlight,
|
|
734
|
+
value: valueProp,
|
|
735
|
+
defaultValue,
|
|
736
|
+
onValueChange,
|
|
737
|
+
open: openProp,
|
|
738
|
+
defaultOpen,
|
|
739
|
+
onOpenChange,
|
|
740
|
+
className,
|
|
741
|
+
children,
|
|
742
|
+
...rest
|
|
743
|
+
}, forwardedRef) {
|
|
744
|
+
const ref = useForwardedRef(forwardedRef);
|
|
745
|
+
const [value, setValue, valueTick] = useControlled(valueProp, defaultValue, onValueChange);
|
|
746
|
+
const [open, setOpen, openTick] = useControlled(openProp, defaultOpen ?? false, onOpenChange);
|
|
747
|
+
const api = useEnhancer(
|
|
748
|
+
ref,
|
|
749
|
+
enhanceCombobox,
|
|
750
|
+
{
|
|
751
|
+
filter,
|
|
752
|
+
autoHighlight,
|
|
753
|
+
defaultValue: value,
|
|
754
|
+
defaultOpen: open,
|
|
755
|
+
onValueChange: setValue,
|
|
756
|
+
onOpenChange: setOpen
|
|
757
|
+
},
|
|
758
|
+
[filter, autoHighlight]
|
|
759
|
+
);
|
|
760
|
+
useSyncApi(
|
|
761
|
+
api,
|
|
762
|
+
valueProp,
|
|
763
|
+
(api2, value2) => {
|
|
764
|
+
if (api2.value !== value2) api2.setValue(value2, { silent: true });
|
|
765
|
+
},
|
|
766
|
+
valueTick
|
|
767
|
+
);
|
|
768
|
+
useSyncApi(
|
|
769
|
+
api,
|
|
770
|
+
openProp,
|
|
771
|
+
(api2, open2) => {
|
|
772
|
+
if (api2.open !== open2) api2.setOpen(open2, { silent: true });
|
|
773
|
+
},
|
|
774
|
+
openTick
|
|
775
|
+
);
|
|
776
|
+
return /* @__PURE__ */ jsx("div", { ...rest, ref, className: cx("hl-combobox", className), "data-hl-combobox": true, children });
|
|
777
|
+
});
|
|
778
|
+
var ComboboxInput = forwardRef(
|
|
779
|
+
function ComboboxInput2({ styled = true, className, ...rest }, ref) {
|
|
780
|
+
const props = useFieldControl(rest);
|
|
781
|
+
return /* @__PURE__ */ jsx("input", { ...props, ref, className: cx(styled && "hl-input", className) });
|
|
782
|
+
}
|
|
783
|
+
);
|
|
784
|
+
var ComboboxList = forwardRef(function ComboboxList2({ children, ...rest }, ref) {
|
|
785
|
+
return /* @__PURE__ */ jsx("ul", { ...rest, ref, role: "listbox", children });
|
|
786
|
+
});
|
|
787
|
+
var ComboboxOption = forwardRef(
|
|
788
|
+
function ComboboxOption2({ value, disabled, children, ...rest }, ref) {
|
|
789
|
+
return /* @__PURE__ */ jsx(
|
|
790
|
+
"li",
|
|
791
|
+
{
|
|
792
|
+
...rest,
|
|
793
|
+
ref,
|
|
794
|
+
role: "option",
|
|
795
|
+
"aria-disabled": disabled || void 0,
|
|
796
|
+
"data-hl-value": value,
|
|
797
|
+
children: children ?? value
|
|
798
|
+
}
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
);
|
|
802
|
+
var Command = forwardRef(function Command2({
|
|
803
|
+
hotkey,
|
|
804
|
+
query: queryProp,
|
|
805
|
+
defaultQuery,
|
|
806
|
+
onQueryChange,
|
|
807
|
+
onCommand,
|
|
808
|
+
className,
|
|
809
|
+
children,
|
|
810
|
+
...rest
|
|
811
|
+
}, forwardedRef) {
|
|
812
|
+
const ref = useForwardedRef(forwardedRef);
|
|
813
|
+
const [query, setQuery, syncTick] = useControlled(queryProp, defaultQuery, onQueryChange);
|
|
814
|
+
const api = useEnhancer(
|
|
815
|
+
ref,
|
|
816
|
+
enhanceCommand,
|
|
817
|
+
{ hotkey, defaultValue: query, onValueChange: setQuery, onCommand },
|
|
818
|
+
[hotkey]
|
|
819
|
+
);
|
|
820
|
+
useSyncApi(
|
|
821
|
+
api,
|
|
822
|
+
queryProp,
|
|
823
|
+
(api2, query2) => {
|
|
824
|
+
if (api2.value !== query2) api2.setValue(query2, { silent: true });
|
|
825
|
+
},
|
|
826
|
+
syncTick
|
|
827
|
+
);
|
|
828
|
+
return /* @__PURE__ */ jsx(
|
|
829
|
+
"div",
|
|
830
|
+
{
|
|
831
|
+
...rest,
|
|
832
|
+
ref,
|
|
833
|
+
className: cx("hl-command", className),
|
|
834
|
+
"data-hl-command": true,
|
|
835
|
+
"data-hl-hotkey": hotkey,
|
|
836
|
+
children
|
|
837
|
+
}
|
|
838
|
+
);
|
|
839
|
+
});
|
|
840
|
+
var CommandInput = forwardRef(function CommandInput2({ styled = true, className, ...rest }, ref) {
|
|
841
|
+
return /* @__PURE__ */ jsx(
|
|
842
|
+
"input",
|
|
843
|
+
{
|
|
844
|
+
...rest,
|
|
845
|
+
ref,
|
|
846
|
+
className: cx(styled && "hl-command-input", className),
|
|
847
|
+
"data-hl-command-input": true
|
|
848
|
+
}
|
|
849
|
+
);
|
|
850
|
+
});
|
|
851
|
+
var CommandList = forwardRef(function CommandList2({ className, children, ...rest }, ref) {
|
|
852
|
+
return /* @__PURE__ */ jsx(
|
|
853
|
+
"div",
|
|
854
|
+
{
|
|
855
|
+
...rest,
|
|
856
|
+
ref,
|
|
857
|
+
className: cx("hl-command-list", className),
|
|
858
|
+
"data-hl-command-list": true,
|
|
859
|
+
role: "listbox",
|
|
860
|
+
children
|
|
861
|
+
}
|
|
862
|
+
);
|
|
863
|
+
});
|
|
864
|
+
var CommandGroup = forwardRef(function CommandGroup2({ label, className, children, ...rest }, ref) {
|
|
865
|
+
return /* @__PURE__ */ jsxs("div", { ...rest, ref, className: cx("hl-command-group", className), "data-hl-command-group": true, children: [
|
|
866
|
+
label != null && /* @__PURE__ */ jsx("div", { className: "hl-command-group-label", role: "presentation", children: label }),
|
|
867
|
+
children
|
|
868
|
+
] });
|
|
869
|
+
});
|
|
870
|
+
var CommandItem = forwardRef(function CommandItem2({ value, keywords, icon, children, ...rest }, ref) {
|
|
871
|
+
return /* @__PURE__ */ jsxs("div", { ...rest, ref, role: "option", "data-hl-value": value, "data-hl-keywords": keywords, children: [
|
|
872
|
+
icon,
|
|
873
|
+
/* @__PURE__ */ jsx("span", { children })
|
|
874
|
+
] });
|
|
875
|
+
});
|
|
876
|
+
var CommandEmpty = forwardRef(function CommandEmpty2({ className, children = "No results found.", ...rest }, ref) {
|
|
877
|
+
return /* @__PURE__ */ jsx(
|
|
878
|
+
"div",
|
|
879
|
+
{
|
|
880
|
+
...rest,
|
|
881
|
+
ref,
|
|
882
|
+
className: cx("hl-command-empty", className),
|
|
883
|
+
"data-hl-command-empty": true,
|
|
884
|
+
hidden: true,
|
|
885
|
+
children
|
|
886
|
+
}
|
|
887
|
+
);
|
|
888
|
+
});
|
|
889
|
+
var Input = forwardRef(function Input2({ size, invalid, className, ...rest }, ref) {
|
|
890
|
+
const props = useFieldControl(rest, invalid);
|
|
891
|
+
return /* @__PURE__ */ jsx(
|
|
892
|
+
"input",
|
|
893
|
+
{
|
|
894
|
+
...props,
|
|
895
|
+
ref,
|
|
896
|
+
className: cx("hl-input", className),
|
|
897
|
+
"data-hl-size": size,
|
|
898
|
+
"data-hl-invalid": props["aria-invalid"] || void 0
|
|
899
|
+
}
|
|
900
|
+
);
|
|
901
|
+
});
|
|
902
|
+
var Textarea = forwardRef(function Textarea2({ invalid, autosize, className, ...rest }, ref) {
|
|
903
|
+
const props = useFieldControl(rest, invalid);
|
|
904
|
+
return /* @__PURE__ */ jsx(
|
|
905
|
+
"textarea",
|
|
906
|
+
{
|
|
907
|
+
...props,
|
|
908
|
+
ref,
|
|
909
|
+
className: cx("hl-textarea", className),
|
|
910
|
+
"data-hl-autosize": autosize || void 0,
|
|
911
|
+
"data-hl-invalid": props["aria-invalid"] || void 0
|
|
912
|
+
}
|
|
913
|
+
);
|
|
914
|
+
});
|
|
915
|
+
var Select = forwardRef(function Select2({ size, invalid, options, className, children, ...rest }, ref) {
|
|
916
|
+
const props = useFieldControl(rest, invalid);
|
|
917
|
+
return /* @__PURE__ */ jsx("span", { className: "hl-select-wrapper", children: /* @__PURE__ */ jsx(
|
|
918
|
+
"select",
|
|
919
|
+
{
|
|
920
|
+
...props,
|
|
921
|
+
ref,
|
|
922
|
+
className: cx("hl-select", className),
|
|
923
|
+
"data-hl-size": size,
|
|
924
|
+
"data-hl-invalid": props["aria-invalid"] || void 0,
|
|
925
|
+
children: options ? options.map((option) => /* @__PURE__ */ jsx("option", { value: option.value, disabled: option.disabled, children: option.label }, option.value)) : children
|
|
926
|
+
}
|
|
927
|
+
) });
|
|
928
|
+
});
|
|
929
|
+
var Checkbox = forwardRef(function Checkbox2({ children, className, ...rest }, ref) {
|
|
930
|
+
const props = useFieldControl(rest);
|
|
931
|
+
return /* @__PURE__ */ jsxs("label", { className: cx("hl-checkbox", className), children: [
|
|
932
|
+
/* @__PURE__ */ jsx("input", { ...props, ref, type: "checkbox" }),
|
|
933
|
+
children != null && /* @__PURE__ */ jsx("span", { children })
|
|
934
|
+
] });
|
|
935
|
+
});
|
|
936
|
+
var RadioGroupContext = createContext(null);
|
|
937
|
+
var Radio = forwardRef(function Radio2({ children, className, value, ...rest }, ref) {
|
|
938
|
+
const group = useContext(RadioGroupContext);
|
|
939
|
+
return /* @__PURE__ */ jsxs("label", { className: cx("hl-radio", className), children: [
|
|
940
|
+
/* @__PURE__ */ jsx(
|
|
941
|
+
"input",
|
|
942
|
+
{
|
|
943
|
+
...rest,
|
|
944
|
+
ref,
|
|
945
|
+
type: "radio",
|
|
946
|
+
name: rest.name ?? group?.name,
|
|
947
|
+
value,
|
|
948
|
+
checked: group ? group.value === value : rest.checked,
|
|
949
|
+
onChange: (e) => {
|
|
950
|
+
group?.setValue(value);
|
|
951
|
+
rest.onChange?.(e);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
),
|
|
955
|
+
children != null && /* @__PURE__ */ jsx("span", { children })
|
|
956
|
+
] });
|
|
957
|
+
});
|
|
958
|
+
var RadioGroup = forwardRef(function RadioGroup2({
|
|
959
|
+
name,
|
|
960
|
+
value: valueProp,
|
|
961
|
+
defaultValue,
|
|
962
|
+
onValueChange,
|
|
963
|
+
orientation,
|
|
964
|
+
className,
|
|
965
|
+
children,
|
|
966
|
+
...rest
|
|
967
|
+
}, ref) {
|
|
968
|
+
const [value, setValue] = useControlled(valueProp, defaultValue, onValueChange);
|
|
969
|
+
const groupName = useHlId("radio", name);
|
|
970
|
+
return /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { name: groupName, value, setValue }, children: /* @__PURE__ */ jsx(
|
|
971
|
+
"div",
|
|
972
|
+
{
|
|
973
|
+
...rest,
|
|
974
|
+
ref,
|
|
975
|
+
role: "radiogroup",
|
|
976
|
+
className: cx("hl-radio-group", className),
|
|
977
|
+
"data-hl-orientation": orientation,
|
|
978
|
+
"aria-orientation": orientation,
|
|
979
|
+
children
|
|
980
|
+
}
|
|
981
|
+
) });
|
|
982
|
+
});
|
|
983
|
+
var SegmentedControl = forwardRef(
|
|
984
|
+
function SegmentedControl2({ options, value: valueProp, defaultValue, onValueChange, name, size, className, ...rest }, ref) {
|
|
985
|
+
const [value, setValue] = useControlled(
|
|
986
|
+
valueProp,
|
|
987
|
+
defaultValue ?? options[0]?.value,
|
|
988
|
+
onValueChange
|
|
989
|
+
);
|
|
990
|
+
const groupName = useHlId("segmented", name);
|
|
991
|
+
return /* @__PURE__ */ jsx(
|
|
992
|
+
"div",
|
|
993
|
+
{
|
|
994
|
+
...rest,
|
|
995
|
+
ref,
|
|
996
|
+
role: "radiogroup",
|
|
997
|
+
className: cx("hl-segmented", className),
|
|
998
|
+
"data-hl-size": size,
|
|
999
|
+
children: options.map((option) => /* @__PURE__ */ jsxs("label", { className: "hl-segmented-item", children: [
|
|
1000
|
+
/* @__PURE__ */ jsx(
|
|
1001
|
+
"input",
|
|
1002
|
+
{
|
|
1003
|
+
type: "radio",
|
|
1004
|
+
name: groupName,
|
|
1005
|
+
value: option.value,
|
|
1006
|
+
checked: value === option.value,
|
|
1007
|
+
disabled: option.disabled,
|
|
1008
|
+
onChange: () => setValue(option.value)
|
|
1009
|
+
}
|
|
1010
|
+
),
|
|
1011
|
+
/* @__PURE__ */ jsx("span", { children: option.label })
|
|
1012
|
+
] }, option.value))
|
|
1013
|
+
}
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
);
|
|
1017
|
+
var Slider = forwardRef(function Slider2({ className, ...rest }, ref) {
|
|
1018
|
+
const props = useFieldControl(rest);
|
|
1019
|
+
return /* @__PURE__ */ jsx("input", { ...props, ref, type: "range", className: cx("hl-slider", className) });
|
|
1020
|
+
});
|
|
1021
|
+
var Avatar = forwardRef(function Avatar2({ src, alt = "", fallback, size, shape, className, children, ...rest }, ref) {
|
|
1022
|
+
const [failed, setFailed] = useState(false);
|
|
1023
|
+
const showImage = src && !failed;
|
|
1024
|
+
return /* @__PURE__ */ jsx(
|
|
1025
|
+
"span",
|
|
1026
|
+
{
|
|
1027
|
+
...rest,
|
|
1028
|
+
ref,
|
|
1029
|
+
className: ["hl-avatar", className].filter(Boolean).join(" "),
|
|
1030
|
+
"data-hl-size": size,
|
|
1031
|
+
"data-hl-shape": shape === "square" ? "square" : void 0,
|
|
1032
|
+
children: showImage ? /* @__PURE__ */ jsx("img", { src, alt, onError: () => setFailed(true) }) : fallback ?? children
|
|
1033
|
+
}
|
|
1034
|
+
);
|
|
1035
|
+
});
|
|
1036
|
+
var AvatarGroup = forwardRef(function AvatarGroup2({ className, children, ...rest }, ref) {
|
|
1037
|
+
return /* @__PURE__ */ jsx("div", { ...rest, ref, className: ["hl-avatar-group", className].filter(Boolean).join(" "), children });
|
|
1038
|
+
});
|
|
1039
|
+
var ELLIPSIS = "ellipsis";
|
|
1040
|
+
function range(start, end) {
|
|
1041
|
+
return Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
|
1042
|
+
}
|
|
1043
|
+
function paginationRange(page, count, siblingCount) {
|
|
1044
|
+
const totalNumbers = siblingCount * 2 + 5;
|
|
1045
|
+
if (totalNumbers >= count) return range(1, count);
|
|
1046
|
+
const leftSibling = Math.max(page - siblingCount, 1);
|
|
1047
|
+
const rightSibling = Math.min(page + siblingCount, count);
|
|
1048
|
+
const showLeftDots = leftSibling > 2;
|
|
1049
|
+
const showRightDots = rightSibling < count - 1;
|
|
1050
|
+
if (!showLeftDots && showRightDots) {
|
|
1051
|
+
return [...range(1, siblingCount * 2 + 3), ELLIPSIS, count];
|
|
1052
|
+
}
|
|
1053
|
+
if (showLeftDots && !showRightDots) {
|
|
1054
|
+
return [1, ELLIPSIS, ...range(count - (siblingCount * 2 + 2), count)];
|
|
1055
|
+
}
|
|
1056
|
+
return [1, ELLIPSIS, ...range(leftSibling, rightSibling), ELLIPSIS, count];
|
|
1057
|
+
}
|
|
1058
|
+
var Pagination = forwardRef(function Pagination2({
|
|
1059
|
+
page,
|
|
1060
|
+
count,
|
|
1061
|
+
onPageChange,
|
|
1062
|
+
siblingCount = 1,
|
|
1063
|
+
showControls = true,
|
|
1064
|
+
prevLabel = "\u2039",
|
|
1065
|
+
nextLabel = "\u203A",
|
|
1066
|
+
className,
|
|
1067
|
+
...rest
|
|
1068
|
+
}, ref) {
|
|
1069
|
+
const items = paginationRange(page, count, siblingCount);
|
|
1070
|
+
const go = (target) => {
|
|
1071
|
+
if (target >= 1 && target <= count && target !== page) onPageChange?.(target);
|
|
1072
|
+
};
|
|
1073
|
+
return /* @__PURE__ */ jsx(
|
|
1074
|
+
"nav",
|
|
1075
|
+
{
|
|
1076
|
+
...rest,
|
|
1077
|
+
ref,
|
|
1078
|
+
className: cx("hl-pagination", className),
|
|
1079
|
+
"aria-label": rest["aria-label"] ?? "Pagination",
|
|
1080
|
+
children: /* @__PURE__ */ jsxs("ul", { children: [
|
|
1081
|
+
showControls && /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
1082
|
+
"button",
|
|
1083
|
+
{
|
|
1084
|
+
type: "button",
|
|
1085
|
+
className: "hl-pagination-item",
|
|
1086
|
+
"aria-label": "Previous page",
|
|
1087
|
+
disabled: page <= 1,
|
|
1088
|
+
onClick: () => go(page - 1),
|
|
1089
|
+
children: prevLabel
|
|
1090
|
+
}
|
|
1091
|
+
) }),
|
|
1092
|
+
items.map(
|
|
1093
|
+
(item, i) => item === ELLIPSIS ? /* @__PURE__ */ jsx("li", { "aria-hidden": "true", children: /* @__PURE__ */ jsx("span", { className: "hl-pagination-ellipsis", children: "\u2026" }) }, `e${i}`) : /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
1094
|
+
"button",
|
|
1095
|
+
{
|
|
1096
|
+
type: "button",
|
|
1097
|
+
className: "hl-pagination-item",
|
|
1098
|
+
"aria-current": item === page ? "page" : void 0,
|
|
1099
|
+
"aria-label": `Page ${item}`,
|
|
1100
|
+
onClick: () => go(item),
|
|
1101
|
+
children: item
|
|
1102
|
+
}
|
|
1103
|
+
) }, item)
|
|
1104
|
+
),
|
|
1105
|
+
showControls && /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
1106
|
+
"button",
|
|
1107
|
+
{
|
|
1108
|
+
type: "button",
|
|
1109
|
+
className: "hl-pagination-item",
|
|
1110
|
+
"aria-label": "Next page",
|
|
1111
|
+
disabled: page >= count,
|
|
1112
|
+
onClick: () => go(page + 1),
|
|
1113
|
+
children: nextLabel
|
|
1114
|
+
}
|
|
1115
|
+
) })
|
|
1116
|
+
] })
|
|
1117
|
+
}
|
|
1118
|
+
);
|
|
1119
|
+
});
|
|
1120
|
+
|
|
1121
|
+
export { Accordion, AccordionItem, Avatar, AvatarGroup, Checkbox, Combobox, ComboboxInput, ComboboxList, ComboboxOption, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Disclosure, Drawer, Dropdown, DropdownGroup, DropdownItem, DropdownMenu, DropdownSeparator, DropdownTrigger, Field, FieldError, FieldHelp, FieldLabel, Fieldset, Input, Menu, MenuItem, MenuSubmenu, Modal, Pagination, Popover, Radio, RadioGroup, SegmentedControl, Select, Slider, Switch, Tab, TabList, TabPanel, Tabs, Textarea, ToastRegion, Toc, Tooltip, useEnhancer, useField, useToast };
|