@hydrateless/react 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -22
- package/dist/index.d.ts +315 -117
- package/dist/index.js +435 -310
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,62 +19,68 @@ import 'hydrateless/hydrateless.css';
|
|
|
19
19
|
## Components
|
|
20
20
|
|
|
21
21
|
```tsx
|
|
22
|
-
import { Tabs,
|
|
22
|
+
import { Tabs, TabList, Tab, TabPanel } from '@hydrateless/react';
|
|
23
23
|
|
|
24
24
|
function Example() {
|
|
25
25
|
return (
|
|
26
|
-
<Tabs
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
|
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}
|
|
50
|
-
|
|
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.
|
|
70
|
-
|
|
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 */}
|