@hydrateless/react 0.7.0 → 0.8.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 +1 -1
- package/dist/index.d.ts +64 -40
- package/dist/index.js +91 -55
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { DependencyList, RefObject, HTMLAttributes, ReactNode, ButtonHTMLAttributes, LiHTMLAttributes, AnchorHTMLAttributes, ReactElement, InputHTMLAttributes, TextareaHTMLAttributes, SelectHTMLAttributes, LabelHTMLAttributes, ProgressHTMLAttributes } from 'react';
|
|
3
3
|
import * as _hydrateless_enhancers from '@hydrateless/enhancers';
|
|
4
|
-
import { EnhancerHandle, AccordionApi, DropdownApi, TabsApi, EnhanceTocOptions, TooltipApi, EnhanceTabsOptions, EnhanceDropdownOptions, EnhanceMenuOptions, ToastApi, EnhanceComboboxOptions } from '@hydrateless/enhancers';
|
|
5
|
-
export { AccordionApi, ComboboxApi, Disposer, DrawerApi, DropdownApi, EnhancerHandle, ModalApi, PopoverApi, TabsApi, ToastApi, TooltipApi } from '@hydrateless/enhancers';
|
|
4
|
+
import { EnhancerHandle, AccordionApi, DropdownApi, TabsApi, EnhanceTocOptions, TocApi, TooltipApi, EnhanceTabsOptions, EnhanceDropdownOptions, EnhanceMenuOptions, ToastApi, EnhanceComboboxOptions } from '@hydrateless/enhancers';
|
|
5
|
+
export { AccordionApi, ComboboxApi, CommandApi, DisclosureApi, Disposer, DrawerApi, DropdownApi, EnhancerHandle, MenuApi, ModalApi, PopoverApi, TabsApi, ToastApi, TocApi, TooltipApi } from '@hydrateless/enhancers';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Attach any Hydrateless enhancer to a DOM node for the lifetime of a
|
|
@@ -42,11 +42,6 @@ declare const useAccordion: <T extends HTMLElement = HTMLDivElement>(allowMultip
|
|
|
42
42
|
ref: react.RefObject<T | null>;
|
|
43
43
|
api: react.RefObject<AccordionApi | null>;
|
|
44
44
|
};
|
|
45
|
-
/** Ref hook that groups `[data-hl-disclosure]` elements for mutual exclusivity. */
|
|
46
|
-
declare const useDisclosureGroup: <T extends HTMLElement = HTMLElement>(allowMultiple?: boolean) => {
|
|
47
|
-
ref: react.RefObject<T | null>;
|
|
48
|
-
api: react.RefObject<null>;
|
|
49
|
-
};
|
|
50
45
|
/** Ref hook that wires modal openers/closers + focus trap within a container. */
|
|
51
46
|
declare const useModalGroup: <T extends HTMLElement = HTMLElement>(closeOnBackdrop?: boolean) => {
|
|
52
47
|
ref: react.RefObject<T | null>;
|
|
@@ -55,7 +50,7 @@ declare const useModalGroup: <T extends HTMLElement = HTMLElement>(closeOnBackdr
|
|
|
55
50
|
/** Ref hook that builds a table of contents from the surrounding document. */
|
|
56
51
|
declare const useTocEnhancer: <T extends HTMLElement = HTMLElement>(options?: EnhanceTocOptions) => {
|
|
57
52
|
ref: react.RefObject<T | null>;
|
|
58
|
-
api: react.RefObject<null>;
|
|
53
|
+
api: react.RefObject<TocApi | null>;
|
|
59
54
|
};
|
|
60
55
|
|
|
61
56
|
/** Props for {@link Accordion}. */
|
|
@@ -89,15 +84,25 @@ declare function AccordionItem({ summary, value, defaultOpen, children, ...rest
|
|
|
89
84
|
/** Props for {@link Disclosure}. */
|
|
90
85
|
interface DisclosureProps extends Omit<HTMLAttributes<HTMLDetailsElement>, 'title'> {
|
|
91
86
|
summary: ReactNode;
|
|
87
|
+
/** Controlled open state (pair with `onOpenChange`). */
|
|
88
|
+
open?: boolean;
|
|
89
|
+
/** Open the disclosure initially for uncontrolled usage. */
|
|
92
90
|
defaultOpen?: boolean;
|
|
91
|
+
/** Called after the disclosure opens or closes. */
|
|
92
|
+
onOpenChange?: (open: boolean) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Group name. Disclosures sharing a `name` are exclusive: the browser closes
|
|
95
|
+
* the others when one opens, with no JavaScript.
|
|
96
|
+
*/
|
|
97
|
+
name?: string;
|
|
93
98
|
}
|
|
94
99
|
/**
|
|
95
|
-
* A single expandable section
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
100
|
+
* A single expandable section built on native `<details>`, which handles
|
|
101
|
+
* open/close (and exclusive groups, via the `name` attribute) on its own.
|
|
102
|
+
* Open state works uncontrolled (`defaultOpen`) or controlled (`open` +
|
|
103
|
+
* `onOpenChange`).
|
|
99
104
|
*/
|
|
100
|
-
declare function Disclosure({ summary, defaultOpen, className, children, ...rest }: DisclosureProps): react.JSX.Element;
|
|
105
|
+
declare function Disclosure({ summary, open, defaultOpen, onOpenChange, name, className, children, ...rest }: DisclosureProps): react.JSX.Element;
|
|
101
106
|
|
|
102
107
|
/** Props for {@link Tabs}. */
|
|
103
108
|
interface TabsProps extends HTMLAttributes<HTMLDivElement> {
|
|
@@ -195,13 +200,18 @@ type DropdownSeparatorProps = Omit<LiHTMLAttributes<HTMLLIElement>, 'role'>;
|
|
|
195
200
|
declare function DropdownSeparator(props: DropdownSeparatorProps): react.JSX.Element;
|
|
196
201
|
|
|
197
202
|
/** Props for {@link Menu}. */
|
|
198
|
-
interface MenuProps extends HTMLAttributes<HTMLUListElement> {
|
|
203
|
+
interface MenuProps extends Omit<HTMLAttributes<HTMLUListElement>, 'onSelect'> {
|
|
199
204
|
orientation?: EnhanceMenuOptions['orientation'];
|
|
205
|
+
/** Called with the open submenu's value (or `null`) after every change. */
|
|
206
|
+
onOpenChange?: (value: string | null) => void;
|
|
207
|
+
/** Called with the item's value when a leaf menu item is activated. */
|
|
208
|
+
onSelect?: (value: string) => void;
|
|
200
209
|
}
|
|
201
210
|
/**
|
|
202
|
-
* Menubar / navigation menu with single-level submenus
|
|
203
|
-
* `<MenuItem>`; nest items by passing a `submenu`. The
|
|
204
|
-
* tabindex, orientation-aware arrow navigation, and
|
|
211
|
+
* Menubar / navigation menu with single-level submenus rendered in the top
|
|
212
|
+
* layer. Compose with `<MenuItem>`; nest items by passing a `submenu`. The
|
|
213
|
+
* enhancer wires roving tabindex, orientation-aware arrow navigation, and
|
|
214
|
+
* submenu toggling.
|
|
205
215
|
*
|
|
206
216
|
* ```tsx
|
|
207
217
|
* <Menu orientation="horizontal">
|
|
@@ -210,11 +220,13 @@ interface MenuProps extends HTMLAttributes<HTMLUListElement> {
|
|
|
210
220
|
* </Menu>
|
|
211
221
|
* ```
|
|
212
222
|
*/
|
|
213
|
-
declare function Menu({ orientation, children, ...rest }: MenuProps): react.JSX.Element;
|
|
223
|
+
declare function Menu({ orientation, onOpenChange, onSelect, children, ...rest }: MenuProps): react.JSX.Element;
|
|
214
224
|
/** Props for {@link MenuItem}. */
|
|
215
|
-
interface MenuItemProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'href' | 'type'> {
|
|
225
|
+
interface MenuItemProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'href' | 'type' | 'value'> {
|
|
216
226
|
/** Render as a link instead of a button. */
|
|
217
227
|
href?: string;
|
|
228
|
+
/** Stable value identifying this item; defaults to its label text. */
|
|
229
|
+
value?: string;
|
|
218
230
|
/** Convenience handler fired on activation. */
|
|
219
231
|
onSelect?: () => void;
|
|
220
232
|
/** Nested `<MenuItem>`s; renders a single-level submenu. */
|
|
@@ -226,21 +238,25 @@ interface MenuItemProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'h
|
|
|
226
238
|
* A menu entry. Children are the label; pass `submenu` to nest a flyout. With
|
|
227
239
|
* `href` it renders an anchor, otherwise a button.
|
|
228
240
|
*/
|
|
229
|
-
declare function MenuItem({ href, onSelect, onClick, submenu, anchorProps, children, ...rest }: MenuItemProps): react.JSX.Element;
|
|
241
|
+
declare function MenuItem({ href, value, onSelect, onClick, submenu, anchorProps, children, ...rest }: MenuItemProps): react.JSX.Element;
|
|
230
242
|
|
|
231
243
|
/** Props for {@link Modal}. */
|
|
232
244
|
interface ModalProps extends Omit<HTMLAttributes<HTMLDialogElement>, 'title'> {
|
|
233
|
-
open
|
|
245
|
+
/** Controlled open state (pair with `onOpenChange`). */
|
|
246
|
+
open?: boolean;
|
|
247
|
+
/** Open the dialog initially for uncontrolled usage. */
|
|
248
|
+
defaultOpen?: boolean;
|
|
234
249
|
/** Called after the dialog opens or closes (Escape, backdrop, close buttons). */
|
|
235
250
|
onOpenChange?: (open: boolean) => void;
|
|
236
251
|
closeOnBackdrop?: boolean;
|
|
237
252
|
}
|
|
238
253
|
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* `<
|
|
243
|
-
*
|
|
254
|
+
* Dialog overlay built on the native `<dialog>` element and the modal
|
|
255
|
+
* enhancer, which adds a focus trap, body scroll-lock, and a background
|
|
256
|
+
* `inert` barrier. Compose with `<ModalHeader>`, `<ModalBody>`, and
|
|
257
|
+
* `<ModalFooter>`. Open state works uncontrolled (`defaultOpen`, or a
|
|
258
|
+
* `command="show-modal"` invoker button) or controlled (`open` +
|
|
259
|
+
* `onOpenChange`).
|
|
244
260
|
*
|
|
245
261
|
* ```tsx
|
|
246
262
|
* <Modal open={open} onOpenChange={setOpen}>
|
|
@@ -250,7 +266,7 @@ interface ModalProps extends Omit<HTMLAttributes<HTMLDialogElement>, 'title'> {
|
|
|
250
266
|
* </Modal>
|
|
251
267
|
* ```
|
|
252
268
|
*/
|
|
253
|
-
declare function Modal({ open, onOpenChange, closeOnBackdrop, className, children, ...rest }: ModalProps): react.JSX.Element;
|
|
269
|
+
declare function Modal({ open, defaultOpen, onOpenChange, closeOnBackdrop, className, children, ...rest }: ModalProps): react.JSX.Element;
|
|
254
270
|
/** Props shared by the {@link Modal} section components. */
|
|
255
271
|
type ModalSectionProps = HTMLAttributes<HTMLDivElement>;
|
|
256
272
|
/** Modal heading region; its content labels the dialog for assistive tech. */
|
|
@@ -262,19 +278,24 @@ declare function ModalFooter({ className, ...rest }: ModalSectionProps): react.J
|
|
|
262
278
|
|
|
263
279
|
/** Props for {@link Drawer}. */
|
|
264
280
|
interface DrawerProps extends Omit<HTMLAttributes<HTMLDialogElement>, 'title'> {
|
|
265
|
-
open
|
|
281
|
+
/** Controlled open state (pair with `onOpenChange`). */
|
|
282
|
+
open?: boolean;
|
|
283
|
+
/** Open the drawer initially for uncontrolled usage. */
|
|
284
|
+
defaultOpen?: boolean;
|
|
266
285
|
/** Called after the drawer opens or closes (Escape, backdrop, close buttons). */
|
|
267
286
|
onOpenChange?: (open: boolean) => void;
|
|
268
287
|
side?: 'left' | 'right';
|
|
269
288
|
closeOnBackdrop?: boolean;
|
|
270
289
|
}
|
|
271
290
|
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
291
|
+
* Off-canvas panel built on the native `<dialog>` element and the drawer
|
|
292
|
+
* enhancer (focus trap, scroll-lock, background `inert`). Mirrors
|
|
274
293
|
* {@link Modal} but slides in from the chosen `side`. Compose with
|
|
275
|
-
* `<DrawerHeader>`, `<DrawerBody>`, and `<DrawerFooter>`.
|
|
294
|
+
* `<DrawerHeader>`, `<DrawerBody>`, and `<DrawerFooter>`. Open state works
|
|
295
|
+
* uncontrolled (`defaultOpen`, or an invoker button) or controlled (`open` +
|
|
296
|
+
* `onOpenChange`).
|
|
276
297
|
*/
|
|
277
|
-
declare function Drawer({ open, onOpenChange, side, closeOnBackdrop, className, children, ...rest }: DrawerProps): react.JSX.Element;
|
|
298
|
+
declare function Drawer({ open, defaultOpen, onOpenChange, side, closeOnBackdrop, className, children, ...rest }: DrawerProps): react.JSX.Element;
|
|
278
299
|
/** Props shared by the {@link Drawer} section components. */
|
|
279
300
|
type DrawerSectionProps = HTMLAttributes<HTMLDivElement>;
|
|
280
301
|
/** Drawer heading region. */
|
|
@@ -286,19 +307,22 @@ declare function DrawerFooter({ className, ...rest }: DrawerSectionProps): react
|
|
|
286
307
|
|
|
287
308
|
/** Props for {@link Popover}. */
|
|
288
309
|
interface PopoverProps extends HTMLAttributes<HTMLDivElement> {
|
|
289
|
-
open
|
|
310
|
+
/** Controlled open state (pair with `onOpenChange`). */
|
|
311
|
+
open?: boolean;
|
|
312
|
+
/** Show the popover initially for uncontrolled usage. */
|
|
313
|
+
defaultOpen?: boolean;
|
|
290
314
|
/** Called when the browser's light-dismiss (Escape or outside click) closes it. */
|
|
291
315
|
onOpenChange?: (open: boolean) => void;
|
|
292
316
|
children?: ReactNode;
|
|
293
317
|
}
|
|
294
318
|
/**
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
319
|
+
* Floating content built on the native Popover API. The surface lives in the
|
|
320
|
+
* top layer with light-dismiss and Escape handled by the browser; visibility
|
|
321
|
+
* works uncontrolled (`defaultOpen`, or a `popovertarget` trigger button) or
|
|
322
|
+
* controlled (`open` + `onOpenChange`). Position it with the
|
|
323
|
+
* `hydrateless/popover.css` styles.
|
|
300
324
|
*/
|
|
301
|
-
declare function Popover({ open, onOpenChange, children, ...rest }: PopoverProps): react.JSX.Element;
|
|
325
|
+
declare function Popover({ open, defaultOpen, onOpenChange, children, ...rest }: PopoverProps): react.JSX.Element;
|
|
302
326
|
|
|
303
327
|
/** Props for {@link Tooltip}. */
|
|
304
328
|
interface TooltipProps {
|
|
@@ -728,4 +752,4 @@ declare const Separator: react.ForwardRefExoticComponent<SeparatorProps & react.
|
|
|
728
752
|
/** Join truthy class names into a single string. */
|
|
729
753
|
declare function cx(...classes: Array<string | false | null | undefined>): string;
|
|
730
754
|
|
|
731
|
-
export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, Alert, type AlertProps, Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, Badge, type BadgeProps, Breadcrumb, BreadcrumbItem, type BreadcrumbItemProps, type BreadcrumbProps, Button, type ButtonProps, Card, CardBody, CardDescription, CardFooter, CardHeader, type CardProps, type CardSectionProps, CardTitle, Checkbox, type CheckboxProps, Combobox, ComboboxInput, type ComboboxInputProps, ComboboxList, type ComboboxListProps, ComboboxOption, type ComboboxOptionProps, type ComboboxProps, Command, CommandEmpty, type CommandEmptyProps, CommandGroup, type CommandGroupProps, CommandInput, type CommandInputProps, CommandItem, type CommandItemProps, CommandList, type CommandListProps, type CommandProps, Disclosure, type DisclosureProps, Drawer, DrawerBody, DrawerFooter, DrawerHeader, type DrawerProps, type DrawerSectionProps, Dropdown, DropdownItem, type DropdownItemProps, DropdownMenu, type DropdownMenuProps, type DropdownProps, DropdownSeparator, type DropdownSeparatorProps, DropdownTrigger, type DropdownTriggerProps, Field, FieldError, FieldHelp, FieldLabel, type FieldLabelProps, type FieldProps, Fieldset, type FieldsetProps, Input, type InputProps, Kbd, type KbdProps, Menu, MenuItem, type MenuItemProps, type MenuProps, Modal, ModalBody, ModalFooter, ModalHeader, type ModalProps, type ModalSectionProps, Pagination, type PaginationProps, Popover, type PopoverProps, Progress, type ProgressProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, Select, type SelectOption, type SelectProps, Separator, type SeparatorProps, Skeleton, type SkeletonProps, SkipLink, type SkipLinkProps, Slider, type SliderProps, Spinner, type SpinnerProps, Switch, type SwitchProps, Tab, TabList, type TabListProps, TabPanel, type TabPanelProps, type TabProps, Tabs, type TabsProps, Textarea, type TextareaProps, ToastRegion, type ToastRegionProps, Toc, type TocProps, Tooltip, type TooltipProps, cx, useAccordion,
|
|
755
|
+
export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, Alert, type AlertProps, Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, Badge, type BadgeProps, Breadcrumb, BreadcrumbItem, type BreadcrumbItemProps, type BreadcrumbProps, Button, type ButtonProps, Card, CardBody, CardDescription, CardFooter, CardHeader, type CardProps, type CardSectionProps, CardTitle, Checkbox, type CheckboxProps, Combobox, ComboboxInput, type ComboboxInputProps, ComboboxList, type ComboboxListProps, ComboboxOption, type ComboboxOptionProps, type ComboboxProps, Command, CommandEmpty, type CommandEmptyProps, CommandGroup, type CommandGroupProps, CommandInput, type CommandInputProps, CommandItem, type CommandItemProps, CommandList, type CommandListProps, type CommandProps, Disclosure, type DisclosureProps, Drawer, DrawerBody, DrawerFooter, DrawerHeader, type DrawerProps, type DrawerSectionProps, Dropdown, DropdownItem, type DropdownItemProps, DropdownMenu, type DropdownMenuProps, type DropdownProps, DropdownSeparator, type DropdownSeparatorProps, DropdownTrigger, type DropdownTriggerProps, Field, FieldError, FieldHelp, FieldLabel, type FieldLabelProps, type FieldProps, Fieldset, type FieldsetProps, Input, type InputProps, Kbd, type KbdProps, Menu, MenuItem, type MenuItemProps, type MenuProps, Modal, ModalBody, ModalFooter, ModalHeader, type ModalProps, type ModalSectionProps, Pagination, type PaginationProps, Popover, type PopoverProps, Progress, type ProgressProps, Radio, RadioGroup, type RadioGroupProps, type RadioProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, Select, type SelectOption, type SelectProps, Separator, type SeparatorProps, Skeleton, type SkeletonProps, SkipLink, type SkipLinkProps, Slider, type SliderProps, Spinner, type SpinnerProps, Switch, type SwitchProps, Tab, TabList, type TabListProps, TabPanel, type TabPanelProps, type TabProps, Tabs, type TabsProps, Textarea, type TextareaProps, ToastRegion, type ToastRegionProps, Toc, type TocProps, Tooltip, type TooltipProps, cx, useAccordion, useDropdown, useEnhancer, useField, useModalGroup, useTabs, useToast, useTocEnhancer, useTooltip };
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,6 @@ function useEnhancer(enhance, deps = []) {
|
|
|
19
19
|
// src/hooks.ts
|
|
20
20
|
import {
|
|
21
21
|
enhanceAccordion,
|
|
22
|
-
enhanceDisclosure,
|
|
23
22
|
enhanceDropdown,
|
|
24
23
|
enhanceModal,
|
|
25
24
|
enhanceTabs,
|
|
@@ -30,7 +29,6 @@ var useTabs = () => useEnhancer((el) => enhanceTabs(el));
|
|
|
30
29
|
var useDropdown = () => useEnhancer((el) => enhanceDropdown(el));
|
|
31
30
|
var useTooltip = () => useEnhancer((el) => enhanceTooltip(el));
|
|
32
31
|
var useAccordion = (allowMultiple = false) => useEnhancer((el) => enhanceAccordion(el, { allowMultiple }), [allowMultiple]);
|
|
33
|
-
var useDisclosureGroup = (allowMultiple = false) => useEnhancer((el) => enhanceDisclosure(el, { allowMultiple }), [allowMultiple]);
|
|
34
32
|
var useModalGroup = (closeOnBackdrop = true) => useEnhancer((el) => enhanceModal(el, { closeOnBackdrop }), [closeOnBackdrop]);
|
|
35
33
|
var useTocEnhancer = (options) => useEnhancer(
|
|
36
34
|
(el) => enhanceToc(el.ownerDocument, options),
|
|
@@ -95,23 +93,45 @@ function AccordionItem({
|
|
|
95
93
|
}
|
|
96
94
|
|
|
97
95
|
// src/Disclosure.tsx
|
|
98
|
-
import { useEffect as useEffect3
|
|
96
|
+
import { useEffect as useEffect3 } from "react";
|
|
97
|
+
import { enhanceDisclosure } from "@hydrateless/enhancers";
|
|
99
98
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
100
99
|
function Disclosure({
|
|
101
100
|
summary,
|
|
102
|
-
|
|
101
|
+
open,
|
|
102
|
+
defaultOpen,
|
|
103
|
+
onOpenChange,
|
|
104
|
+
name,
|
|
103
105
|
className,
|
|
104
106
|
children,
|
|
105
107
|
...rest
|
|
106
108
|
}) {
|
|
107
|
-
const
|
|
109
|
+
const onOpenChangeRef = useLatest(onOpenChange);
|
|
110
|
+
const initialOpenRef = useLatest(open ?? defaultOpen);
|
|
111
|
+
const { ref, api } = useEnhancer(
|
|
112
|
+
(el) => enhanceDisclosure(el, {
|
|
113
|
+
defaultOpen: initialOpenRef.current,
|
|
114
|
+
onOpenChange: (next) => onOpenChangeRef.current?.(next)
|
|
115
|
+
}),
|
|
116
|
+
[]
|
|
117
|
+
);
|
|
108
118
|
useEffect3(() => {
|
|
109
|
-
if (
|
|
110
|
-
}, [
|
|
111
|
-
return /* @__PURE__ */ jsxs2(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
119
|
+
if (open != null) api.current?.setOpen(open);
|
|
120
|
+
}, [open, api]);
|
|
121
|
+
return /* @__PURE__ */ jsxs2(
|
|
122
|
+
"details",
|
|
123
|
+
{
|
|
124
|
+
...rest,
|
|
125
|
+
name,
|
|
126
|
+
className: cx("hl-disclosure", className),
|
|
127
|
+
"data-hl-disclosure": true,
|
|
128
|
+
ref,
|
|
129
|
+
children: [
|
|
130
|
+
/* @__PURE__ */ jsx2("summary", { children: summary }),
|
|
131
|
+
/* @__PURE__ */ jsx2("div", { className: "hl-disclosure-panel", children })
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
);
|
|
115
135
|
}
|
|
116
136
|
|
|
117
137
|
// src/Tabs.tsx
|
|
@@ -210,18 +230,25 @@ function DropdownSeparator(props) {
|
|
|
210
230
|
}
|
|
211
231
|
|
|
212
232
|
// src/Menu.tsx
|
|
213
|
-
import {
|
|
214
|
-
useEffect as useEffect6,
|
|
215
|
-
useRef as useRef5
|
|
216
|
-
} from "react";
|
|
217
233
|
import { enhanceMenu } from "@hydrateless/enhancers";
|
|
218
234
|
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
219
|
-
function Menu({
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
235
|
+
function Menu({
|
|
236
|
+
orientation = "horizontal",
|
|
237
|
+
onOpenChange,
|
|
238
|
+
onSelect,
|
|
239
|
+
children,
|
|
240
|
+
...rest
|
|
241
|
+
}) {
|
|
242
|
+
const onOpenChangeRef = useLatest(onOpenChange);
|
|
243
|
+
const onSelectRef = useLatest(onSelect);
|
|
244
|
+
const { ref } = useEnhancer(
|
|
245
|
+
(el) => enhanceMenu(el, {
|
|
246
|
+
orientation,
|
|
247
|
+
onOpenChange: (value) => onOpenChangeRef.current?.(value),
|
|
248
|
+
onSelect: (value) => onSelectRef.current?.(value)
|
|
249
|
+
}),
|
|
250
|
+
[orientation]
|
|
251
|
+
);
|
|
225
252
|
return /* @__PURE__ */ jsx5(
|
|
226
253
|
"ul",
|
|
227
254
|
{
|
|
@@ -236,6 +263,7 @@ function Menu({ orientation = "horizontal", children, ...rest }) {
|
|
|
236
263
|
}
|
|
237
264
|
function MenuItem({
|
|
238
265
|
href,
|
|
266
|
+
value,
|
|
239
267
|
onSelect,
|
|
240
268
|
onClick,
|
|
241
269
|
submenu,
|
|
@@ -245,12 +273,13 @@ function MenuItem({
|
|
|
245
273
|
}) {
|
|
246
274
|
const hasSubmenu = submenu != null;
|
|
247
275
|
return /* @__PURE__ */ jsxs3("li", { role: "none", children: [
|
|
248
|
-
href && !hasSubmenu ? /* @__PURE__ */ jsx5("a", { ...anchorProps, role: "menuitem", href, children }) : /* @__PURE__ */ jsx5(
|
|
276
|
+
href && !hasSubmenu ? /* @__PURE__ */ jsx5("a", { ...anchorProps, role: "menuitem", href, "data-hl-value": value, children }) : /* @__PURE__ */ jsx5(
|
|
249
277
|
"button",
|
|
250
278
|
{
|
|
251
279
|
...rest,
|
|
252
280
|
type: "button",
|
|
253
281
|
role: "menuitem",
|
|
282
|
+
"data-hl-value": value,
|
|
254
283
|
onClick: (e) => {
|
|
255
284
|
onSelect?.();
|
|
256
285
|
onClick?.(e);
|
|
@@ -263,11 +292,12 @@ function MenuItem({
|
|
|
263
292
|
}
|
|
264
293
|
|
|
265
294
|
// src/Modal.tsx
|
|
266
|
-
import { useEffect as
|
|
295
|
+
import { useEffect as useEffect6 } from "react";
|
|
267
296
|
import { enhanceModal as enhanceModal2 } from "@hydrateless/enhancers";
|
|
268
297
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
269
298
|
function Modal({
|
|
270
299
|
open,
|
|
300
|
+
defaultOpen,
|
|
271
301
|
onOpenChange,
|
|
272
302
|
closeOnBackdrop = true,
|
|
273
303
|
className,
|
|
@@ -275,15 +305,17 @@ function Modal({
|
|
|
275
305
|
...rest
|
|
276
306
|
}) {
|
|
277
307
|
const onOpenChangeRef = useLatest(onOpenChange);
|
|
308
|
+
const initialOpenRef = useLatest(open ?? defaultOpen);
|
|
278
309
|
const { ref, api } = useEnhancer(
|
|
279
310
|
(el) => enhanceModal2(el, {
|
|
280
311
|
closeOnBackdrop,
|
|
312
|
+
defaultOpen: initialOpenRef.current,
|
|
281
313
|
onOpenChange: (next) => onOpenChangeRef.current?.(next)
|
|
282
314
|
}),
|
|
283
315
|
[closeOnBackdrop]
|
|
284
316
|
);
|
|
285
|
-
|
|
286
|
-
api.current?.setOpen(open);
|
|
317
|
+
useEffect6(() => {
|
|
318
|
+
if (open != null) api.current?.setOpen(open);
|
|
287
319
|
}, [open, api]);
|
|
288
320
|
return /* @__PURE__ */ jsx6("dialog", { ...rest, ref, "data-hl-modal": true, className: cx("hl-modal", className), children });
|
|
289
321
|
}
|
|
@@ -298,11 +330,12 @@ function ModalFooter({ className, ...rest }) {
|
|
|
298
330
|
}
|
|
299
331
|
|
|
300
332
|
// src/Drawer.tsx
|
|
301
|
-
import { useEffect as
|
|
333
|
+
import { useEffect as useEffect7 } from "react";
|
|
302
334
|
import { enhanceDrawer } from "@hydrateless/enhancers";
|
|
303
335
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
304
336
|
function Drawer({
|
|
305
337
|
open,
|
|
338
|
+
defaultOpen,
|
|
306
339
|
onOpenChange,
|
|
307
340
|
side = "right",
|
|
308
341
|
closeOnBackdrop = true,
|
|
@@ -311,15 +344,17 @@ function Drawer({
|
|
|
311
344
|
...rest
|
|
312
345
|
}) {
|
|
313
346
|
const onOpenChangeRef = useLatest(onOpenChange);
|
|
347
|
+
const initialOpenRef = useLatest(open ?? defaultOpen);
|
|
314
348
|
const { ref, api } = useEnhancer(
|
|
315
349
|
(el) => enhanceDrawer(el, {
|
|
316
350
|
closeOnBackdrop,
|
|
351
|
+
defaultOpen: initialOpenRef.current,
|
|
317
352
|
onOpenChange: (next) => onOpenChangeRef.current?.(next)
|
|
318
353
|
}),
|
|
319
354
|
[closeOnBackdrop]
|
|
320
355
|
);
|
|
321
|
-
|
|
322
|
-
api.current?.setOpen(open);
|
|
356
|
+
useEffect7(() => {
|
|
357
|
+
if (open != null) api.current?.setOpen(open);
|
|
323
358
|
}, [open, api]);
|
|
324
359
|
return /* @__PURE__ */ jsx7(
|
|
325
360
|
"dialog",
|
|
@@ -344,17 +379,21 @@ function DrawerFooter({ className, ...rest }) {
|
|
|
344
379
|
}
|
|
345
380
|
|
|
346
381
|
// src/Popover.tsx
|
|
347
|
-
import { useEffect as
|
|
382
|
+
import { useEffect as useEffect8 } from "react";
|
|
348
383
|
import { enhancePopover } from "@hydrateless/enhancers";
|
|
349
384
|
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
350
|
-
function Popover({ open, onOpenChange, children, ...rest }) {
|
|
385
|
+
function Popover({ open, defaultOpen, onOpenChange, children, ...rest }) {
|
|
351
386
|
const onOpenChangeRef = useLatest(onOpenChange);
|
|
387
|
+
const initialOpenRef = useLatest(open ?? defaultOpen);
|
|
352
388
|
const { ref, api } = useEnhancer(
|
|
353
|
-
(el) => enhancePopover(el, {
|
|
389
|
+
(el) => enhancePopover(el, {
|
|
390
|
+
defaultOpen: initialOpenRef.current,
|
|
391
|
+
onOpenChange: (next) => onOpenChangeRef.current?.(next)
|
|
392
|
+
}),
|
|
354
393
|
[]
|
|
355
394
|
);
|
|
356
|
-
|
|
357
|
-
api.current?.setOpen(open);
|
|
395
|
+
useEffect8(() => {
|
|
396
|
+
if (open != null) api.current?.setOpen(open);
|
|
358
397
|
}, [open, api]);
|
|
359
398
|
return /* @__PURE__ */ jsx8("div", { ...rest, ref, "data-hl-popover": true, popover: "auto", role: "dialog", children });
|
|
360
399
|
}
|
|
@@ -363,17 +402,17 @@ function Popover({ open, onOpenChange, children, ...rest }) {
|
|
|
363
402
|
import {
|
|
364
403
|
cloneElement,
|
|
365
404
|
isValidElement,
|
|
366
|
-
useEffect as
|
|
405
|
+
useEffect as useEffect9,
|
|
367
406
|
useId,
|
|
368
|
-
useRef as
|
|
407
|
+
useRef as useRef4
|
|
369
408
|
} from "react";
|
|
370
409
|
import { enhanceTooltip as enhanceTooltip2 } from "@hydrateless/enhancers";
|
|
371
410
|
import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
372
411
|
function Tooltip({ label, children, id }) {
|
|
373
412
|
const generatedId = useId().replace(/:/g, "");
|
|
374
413
|
const tipId = id ?? `hl-tip-${generatedId}`;
|
|
375
|
-
const ref =
|
|
376
|
-
|
|
414
|
+
const ref = useRef4(null);
|
|
415
|
+
useEffect9(() => {
|
|
377
416
|
if (!ref.current) return;
|
|
378
417
|
return enhanceTooltip2(ref.current).destroy;
|
|
379
418
|
}, [tipId]);
|
|
@@ -418,12 +457,12 @@ function SkipLink({ children = "Skip to content", className, ...rest }) {
|
|
|
418
457
|
}
|
|
419
458
|
|
|
420
459
|
// src/Toc.tsx
|
|
421
|
-
import { useEffect as
|
|
460
|
+
import { useEffect as useEffect10, useRef as useRef5 } from "react";
|
|
422
461
|
import { enhanceToc as enhanceToc2 } from "@hydrateless/enhancers";
|
|
423
462
|
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
424
463
|
function Toc({ contentSelector, headings, scrollSpy, ...rest }) {
|
|
425
|
-
const ref =
|
|
426
|
-
|
|
464
|
+
const ref = useRef5(null);
|
|
465
|
+
useEffect10(() => {
|
|
427
466
|
if (!ref.current) return;
|
|
428
467
|
return enhanceToc2(ref.current.ownerDocument, { contentSelector, headings, scrollSpy }).destroy;
|
|
429
468
|
}, [contentSelector, headings, scrollSpy]);
|
|
@@ -431,7 +470,7 @@ function Toc({ contentSelector, headings, scrollSpy, ...rest }) {
|
|
|
431
470
|
}
|
|
432
471
|
|
|
433
472
|
// src/Toast.tsx
|
|
434
|
-
import { useEffect as
|
|
473
|
+
import { useEffect as useEffect11, useRef as useRef6 } from "react";
|
|
435
474
|
import { enhanceToast } from "@hydrateless/enhancers";
|
|
436
475
|
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
437
476
|
var sharedApi = null;
|
|
@@ -447,8 +486,8 @@ var facade = {
|
|
|
447
486
|
dismiss: (toast) => ensureApi().dismiss(toast)
|
|
448
487
|
};
|
|
449
488
|
function ToastRegion(props) {
|
|
450
|
-
const ref =
|
|
451
|
-
|
|
489
|
+
const ref = useRef6(null);
|
|
490
|
+
useEffect11(() => {
|
|
452
491
|
if (!ref.current) return;
|
|
453
492
|
const handle = enhanceToast(ref.current.ownerDocument);
|
|
454
493
|
sharedApi = handle.api;
|
|
@@ -465,7 +504,7 @@ function useToast() {
|
|
|
465
504
|
|
|
466
505
|
// src/Combobox.tsx
|
|
467
506
|
import {
|
|
468
|
-
useEffect as
|
|
507
|
+
useEffect as useEffect12
|
|
469
508
|
} from "react";
|
|
470
509
|
import {
|
|
471
510
|
enhanceCombobox
|
|
@@ -491,7 +530,7 @@ function Combobox({
|
|
|
491
530
|
}),
|
|
492
531
|
[filter, autoHighlight]
|
|
493
532
|
);
|
|
494
|
-
|
|
533
|
+
useEffect12(() => {
|
|
495
534
|
if (value != null) api.current?.setValue(value);
|
|
496
535
|
}, [value, api]);
|
|
497
536
|
return /* @__PURE__ */ jsx15("div", { ...rest, ref, "data-hl-combobox": true, children });
|
|
@@ -508,16 +547,16 @@ function ComboboxOption({ value, children, ...rest }) {
|
|
|
508
547
|
|
|
509
548
|
// src/Command.tsx
|
|
510
549
|
import {
|
|
511
|
-
useEffect as
|
|
512
|
-
useRef as
|
|
550
|
+
useEffect as useEffect13,
|
|
551
|
+
useRef as useRef7
|
|
513
552
|
} from "react";
|
|
514
553
|
import { enhanceCommand } from "@hydrateless/enhancers";
|
|
515
554
|
import { jsx as jsx16, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
516
555
|
function Command({ hotkey, onSelect, children, ...rest }) {
|
|
517
|
-
const ref =
|
|
518
|
-
const onSelectRef =
|
|
556
|
+
const ref = useRef7(null);
|
|
557
|
+
const onSelectRef = useRef7(onSelect);
|
|
519
558
|
onSelectRef.current = onSelect;
|
|
520
|
-
|
|
559
|
+
useEffect13(() => {
|
|
521
560
|
const el = ref.current;
|
|
522
561
|
if (!el) return;
|
|
523
562
|
const handle = enhanceCommand(el, {
|
|
@@ -683,9 +722,7 @@ function Field({
|
|
|
683
722
|
helpId: `${baseId}-help`,
|
|
684
723
|
errorId: `${baseId}-error`,
|
|
685
724
|
invalid,
|
|
686
|
-
required
|
|
687
|
-
hasHelp: true,
|
|
688
|
-
hasError: invalid
|
|
725
|
+
required
|
|
689
726
|
};
|
|
690
727
|
return /* @__PURE__ */ jsx22(FieldContext.Provider, { value, children: /* @__PURE__ */ jsx22(
|
|
691
728
|
"div",
|
|
@@ -704,7 +741,7 @@ function useFieldContext(component) {
|
|
|
704
741
|
}
|
|
705
742
|
function useField() {
|
|
706
743
|
const ctx = useFieldContext("useField");
|
|
707
|
-
const describedBy = [ctx.
|
|
744
|
+
const describedBy = [ctx.helpId, ctx.invalid ? ctx.errorId : null].filter(Boolean).join(" ");
|
|
708
745
|
return {
|
|
709
746
|
id: ctx.id,
|
|
710
747
|
"aria-describedby": describedBy || void 0,
|
|
@@ -1173,7 +1210,6 @@ export {
|
|
|
1173
1210
|
Tooltip,
|
|
1174
1211
|
cx,
|
|
1175
1212
|
useAccordion,
|
|
1176
|
-
useDisclosureGroup,
|
|
1177
1213
|
useDropdown,
|
|
1178
1214
|
useEnhancer,
|
|
1179
1215
|
useField,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hydrateless/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "React bindings for Hydrateless: hooks and components that wire the framework-agnostic enhancers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"test": "vitest run"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@hydrateless/enhancers": "^0.
|
|
31
|
+
"@hydrateless/enhancers": "^0.8.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"react": ">=18"
|