@hydrateless/svelte 0.8.0 → 0.9.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 +173 -38
- package/dist/components/Accordion.svelte +28 -17
- package/dist/components/Accordion.svelte.d.ts +3 -0
- package/dist/components/AccordionItem.svelte +17 -11
- package/dist/components/AccordionItem.svelte.d.ts +5 -3
- package/dist/components/Alert.svelte +4 -0
- package/dist/components/Alert.svelte.d.ts +4 -0
- package/dist/components/Avatar.svelte +5 -0
- package/dist/components/Avatar.svelte.d.ts +5 -0
- package/dist/components/AvatarGroup.svelte +1 -0
- package/dist/components/AvatarGroup.svelte.d.ts +1 -0
- package/dist/components/Badge.svelte +4 -0
- package/dist/components/Badge.svelte.d.ts +4 -0
- package/dist/components/Breadcrumb.svelte +1 -0
- package/dist/components/Breadcrumb.svelte.d.ts +1 -0
- package/dist/components/BreadcrumbItem.svelte +3 -0
- package/dist/components/BreadcrumbItem.svelte.d.ts +3 -0
- package/dist/components/Button.svelte +7 -0
- package/dist/components/Button.svelte.d.ts +7 -0
- package/dist/components/Card.svelte +2 -0
- package/dist/components/Card.svelte.d.ts +2 -0
- package/dist/components/CardBody.svelte +1 -0
- package/dist/components/CardBody.svelte.d.ts +1 -0
- package/dist/components/CardDescription.svelte +1 -0
- package/dist/components/CardDescription.svelte.d.ts +1 -0
- package/dist/components/CardFooter.svelte +1 -0
- package/dist/components/CardFooter.svelte.d.ts +1 -0
- package/dist/components/CardHeader.svelte +1 -0
- package/dist/components/CardHeader.svelte.d.ts +1 -0
- package/dist/components/CardTitle.svelte +1 -0
- package/dist/components/CardTitle.svelte.d.ts +1 -0
- package/dist/components/Checkbox.svelte +24 -2
- package/dist/components/Checkbox.svelte.d.ts +2 -0
- package/dist/components/Combobox.svelte +37 -26
- package/dist/components/Combobox.svelte.d.ts +12 -3
- package/dist/components/ComboboxInput.svelte +21 -2
- package/dist/components/ComboboxInput.svelte.d.ts +1 -0
- package/dist/components/ComboboxList.svelte +4 -1
- package/dist/components/ComboboxList.svelte.d.ts +1 -0
- package/dist/components/ComboboxOption.svelte +6 -2
- package/dist/components/ComboboxOption.svelte.d.ts +4 -0
- package/dist/components/Command.svelte +36 -9
- package/dist/components/Command.svelte.d.ts +12 -5
- package/dist/components/CommandEmpty.svelte +1 -0
- package/dist/components/CommandEmpty.svelte.d.ts +1 -0
- package/dist/components/CommandGroup.svelte +1 -0
- package/dist/components/CommandGroup.svelte.d.ts +1 -0
- package/dist/components/CommandItem.svelte +2 -0
- package/dist/components/CommandItem.svelte.d.ts +2 -0
- package/dist/components/CommandList.svelte +1 -0
- package/dist/components/CommandList.svelte.d.ts +1 -0
- package/dist/components/Disclosure.svelte +29 -19
- package/dist/components/Disclosure.svelte.d.ts +6 -1
- package/dist/components/Drawer.svelte +26 -20
- package/dist/components/Drawer.svelte.d.ts +6 -1
- package/dist/components/DrawerBody.svelte +1 -0
- package/dist/components/DrawerBody.svelte.d.ts +1 -0
- package/dist/components/DrawerFooter.svelte +1 -0
- package/dist/components/DrawerFooter.svelte.d.ts +1 -0
- package/dist/components/DrawerHeader.svelte +1 -0
- package/dist/components/DrawerHeader.svelte.d.ts +1 -0
- package/dist/components/Dropdown.svelte +45 -24
- package/dist/components/Dropdown.svelte.d.ts +13 -2
- package/dist/components/DropdownGroup.svelte +19 -0
- package/dist/components/DropdownGroup.svelte.d.ts +11 -0
- package/dist/components/DropdownItem.svelte +28 -4
- package/dist/components/DropdownItem.svelte.d.ts +11 -2
- package/dist/components/DropdownMenu.svelte +14 -2
- package/dist/components/DropdownMenu.svelte.d.ts +1 -0
- package/dist/components/DropdownSeparator.svelte +3 -2
- package/dist/components/DropdownTrigger.svelte +14 -2
- package/dist/components/DropdownTrigger.svelte.d.ts +1 -0
- package/dist/components/Field.svelte +42 -3
- package/dist/components/Field.svelte.d.ts +16 -0
- package/dist/components/FieldError.svelte +4 -3
- package/dist/components/FieldError.svelte.d.ts +1 -0
- package/dist/components/FieldHelp.svelte +4 -3
- package/dist/components/FieldHelp.svelte.d.ts +1 -0
- package/dist/components/FieldLabel.svelte +4 -3
- package/dist/components/FieldLabel.svelte.d.ts +1 -0
- package/dist/components/Fieldset.svelte +2 -0
- package/dist/components/Fieldset.svelte.d.ts +2 -0
- package/dist/components/Input.svelte +22 -6
- package/dist/components/Input.svelte.d.ts +3 -0
- package/dist/components/Kbd.svelte +1 -0
- package/dist/components/Kbd.svelte.d.ts +1 -0
- package/dist/components/Menu.svelte +36 -23
- package/dist/components/Menu.svelte.d.ts +18 -5
- package/dist/components/MenuItem.svelte +46 -18
- package/dist/components/MenuItem.svelte.d.ts +10 -7
- package/dist/components/MenuSubmenu.svelte +30 -0
- package/dist/components/MenuSubmenu.svelte.d.ts +17 -0
- package/dist/components/Modal.svelte +17 -18
- package/dist/components/Modal.svelte.d.ts +4 -0
- package/dist/components/ModalBody.svelte +1 -0
- package/dist/components/ModalBody.svelte.d.ts +1 -0
- package/dist/components/ModalFooter.svelte +1 -0
- package/dist/components/ModalFooter.svelte.d.ts +1 -0
- package/dist/components/ModalHeader.svelte +1 -0
- package/dist/components/ModalHeader.svelte.d.ts +1 -0
- package/dist/components/Pagination.svelte +5 -0
- package/dist/components/Pagination.svelte.d.ts +5 -0
- package/dist/components/Popover.svelte +37 -20
- package/dist/components/Popover.svelte.d.ts +12 -2
- package/dist/components/Progress.svelte +4 -0
- package/dist/components/Progress.svelte.d.ts +4 -0
- package/dist/components/Radio.svelte +2 -0
- package/dist/components/Radio.svelte.d.ts +2 -0
- package/dist/components/RadioGroup.svelte +34 -4
- package/dist/components/RadioGroup.svelte.d.ts +10 -1
- package/dist/components/SegmentedControl.svelte +25 -10
- package/dist/components/SegmentedControl.svelte.d.ts +11 -3
- package/dist/components/Select.svelte +16 -5
- package/dist/components/Select.svelte.d.ts +4 -0
- package/dist/components/Separator.svelte +2 -0
- package/dist/components/Separator.svelte.d.ts +2 -0
- package/dist/components/Skeleton.svelte +6 -3
- package/dist/components/Skeleton.svelte.d.ts +4 -1
- package/dist/components/SkipLink.svelte +1 -0
- package/dist/components/SkipLink.svelte.d.ts +1 -0
- package/dist/components/Slider.svelte +23 -2
- package/dist/components/Slider.svelte.d.ts +1 -0
- package/dist/components/Spinner.svelte +2 -0
- package/dist/components/Spinner.svelte.d.ts +2 -0
- package/dist/components/Switch.svelte +25 -2
- package/dist/components/Switch.svelte.d.ts +2 -0
- package/dist/components/Tab.svelte +16 -2
- package/dist/components/Tab.svelte.d.ts +1 -0
- package/dist/components/TabList.svelte +1 -0
- package/dist/components/TabList.svelte.d.ts +1 -0
- package/dist/components/TabPanel.svelte +8 -1
- package/dist/components/TabPanel.svelte.d.ts +1 -0
- package/dist/components/Table.svelte +30 -0
- package/dist/components/Table.svelte.d.ts +17 -0
- package/dist/components/Tabs.svelte +41 -19
- package/dist/components/Tabs.svelte.d.ts +6 -1
- package/dist/components/Textarea.svelte +26 -6
- package/dist/components/Textarea.svelte.d.ts +5 -0
- package/dist/components/ToastRegion.svelte +18 -2
- package/dist/components/ToastRegion.svelte.d.ts +8 -1
- package/dist/components/Toc.svelte +19 -8
- package/dist/components/Toc.svelte.d.ts +6 -0
- package/dist/components/Tooltip.svelte +57 -19
- package/dist/components/Tooltip.svelte.d.ts +16 -7
- package/dist/context.d.ts +84 -8
- package/dist/context.js +60 -11
- package/dist/index.d.ts +8 -4
- package/dist/index.js +6 -4
- package/dist/toast.d.ts +12 -7
- package/dist/toast.js +20 -11
- package/dist/useEnhancer.svelte.d.ts +40 -0
- package/dist/useEnhancer.svelte.js +58 -0
- package/package.json +4 -4
- package/dist/actions.d.ts +0 -25
- package/dist/actions.js +0 -31
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# @hydrateless/svelte
|
|
2
2
|
|
|
3
|
-
Svelte bindings for [Hydrateless](https://github.com/hydrateless/hydrateless)
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Svelte 5 bindings for [Hydrateless](https://github.com/hydrateless/hydrateless):
|
|
4
|
+
components built on runes and attachments that render the same semantic markup
|
|
5
|
+
as the CSS package and hand behavior to the framework-agnostic enhancers on the
|
|
6
|
+
client. Everything server-renders, and the enhancers are no-ops without a DOM.
|
|
6
7
|
|
|
7
8
|
## Install
|
|
8
9
|
|
|
@@ -10,45 +11,19 @@ automatically when the element is destroyed.
|
|
|
10
11
|
npm install hydrateless @hydrateless/svelte
|
|
11
12
|
```
|
|
12
13
|
|
|
13
|
-
Import the CSS once (
|
|
14
|
+
Import the CSS once (for example, in your root layout):
|
|
14
15
|
|
|
15
16
|
```ts
|
|
16
17
|
import 'hydrateless/hydrateless.css';
|
|
17
18
|
```
|
|
18
19
|
|
|
19
|
-
## Actions
|
|
20
|
-
|
|
21
|
-
```svelte
|
|
22
|
-
<script lang="ts">
|
|
23
|
-
import { tabs, dropdown } from '@hydrateless/svelte';
|
|
24
|
-
</script>
|
|
25
|
-
|
|
26
|
-
<div use:tabs data-hl-tabs>
|
|
27
|
-
<div role="tablist">
|
|
28
|
-
<button role="tab">Overview</button>
|
|
29
|
-
<button role="tab">Install</button>
|
|
30
|
-
</div>
|
|
31
|
-
<div role="tabpanel">Zero runtime by default.</div>
|
|
32
|
-
<div role="tabpanel"><code>npm i hydrateless</code></div>
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
<div use:dropdown data-hl-dropdown>
|
|
36
|
-
<button data-hl-dropdown-trigger>Actions</button>
|
|
37
|
-
<ul data-hl-dropdown-menu>
|
|
38
|
-
<li><button role="menuitem">Edit</button></li>
|
|
39
|
-
<li><button role="menuitem">Delete</button></li>
|
|
40
|
-
</ul>
|
|
41
|
-
</div>
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Available actions: `accordion`, `disclosure`, `tabs`, `dropdown`, `modal`,
|
|
45
|
-
`drawer`, `popover`, `tooltip`, `toc`. For container-scoped components (modal,
|
|
46
|
-
drawer, popover, tooltip) put the action on a wrapper that contains the trigger
|
|
47
|
-
and target.
|
|
48
|
-
|
|
49
20
|
## Components
|
|
50
21
|
|
|
51
|
-
Interactive components
|
|
22
|
+
Interactive components are controlled or uncontrolled. Bind the primary state
|
|
23
|
+
(`bind:value`, `bind:open`, `bind:query`), seed it with `defaultValue`,
|
|
24
|
+
`defaultOpen`, or `defaultQuery`, and observe it through `onValueChange`,
|
|
25
|
+
`onOpenChange`, or `onQueryChange`. Every component forwards `class`, `id`, and
|
|
26
|
+
the rest of its attributes to its root element.
|
|
52
27
|
|
|
53
28
|
```svelte
|
|
54
29
|
<script lang="ts">
|
|
@@ -73,20 +48,180 @@ Interactive components support two-way binding on their state:
|
|
|
73
48
|
</Modal>
|
|
74
49
|
```
|
|
75
50
|
|
|
51
|
+
Tabs, Accordion, and Disclosure render their selected or open state on the
|
|
52
|
+
server (`aria-selected`, `hidden`, `open`), so nothing flashes before the
|
|
53
|
+
enhancer hydrates.
|
|
54
|
+
|
|
55
|
+
### Dropdown
|
|
56
|
+
|
|
57
|
+
The menu is a native `popover` and the trigger carries a matching
|
|
58
|
+
`popovertarget`, so the menu opens before any script runs. Items can be plain
|
|
59
|
+
actions, checkboxes, or radios; group radios with `<DropdownGroup>`.
|
|
60
|
+
|
|
61
|
+
```svelte
|
|
62
|
+
<script lang="ts">
|
|
63
|
+
import {
|
|
64
|
+
Dropdown,
|
|
65
|
+
DropdownTrigger,
|
|
66
|
+
DropdownMenu,
|
|
67
|
+
DropdownItem,
|
|
68
|
+
DropdownGroup,
|
|
69
|
+
DropdownSeparator,
|
|
70
|
+
} from '@hydrateless/svelte';
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<Dropdown closeOnSelect={false} onSelect={(value, item, checked) => console.log(value, checked)}>
|
|
74
|
+
<DropdownTrigger>View</DropdownTrigger>
|
|
75
|
+
<DropdownMenu>
|
|
76
|
+
<DropdownItem value="refresh">Refresh</DropdownItem>
|
|
77
|
+
<DropdownSeparator />
|
|
78
|
+
<DropdownGroup label="Density">
|
|
79
|
+
<DropdownItem role="menuitemradio" value="compact" checked>Compact</DropdownItem>
|
|
80
|
+
<DropdownItem role="menuitemradio" value="comfortable">Comfortable</DropdownItem>
|
|
81
|
+
</DropdownGroup>
|
|
82
|
+
<DropdownItem role="menuitemcheckbox" value="grid">Show grid</DropdownItem>
|
|
83
|
+
</DropdownMenu>
|
|
84
|
+
</Dropdown>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Menu
|
|
88
|
+
|
|
89
|
+
`<Menu>` is a menubar (or a vertical menu) whose value is the open submenu:
|
|
90
|
+
`bind:value` gives you a `string | null`. Nest items in `<MenuSubmenu>`.
|
|
91
|
+
|
|
92
|
+
```svelte
|
|
93
|
+
<Menu bind:value={openSubmenu} onSelect={(value) => navigate(value)}>
|
|
94
|
+
<MenuItem href="/">Home</MenuItem>
|
|
95
|
+
<MenuSubmenu label="Resources" value="resources">
|
|
96
|
+
<MenuItem href="/docs">Docs</MenuItem>
|
|
97
|
+
<MenuItem value="blog">Blog</MenuItem>
|
|
98
|
+
</MenuSubmenu>
|
|
99
|
+
</Menu>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Command
|
|
103
|
+
|
|
104
|
+
`<Command>` binds its filter text as `query`; `onCommand(value, item)` fires
|
|
105
|
+
when a command runs. Give it a `hotkey` to open its hosting `<dialog>` with
|
|
106
|
+
Cmd/Ctrl plus that key.
|
|
107
|
+
|
|
108
|
+
```svelte
|
|
109
|
+
<Command bind:query hotkey="k" onCommand={(value) => run(value)}>
|
|
110
|
+
<CommandInput placeholder="Type a command" />
|
|
111
|
+
<CommandList>
|
|
112
|
+
<CommandItem value="new-file">New file</CommandItem>
|
|
113
|
+
</CommandList>
|
|
114
|
+
<CommandEmpty />
|
|
115
|
+
</Command>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Forms
|
|
119
|
+
|
|
120
|
+
Wrap a control in `<Field>` and it picks up the field's `id`,
|
|
121
|
+
`aria-describedby`, `aria-invalid`, and `required` automatically. This applies
|
|
122
|
+
to `Input`, `Textarea`, `Select`, `Checkbox`, `Switch`, `Slider`, and
|
|
123
|
+
`ComboboxInput`; outside a Field they render as plain controls.
|
|
124
|
+
|
|
125
|
+
```svelte
|
|
126
|
+
<Field invalid={!valid} required>
|
|
127
|
+
<FieldLabel>Email</FieldLabel>
|
|
128
|
+
<Input type="email" bind:value={email} />
|
|
129
|
+
<FieldHelp>We never share it.</FieldHelp>
|
|
130
|
+
<FieldError
|
|
131
|
+
>{#if !valid}Enter a valid email.{/if}</FieldError
|
|
132
|
+
>
|
|
133
|
+
</Field>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
For a custom control, call `useField()` during initialization. It returns
|
|
137
|
+
`{ id, describedBy, invalid, required }` inside a Field and `null` outside one;
|
|
138
|
+
the properties are getters, so they stay reactive in your template.
|
|
139
|
+
|
|
140
|
+
```svelte
|
|
141
|
+
<script lang="ts">
|
|
142
|
+
import { useField } from '@hydrateless/svelte';
|
|
143
|
+
|
|
144
|
+
const field = useField();
|
|
145
|
+
</script>
|
|
146
|
+
|
|
147
|
+
<input
|
|
148
|
+
id={field?.id}
|
|
149
|
+
required={field?.required || undefined}
|
|
150
|
+
aria-describedby={field?.describedBy}
|
|
151
|
+
aria-invalid={field?.invalid || undefined}
|
|
152
|
+
/>
|
|
153
|
+
```
|
|
154
|
+
|
|
76
155
|
## Toasts
|
|
77
156
|
|
|
78
|
-
|
|
157
|
+
Mount a `<ToastRegion>` where toasts should appear (it's enhanced on mount),
|
|
158
|
+
then call `useToast()` from anywhere. Without a region, the first `show`
|
|
159
|
+
appends one to `<body>`.
|
|
79
160
|
|
|
80
161
|
```svelte
|
|
81
162
|
<script lang="ts">
|
|
82
|
-
import { useToast } from '@hydrateless/svelte';
|
|
163
|
+
import { ToastRegion, useToast } from '@hydrateless/svelte';
|
|
83
164
|
|
|
84
165
|
const toast = useToast();
|
|
85
166
|
</script>
|
|
86
167
|
|
|
87
|
-
<button onclick={() => toast.show('Saved', {
|
|
168
|
+
<button onclick={() => toast.show('Saved', { intent: 'success', duration: 4000 })}>Save</button>
|
|
169
|
+
<ToastRegion />
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`show(message, { duration, intent })` returns the toast element; pass it to
|
|
173
|
+
`dismiss(el)` to remove it early. `intent` is one of `info`, `success`,
|
|
174
|
+
`warning`, or `danger` (`danger` toasts are announced assertively).
|
|
175
|
+
|
|
176
|
+
## useEnhancer
|
|
177
|
+
|
|
178
|
+
Every component is built on one attachment factory, and it's exported so a
|
|
179
|
+
custom wrapper behaves exactly like the shipped ones. Pass an enhancer and a
|
|
180
|
+
function returning its options; the returned `attach` runs the enhancer when the
|
|
181
|
+
element mounts and destroys it when the element leaves or the options change.
|
|
182
|
+
`api` is the enhancer's imperative handle (or `null` while detached).
|
|
183
|
+
|
|
184
|
+
```svelte
|
|
185
|
+
<script lang="ts">
|
|
186
|
+
import { enhanceTabs } from '@hydrateless/enhancers';
|
|
187
|
+
import { useEnhancer } from '@hydrateless/svelte';
|
|
188
|
+
|
|
189
|
+
let { activation = 'manual' } = $props();
|
|
190
|
+
const tabs = useEnhancer(enhanceTabs, () => ({ activation }));
|
|
191
|
+
</script>
|
|
192
|
+
|
|
193
|
+
<button onclick={() => tabs.api?.setValue('install')}>Jump to Install</button>
|
|
194
|
+
<div data-hl-tabs {@attach tabs.attach}>...</div>
|
|
88
195
|
```
|
|
89
196
|
|
|
197
|
+
Reactive state read inside the options function re-runs the enhancer; wrap
|
|
198
|
+
seed values (like a bound `value` passed as `defaultValue`) in `untrack` to
|
|
199
|
+
keep them from doing so.
|
|
200
|
+
|
|
201
|
+
## Changes from 0.x actions
|
|
202
|
+
|
|
203
|
+
- The `use:` actions (`tabs`, `dropdown`, and so on) are gone; use
|
|
204
|
+
`useEnhancer` or the components.
|
|
205
|
+
- `fieldBindings()` and `getFieldContext()` are replaced by `useField()`.
|
|
206
|
+
- `Menu` exposes `value`/`defaultValue`/`onValueChange` (the open submenu)
|
|
207
|
+
instead of `open`/`onOpenChange`; submenus are `<MenuSubmenu>` instead of a
|
|
208
|
+
`submenu` snippet.
|
|
209
|
+
- `Command` exposes `query`/`defaultQuery`/`onQueryChange` and `onCommand`
|
|
210
|
+
instead of `onSelect`.
|
|
211
|
+
- `Dropdown` adds `onSelect(value, item, checked)`, `closeOnSelect`, and
|
|
212
|
+
`placement`; `DropdownItem` adds `value`, `disabled`, `role`, and `checked`;
|
|
213
|
+
`DropdownGroup` is new.
|
|
214
|
+
- `Drawer` `side` is `'start' | 'end'` (default `end`) and renders
|
|
215
|
+
`data-hl-side`.
|
|
216
|
+
- `Tooltip` takes `content` (text or snippet), `placement`, `showDelay`,
|
|
217
|
+
`hideDelay`, and `bind:open`.
|
|
218
|
+
- Toast options use `intent` instead of `variant`.
|
|
219
|
+
- `Skeleton` takes `shape` instead of `variant`.
|
|
220
|
+
- `AccordionItem` drops `defaultOpen`; open items come from the Accordion's
|
|
221
|
+
`value`/`defaultValue`.
|
|
222
|
+
- `SegmentedControl` defaults to its first option when uncontrolled.
|
|
223
|
+
- `Table` is new.
|
|
224
|
+
|
|
90
225
|
## License
|
|
91
226
|
|
|
92
227
|
[MIT](../../LICENSE)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { enhanceAccordion
|
|
2
|
+
import { enhanceAccordion } from '@hydrateless/enhancers';
|
|
3
3
|
import { untrack } from 'svelte';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
5
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
import { setAccordionContext } from '../context.js';
|
|
7
|
+
import { useEnhancer } from '../useEnhancer.svelte.js';
|
|
6
8
|
|
|
7
9
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
8
10
|
/** Allow more than one panel to stay open at a time. */
|
|
@@ -11,6 +13,9 @@
|
|
|
11
13
|
value?: string[];
|
|
12
14
|
/** Initially open item values for uncontrolled usage. */
|
|
13
15
|
defaultValue?: string[];
|
|
16
|
+
/** Called with the open item values after every change. */
|
|
17
|
+
onValueChange?: (value: string[]) => void;
|
|
18
|
+
/** One or more `<AccordionItem>`s. */
|
|
14
19
|
children?: Snippet;
|
|
15
20
|
}
|
|
16
21
|
|
|
@@ -18,31 +23,37 @@
|
|
|
18
23
|
allowMultiple = false,
|
|
19
24
|
value = $bindable(),
|
|
20
25
|
defaultValue,
|
|
26
|
+
onValueChange,
|
|
21
27
|
children,
|
|
22
28
|
...rest
|
|
23
29
|
}: Props = $props();
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
31
|
+
if (value === undefined) value = defaultValue ?? [];
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return () => {
|
|
36
|
-
handle.destroy();
|
|
37
|
-
api = null;
|
|
38
|
-
};
|
|
33
|
+
// Items register in document order so each `<details>` can render `open`
|
|
34
|
+
// on the server from the shared value.
|
|
35
|
+
let itemCount = 0;
|
|
36
|
+
setAccordionContext({
|
|
37
|
+
get value() {
|
|
38
|
+
return value ?? [];
|
|
39
|
+
},
|
|
40
|
+
registerItem: () => itemCount++,
|
|
39
41
|
});
|
|
40
42
|
|
|
43
|
+
const accordion = useEnhancer(enhanceAccordion, () => ({
|
|
44
|
+
allowMultiple,
|
|
45
|
+
defaultValue: untrack(() => value),
|
|
46
|
+
onValueChange: (next) => {
|
|
47
|
+
value = next;
|
|
48
|
+
onValueChange?.(next);
|
|
49
|
+
},
|
|
50
|
+
}));
|
|
51
|
+
|
|
41
52
|
$effect(() => {
|
|
42
|
-
if (value != null) api?.setValue(value);
|
|
53
|
+
if (value != null) accordion.api?.setValue(value);
|
|
43
54
|
});
|
|
44
55
|
</script>
|
|
45
56
|
|
|
46
|
-
<div {...rest} data-hl-accordion
|
|
57
|
+
<div {...rest} data-hl-accordion {@attach accordion.attach}>
|
|
47
58
|
{@render children?.()}
|
|
48
59
|
</div>
|
|
@@ -7,6 +7,9 @@ interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
|
7
7
|
value?: string[];
|
|
8
8
|
/** Initially open item values for uncontrolled usage. */
|
|
9
9
|
defaultValue?: string[];
|
|
10
|
+
/** Called with the open item values after every change. */
|
|
11
|
+
onValueChange?: (value: string[]) => void;
|
|
12
|
+
/** One or more `<AccordionItem>`s. */
|
|
10
13
|
children?: Snippet;
|
|
11
14
|
}
|
|
12
15
|
declare const Accordion: import("svelte").Component<Props, {}, "value">;
|
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
import { getAccordionContext } from '../context.js';
|
|
4
5
|
|
|
5
6
|
interface Props extends Omit<HTMLAttributes<HTMLDetailsElement>, 'title'> {
|
|
6
|
-
/** The clickable summary/trigger row. */
|
|
7
|
-
summary?: Snippet;
|
|
8
7
|
/** Stable value identifying this item; defaults to its index. */
|
|
9
8
|
value?: string;
|
|
10
|
-
|
|
9
|
+
/** Plain-text header. Use the `summary` snippet for rich content. */
|
|
10
|
+
title?: string;
|
|
11
|
+
/** The clickable summary/trigger row; overrides `title`. */
|
|
12
|
+
summary?: Snippet;
|
|
13
|
+
/** Panel content. */
|
|
11
14
|
children?: Snippet;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
let {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
$
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
let { value, title, summary, children, ...rest }: Props = $props();
|
|
18
|
+
const accordion = getAccordionContext();
|
|
19
|
+
const index = accordion?.registerItem() ?? 0;
|
|
20
|
+
const ownValue = $derived(value ?? String(index));
|
|
21
|
+
// Rendered on the server from the Accordion's value so the open panel shows
|
|
22
|
+
// before the enhancer runs; the enhancer then keeps `open` in step.
|
|
23
|
+
const open = $derived(accordion ? accordion.value.includes(ownValue) : undefined);
|
|
20
24
|
</script>
|
|
21
25
|
|
|
22
|
-
<details {...rest}
|
|
23
|
-
<summary
|
|
26
|
+
<details {...rest} data-hl-value={value} {open}>
|
|
27
|
+
<summary
|
|
28
|
+
>{#if summary}{@render summary()}{:else}{title}{/if}</summary
|
|
29
|
+
>
|
|
24
30
|
<div class="hl-accordion-panel">{@render children?.()}</div>
|
|
25
31
|
</details>
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends Omit<HTMLAttributes<HTMLDetailsElement>, 'title'> {
|
|
4
|
-
/** The clickable summary/trigger row. */
|
|
5
|
-
summary?: Snippet;
|
|
6
4
|
/** Stable value identifying this item; defaults to its index. */
|
|
7
5
|
value?: string;
|
|
8
|
-
|
|
6
|
+
/** Plain-text header. Use the `summary` snippet for rich content. */
|
|
7
|
+
title?: string;
|
|
8
|
+
/** The clickable summary/trigger row; overrides `title`. */
|
|
9
|
+
summary?: Snippet;
|
|
10
|
+
/** Panel content. */
|
|
9
11
|
children?: Snippet;
|
|
10
12
|
}
|
|
11
13
|
declare const AccordionItem: import("svelte").Component<Props, {}, "">;
|
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
type Intent = 'neutral' | 'primary' | 'danger' | 'success' | 'warning' | 'info';
|
|
6
6
|
|
|
7
7
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
/** Semantic tone; sets `data-hl-intent`. */
|
|
8
9
|
intent?: Intent;
|
|
10
|
+
/** Bold heading shown above the message. */
|
|
9
11
|
title?: string;
|
|
12
|
+
/** Leading icon. */
|
|
10
13
|
icon?: Snippet;
|
|
14
|
+
/** Message body. */
|
|
11
15
|
children?: Snippet;
|
|
12
16
|
}
|
|
13
17
|
|
|
@@ -2,9 +2,13 @@ import type { Snippet } from 'svelte';
|
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
type Intent = 'neutral' | 'primary' | 'danger' | 'success' | 'warning' | 'info';
|
|
4
4
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/** Semantic tone; sets `data-hl-intent`. */
|
|
5
6
|
intent?: Intent;
|
|
7
|
+
/** Bold heading shown above the message. */
|
|
6
8
|
title?: string;
|
|
9
|
+
/** Leading icon. */
|
|
7
10
|
icon?: Snippet;
|
|
11
|
+
/** Message body. */
|
|
8
12
|
children?: Snippet;
|
|
9
13
|
}
|
|
10
14
|
declare const Alert: import("svelte").Component<Props, {}, "">;
|
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
|
|
5
5
|
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
6
|
+
/** Image source; on load failure the fallback `children` render instead. */
|
|
6
7
|
src?: string;
|
|
8
|
+
/** Alternative text for the image; empty when the name is shown alongside. */
|
|
7
9
|
alt?: string;
|
|
10
|
+
/** Avatar size. */
|
|
8
11
|
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
12
|
+
/** Avatar shape. Defaults to a circle. */
|
|
9
13
|
shape?: 'circle' | 'square';
|
|
14
|
+
/** Fallback content, typically initials. */
|
|
10
15
|
children?: Snippet;
|
|
11
16
|
}
|
|
12
17
|
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
4
|
+
/** Image source; on load failure the fallback `children` render instead. */
|
|
4
5
|
src?: string;
|
|
6
|
+
/** Alternative text for the image; empty when the name is shown alongside. */
|
|
5
7
|
alt?: string;
|
|
8
|
+
/** Avatar size. */
|
|
6
9
|
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
10
|
+
/** Avatar shape. Defaults to a circle. */
|
|
7
11
|
shape?: 'circle' | 'square';
|
|
12
|
+
/** Fallback content, typically initials. */
|
|
8
13
|
children?: Snippet;
|
|
9
14
|
}
|
|
10
15
|
declare const Avatar: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** Overlapping `<Avatar>`s. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const AvatarGroup: import("svelte").Component<Props, {}, "">;
|
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
|
|
5
5
|
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
6
|
+
/** Semantic tone; sets `data-hl-intent`. */
|
|
6
7
|
intent?: 'neutral' | 'primary' | 'danger' | 'success' | 'warning' | 'info';
|
|
8
|
+
/** Visual style. */
|
|
7
9
|
variant?: 'soft' | 'solid' | 'outline';
|
|
10
|
+
/** Badge size. */
|
|
8
11
|
size?: 'sm' | 'md';
|
|
12
|
+
/** Badge text. */
|
|
9
13
|
children?: Snippet;
|
|
10
14
|
}
|
|
11
15
|
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
4
|
+
/** Semantic tone; sets `data-hl-intent`. */
|
|
4
5
|
intent?: 'neutral' | 'primary' | 'danger' | 'success' | 'warning' | 'info';
|
|
6
|
+
/** Visual style. */
|
|
5
7
|
variant?: 'soft' | 'solid' | 'outline';
|
|
8
|
+
/** Badge size. */
|
|
6
9
|
size?: 'sm' | 'md';
|
|
10
|
+
/** Badge text. */
|
|
7
11
|
children?: Snippet;
|
|
8
12
|
}
|
|
9
13
|
declare const Badge: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLElement> {
|
|
4
|
+
/** `<BreadcrumbItem>`s, first to current. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const Breadcrumb: import("svelte").Component<Props, {}, "">;
|
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
import type { HTMLLiAttributes } from 'svelte/elements';
|
|
4
4
|
|
|
5
5
|
interface Props extends HTMLLiAttributes {
|
|
6
|
+
/** Link target; omitted for the current page. */
|
|
6
7
|
href?: string;
|
|
8
|
+
/** Mark this item as the current page (`aria-current="page"`). */
|
|
7
9
|
current?: boolean;
|
|
10
|
+
/** Item label. */
|
|
8
11
|
children?: Snippet;
|
|
9
12
|
}
|
|
10
13
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLLiAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLLiAttributes {
|
|
4
|
+
/** Link target; omitted for the current page. */
|
|
4
5
|
href?: string;
|
|
6
|
+
/** Mark this item as the current page (`aria-current="page"`). */
|
|
5
7
|
current?: boolean;
|
|
8
|
+
/** Item label. */
|
|
6
9
|
children?: Snippet;
|
|
7
10
|
}
|
|
8
11
|
declare const BreadcrumbItem: import("svelte").Component<Props, {}, "">;
|
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
4
4
|
|
|
5
5
|
interface Props extends HTMLButtonAttributes {
|
|
6
|
+
/** Visual style. */
|
|
6
7
|
variant?: 'solid' | 'soft' | 'outline' | 'ghost' | 'link';
|
|
8
|
+
/** Semantic tone; sets `data-hl-intent`. */
|
|
7
9
|
intent?: 'neutral' | 'primary' | 'danger' | 'success' | 'warning' | 'info';
|
|
10
|
+
/** Button size. */
|
|
8
11
|
size?: 'sm' | 'md' | 'lg';
|
|
12
|
+
/** Stretch to the container's full inline size. */
|
|
9
13
|
block?: boolean;
|
|
14
|
+
/** Square icon-only button; remember to pass `aria-label`. */
|
|
10
15
|
icon?: boolean;
|
|
16
|
+
/** Show a spinner and disable the button while work is pending. */
|
|
11
17
|
loading?: boolean;
|
|
18
|
+
/** Button label. */
|
|
12
19
|
children?: Snippet;
|
|
13
20
|
}
|
|
14
21
|
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLButtonAttributes {
|
|
4
|
+
/** Visual style. */
|
|
4
5
|
variant?: 'solid' | 'soft' | 'outline' | 'ghost' | 'link';
|
|
6
|
+
/** Semantic tone; sets `data-hl-intent`. */
|
|
5
7
|
intent?: 'neutral' | 'primary' | 'danger' | 'success' | 'warning' | 'info';
|
|
8
|
+
/** Button size. */
|
|
6
9
|
size?: 'sm' | 'md' | 'lg';
|
|
10
|
+
/** Stretch to the container's full inline size. */
|
|
7
11
|
block?: boolean;
|
|
12
|
+
/** Square icon-only button; remember to pass `aria-label`. */
|
|
8
13
|
icon?: boolean;
|
|
14
|
+
/** Show a spinner and disable the button while work is pending. */
|
|
9
15
|
loading?: boolean;
|
|
16
|
+
/** Button label. */
|
|
10
17
|
children?: Snippet;
|
|
11
18
|
}
|
|
12
19
|
declare const Button: import("svelte").Component<Props, {}, "">;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
|
|
5
5
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
6
|
+
/** Add hover/focus affordances for a clickable card. */
|
|
6
7
|
interactive?: boolean;
|
|
8
|
+
/** Card sections: `<CardHeader>`, `<CardBody>`, `<CardFooter>`. */
|
|
7
9
|
children?: Snippet;
|
|
8
10
|
}
|
|
9
11
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** Add hover/focus affordances for a clickable card. */
|
|
4
5
|
interactive?: boolean;
|
|
6
|
+
/** Card sections: `<CardHeader>`, `<CardBody>`, `<CardFooter>`. */
|
|
5
7
|
children?: Snippet;
|
|
6
8
|
}
|
|
7
9
|
declare const Card: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** Main card content. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const CardBody: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLAttributes<HTMLParagraphElement> {
|
|
4
|
+
/** Supporting text under the title. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const CardDescription: import("svelte").Component<Props, {}, "">;
|