@hydrateless/react 0.5.0 → 0.7.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 CHANGED
@@ -10,7 +10,7 @@ enhancers, with automatic cleanup on unmount.
10
10
  npm install hydrateless @hydrateless/react
11
11
  ```
12
12
 
13
- Import the CSS once (e.g. in your root):
13
+ Import the CSS once (e.g., in your root):
14
14
 
15
15
  ```ts
16
16
  import 'hydrateless/hydrateless.css';
@@ -19,62 +19,68 @@ import 'hydrateless/hydrateless.css';
19
19
  ## Components
20
20
 
21
21
  ```tsx
22
- import { Tabs, Dropdown, Modal, ToastProvider, useToast } from '@hydrateless/react';
22
+ import { Tabs, TabList, Tab, TabPanel } from '@hydrateless/react';
23
23
 
24
24
  function Example() {
25
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
- />
26
+ <Tabs defaultValue="overview">
27
+ <TabList>
28
+ <Tab value="overview">Overview</Tab>
29
+ <Tab value="install">Install</Tab>
30
+ </TabList>
31
+ <TabPanel>Zero runtime by default.</TabPanel>
32
+ <TabPanel>
33
+ <code>npm i hydrateless</code>
34
+ </TabPanel>
35
+ </Tabs>
32
36
  );
33
37
  }
34
38
  ```
35
39
 
36
- Available: `Accordion` / `AccordionItem`, `Disclosure`, `Tabs`, `Dropdown`,
37
- `Modal`, `Drawer`, `Popover`, `Tooltip`, `Breadcrumb`, `Switch`, `SkipLink`,
38
- `Toc`, and `ToastProvider` + `useToast`.
40
+ Interactive components work uncontrolled (`defaultValue` / `defaultOpen`) or
41
+ fully controlled (`value` + `onValueChange`, `open` + `onOpenChange`).
39
42
 
40
43
  ### Controlled dialogs
41
44
 
42
45
  `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):
46
+ `<dialog>` element plus the modal enhancer (focus trap, scroll-lock, background
47
+ `inert`). Escape and backdrop clicks report back through `onOpenChange`:
44
48
 
45
49
  ```tsx
46
50
  const [open, setOpen] = useState(false);
47
51
 
48
52
  <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.
53
+ <Modal open={open} onOpenChange={setOpen}>
54
+ <ModalHeader>Title</ModalHeader>
55
+ <ModalBody>Body content.</ModalBody>
56
+ <ModalFooter><button onClick={() => setOpen(false)}>Close</button></ModalFooter>
51
57
  </Modal>;
52
58
  ```
53
59
 
54
60
  ### Toasts
55
61
 
62
+ `useToast()` works anywhere, no provider required. Render `<ToastRegion />`
63
+ once if you want to control where toasts appear:
64
+
56
65
  ```tsx
57
66
  function Save() {
58
67
  const toast = useToast();
59
- return <button onClick={() => toast.show('Saved')}>Save</button>;
68
+ return <button onClick={() => toast.show('Saved', { variant: 'success' })}>Save</button>;
60
69
  }
61
-
62
- <ToastProvider>
63
- <Save />
64
- </ToastProvider>;
65
70
  ```
66
71
 
67
72
  ## Hooks
68
73
 
69
- For your own markup, attach any enhancer with a ref. The enhancer's disposer is
70
- called automatically on unmount:
74
+ For your own markup, attach any enhancer with a ref. You get the enhancer's
75
+ imperative API back, and the instance is destroyed automatically on unmount:
71
76
 
72
77
  ```tsx
73
78
  import { useEnhancer } from '@hydrateless/react';
74
- import { enhanceTabs } from '@hydrateless/enhancers';
79
+ import { enhanceTabs, type TabsApi } from '@hydrateless/enhancers';
75
80
 
76
81
  function CustomTabs() {
77
- const ref = useEnhancer<HTMLDivElement>(enhanceTabs);
82
+ const { ref, api } = useEnhancer<HTMLDivElement, TabsApi>((el) => enhanceTabs(el));
83
+ // api.current?.setValue('install')
78
84
  return (
79
85
  <div data-hl-tabs ref={ref}>
80
86
  {/* tablist + tabpanels */}