@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
|
@@ -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,23 @@
|
|
|
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 { useEnhancer } from '../useEnhancer.svelte.js';
|
|
6
8
|
|
|
7
9
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
10
|
+
/** `manual` (default): arrows move focus, Enter/Space selects. `automatic`: arrows select. */
|
|
8
11
|
activation?: EnhanceTabsOptions['activation'];
|
|
12
|
+
/** Layout of the tab list; also picks the arrow keys used. */
|
|
9
13
|
orientation?: EnhanceTabsOptions['orientation'];
|
|
10
14
|
/** Selected tab value; two-way bindable (`bind:value`). */
|
|
11
15
|
value?: string;
|
|
12
|
-
/**
|
|
16
|
+
/** Initially selected tab for uncontrolled usage. Defaults to the first tab. */
|
|
13
17
|
defaultValue?: string;
|
|
18
|
+
/** Called with the new tab value after every selection change. */
|
|
19
|
+
onValueChange?: (value: string) => void;
|
|
20
|
+
/** A `<TabList>` followed by one `<TabPanel>` per tab. */
|
|
14
21
|
children?: Snippet;
|
|
15
22
|
}
|
|
16
23
|
|
|
@@ -19,32 +26,47 @@
|
|
|
19
26
|
orientation,
|
|
20
27
|
value = $bindable(),
|
|
21
28
|
defaultValue,
|
|
29
|
+
onValueChange,
|
|
22
30
|
children,
|
|
23
31
|
...rest
|
|
24
32
|
}: Props = $props();
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
34
|
+
if (value === undefined) value = defaultValue;
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
36
|
+
// Tabs and panels register in document order so `aria-selected`/`hidden`
|
|
37
|
+
// render on the server and the enhancer finds them already in agreement.
|
|
38
|
+
const tabValues: string[] = [];
|
|
39
|
+
let panelCount = 0;
|
|
40
|
+
setTabsContext({
|
|
41
|
+
get value() {
|
|
42
|
+
return value ?? tabValues[0];
|
|
43
|
+
},
|
|
44
|
+
registerTab(tabValue) {
|
|
45
|
+
const index = tabValues.length;
|
|
46
|
+
tabValues.push(tabValue ?? String(index));
|
|
47
|
+
return index;
|
|
48
|
+
},
|
|
49
|
+
registerPanel() {
|
|
50
|
+
return panelCount++;
|
|
51
|
+
},
|
|
52
|
+
tabValueAt: (index) => tabValues[index],
|
|
41
53
|
});
|
|
42
54
|
|
|
55
|
+
const tabs = useEnhancer(enhanceTabs, () => ({
|
|
56
|
+
activation,
|
|
57
|
+
orientation,
|
|
58
|
+
defaultValue: untrack(() => value),
|
|
59
|
+
onValueChange: (next) => {
|
|
60
|
+
value = next;
|
|
61
|
+
onValueChange?.(next);
|
|
62
|
+
},
|
|
63
|
+
}));
|
|
64
|
+
|
|
43
65
|
$effect(() => {
|
|
44
|
-
if (value != null) api?.setValue(value);
|
|
66
|
+
if (value != null) tabs.api?.setValue(value);
|
|
45
67
|
});
|
|
46
68
|
</script>
|
|
47
69
|
|
|
48
|
-
<div {...rest} data-hl-tabs
|
|
70
|
+
<div {...rest} data-hl-tabs data-hl-orientation={orientation} {@attach tabs.attach}>
|
|
49
71
|
{@render children?.()}
|
|
50
72
|
</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,75 @@
|
|
|
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 { useEnhancer } from '../useEnhancer.svelte.js';
|
|
4
6
|
|
|
5
|
-
interface Props {
|
|
6
|
-
/** The hint
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
8
|
+
/** The hint shown on hover/focus: plain text or a snippet for rich content. */
|
|
9
|
+
content?: string | Snippet;
|
|
10
|
+
/** Preferred placement relative to the trigger. Defaults to `top`. */
|
|
11
|
+
placement?: EnhanceTooltipOptions['placement'];
|
|
12
|
+
/** Delay in ms before showing on hover. Focus shows immediately. */
|
|
13
|
+
showDelay?: number;
|
|
14
|
+
/** Grace period in ms before hiding, so the pointer can reach the tip. */
|
|
15
|
+
hideDelay?: number;
|
|
16
|
+
/** Whether the tip is shown; two-way bindable (`bind:open`). */
|
|
17
|
+
open?: boolean;
|
|
18
|
+
/** Called after the tip shows or hides. */
|
|
19
|
+
onOpenChange?: (open: boolean) => void;
|
|
11
20
|
/** A single focusable element that triggers the tooltip. */
|
|
12
21
|
children?: Snippet;
|
|
13
22
|
}
|
|
14
23
|
|
|
15
|
-
let {
|
|
24
|
+
let {
|
|
25
|
+
content,
|
|
26
|
+
placement,
|
|
27
|
+
showDelay,
|
|
28
|
+
hideDelay,
|
|
29
|
+
open = $bindable(),
|
|
30
|
+
onOpenChange,
|
|
31
|
+
class: klass,
|
|
32
|
+
style,
|
|
33
|
+
children,
|
|
34
|
+
...rest
|
|
35
|
+
}: Props = $props();
|
|
16
36
|
// SSR-safe: $props.id() is stable across server and client renders.
|
|
17
37
|
const generatedId = $props.id();
|
|
18
|
-
const tipId =
|
|
19
|
-
|
|
38
|
+
const tipId = `hl-tip-${generatedId}`;
|
|
39
|
+
|
|
40
|
+
// The trigger is whatever the consumer renders first, so it's linked to the
|
|
41
|
+
// tip here rather than asking them to repeat the id.
|
|
42
|
+
const tooltip = useEnhancer(
|
|
43
|
+
(node: HTMLElement, options?: Partial<EnhanceTooltipOptions>) => {
|
|
44
|
+
const trigger = node.querySelector<HTMLElement>(':scope > :first-child');
|
|
45
|
+
trigger?.setAttribute('data-hl-tooltip', tipId);
|
|
46
|
+
trigger?.setAttribute('aria-describedby', tipId);
|
|
47
|
+
return enhanceTooltip(node, options);
|
|
48
|
+
},
|
|
49
|
+
() => ({
|
|
50
|
+
placement,
|
|
51
|
+
showDelay,
|
|
52
|
+
hideDelay,
|
|
53
|
+
onOpenChange: (next) => {
|
|
54
|
+
open = next;
|
|
55
|
+
onOpenChange?.(next);
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
20
59
|
|
|
21
60
|
$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;
|
|
61
|
+
if (open != null) tooltip.api?.setOpen(open);
|
|
29
62
|
});
|
|
30
63
|
</script>
|
|
31
64
|
|
|
32
|
-
<span
|
|
65
|
+
<span
|
|
66
|
+
{...rest}
|
|
67
|
+
class={['hl-tooltip-anchor', klass]}
|
|
68
|
+
style={['position:relative;display:inline-block', style].filter(Boolean).join(';')}
|
|
69
|
+
{@attach tooltip.attach}
|
|
70
|
+
>
|
|
33
71
|
{@render children?.()}
|
|
34
72
|
<span id={tipId} role="tooltip" hidden
|
|
35
|
-
>{#if
|
|
73
|
+
>{#if typeof content === 'function'}{@render content()}{:else}{content}{/if}</span
|
|
36
74
|
>
|
|
37
75
|
</span>
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
+
import { type EnhanceTooltipOptions } from '@hydrateless/enhancers';
|
|
1
2
|
import type { Snippet } from 'svelte';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
5
|
+
/** The hint shown on hover/focus: plain text or a snippet for rich content. */
|
|
6
|
+
content?: string | Snippet;
|
|
7
|
+
/** Preferred placement relative to the trigger. Defaults to `top`. */
|
|
8
|
+
placement?: EnhanceTooltipOptions['placement'];
|
|
9
|
+
/** Delay in ms before showing on hover. Focus shows immediately. */
|
|
10
|
+
showDelay?: number;
|
|
11
|
+
/** Grace period in ms before hiding, so the pointer can reach the tip. */
|
|
12
|
+
hideDelay?: number;
|
|
13
|
+
/** Whether the tip is shown; two-way bindable (`bind:open`). */
|
|
14
|
+
open?: boolean;
|
|
15
|
+
/** Called after the tip shows or hides. */
|
|
16
|
+
onOpenChange?: (open: boolean) => void;
|
|
8
17
|
/** A single focusable element that triggers the tooltip. */
|
|
9
18
|
children?: Snippet;
|
|
10
19
|
}
|
|
11
|
-
declare const Tooltip: import("svelte").Component<Props, {}, "">;
|
|
20
|
+
declare const Tooltip: import("svelte").Component<Props, {}, "open">;
|
|
12
21
|
type Tooltip = ReturnType<typeof Tooltip>;
|
|
13
22
|
export default Tooltip;
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* What a Field shares with its descendants. The getters stay live, so controls
|
|
3
|
+
* re-render when `invalid`/`required` change.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
2
6
|
export interface FieldContext {
|
|
3
7
|
readonly id: string;
|
|
4
8
|
readonly helpId: string;
|
|
@@ -6,19 +10,91 @@ export interface FieldContext {
|
|
|
6
10
|
readonly invalid: boolean;
|
|
7
11
|
readonly required: boolean;
|
|
8
12
|
}
|
|
9
|
-
/** Publish {@link FieldContext}
|
|
13
|
+
/** Publish a {@link FieldContext}; called by `<Field>` only. @internal */
|
|
10
14
|
export declare function setFieldContext(ctx: FieldContext): void;
|
|
11
|
-
/** Read the nearest {@link FieldContext}, or `undefined` outside a Field. */
|
|
15
|
+
/** Read the nearest {@link FieldContext}, or `undefined` outside a Field. @internal */
|
|
12
16
|
export declare function getFieldContext(): FieldContext | undefined;
|
|
13
|
-
/**
|
|
14
|
-
export
|
|
15
|
-
/**
|
|
17
|
+
/** Attributes a custom control should render to join the enclosing Field. */
|
|
18
|
+
export interface FieldBindings {
|
|
19
|
+
/** The control's `id`; the Field's label points at it. */
|
|
20
|
+
readonly id: string;
|
|
21
|
+
/** Space-separated ids for `aria-describedby` (help text, plus the error when invalid). */
|
|
22
|
+
readonly describedBy: string | undefined;
|
|
23
|
+
/** Whether the Field is currently invalid; render as `aria-invalid`. */
|
|
24
|
+
readonly invalid: boolean;
|
|
25
|
+
/** Whether the Field is required; render as `required`. */
|
|
26
|
+
readonly required: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Wire a custom control into the enclosing `<Field>`. Returns `null` outside a
|
|
30
|
+
* Field, so controls can call it unconditionally. Must be called during
|
|
31
|
+
* component initialization, like any context read. The returned object's
|
|
32
|
+
* properties are getters, so they stay reactive in the template:
|
|
33
|
+
*
|
|
34
|
+
* ```svelte
|
|
35
|
+
* <script lang="ts">
|
|
36
|
+
* const field = useField();
|
|
37
|
+
* </script>
|
|
38
|
+
*
|
|
39
|
+
* <input id={field?.id} aria-describedby={field?.describedBy} aria-invalid={field?.invalid || undefined} />
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function useField(): FieldBindings | null;
|
|
43
|
+
/** Shared state a RadioGroup provides to its radios (name, selected value, and a setter). @internal */
|
|
16
44
|
export interface RadioGroupContext {
|
|
17
45
|
readonly name: string | undefined;
|
|
18
46
|
readonly value: string | undefined;
|
|
19
47
|
select: (value: string) => void;
|
|
20
48
|
}
|
|
21
|
-
/** Publish {@link RadioGroupContext}
|
|
49
|
+
/** Publish a {@link RadioGroupContext}; called by `<RadioGroup>` only. @internal */
|
|
22
50
|
export declare function setRadioGroupContext(ctx: RadioGroupContext): void;
|
|
23
|
-
/** Read the nearest {@link RadioGroupContext}, or `undefined` outside a group. */
|
|
51
|
+
/** Read the nearest {@link RadioGroupContext}, or `undefined` outside a group. @internal */
|
|
24
52
|
export declare function getRadioGroupContext(): RadioGroupContext | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Ids a Dropdown generates so the trigger's `popovertarget` and the menu's
|
|
55
|
+
* `id` agree in server-rendered markup, before any script runs.
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export interface DropdownContext {
|
|
59
|
+
readonly menuId: string;
|
|
60
|
+
readonly triggerId: string;
|
|
61
|
+
}
|
|
62
|
+
/** Publish a {@link DropdownContext}; called by `<Dropdown>` only. @internal */
|
|
63
|
+
export declare function setDropdownContext(ctx: DropdownContext): void;
|
|
64
|
+
/** Read the nearest {@link DropdownContext}, or `undefined` outside a Dropdown. @internal */
|
|
65
|
+
export declare function getDropdownContext(): DropdownContext | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Selection state a Tabs root shares with its tabs and panels so `aria-selected`,
|
|
68
|
+
* `tabindex`, and `hidden` can be rendered on the server. Tabs and panels
|
|
69
|
+
* register in document order; a panel pairs with the tab at the same index.
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
export interface TabsContext {
|
|
73
|
+
/** The selected tab's value (falls back to the first registered tab). */
|
|
74
|
+
readonly value: string | undefined;
|
|
75
|
+
/** Register a tab and get its index. `value` defaults to that index. */
|
|
76
|
+
registerTab: (value: string | undefined) => number;
|
|
77
|
+
/** Register a panel and get its index. */
|
|
78
|
+
registerPanel: () => number;
|
|
79
|
+
/** Value of the tab registered at `index`. */
|
|
80
|
+
tabValueAt: (index: number) => string | undefined;
|
|
81
|
+
}
|
|
82
|
+
/** Publish a {@link TabsContext}; called by `<Tabs>` only. @internal */
|
|
83
|
+
export declare function setTabsContext(ctx: TabsContext): void;
|
|
84
|
+
/** Read the nearest {@link TabsContext}, or `undefined` outside Tabs. @internal */
|
|
85
|
+
export declare function getTabsContext(): TabsContext | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Open-item state an Accordion shares with its items so each `<details>` can
|
|
88
|
+
* render its `open` attribute on the server.
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
export interface AccordionContext {
|
|
92
|
+
/** Values of the open items. */
|
|
93
|
+
readonly value: readonly string[];
|
|
94
|
+
/** Register an item and get its index, which is its default value. */
|
|
95
|
+
registerItem: () => number;
|
|
96
|
+
}
|
|
97
|
+
/** Publish an {@link AccordionContext}; called by `<Accordion>` only. @internal */
|
|
98
|
+
export declare function setAccordionContext(ctx: AccordionContext): void;
|
|
99
|
+
/** Read the nearest {@link AccordionContext}, or `undefined` outside an Accordion. @internal */
|
|
100
|
+
export declare function getAccordionContext(): AccordionContext | undefined;
|
package/dist/context.js
CHANGED
|
@@ -1,31 +1,80 @@
|
|
|
1
1
|
import { getContext, setContext } from 'svelte';
|
|
2
2
|
const FIELD_KEY = Symbol('hl-field');
|
|
3
|
-
/** Publish {@link FieldContext}
|
|
3
|
+
/** Publish a {@link FieldContext}; called by `<Field>` only. @internal */
|
|
4
4
|
export function setFieldContext(ctx) {
|
|
5
5
|
setContext(FIELD_KEY, ctx);
|
|
6
6
|
}
|
|
7
|
-
/** Read the nearest {@link FieldContext}, or `undefined` outside a Field. */
|
|
7
|
+
/** Read the nearest {@link FieldContext}, or `undefined` outside a Field. @internal */
|
|
8
8
|
export function getFieldContext() {
|
|
9
9
|
return getContext(FIELD_KEY);
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Wire a custom control into the enclosing `<Field>`. Returns `null` outside a
|
|
13
|
+
* Field, so controls can call it unconditionally. Must be called during
|
|
14
|
+
* component initialization, like any context read. The returned object's
|
|
15
|
+
* properties are getters, so they stay reactive in the template:
|
|
16
|
+
*
|
|
17
|
+
* ```svelte
|
|
18
|
+
* <script lang="ts">
|
|
19
|
+
* const field = useField();
|
|
20
|
+
* </script>
|
|
21
|
+
*
|
|
22
|
+
* <input id={field?.id} aria-describedby={field?.describedBy} aria-invalid={field?.invalid || undefined} />
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function useField() {
|
|
13
26
|
const ctx = getFieldContext();
|
|
14
27
|
if (!ctx)
|
|
15
|
-
return
|
|
16
|
-
const describedBy = [ctx.helpId, ctx.invalid ? ctx.errorId : null].filter(Boolean).join(' ');
|
|
28
|
+
return null;
|
|
17
29
|
return {
|
|
18
|
-
id
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
get id() {
|
|
31
|
+
return ctx.id;
|
|
32
|
+
},
|
|
33
|
+
get describedBy() {
|
|
34
|
+
const ids = [ctx.helpId, ctx.invalid ? ctx.errorId : null].filter(Boolean).join(' ');
|
|
35
|
+
return ids || undefined;
|
|
36
|
+
},
|
|
37
|
+
get invalid() {
|
|
38
|
+
return ctx.invalid;
|
|
39
|
+
},
|
|
40
|
+
get required() {
|
|
41
|
+
return ctx.required;
|
|
42
|
+
},
|
|
21
43
|
};
|
|
22
44
|
}
|
|
23
45
|
const RADIO_GROUP_KEY = Symbol('hl-radio-group');
|
|
24
|
-
/** Publish {@link RadioGroupContext}
|
|
46
|
+
/** Publish a {@link RadioGroupContext}; called by `<RadioGroup>` only. @internal */
|
|
25
47
|
export function setRadioGroupContext(ctx) {
|
|
26
48
|
setContext(RADIO_GROUP_KEY, ctx);
|
|
27
49
|
}
|
|
28
|
-
/** Read the nearest {@link RadioGroupContext}, or `undefined` outside a group. */
|
|
50
|
+
/** Read the nearest {@link RadioGroupContext}, or `undefined` outside a group. @internal */
|
|
29
51
|
export function getRadioGroupContext() {
|
|
30
52
|
return getContext(RADIO_GROUP_KEY);
|
|
31
53
|
}
|
|
54
|
+
const DROPDOWN_KEY = Symbol('hl-dropdown');
|
|
55
|
+
/** Publish a {@link DropdownContext}; called by `<Dropdown>` only. @internal */
|
|
56
|
+
export function setDropdownContext(ctx) {
|
|
57
|
+
setContext(DROPDOWN_KEY, ctx);
|
|
58
|
+
}
|
|
59
|
+
/** Read the nearest {@link DropdownContext}, or `undefined` outside a Dropdown. @internal */
|
|
60
|
+
export function getDropdownContext() {
|
|
61
|
+
return getContext(DROPDOWN_KEY);
|
|
62
|
+
}
|
|
63
|
+
const TABS_KEY = Symbol('hl-tabs');
|
|
64
|
+
/** Publish a {@link TabsContext}; called by `<Tabs>` only. @internal */
|
|
65
|
+
export function setTabsContext(ctx) {
|
|
66
|
+
setContext(TABS_KEY, ctx);
|
|
67
|
+
}
|
|
68
|
+
/** Read the nearest {@link TabsContext}, or `undefined` outside Tabs. @internal */
|
|
69
|
+
export function getTabsContext() {
|
|
70
|
+
return getContext(TABS_KEY);
|
|
71
|
+
}
|
|
72
|
+
const ACCORDION_KEY = Symbol('hl-accordion');
|
|
73
|
+
/** Publish an {@link AccordionContext}; called by `<Accordion>` only. @internal */
|
|
74
|
+
export function setAccordionContext(ctx) {
|
|
75
|
+
setContext(ACCORDION_KEY, ctx);
|
|
76
|
+
}
|
|
77
|
+
/** Read the nearest {@link AccordionContext}, or `undefined` outside an Accordion. @internal */
|
|
78
|
+
export function getAccordionContext() {
|
|
79
|
+
return getContext(ACCORDION_KEY);
|
|
80
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { useEnhancer } from './useEnhancer.svelte.js';
|
|
2
|
+
export type { UseEnhancer } from './useEnhancer.svelte.js';
|
|
3
|
+
export { useField } from './context.js';
|
|
4
|
+
export type { FieldBindings } from './context.js';
|
|
2
5
|
export { useToast } from './toast.js';
|
|
3
|
-
export { fieldBindings } from './context.js';
|
|
4
|
-
export type { FieldContext, RadioGroupContext } from './context.js';
|
|
5
6
|
export { default as Accordion } from './components/Accordion.svelte';
|
|
6
7
|
export { default as AccordionItem } from './components/AccordionItem.svelte';
|
|
7
8
|
export { default as Disclosure } from './components/Disclosure.svelte';
|
|
@@ -13,9 +14,11 @@ export { default as Dropdown } from './components/Dropdown.svelte';
|
|
|
13
14
|
export { default as DropdownTrigger } from './components/DropdownTrigger.svelte';
|
|
14
15
|
export { default as DropdownMenu } from './components/DropdownMenu.svelte';
|
|
15
16
|
export { default as DropdownItem } from './components/DropdownItem.svelte';
|
|
17
|
+
export { default as DropdownGroup } from './components/DropdownGroup.svelte';
|
|
16
18
|
export { default as DropdownSeparator } from './components/DropdownSeparator.svelte';
|
|
17
19
|
export { default as Menu } from './components/Menu.svelte';
|
|
18
20
|
export { default as MenuItem } from './components/MenuItem.svelte';
|
|
21
|
+
export { default as MenuSubmenu } from './components/MenuSubmenu.svelte';
|
|
19
22
|
export { default as Modal } from './components/Modal.svelte';
|
|
20
23
|
export { default as ModalHeader } from './components/ModalHeader.svelte';
|
|
21
24
|
export { default as ModalBody } from './components/ModalBody.svelte';
|
|
@@ -69,7 +72,8 @@ export { default as Avatar } from './components/Avatar.svelte';
|
|
|
69
72
|
export { default as AvatarGroup } from './components/AvatarGroup.svelte';
|
|
70
73
|
export { default as Kbd } from './components/Kbd.svelte';
|
|
71
74
|
export { default as Separator } from './components/Separator.svelte';
|
|
75
|
+
export { default as Table } from './components/Table.svelte';
|
|
72
76
|
export { default as Pagination } from './components/Pagination.svelte';
|
|
73
77
|
export { default as Toc } from './components/Toc.svelte';
|
|
74
78
|
export { default as SkipLink } from './components/SkipLink.svelte';
|
|
75
|
-
export type { AccordionApi, CommandApi, ComboboxApi, DisclosureApi, Disposer, DrawerApi, DropdownApi, EnhancerHandle, MenuApi, ModalApi, PopoverApi, TabsApi, ToastApi, TocApi, TooltipApi, } from '@hydrateless/enhancers';
|
|
79
|
+
export type { AccordionApi, CommandApi, ComboboxApi, DisclosureApi, Disposer, DrawerApi, DropdownApi, EnhancerHandle, MenuApi, ModalApi, PopoverApi, TabsApi, ToastApi, ToastIntent, ToastOptions, TocApi, TooltipApi, } from '@hydrateless/enhancers';
|