@hydrateless/react 0.3.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 ADDED
@@ -0,0 +1,91 @@
1
+ # @hydrateless/react
2
+
3
+ React bindings for [Hydrateless](https://github.com/hydrateless/hydrateless). Thin
4
+ hooks and components that render semantic HTML and wire the framework-agnostic
5
+ enhancers, with automatic cleanup on unmount.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install hydrateless @hydrateless/react
11
+ ```
12
+
13
+ Import the CSS once (e.g. in your root):
14
+
15
+ ```ts
16
+ import 'hydrateless/hydrateless.css';
17
+ ```
18
+
19
+ ## Components
20
+
21
+ ```tsx
22
+ import { Tabs, Dropdown, Modal, ToastProvider, useToast } from '@hydrateless/react';
23
+
24
+ function Example() {
25
+ return (
26
+ <Tabs
27
+ items={[
28
+ { label: 'Overview', content: <p>Zero-runtime by default.</p> },
29
+ { label: 'Install', content: <code>npm i hydrateless</code> },
30
+ ]}
31
+ />
32
+ );
33
+ }
34
+ ```
35
+
36
+ Available: `Accordion` / `AccordionItem`, `Disclosure`, `Tabs`, `Dropdown`,
37
+ `Modal`, `Drawer`, `Popover`, `Tooltip`, `Breadcrumb`, `Switch`, `SkipLink`,
38
+ `Toc`, and `ToastProvider` + `useToast`.
39
+
40
+ ### Controlled dialogs
41
+
42
+ `Modal` and `Drawer` are controlled via the `open` prop and built on the native
43
+ `<dialog>` element (focus is contained by the browser's top layer):
44
+
45
+ ```tsx
46
+ const [open, setOpen] = useState(false);
47
+
48
+ <button onClick={() => setOpen(true)}>Open</button>
49
+ <Modal open={open} onClose={() => setOpen(false)} title="Title" footer={<button onClick={() => setOpen(false)}>Close</button>}>
50
+ Body content.
51
+ </Modal>;
52
+ ```
53
+
54
+ ### Toasts
55
+
56
+ ```tsx
57
+ function Save() {
58
+ const toast = useToast();
59
+ return <button onClick={() => toast.show('Saved')}>Save</button>;
60
+ }
61
+
62
+ <ToastProvider>
63
+ <Save />
64
+ </ToastProvider>;
65
+ ```
66
+
67
+ ## Hooks
68
+
69
+ For your own markup, attach any enhancer with a ref. The enhancer's disposer is
70
+ called automatically on unmount:
71
+
72
+ ```tsx
73
+ import { useEnhancer } from '@hydrateless/react';
74
+ import { enhanceTabs } from '@hydrateless/enhancers';
75
+
76
+ function CustomTabs() {
77
+ const ref = useEnhancer<HTMLDivElement>(enhanceTabs);
78
+ return (
79
+ <div data-hl-tabs ref={ref}>
80
+ {/* tablist + tabpanels */}
81
+ </div>
82
+ );
83
+ }
84
+ ```
85
+
86
+ Convenience hooks: `useTabs`, `useDropdown`, `useTooltip`, `useAccordion`,
87
+ `useDisclosureGroup`, `useModalGroup`, `useTocEnhancer`.
88
+
89
+ ## License
90
+
91
+ [MIT](../../LICENSE)
@@ -0,0 +1,183 @@
1
+ import * as react from 'react';
2
+ import { DependencyList, RefObject, HTMLAttributes, ReactNode, ReactElement, InputHTMLAttributes, AnchorHTMLAttributes } from 'react';
3
+ import { Disposer, EnhanceTocOptions, ToastApi } from '@hydrateless/enhancers';
4
+ export { Disposer } from '@hydrateless/enhancers';
5
+
6
+ /**
7
+ * Attach any Hydrateless enhancer to a DOM node for the lifetime of a
8
+ * component. Returns a ref to spread onto the element you want enhanced; the
9
+ * enhancer's disposer is called automatically on unmount (and before re-running
10
+ * when `deps` change), so there are no leaked listeners across renders.
11
+ *
12
+ * ```tsx
13
+ * const ref = useEnhancer<HTMLDivElement>(enhanceTabs);
14
+ * return <div data-hl-tabs ref={ref}>…</div>;
15
+ * ```
16
+ */
17
+ declare function useEnhancer<T extends HTMLElement = HTMLElement>(enhance: (container: HTMLElement) => Disposer, deps?: DependencyList): RefObject<T | null>;
18
+
19
+ /** Ref hook that wires tabs ARIA + keyboard navigation onto a container. */
20
+ declare const useTabs: <T extends HTMLElement = HTMLDivElement>() => react.RefObject<T | null>;
21
+ /** Ref hook that wires a dropdown menu onto a container. */
22
+ declare const useDropdown: <T extends HTMLElement = HTMLDivElement>() => react.RefObject<T | null>;
23
+ /** Ref hook that wires tooltips onto all `[data-hl-tooltip]` triggers inside. */
24
+ declare const useTooltip: <T extends HTMLElement = HTMLElement>() => react.RefObject<T | null>;
25
+ /** Ref hook that enforces single-open accordion behavior on a container. */
26
+ declare const useAccordion: <T extends HTMLElement = HTMLDivElement>(allowMultiple?: boolean) => react.RefObject<T | null>;
27
+ /** Ref hook that groups `[data-hl-disclosure]` elements for mutual exclusivity. */
28
+ declare const useDisclosureGroup: <T extends HTMLElement = HTMLElement>(allowMultiple?: boolean) => react.RefObject<T | null>;
29
+ /** Ref hook that wires modal openers/closers + focus trap within a container. */
30
+ declare const useModalGroup: <T extends HTMLElement = HTMLElement>(closeOnBackdrop?: boolean) => react.RefObject<T | null>;
31
+ /** Ref hook that builds a table of contents from the surrounding document. */
32
+ declare const useTocEnhancer: <T extends HTMLElement = HTMLElement>(options?: EnhanceTocOptions) => react.RefObject<T | null>;
33
+
34
+ interface AccordionProps extends HTMLAttributes<HTMLDivElement> {
35
+ /** Allow more than one panel to stay open at a time. */
36
+ allowMultiple?: boolean;
37
+ }
38
+ declare function Accordion({ allowMultiple, children, ...rest }: AccordionProps): react.JSX.Element;
39
+ interface AccordionItemProps extends Omit<HTMLAttributes<HTMLDetailsElement>, 'title'> {
40
+ summary: ReactNode;
41
+ defaultOpen?: boolean;
42
+ }
43
+ declare function AccordionItem({ summary, defaultOpen, children, ...rest }: AccordionItemProps): react.JSX.Element;
44
+
45
+ interface DisclosureProps extends Omit<HTMLAttributes<HTMLDetailsElement>, 'title'> {
46
+ summary: ReactNode;
47
+ defaultOpen?: boolean;
48
+ }
49
+ /**
50
+ * A single expandable section. Purely presentational — native `<details>`
51
+ * handles open/close, so no enhancer is required for a lone disclosure. Use
52
+ * `useEnhancer(enhanceDisclosure)` on a wrapper if you need a mutually
53
+ * exclusive group.
54
+ */
55
+ declare function Disclosure({ summary, defaultOpen, children, ...rest }: DisclosureProps): react.JSX.Element;
56
+
57
+ interface TabItem {
58
+ label: ReactNode;
59
+ content: ReactNode;
60
+ }
61
+ interface TabsProps extends HTMLAttributes<HTMLDivElement> {
62
+ items: TabItem[];
63
+ }
64
+ /**
65
+ * Tabbed interface. The enhancer wires ARIA roles, roving tabindex, and arrow
66
+ * key navigation once the markup is rendered.
67
+ */
68
+ declare function Tabs({ items, ...rest }: TabsProps): react.JSX.Element;
69
+
70
+ interface DropdownItem {
71
+ label: ReactNode;
72
+ onSelect?: () => void;
73
+ separator?: boolean;
74
+ disabled?: boolean;
75
+ }
76
+ interface DropdownProps extends HTMLAttributes<HTMLDivElement> {
77
+ trigger: ReactNode;
78
+ items: DropdownItem[];
79
+ }
80
+ /**
81
+ * Button-triggered menu following the WAI-ARIA menu pattern. The enhancer adds
82
+ * keyboard navigation, typeahead, and `aria-expanded`/`role` wiring.
83
+ */
84
+ declare function Dropdown({ trigger, items, ...rest }: DropdownProps): react.JSX.Element;
85
+
86
+ interface ModalProps extends Omit<HTMLAttributes<HTMLDialogElement>, 'title' | 'onClick'> {
87
+ open: boolean;
88
+ onClose?: () => void;
89
+ title?: ReactNode;
90
+ footer?: ReactNode;
91
+ closeOnBackdrop?: boolean;
92
+ }
93
+ /**
94
+ * Controlled dialog overlay. Driven by the `open` prop via the native
95
+ * `<dialog>` element, which provides focus containment in the top layer. Wire
96
+ * `onClose` so Escape and backdrop clicks can update your state.
97
+ */
98
+ declare function Modal({ open, onClose, title, footer, closeOnBackdrop, className, children, ...rest }: ModalProps): react.JSX.Element;
99
+
100
+ interface DrawerProps extends Omit<HTMLAttributes<HTMLDialogElement>, 'title' | 'onClick'> {
101
+ open: boolean;
102
+ onClose?: () => void;
103
+ side?: 'left' | 'right';
104
+ title?: ReactNode;
105
+ footer?: ReactNode;
106
+ closeOnBackdrop?: boolean;
107
+ }
108
+ /**
109
+ * Controlled off-canvas panel built on the native `<dialog>` element. Mirrors
110
+ * {@link Modal} but slides in from the chosen `side`.
111
+ */
112
+ declare function Drawer({ open, onClose, side, title, footer, closeOnBackdrop, className, children, ...rest }: DrawerProps): react.JSX.Element;
113
+
114
+ interface PopoverProps extends HTMLAttributes<HTMLDivElement> {
115
+ open: boolean;
116
+ children?: ReactNode;
117
+ }
118
+ /**
119
+ * Controlled floating content. Visibility follows the `open` prop. Pair it with
120
+ * your own trigger button (toggling `open`) and position it with the
121
+ * `hydrateless/popover.css` styles.
122
+ */
123
+ declare function Popover({ open, children, ...rest }: PopoverProps): react.JSX.Element;
124
+
125
+ interface TooltipProps {
126
+ /** The hint text shown on hover/focus. */
127
+ label: ReactNode;
128
+ /** A single focusable element that triggers the tooltip. */
129
+ children: ReactElement;
130
+ id?: string;
131
+ }
132
+ /**
133
+ * Adds an accessible tooltip to a focusable trigger. The enhancer toggles the
134
+ * tip on hover/focus and dismisses it on Escape.
135
+ */
136
+ declare function Tooltip({ label, children, id }: TooltipProps): react.JSX.Element;
137
+
138
+ interface BreadcrumbItem {
139
+ label: ReactNode;
140
+ href?: string;
141
+ current?: boolean;
142
+ }
143
+ interface BreadcrumbProps extends HTMLAttributes<HTMLElement> {
144
+ items: BreadcrumbItem[];
145
+ }
146
+ /** Semantic breadcrumb navigation (`<nav> > <ol>`). CSS-only, no enhancer. */
147
+ declare function Breadcrumb({ items, ...rest }: BreadcrumbProps): react.JSX.Element;
148
+
149
+ interface SwitchProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
150
+ children?: ReactNode;
151
+ }
152
+ /** Toggle switch built on a native checkbox. CSS-only. */
153
+ declare function Switch({ children, className, ...rest }: SwitchProps): react.JSX.Element;
154
+
155
+ type SkipLinkProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
156
+ children?: ReactNode;
157
+ };
158
+ /** Accessibility skip-navigation link, visually hidden until focused. */
159
+ declare function SkipLink({ children, className, ...rest }: SkipLinkProps): react.JSX.Element;
160
+
161
+ interface TocProps extends HTMLAttributes<HTMLElement> {
162
+ /** CSS selector for the content root to scan for headings. */
163
+ contentSelector?: string;
164
+ /** Comma-separated heading selector, e.g. `"h2,h3"`. */
165
+ headings?: string;
166
+ /** Highlight the current section while scrolling. */
167
+ scrollSpy?: boolean;
168
+ }
169
+ /** Auto-generated table of contents with optional scroll-spy. */
170
+ declare function Toc({ contentSelector, headings, scrollSpy, ...rest }: TocProps): react.JSX.Element;
171
+
172
+ interface ToastProviderProps {
173
+ children?: ReactNode;
174
+ }
175
+ /**
176
+ * Provides a toast region and exposes the imperative toast API via
177
+ * {@link useToast}. Render once near the root of your app.
178
+ */
179
+ declare function ToastProvider({ children }: ToastProviderProps): react.JSX.Element;
180
+ /** Access the toast API. Must be called within a {@link ToastProvider}. */
181
+ declare function useToast(): ToastApi;
182
+
183
+ export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, Breadcrumb, type BreadcrumbItem, type BreadcrumbProps, Disclosure, type DisclosureProps, Drawer, type DrawerProps, Dropdown, type DropdownItem, type DropdownProps, Modal, type ModalProps, Popover, type PopoverProps, SkipLink, type SkipLinkProps, Switch, type SwitchProps, type TabItem, Tabs, type TabsProps, ToastProvider, type ToastProviderProps, Toc, type TocProps, Tooltip, type TooltipProps, useAccordion, useDisclosureGroup, useDropdown, useEnhancer, useModalGroup, useTabs, useToast, useTocEnhancer, useTooltip };
package/dist/index.js ADDED
@@ -0,0 +1,340 @@
1
+ // src/useEnhancer.ts
2
+ import { useEffect, useRef } from "react";
3
+ function useEnhancer(enhance, deps = []) {
4
+ const ref = useRef(null);
5
+ useEffect(() => {
6
+ const el = ref.current;
7
+ if (!el) return;
8
+ return enhance(el);
9
+ }, deps);
10
+ return ref;
11
+ }
12
+
13
+ // src/hooks.ts
14
+ import {
15
+ enhanceAccordion,
16
+ enhanceDisclosure,
17
+ enhanceDropdown,
18
+ enhanceModal,
19
+ enhanceTabs,
20
+ enhanceToc,
21
+ enhanceTooltip
22
+ } from "@hydrateless/enhancers";
23
+ var useTabs = () => useEnhancer((el) => enhanceTabs(el));
24
+ var useDropdown = () => useEnhancer((el) => enhanceDropdown(el));
25
+ var useTooltip = () => useEnhancer((el) => enhanceTooltip(el));
26
+ var useAccordion = (allowMultiple = false) => useEnhancer((el) => enhanceAccordion(el, { allowMultiple }), [allowMultiple]);
27
+ var useDisclosureGroup = (allowMultiple = false) => useEnhancer((el) => enhanceDisclosure(el, { allowMultiple }), [allowMultiple]);
28
+ var useModalGroup = (closeOnBackdrop = true) => useEnhancer((el) => enhanceModal(el, { closeOnBackdrop }), [closeOnBackdrop]);
29
+ var useTocEnhancer = (options) => useEnhancer(
30
+ (el) => enhanceToc(el.ownerDocument, options),
31
+ [options?.contentSelector, options?.headings, options?.scrollSpy]
32
+ );
33
+
34
+ // src/Accordion.tsx
35
+ import { useEffect as useEffect2, useRef as useRef2 } from "react";
36
+ import { enhanceAccordion as enhanceAccordion2 } from "@hydrateless/enhancers";
37
+ import { jsx, jsxs } from "react/jsx-runtime";
38
+ function Accordion({ allowMultiple = false, children, ...rest }) {
39
+ const ref = useRef2(null);
40
+ useEffect2(() => {
41
+ if (!ref.current) return;
42
+ return enhanceAccordion2(ref.current, { allowMultiple });
43
+ }, [allowMultiple]);
44
+ return /* @__PURE__ */ jsx("div", { ...rest, "data-hl-accordion": true, ref, children });
45
+ }
46
+ function AccordionItem({
47
+ summary,
48
+ defaultOpen = false,
49
+ children,
50
+ ...rest
51
+ }) {
52
+ const ref = useRef2(null);
53
+ useEffect2(() => {
54
+ if (ref.current && defaultOpen) ref.current.open = true;
55
+ }, [defaultOpen]);
56
+ return /* @__PURE__ */ jsxs("details", { ...rest, ref, children: [
57
+ /* @__PURE__ */ jsx("summary", { children: summary }),
58
+ /* @__PURE__ */ jsx("div", { className: "accordion-panel", children })
59
+ ] });
60
+ }
61
+
62
+ // src/Disclosure.tsx
63
+ import { useEffect as useEffect3, useRef as useRef3 } from "react";
64
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
65
+ function Disclosure({ summary, defaultOpen = false, children, ...rest }) {
66
+ const ref = useRef3(null);
67
+ useEffect3(() => {
68
+ if (ref.current && defaultOpen) ref.current.open = true;
69
+ }, [defaultOpen]);
70
+ return /* @__PURE__ */ jsxs2("details", { ...rest, className: "hydrateless-disclosure", "data-hl-disclosure": true, ref, children: [
71
+ /* @__PURE__ */ jsx2("summary", { children: summary }),
72
+ /* @__PURE__ */ jsx2("div", { className: "disclosure-panel", children })
73
+ ] });
74
+ }
75
+
76
+ // src/Tabs.tsx
77
+ import { useEffect as useEffect4, useRef as useRef4 } from "react";
78
+ 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);
82
+ 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
+ ] });
90
+ }
91
+
92
+ // 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);
98
+ useEffect5(() => {
99
+ 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
+ ) })
116
+ ] });
117
+ }
118
+
119
+ // 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";
122
+ function Modal({
123
+ open,
124
+ onClose,
125
+ title,
126
+ footer,
127
+ closeOnBackdrop = true,
128
+ className,
129
+ children,
130
+ ...rest
131
+ }) {
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
+ }
162
+ );
163
+ }
164
+
165
+ // 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";
168
+ function Drawer({
169
+ open,
170
+ onClose,
171
+ side = "right",
172
+ title,
173
+ footer,
174
+ closeOnBackdrop = true,
175
+ className,
176
+ children,
177
+ ...rest
178
+ }) {
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(
197
+ "dialog",
198
+ {
199
+ ...rest,
200
+ ref,
201
+ "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
+ ]
209
+ }
210
+ );
211
+ }
212
+
213
+ // 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 });
217
+ }
218
+
219
+ // src/Tooltip.tsx
220
+ import {
221
+ cloneElement,
222
+ isValidElement,
223
+ useEffect as useEffect8,
224
+ useId,
225
+ useRef as useRef8
226
+ } from "react";
227
+ import { enhanceTooltip as enhanceTooltip2 } from "@hydrateless/enhancers";
228
+ import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
229
+ function Tooltip({ label, children, id }) {
230
+ const generatedId = useId().replace(/:/g, "");
231
+ const tipId = id ?? `hl-tip-${generatedId}`;
232
+ const ref = useRef8(null);
233
+ useEffect8(() => {
234
+ if (!ref.current) return;
235
+ return enhanceTooltip2(ref.current);
236
+ }, [tipId]);
237
+ const trigger = isValidElement(children) ? cloneElement(children, {
238
+ "data-hl-tooltip": tipId,
239
+ "aria-describedby": tipId
240
+ }) : children;
241
+ return /* @__PURE__ */ jsxs7("span", { ref, style: { position: "relative", display: "inline-block" }, children: [
242
+ trigger,
243
+ /* @__PURE__ */ jsx8("span", { id: tipId, role: "tooltip", hidden: true, children: label })
244
+ ] });
245
+ }
246
+
247
+ // 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)) }) });
251
+ }
252
+
253
+ // src/Switch.tsx
254
+ import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
255
+ 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 }),
258
+ children
259
+ ] });
260
+ }
261
+
262
+ // src/SkipLink.tsx
263
+ import { jsx as jsx11 } from "react/jsx-runtime";
264
+ function SkipLink({ children = "Skip to content", className, ...rest }) {
265
+ return /* @__PURE__ */ jsx11("a", { ...rest, className: ["a11y-skip-link", className].filter(Boolean).join(" "), children });
266
+ }
267
+
268
+ // src/Toc.tsx
269
+ import { useEffect as useEffect9, useRef as useRef9 } from "react";
270
+ import { enhanceToc as enhanceToc2 } from "@hydrateless/enhancers";
271
+ import { jsx as jsx12 } from "react/jsx-runtime";
272
+ function Toc({ contentSelector, headings, scrollSpy, ...rest }) {
273
+ const ref = useRef9(null);
274
+ useEffect9(() => {
275
+ if (!ref.current) return;
276
+ return enhanceToc2(ref.current.ownerDocument, { contentSelector, headings, scrollSpy });
277
+ }, [contentSelector, headings, scrollSpy]);
278
+ return /* @__PURE__ */ jsx12("nav", { ...rest, "data-hl-toc": true, ref });
279
+ }
280
+
281
+ // src/Toast.tsx
282
+ import { createContext, useContext, useEffect as useEffect10, useRef as useRef10 } from "react";
283
+ 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;
299
+ return () => {
300
+ api.destroy();
301
+ apiRef.current = null;
302
+ };
303
+ }, []);
304
+ return /* @__PURE__ */ jsxs9(ToastContext.Provider, { value: facade.current, children: [
305
+ children,
306
+ /* @__PURE__ */ jsx13("div", { "data-hl-toast-region": true, ref: regionRef })
307
+ ] });
308
+ }
309
+ 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
+ export {
317
+ Accordion,
318
+ AccordionItem,
319
+ Breadcrumb,
320
+ Disclosure,
321
+ Drawer,
322
+ Dropdown,
323
+ Modal,
324
+ Popover,
325
+ SkipLink,
326
+ Switch,
327
+ Tabs,
328
+ ToastProvider,
329
+ Toc,
330
+ Tooltip,
331
+ useAccordion,
332
+ useDisclosureGroup,
333
+ useDropdown,
334
+ useEnhancer,
335
+ useModalGroup,
336
+ useTabs,
337
+ useToast,
338
+ useTocEnhancer,
339
+ useTooltip
340
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@hydrateless/react",
3
+ "version": "0.3.0",
4
+ "description": "React bindings for Hydrateless — hooks and components that wire the framework-agnostic enhancers.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/hydrateless/hydrateless.git",
9
+ "directory": "packages/react"
10
+ },
11
+ "type": "module",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "sideEffects": false,
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ }
21
+ },
22
+ "types": "./dist/index.d.ts",
23
+ "scripts": {
24
+ "build": "tsup src/index.ts --dts --format esm --clean --external react",
25
+ "dev": "npm run build -- --watch",
26
+ "typecheck": "tsc -p tsconfig.json --noEmit",
27
+ "lint": "eslint \"src/**/*.{ts,tsx}\"",
28
+ "test": "vitest run"
29
+ },
30
+ "dependencies": {
31
+ "@hydrateless/enhancers": "^0.3.0"
32
+ },
33
+ "peerDependencies": {
34
+ "react": ">=18"
35
+ },
36
+ "devDependencies": {
37
+ "@testing-library/dom": "^10.4.0",
38
+ "@testing-library/react": "^16.1.0",
39
+ "@types/react": "^19.0.0",
40
+ "@types/react-dom": "^19.0.0",
41
+ "jsdom": "^29.0.0",
42
+ "react": "^19.0.0",
43
+ "react-dom": "^19.0.0",
44
+ "vitest": "^4.1.0"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }