@hydrateless/svelte 0.8.0 → 0.10.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 +29 -17
- package/dist/components/Accordion.svelte.d.ts +3 -0
- package/dist/components/AccordionItem.svelte +21 -12
- package/dist/components/AccordionItem.svelte.d.ts +6 -4
- 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 +48 -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 +20 -3
- package/dist/components/Tab.svelte.d.ts +2 -1
- package/dist/components/TabList.svelte +1 -0
- package/dist/components/TabList.svelte.d.ts +1 -0
- package/dist/components/TabPanel.svelte +12 -2
- package/dist/components/TabPanel.svelte.d.ts +2 -1
- package/dist/components/Table.svelte +30 -0
- package/dist/components/Table.svelte.d.ts +17 -0
- package/dist/components/Tabs.svelte +38 -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 +79 -22
- package/dist/components/Tooltip.svelte.d.ts +31 -9
- package/dist/context.d.ts +99 -8
- package/dist/context.js +60 -11
- package/dist/index.d.ts +8 -4
- package/dist/index.js +6 -4
- package/dist/registry.svelte.d.ts +29 -0
- package/dist/registry.svelte.js +44 -0
- package/dist/toast.d.ts +12 -7
- package/dist/toast.js +23 -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
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLTableAttributes } from 'svelte/elements';
|
|
4
|
+
|
|
5
|
+
interface Props extends Omit<HTMLTableAttributes, 'align'> {
|
|
6
|
+
/** Zebra-stripe the body rows. */
|
|
7
|
+
striped?: boolean;
|
|
8
|
+
/** Highlight a body row under the pointer. */
|
|
9
|
+
hover?: boolean;
|
|
10
|
+
/** Default text alignment of cells (logical, RTL-aware). */
|
|
11
|
+
align?: 'start' | 'center' | 'end';
|
|
12
|
+
/** Cell padding scale. */
|
|
13
|
+
size?: 'sm' | 'md' | 'lg';
|
|
14
|
+
/** `<thead>`, `<tbody>`, `<tfoot>`, and `<caption>` as usual. */
|
|
15
|
+
children?: Snippet;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let { striped, hover, align, size, class: klass, children, ...rest }: Props = $props();
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<table
|
|
22
|
+
{...rest}
|
|
23
|
+
class={['hl-table', klass]}
|
|
24
|
+
data-hl-striped={striped || undefined}
|
|
25
|
+
data-hl-hover={hover || undefined}
|
|
26
|
+
data-hl-align={align}
|
|
27
|
+
data-hl-size={size}
|
|
28
|
+
>
|
|
29
|
+
{@render children?.()}
|
|
30
|
+
</table>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLTableAttributes } from 'svelte/elements';
|
|
3
|
+
interface Props extends Omit<HTMLTableAttributes, 'align'> {
|
|
4
|
+
/** Zebra-stripe the body rows. */
|
|
5
|
+
striped?: boolean;
|
|
6
|
+
/** Highlight a body row under the pointer. */
|
|
7
|
+
hover?: boolean;
|
|
8
|
+
/** Default text alignment of cells (logical, RTL-aware). */
|
|
9
|
+
align?: 'start' | 'center' | 'end';
|
|
10
|
+
/** Cell padding scale. */
|
|
11
|
+
size?: 'sm' | 'md' | 'lg';
|
|
12
|
+
/** `<thead>`, `<tbody>`, `<tfoot>`, and `<caption>` as usual. */
|
|
13
|
+
children?: Snippet;
|
|
14
|
+
}
|
|
15
|
+
declare const Table: import("svelte").Component<Props, {}, "">;
|
|
16
|
+
type Table = ReturnType<typeof Table>;
|
|
17
|
+
export default Table;
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { enhanceTabs, type EnhanceTabsOptions
|
|
2
|
+
import { enhanceTabs, type EnhanceTabsOptions } 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 { setTabsContext } from '../context.js';
|
|
7
|
+
import { createRegistry } from '../registry.svelte.js';
|
|
8
|
+
import { useEnhancer } from '../useEnhancer.svelte.js';
|
|
6
9
|
|
|
7
10
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
11
|
+
/** `manual` (default): arrows move focus, Enter/Space selects. `automatic`: arrows select. */
|
|
8
12
|
activation?: EnhanceTabsOptions['activation'];
|
|
13
|
+
/** Layout of the tab list; also picks the arrow keys used. */
|
|
9
14
|
orientation?: EnhanceTabsOptions['orientation'];
|
|
10
15
|
/** Selected tab value; two-way bindable (`bind:value`). */
|
|
11
16
|
value?: string;
|
|
12
|
-
/**
|
|
17
|
+
/** Initially selected tab for uncontrolled usage. Defaults to the first tab. */
|
|
13
18
|
defaultValue?: string;
|
|
19
|
+
/** Called with the new tab value after every selection change. */
|
|
20
|
+
onValueChange?: (value: string) => void;
|
|
21
|
+
/** A `<TabList>` followed by one `<TabPanel>` per tab. */
|
|
14
22
|
children?: Snippet;
|
|
15
23
|
}
|
|
16
24
|
|
|
@@ -19,32 +27,43 @@
|
|
|
19
27
|
orientation,
|
|
20
28
|
value = $bindable(),
|
|
21
29
|
defaultValue,
|
|
30
|
+
onValueChange,
|
|
22
31
|
children,
|
|
23
32
|
...rest
|
|
24
33
|
}: Props = $props();
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
35
|
+
if (value === undefined) value = defaultValue;
|
|
27
36
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
// Tabs and panels register in document order so `aria-selected`/`hidden`
|
|
38
|
+
// render on the server and the enhancer finds them already in agreement.
|
|
39
|
+
// Registries keep indexes live when an `{#each}` adds or removes tabs.
|
|
40
|
+
const tabs = createRegistry<() => string | undefined>();
|
|
41
|
+
const panels = createRegistry();
|
|
42
|
+
const tabValues = $derived(tabs.entries.map((get, index) => get() ?? String(index)));
|
|
43
|
+
setTabsContext({
|
|
44
|
+
get value() {
|
|
45
|
+
return value ?? tabValues[0];
|
|
46
|
+
},
|
|
47
|
+
registerTab: (getValue) => tabs.register(getValue),
|
|
48
|
+
registerPanel: () => panels.register(),
|
|
49
|
+
tabValueAt: (index) => tabValues[index],
|
|
41
50
|
});
|
|
42
51
|
|
|
52
|
+
const enhanced = useEnhancer(enhanceTabs, () => ({
|
|
53
|
+
activation,
|
|
54
|
+
orientation,
|
|
55
|
+
defaultValue: untrack(() => value),
|
|
56
|
+
onValueChange: (next) => {
|
|
57
|
+
value = next;
|
|
58
|
+
onValueChange?.(next);
|
|
59
|
+
},
|
|
60
|
+
}));
|
|
61
|
+
|
|
43
62
|
$effect(() => {
|
|
44
|
-
if (value != null) api?.setValue(value);
|
|
63
|
+
if (value != null) enhanced.api?.setValue(value);
|
|
45
64
|
});
|
|
46
65
|
</script>
|
|
47
66
|
|
|
48
|
-
<div {...rest} data-hl-tabs
|
|
67
|
+
<div {...rest} data-hl-tabs data-hl-orientation={orientation} {@attach enhanced.attach}>
|
|
49
68
|
{@render children?.()}
|
|
50
69
|
</div>
|
|
@@ -2,12 +2,17 @@ import { type EnhanceTabsOptions } from '@hydrateless/enhancers';
|
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/** `manual` (default): arrows move focus, Enter/Space selects. `automatic`: arrows select. */
|
|
5
6
|
activation?: EnhanceTabsOptions['activation'];
|
|
7
|
+
/** Layout of the tab list; also picks the arrow keys used. */
|
|
6
8
|
orientation?: EnhanceTabsOptions['orientation'];
|
|
7
9
|
/** Selected tab value; two-way bindable (`bind:value`). */
|
|
8
10
|
value?: string;
|
|
9
|
-
/**
|
|
11
|
+
/** Initially selected tab for uncontrolled usage. Defaults to the first tab. */
|
|
10
12
|
defaultValue?: string;
|
|
13
|
+
/** Called with the new tab value after every selection change. */
|
|
14
|
+
onValueChange?: (value: string) => void;
|
|
15
|
+
/** A `<TabList>` followed by one `<TabPanel>` per tab. */
|
|
11
16
|
children?: Snippet;
|
|
12
17
|
}
|
|
13
18
|
declare const Tabs: import("svelte").Component<Props, {}, "value">;
|
|
@@ -1,23 +1,43 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLTextareaAttributes } from 'svelte/elements';
|
|
3
|
-
import {
|
|
3
|
+
import { useField } from '../context.js';
|
|
4
4
|
|
|
5
5
|
interface Props extends HTMLTextareaAttributes {
|
|
6
|
+
/** Current value; two-way bindable (`bind:value`). */
|
|
6
7
|
value?: string;
|
|
8
|
+
/** Control size. */
|
|
7
9
|
size?: 'sm' | 'md' | 'lg';
|
|
10
|
+
/** Mark the control invalid; also inherited from an enclosing `<Field invalid>`. */
|
|
8
11
|
invalid?: boolean;
|
|
12
|
+
/** Grow with the content (`field-sizing: content`). */
|
|
13
|
+
autosize?: boolean;
|
|
9
14
|
}
|
|
10
15
|
|
|
11
|
-
let {
|
|
12
|
-
|
|
16
|
+
let {
|
|
17
|
+
value = $bindable(),
|
|
18
|
+
size,
|
|
19
|
+
invalid = false,
|
|
20
|
+
autosize = false,
|
|
21
|
+
id,
|
|
22
|
+
required,
|
|
23
|
+
'aria-describedby': describedBy,
|
|
24
|
+
class: klass,
|
|
25
|
+
...rest
|
|
26
|
+
}: Props = $props();
|
|
27
|
+
// Optional: wires id/aria-describedby/aria-invalid/required when inside a <Field>.
|
|
28
|
+
const field = useField();
|
|
29
|
+
const isInvalid = $derived(invalid || Boolean(field?.invalid));
|
|
13
30
|
</script>
|
|
14
31
|
|
|
15
32
|
<textarea
|
|
16
|
-
{...field}
|
|
17
33
|
{...rest}
|
|
34
|
+
id={id ?? field?.id}
|
|
35
|
+
required={required ?? (field?.required || undefined)}
|
|
36
|
+
aria-describedby={describedBy ?? field?.describedBy}
|
|
18
37
|
bind:value
|
|
19
38
|
class={['hl-textarea', klass]}
|
|
20
39
|
data-hl-size={size}
|
|
21
|
-
data-hl-
|
|
22
|
-
|
|
40
|
+
data-hl-autosize={autosize || undefined}
|
|
41
|
+
data-hl-invalid={isInvalid || undefined}
|
|
42
|
+
aria-invalid={isInvalid || undefined}
|
|
23
43
|
></textarea>
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { HTMLTextareaAttributes } from 'svelte/elements';
|
|
2
2
|
interface Props extends HTMLTextareaAttributes {
|
|
3
|
+
/** Current value; two-way bindable (`bind:value`). */
|
|
3
4
|
value?: string;
|
|
5
|
+
/** Control size. */
|
|
4
6
|
size?: 'sm' | 'md' | 'lg';
|
|
7
|
+
/** Mark the control invalid; also inherited from an enclosing `<Field invalid>`. */
|
|
5
8
|
invalid?: boolean;
|
|
9
|
+
/** Grow with the content (`field-sizing: content`). */
|
|
10
|
+
autosize?: boolean;
|
|
6
11
|
}
|
|
7
12
|
declare const Textarea: import("svelte").Component<Props, {}, "value">;
|
|
8
13
|
type Textarea = ReturnType<typeof Textarea>;
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { enhanceToast, type EnhanceToastOptions } from '@hydrateless/enhancers';
|
|
2
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
import { useEnhancer } from '../useEnhancer.svelte.js';
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
/** Default auto-dismiss duration in ms for toasts shown without one. */
|
|
8
|
+
duration?: number;
|
|
9
|
+
/** Called after a toast appears (`open: true`) or is dismissed (`open: false`). */
|
|
10
|
+
onOpenChange?: EnhanceToastOptions['onOpenChange'];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let { duration, onOpenChange, ...rest }: Props = $props();
|
|
14
|
+
|
|
15
|
+
// Enhanced on mount so `useToast()` adopts this region (and its defaults)
|
|
16
|
+
// instead of appending its own to <body>.
|
|
17
|
+
const toast = useEnhancer(enhanceToast, () => ({
|
|
18
|
+
duration,
|
|
19
|
+
onOpenChange: (open, el) => onOpenChange?.(open, el),
|
|
20
|
+
}));
|
|
5
21
|
</script>
|
|
6
22
|
|
|
7
|
-
<div {...rest} data-hl-toast-region></div>
|
|
23
|
+
<div {...rest} data-hl-toast-region {@attach toast.attach}></div>
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { type EnhanceToastOptions } from '@hydrateless/enhancers';
|
|
1
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
-
|
|
3
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** Default auto-dismiss duration in ms for toasts shown without one. */
|
|
5
|
+
duration?: number;
|
|
6
|
+
/** Called after a toast appears (`open: true`) or is dismissed (`open: false`). */
|
|
7
|
+
onOpenChange?: EnhanceToastOptions['onOpenChange'];
|
|
8
|
+
}
|
|
9
|
+
declare const ToastRegion: import("svelte").Component<Props, {}, "">;
|
|
3
10
|
type ToastRegion = ReturnType<typeof ToastRegion>;
|
|
4
11
|
export default ToastRegion;
|
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { enhanceToc } from '@hydrateless/enhancers';
|
|
2
|
+
import { enhanceToc, type EnhanceTocOptions } from '@hydrateless/enhancers';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
3
4
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
5
|
+
import { useEnhancer } from '../useEnhancer.svelte.js';
|
|
4
6
|
|
|
5
7
|
interface Props extends HTMLAttributes<HTMLElement> {
|
|
8
|
+
/** Selector for the region whose headings populate the list. Defaults to `main, article`. */
|
|
6
9
|
contentSelector?: string;
|
|
10
|
+
/** Selector for which headings to include. Defaults to `h2,h3`. */
|
|
7
11
|
headings?: string;
|
|
12
|
+
/** Highlight the entry for the heading currently in view. Defaults to `true`. */
|
|
8
13
|
scrollSpy?: boolean;
|
|
14
|
+
/** Placeholder shown until the list is built (and restored if the Toc is destroyed). */
|
|
15
|
+
children?: Snippet;
|
|
9
16
|
}
|
|
10
17
|
|
|
11
|
-
let { contentSelector, headings, scrollSpy, ...rest }: Props = $props();
|
|
12
|
-
let host = $state<HTMLElement>();
|
|
18
|
+
let { contentSelector, headings, scrollSpy, children, ...rest }: Props = $props();
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
// The headings live outside the nav, so the enhancer scans the document and
|
|
21
|
+
// finds this nav as the `[data-hl-toc]` root within it.
|
|
22
|
+
const toc = useEnhancer(
|
|
23
|
+
(node: HTMLElement, options?: Partial<EnhanceTocOptions>) =>
|
|
24
|
+
enhanceToc(node.ownerDocument, options),
|
|
25
|
+
() => ({ contentSelector, headings, scrollSpy }),
|
|
26
|
+
);
|
|
18
27
|
</script>
|
|
19
28
|
|
|
20
|
-
<nav {...rest} data-hl-toc
|
|
29
|
+
<nav {...rest} data-hl-toc {@attach toc.attach}>
|
|
30
|
+
{@render children?.()}
|
|
31
|
+
</nav>
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
1
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
3
|
interface Props extends HTMLAttributes<HTMLElement> {
|
|
4
|
+
/** Selector for the region whose headings populate the list. Defaults to `main, article`. */
|
|
3
5
|
contentSelector?: string;
|
|
6
|
+
/** Selector for which headings to include. Defaults to `h2,h3`. */
|
|
4
7
|
headings?: string;
|
|
8
|
+
/** Highlight the entry for the heading currently in view. Defaults to `true`. */
|
|
5
9
|
scrollSpy?: boolean;
|
|
10
|
+
/** Placeholder shown until the list is built (and restored if the Toc is destroyed). */
|
|
11
|
+
children?: Snippet;
|
|
6
12
|
}
|
|
7
13
|
declare const Toc: import("svelte").Component<Props, {}, "">;
|
|
8
14
|
type Toc = ReturnType<typeof Toc>;
|
|
@@ -1,37 +1,94 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { enhanceTooltip } from '@hydrateless/enhancers';
|
|
2
|
+
import { enhanceTooltip, type EnhanceTooltipOptions } from '@hydrateless/enhancers';
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
5
|
+
import type { TooltipTriggerProps } from '../context.js';
|
|
6
|
+
import { useEnhancer } from '../useEnhancer.svelte.js';
|
|
4
7
|
|
|
5
|
-
interface Props {
|
|
6
|
-
/** The hint
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
interface Props extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'> {
|
|
9
|
+
/** The hint shown on hover/focus: plain text or a snippet for rich content. */
|
|
10
|
+
content?: string | Snippet;
|
|
11
|
+
/** Preferred placement relative to the trigger. Defaults to `top`. */
|
|
12
|
+
placement?: EnhanceTooltipOptions['placement'];
|
|
13
|
+
/** Delay in ms before showing on hover. Focus shows immediately. */
|
|
14
|
+
showDelay?: number;
|
|
15
|
+
/** Grace period in ms before hiding, so the pointer can reach the tip. */
|
|
16
|
+
hideDelay?: number;
|
|
17
|
+
/** Whether the tip is shown; two-way bindable (`bind:open`). */
|
|
18
|
+
open?: boolean;
|
|
19
|
+
/** Called after the tip shows or hides. */
|
|
20
|
+
onOpenChange?: (open: boolean) => void;
|
|
21
|
+
/**
|
|
22
|
+
* A single focusable element that triggers the tooltip. The snippet
|
|
23
|
+
* receives the trigger attributes; spread them so server-rendered markup
|
|
24
|
+
* links the trigger to the tip before any script runs:
|
|
25
|
+
*
|
|
26
|
+
* ```svelte
|
|
27
|
+
* <Tooltip content="Save">
|
|
28
|
+
* {#snippet children(trigger)}<Button {...trigger}>Save</Button>{/snippet}
|
|
29
|
+
* </Tooltip>
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Without the spread, the first child is linked on the client instead.
|
|
33
|
+
*/
|
|
34
|
+
children?: Snippet<[TooltipTriggerProps]>;
|
|
13
35
|
}
|
|
14
36
|
|
|
15
|
-
let {
|
|
37
|
+
let {
|
|
38
|
+
content,
|
|
39
|
+
placement,
|
|
40
|
+
showDelay,
|
|
41
|
+
hideDelay,
|
|
42
|
+
open = $bindable(),
|
|
43
|
+
onOpenChange,
|
|
44
|
+
class: klass,
|
|
45
|
+
style,
|
|
46
|
+
children,
|
|
47
|
+
...rest
|
|
48
|
+
}: Props = $props();
|
|
16
49
|
// SSR-safe: $props.id() is stable across server and client renders.
|
|
17
50
|
const generatedId = $props.id();
|
|
18
|
-
const tipId =
|
|
19
|
-
|
|
51
|
+
const tipId = `hl-tip-${generatedId}`;
|
|
52
|
+
const triggerProps: TooltipTriggerProps = {
|
|
53
|
+
'data-hl-tooltip': tipId,
|
|
54
|
+
'aria-describedby': tipId,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Consumers that don't spread the snippet's trigger props still get linked
|
|
58
|
+
// on the client: whatever they rendered first is the trigger.
|
|
59
|
+
const tooltip = useEnhancer(
|
|
60
|
+
(node: HTMLElement, options?: Partial<EnhanceTooltipOptions>) => {
|
|
61
|
+
const trigger = node.querySelector<HTMLElement>(':scope > :first-child');
|
|
62
|
+
if (trigger && !trigger.hasAttribute('data-hl-tooltip')) {
|
|
63
|
+
trigger.setAttribute('data-hl-tooltip', tipId);
|
|
64
|
+
trigger.setAttribute('aria-describedby', tipId);
|
|
65
|
+
}
|
|
66
|
+
return enhanceTooltip(node, options);
|
|
67
|
+
},
|
|
68
|
+
() => ({
|
|
69
|
+
placement,
|
|
70
|
+
showDelay,
|
|
71
|
+
hideDelay,
|
|
72
|
+
onOpenChange: (next) => {
|
|
73
|
+
open = next;
|
|
74
|
+
onOpenChange?.(next);
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
20
78
|
|
|
21
79
|
$effect(() => {
|
|
22
|
-
if (
|
|
23
|
-
const trigger = host.querySelector<HTMLElement>(':scope > :first-child');
|
|
24
|
-
if (trigger) {
|
|
25
|
-
trigger.setAttribute('data-hl-tooltip', tipId);
|
|
26
|
-
trigger.setAttribute('aria-describedby', tipId);
|
|
27
|
-
}
|
|
28
|
-
return enhanceTooltip(host).destroy;
|
|
80
|
+
if (open != null) tooltip.api?.setOpen(open);
|
|
29
81
|
});
|
|
30
82
|
</script>
|
|
31
83
|
|
|
32
|
-
<span
|
|
33
|
-
{
|
|
84
|
+
<span
|
|
85
|
+
{...rest}
|
|
86
|
+
class={['hl-tooltip-anchor', klass]}
|
|
87
|
+
style={['position:relative;display:inline-block', style].filter(Boolean).join(';')}
|
|
88
|
+
{@attach tooltip.attach}
|
|
89
|
+
>
|
|
90
|
+
{@render children?.(triggerProps)}
|
|
34
91
|
<span id={tipId} role="tooltip" hidden
|
|
35
|
-
>{#if
|
|
92
|
+
>{#if typeof content === 'function'}{@render content()}{:else}{content}{/if}</span
|
|
36
93
|
>
|
|
37
94
|
</span>
|
|
@@ -1,13 +1,35 @@
|
|
|
1
|
+
import { type EnhanceTooltipOptions } from '@hydrateless/enhancers';
|
|
1
2
|
import type { Snippet } from 'svelte';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
import type { TooltipTriggerProps } from '../context.js';
|
|
5
|
+
interface Props extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'> {
|
|
6
|
+
/** The hint shown on hover/focus: plain text or a snippet for rich content. */
|
|
7
|
+
content?: string | Snippet;
|
|
8
|
+
/** Preferred placement relative to the trigger. Defaults to `top`. */
|
|
9
|
+
placement?: EnhanceTooltipOptions['placement'];
|
|
10
|
+
/** Delay in ms before showing on hover. Focus shows immediately. */
|
|
11
|
+
showDelay?: number;
|
|
12
|
+
/** Grace period in ms before hiding, so the pointer can reach the tip. */
|
|
13
|
+
hideDelay?: number;
|
|
14
|
+
/** Whether the tip is shown; two-way bindable (`bind:open`). */
|
|
15
|
+
open?: boolean;
|
|
16
|
+
/** Called after the tip shows or hides. */
|
|
17
|
+
onOpenChange?: (open: boolean) => void;
|
|
18
|
+
/**
|
|
19
|
+
* A single focusable element that triggers the tooltip. The snippet
|
|
20
|
+
* receives the trigger attributes; spread them so server-rendered markup
|
|
21
|
+
* links the trigger to the tip before any script runs:
|
|
22
|
+
*
|
|
23
|
+
* ```svelte
|
|
24
|
+
* <Tooltip content="Save">
|
|
25
|
+
* {#snippet children(trigger)}<Button {...trigger}>Save</Button>{/snippet}
|
|
26
|
+
* </Tooltip>
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Without the spread, the first child is linked on the client instead.
|
|
30
|
+
*/
|
|
31
|
+
children?: Snippet<[TooltipTriggerProps]>;
|
|
10
32
|
}
|
|
11
|
-
declare const Tooltip: import("svelte").Component<Props, {}, "">;
|
|
33
|
+
declare const Tooltip: import("svelte").Component<Props, {}, "open">;
|
|
12
34
|
type Tooltip = ReturnType<typeof Tooltip>;
|
|
13
35
|
export default Tooltip;
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Registration } from './registry.svelte.js';
|
|
2
|
+
/**
|
|
3
|
+
* What a Field shares with its descendants. The getters stay live, so controls
|
|
4
|
+
* re-render when `invalid`/`required` change.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
2
7
|
export interface FieldContext {
|
|
3
8
|
readonly id: string;
|
|
4
9
|
readonly helpId: string;
|
|
@@ -6,19 +11,105 @@ export interface FieldContext {
|
|
|
6
11
|
readonly invalid: boolean;
|
|
7
12
|
readonly required: boolean;
|
|
8
13
|
}
|
|
9
|
-
/** Publish {@link FieldContext}
|
|
14
|
+
/** Publish a {@link FieldContext}; called by `<Field>` only. @internal */
|
|
10
15
|
export declare function setFieldContext(ctx: FieldContext): void;
|
|
11
|
-
/** Read the nearest {@link FieldContext}, or `undefined` outside a Field. */
|
|
16
|
+
/** Read the nearest {@link FieldContext}, or `undefined` outside a Field. @internal */
|
|
12
17
|
export declare function getFieldContext(): FieldContext | undefined;
|
|
13
|
-
/**
|
|
14
|
-
export
|
|
15
|
-
/**
|
|
18
|
+
/** Attributes a custom control should render to join the enclosing Field. */
|
|
19
|
+
export interface FieldBindings {
|
|
20
|
+
/** The control's `id`; the Field's label points at it. */
|
|
21
|
+
readonly id: string;
|
|
22
|
+
/** Space-separated ids for `aria-describedby` (help text, plus the error when invalid). */
|
|
23
|
+
readonly describedBy: string | undefined;
|
|
24
|
+
/** Whether the Field is currently invalid; render as `aria-invalid`. */
|
|
25
|
+
readonly invalid: boolean;
|
|
26
|
+
/** Whether the Field is required; render as `required`. */
|
|
27
|
+
readonly required: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Wire a custom control into the enclosing `<Field>`. Returns `null` outside a
|
|
31
|
+
* Field, so controls can call it unconditionally. Must be called during
|
|
32
|
+
* component initialization, like any context read. The returned object's
|
|
33
|
+
* properties are getters, so they stay reactive in the template:
|
|
34
|
+
*
|
|
35
|
+
* ```svelte
|
|
36
|
+
* <script lang="ts">
|
|
37
|
+
* const field = useField();
|
|
38
|
+
* </script>
|
|
39
|
+
*
|
|
40
|
+
* <input id={field?.id} aria-describedby={field?.describedBy} aria-invalid={field?.invalid || undefined} />
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function useField(): FieldBindings | null;
|
|
44
|
+
/**
|
|
45
|
+
* Attributes a `<Tooltip>` hands to its `children` snippet. Spread them onto
|
|
46
|
+
* the trigger element so server-rendered markup already links it to the tip.
|
|
47
|
+
*/
|
|
48
|
+
export interface TooltipTriggerProps {
|
|
49
|
+
/** Marks the trigger and names the tip it describes. */
|
|
50
|
+
'data-hl-tooltip': string;
|
|
51
|
+
/** Points at the tip so assistive tech announces it. */
|
|
52
|
+
'aria-describedby': string;
|
|
53
|
+
}
|
|
54
|
+
/** Shared state a RadioGroup provides to its radios (name, selected value, and a setter). @internal */
|
|
16
55
|
export interface RadioGroupContext {
|
|
17
56
|
readonly name: string | undefined;
|
|
18
57
|
readonly value: string | undefined;
|
|
19
58
|
select: (value: string) => void;
|
|
20
59
|
}
|
|
21
|
-
/** Publish {@link RadioGroupContext}
|
|
60
|
+
/** Publish a {@link RadioGroupContext}; called by `<RadioGroup>` only. @internal */
|
|
22
61
|
export declare function setRadioGroupContext(ctx: RadioGroupContext): void;
|
|
23
|
-
/** Read the nearest {@link RadioGroupContext}, or `undefined` outside a group. */
|
|
62
|
+
/** Read the nearest {@link RadioGroupContext}, or `undefined` outside a group. @internal */
|
|
24
63
|
export declare function getRadioGroupContext(): RadioGroupContext | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Ids a Dropdown generates so the trigger's `popovertarget` and the menu's
|
|
66
|
+
* `id` agree in server-rendered markup, before any script runs, plus the live
|
|
67
|
+
* open state so the trigger's `aria-expanded` renders correctly too.
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export interface DropdownContext {
|
|
71
|
+
readonly menuId: string;
|
|
72
|
+
readonly triggerId: string;
|
|
73
|
+
readonly open: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** Publish a {@link DropdownContext}; called by `<Dropdown>` only. @internal */
|
|
76
|
+
export declare function setDropdownContext(ctx: DropdownContext): void;
|
|
77
|
+
/** Read the nearest {@link DropdownContext}, or `undefined` outside a Dropdown. @internal */
|
|
78
|
+
export declare function getDropdownContext(): DropdownContext | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Selection state a Tabs root shares with its tabs and panels so `aria-selected`,
|
|
81
|
+
* `tabindex`, and `hidden` can be rendered on the server. Tabs and panels
|
|
82
|
+
* register in document order; a panel pairs with the tab at the same index.
|
|
83
|
+
* Indexes are live, so an `{#each}` that adds or removes tabs renumbers the
|
|
84
|
+
* rest; children unregister on destroy.
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
export interface TabsContext {
|
|
88
|
+
/** The selected tab's value (falls back to the first registered tab). */
|
|
89
|
+
readonly value: string | undefined;
|
|
90
|
+
/** Register a tab by a getter for its value, which defaults to its index. */
|
|
91
|
+
registerTab: (value: () => string | undefined) => Registration;
|
|
92
|
+
/** Register a panel. */
|
|
93
|
+
registerPanel: () => Registration;
|
|
94
|
+
/** Value of the tab registered at `index`. */
|
|
95
|
+
tabValueAt: (index: number) => string | undefined;
|
|
96
|
+
}
|
|
97
|
+
/** Publish a {@link TabsContext}; called by `<Tabs>` only. @internal */
|
|
98
|
+
export declare function setTabsContext(ctx: TabsContext): void;
|
|
99
|
+
/** Read the nearest {@link TabsContext}, or `undefined` outside Tabs. @internal */
|
|
100
|
+
export declare function getTabsContext(): TabsContext | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Open-item state an Accordion shares with its items so each `<details>` can
|
|
103
|
+
* render its `open` attribute on the server.
|
|
104
|
+
* @internal
|
|
105
|
+
*/
|
|
106
|
+
export interface AccordionContext {
|
|
107
|
+
/** Values of the open items. */
|
|
108
|
+
readonly value: readonly string[];
|
|
109
|
+
/** Register an item; its live index is its default value. */
|
|
110
|
+
registerItem: () => Registration;
|
|
111
|
+
}
|
|
112
|
+
/** Publish an {@link AccordionContext}; called by `<Accordion>` only. @internal */
|
|
113
|
+
export declare function setAccordionContext(ctx: AccordionContext): void;
|
|
114
|
+
/** Read the nearest {@link AccordionContext}, or `undefined` outside an Accordion. @internal */
|
|
115
|
+
export declare function getAccordionContext(): AccordionContext | undefined;
|