@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
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLFieldsetAttributes } from 'svelte/elements';
|
|
3
3
|
interface Props extends HTMLFieldsetAttributes {
|
|
4
|
+
/** Group caption rendered as a `<legend>`. */
|
|
4
5
|
legend?: Snippet;
|
|
6
|
+
/** Grouped fields. */
|
|
5
7
|
children?: Snippet;
|
|
6
8
|
}
|
|
7
9
|
declare const Fieldset: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
3
|
-
import {
|
|
3
|
+
import { useField } from '../context.js';
|
|
4
4
|
|
|
5
5
|
interface Props extends Omit<HTMLInputAttributes, 'size'> {
|
|
6
|
+
/** Current value; two-way bindable (`bind:value`). */
|
|
6
7
|
value?: string | number;
|
|
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;
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
let {
|
|
12
|
-
|
|
14
|
+
let {
|
|
15
|
+
value = $bindable(),
|
|
16
|
+
size,
|
|
17
|
+
invalid = false,
|
|
18
|
+
id,
|
|
19
|
+
required,
|
|
20
|
+
'aria-describedby': describedBy,
|
|
21
|
+
class: klass,
|
|
22
|
+
...rest
|
|
23
|
+
}: Props = $props();
|
|
24
|
+
// Optional: wires id/aria-describedby/aria-invalid/required when inside a <Field>.
|
|
25
|
+
const field = useField();
|
|
26
|
+
const isInvalid = $derived(invalid || Boolean(field?.invalid));
|
|
13
27
|
</script>
|
|
14
28
|
|
|
15
29
|
<input
|
|
16
|
-
{...field}
|
|
17
30
|
{...rest}
|
|
31
|
+
id={id ?? field?.id}
|
|
32
|
+
required={required ?? (field?.required || undefined)}
|
|
33
|
+
aria-describedby={describedBy ?? field?.describedBy}
|
|
18
34
|
bind:value
|
|
19
35
|
class={['hl-input', klass]}
|
|
20
36
|
data-hl-size={size}
|
|
21
|
-
data-hl-invalid={
|
|
22
|
-
aria-invalid={
|
|
37
|
+
data-hl-invalid={isInvalid || undefined}
|
|
38
|
+
aria-invalid={isInvalid || undefined}
|
|
23
39
|
/>
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
2
2
|
interface Props extends Omit<HTMLInputAttributes, 'size'> {
|
|
3
|
+
/** Current value; two-way bindable (`bind:value`). */
|
|
3
4
|
value?: string | number;
|
|
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;
|
|
6
9
|
}
|
|
7
10
|
declare const Input: import("svelte").Component<Props, {}, "value">;
|
|
@@ -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
|
+
/** Key name or shortcut text. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const Kbd: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,52 +1,65 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { enhanceMenu, type EnhanceMenuOptions
|
|
2
|
+
import { enhanceMenu, type EnhanceMenuOptions } from '@hydrateless/enhancers';
|
|
3
|
+
import { untrack } from 'svelte';
|
|
3
4
|
import type { Snippet } from 'svelte';
|
|
4
5
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
import { useEnhancer } from '../useEnhancer.svelte.js';
|
|
5
7
|
|
|
6
8
|
interface Props extends Omit<HTMLAttributes<HTMLUListElement>, 'onselect'> {
|
|
9
|
+
/** Layout of the top-level items. Defaults to `horizontal` (a menubar). */
|
|
7
10
|
orientation?: EnhanceMenuOptions['orientation'];
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Value of the open submenu, or `null` when all are closed; two-way
|
|
13
|
+
* bindable (`bind:value`). Submenu values come from `<MenuSubmenu value>`,
|
|
14
|
+
* defaulting to the top-level index.
|
|
15
|
+
*/
|
|
16
|
+
value?: string | null;
|
|
17
|
+
/** Submenu to open initially for uncontrolled usage. */
|
|
18
|
+
defaultValue?: string | null;
|
|
19
|
+
/** Called with the open submenu's value (or `null`) after every change. */
|
|
20
|
+
onValueChange?: (value: string | null) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Called with the item's value when a leaf item is activated. For
|
|
23
|
+
* `menuitemcheckbox`/`menuitemradio` items, `checked` is the new state.
|
|
24
|
+
*/
|
|
25
|
+
onSelect?: (value: string, item: HTMLElement, checked?: boolean) => void;
|
|
26
|
+
/** `<MenuItem>`s and `<MenuSubmenu>`s. */
|
|
12
27
|
children?: Snippet;
|
|
13
28
|
}
|
|
14
29
|
|
|
15
30
|
let {
|
|
16
31
|
orientation = 'horizontal',
|
|
17
|
-
|
|
32
|
+
value = $bindable(),
|
|
33
|
+
defaultValue = null,
|
|
34
|
+
onValueChange,
|
|
18
35
|
onSelect,
|
|
19
36
|
children,
|
|
20
37
|
...rest
|
|
21
38
|
}: Props = $props();
|
|
22
|
-
|
|
23
|
-
|
|
39
|
+
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
40
|
+
if (value === undefined) value = defaultValue;
|
|
24
41
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
handle.destroy();
|
|
35
|
-
api = null;
|
|
36
|
-
};
|
|
37
|
-
});
|
|
42
|
+
const menu = useEnhancer(enhanceMenu, () => ({
|
|
43
|
+
orientation,
|
|
44
|
+
defaultValue: untrack(() => value),
|
|
45
|
+
onValueChange: (next) => {
|
|
46
|
+
value = next;
|
|
47
|
+
onValueChange?.(next);
|
|
48
|
+
},
|
|
49
|
+
onSelect: (itemValue, item, checked) => onSelect?.(itemValue, item, checked),
|
|
50
|
+
}));
|
|
38
51
|
|
|
39
52
|
$effect(() => {
|
|
40
|
-
if (
|
|
53
|
+
if (value !== undefined) menu.api?.setValue(value);
|
|
41
54
|
});
|
|
42
55
|
</script>
|
|
43
56
|
|
|
44
57
|
<ul
|
|
45
58
|
{...rest}
|
|
46
|
-
bind:this={host}
|
|
47
59
|
data-hl-menu
|
|
48
60
|
role={orientation === 'vertical' ? 'menu' : 'menubar'}
|
|
49
61
|
aria-orientation={orientation}
|
|
62
|
+
{@attach menu.attach}
|
|
50
63
|
>
|
|
51
64
|
{@render children?.()}
|
|
52
65
|
</ul>
|
|
@@ -2,13 +2,26 @@ import { type EnhanceMenuOptions } from '@hydrateless/enhancers';
|
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
interface Props extends Omit<HTMLAttributes<HTMLUListElement>, 'onselect'> {
|
|
5
|
+
/** Layout of the top-level items. Defaults to `horizontal` (a menubar). */
|
|
5
6
|
orientation?: EnhanceMenuOptions['orientation'];
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Value of the open submenu, or `null` when all are closed; two-way
|
|
9
|
+
* bindable (`bind:value`). Submenu values come from `<MenuSubmenu value>`,
|
|
10
|
+
* defaulting to the top-level index.
|
|
11
|
+
*/
|
|
12
|
+
value?: string | null;
|
|
13
|
+
/** Submenu to open initially for uncontrolled usage. */
|
|
14
|
+
defaultValue?: string | null;
|
|
15
|
+
/** Called with the open submenu's value (or `null`) after every change. */
|
|
16
|
+
onValueChange?: (value: string | null) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Called with the item's value when a leaf item is activated. For
|
|
19
|
+
* `menuitemcheckbox`/`menuitemradio` items, `checked` is the new state.
|
|
20
|
+
*/
|
|
21
|
+
onSelect?: (value: string, item: HTMLElement, checked?: boolean) => void;
|
|
22
|
+
/** `<MenuItem>`s and `<MenuSubmenu>`s. */
|
|
10
23
|
children?: Snippet;
|
|
11
24
|
}
|
|
12
|
-
declare const Menu: import("svelte").Component<Props, {}, "
|
|
25
|
+
declare const Menu: import("svelte").Component<Props, {}, "value">;
|
|
13
26
|
type Menu = ReturnType<typeof Menu>;
|
|
14
27
|
export default Menu;
|
|
@@ -1,42 +1,70 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
import type {
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
|
|
5
|
-
interface Props extends Omit<
|
|
5
|
+
interface Props extends Omit<HTMLAttributes<HTMLElement>, 'role'> {
|
|
6
6
|
/** Render as a link instead of a button. */
|
|
7
7
|
href?: string;
|
|
8
8
|
/** Stable value identifying this item; defaults to its label text. */
|
|
9
9
|
value?: string;
|
|
10
|
-
/**
|
|
10
|
+
/** Skip the item in keyboard navigation and ignore activation. */
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** `menuitemcheckbox` toggles; `menuitemradio` is exclusive within its menu. */
|
|
13
|
+
role?: 'menuitem' | 'menuitemcheckbox' | 'menuitemradio';
|
|
14
|
+
/** Checked state for checkable roles; rendered as `aria-checked`. */
|
|
15
|
+
checked?: boolean;
|
|
16
|
+
/** Convenience handler fired on activation; the Menu's `onSelect` also fires. */
|
|
11
17
|
onSelect?: () => void;
|
|
12
|
-
/**
|
|
13
|
-
submenu?: Snippet;
|
|
14
|
-
/** Extra attributes for the `<a>` when `href` is set. */
|
|
15
|
-
anchorProps?: HTMLAnchorAttributes;
|
|
18
|
+
/** Item label. */
|
|
16
19
|
children?: Snippet;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
let {
|
|
22
|
+
let {
|
|
23
|
+
href,
|
|
24
|
+
value,
|
|
25
|
+
disabled,
|
|
26
|
+
role = 'menuitem',
|
|
27
|
+
checked,
|
|
28
|
+
onSelect,
|
|
29
|
+
onclick,
|
|
30
|
+
children,
|
|
31
|
+
...rest
|
|
32
|
+
}: Props = $props();
|
|
33
|
+
const checkable = $derived(role !== 'menuitem');
|
|
34
|
+
const ariaChecked = $derived(checkable ? (checked ?? false) : undefined);
|
|
35
|
+
|
|
36
|
+
function handleClick(e: MouseEvent) {
|
|
37
|
+
if (disabled) {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
onSelect?.();
|
|
42
|
+
onclick?.(e as MouseEvent & { currentTarget: EventTarget & HTMLElement });
|
|
43
|
+
}
|
|
20
44
|
</script>
|
|
21
45
|
|
|
22
46
|
<li role="none">
|
|
23
|
-
{#if href
|
|
24
|
-
<a
|
|
47
|
+
{#if href}
|
|
48
|
+
<a
|
|
49
|
+
{...rest}
|
|
50
|
+
{href}
|
|
51
|
+
{role}
|
|
52
|
+
data-hl-value={value}
|
|
53
|
+
aria-disabled={disabled || undefined}
|
|
54
|
+
aria-checked={ariaChecked}
|
|
55
|
+
onclick={handleClick}>{@render children?.()}</a
|
|
56
|
+
>
|
|
25
57
|
{:else}
|
|
26
58
|
<button
|
|
27
59
|
{...rest}
|
|
28
60
|
type="button"
|
|
29
|
-
role
|
|
61
|
+
{role}
|
|
30
62
|
data-hl-value={value}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}}
|
|
63
|
+
disabled={disabled || undefined}
|
|
64
|
+
aria-checked={ariaChecked}
|
|
65
|
+
onclick={handleClick}
|
|
35
66
|
>
|
|
36
67
|
{@render children?.()}
|
|
37
68
|
</button>
|
|
38
69
|
{/if}
|
|
39
|
-
{#if submenu}
|
|
40
|
-
<ul role="menu" data-hl-menu-submenu hidden>{@render submenu()}</ul>
|
|
41
|
-
{/if}
|
|
42
70
|
</li>
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
-
import type {
|
|
3
|
-
interface Props extends Omit<
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
interface Props extends Omit<HTMLAttributes<HTMLElement>, 'role'> {
|
|
4
4
|
/** Render as a link instead of a button. */
|
|
5
5
|
href?: string;
|
|
6
6
|
/** Stable value identifying this item; defaults to its label text. */
|
|
7
7
|
value?: string;
|
|
8
|
-
/**
|
|
8
|
+
/** Skip the item in keyboard navigation and ignore activation. */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** `menuitemcheckbox` toggles; `menuitemradio` is exclusive within its menu. */
|
|
11
|
+
role?: 'menuitem' | 'menuitemcheckbox' | 'menuitemradio';
|
|
12
|
+
/** Checked state for checkable roles; rendered as `aria-checked`. */
|
|
13
|
+
checked?: boolean;
|
|
14
|
+
/** Convenience handler fired on activation; the Menu's `onSelect` also fires. */
|
|
9
15
|
onSelect?: () => void;
|
|
10
|
-
/**
|
|
11
|
-
submenu?: Snippet;
|
|
12
|
-
/** Extra attributes for the `<a>` when `href` is set. */
|
|
13
|
-
anchorProps?: HTMLAnchorAttributes;
|
|
16
|
+
/** Item label. */
|
|
14
17
|
children?: Snippet;
|
|
15
18
|
}
|
|
16
19
|
declare const MenuItem: import("svelte").Component<Props, {}, "">;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
|
|
5
|
+
interface Props extends Omit<HTMLAttributes<HTMLUListElement>, 'title'> {
|
|
6
|
+
/** Plain-text label of the trigger item. Use the `trigger` snippet for rich content. */
|
|
7
|
+
label?: string;
|
|
8
|
+
/** Rich trigger content; overrides `label`. */
|
|
9
|
+
trigger?: Snippet;
|
|
10
|
+
/** Value the Menu reports while this submenu is open; defaults to the top-level index. */
|
|
11
|
+
value?: string;
|
|
12
|
+
/** Skip the trigger in keyboard navigation and keep the submenu closed. */
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
/** Nested `<MenuItem>`s. */
|
|
15
|
+
children?: Snippet;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let { label, trigger, value, disabled, class: klass, children, ...rest }: Props = $props();
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<!-- No `hidden` in the markup: before the enhancer runs, the stylesheet shows
|
|
22
|
+
the submenu on hover/focus-within so the navigation stays usable. -->
|
|
23
|
+
<li role="none">
|
|
24
|
+
<button type="button" role="menuitem" data-hl-value={value} disabled={disabled || undefined}>
|
|
25
|
+
{#if trigger}{@render trigger()}{:else}{label}{/if}
|
|
26
|
+
</button>
|
|
27
|
+
<ul {...rest} role="menu" data-hl-menu-submenu class={klass}>
|
|
28
|
+
{@render children?.()}
|
|
29
|
+
</ul>
|
|
30
|
+
</li>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
interface Props extends Omit<HTMLAttributes<HTMLUListElement>, 'title'> {
|
|
4
|
+
/** Plain-text label of the trigger item. Use the `trigger` snippet for rich content. */
|
|
5
|
+
label?: string;
|
|
6
|
+
/** Rich trigger content; overrides `label`. */
|
|
7
|
+
trigger?: Snippet;
|
|
8
|
+
/** Value the Menu reports while this submenu is open; defaults to the top-level index. */
|
|
9
|
+
value?: string;
|
|
10
|
+
/** Skip the trigger in keyboard navigation and keep the submenu closed. */
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** Nested `<MenuItem>`s. */
|
|
13
|
+
children?: Snippet;
|
|
14
|
+
}
|
|
15
|
+
declare const MenuSubmenu: import("svelte").Component<Props, {}, "">;
|
|
16
|
+
type MenuSubmenu = ReturnType<typeof MenuSubmenu>;
|
|
17
|
+
export default MenuSubmenu;
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { enhanceModal
|
|
2
|
+
import { enhanceModal } from '@hydrateless/enhancers';
|
|
3
3
|
import { untrack } from 'svelte';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
5
|
import type { HTMLDialogAttributes } from 'svelte/elements';
|
|
6
|
+
import { useEnhancer } from '../useEnhancer.svelte.js';
|
|
6
7
|
|
|
7
8
|
interface Props extends HTMLDialogAttributes {
|
|
8
9
|
/** Open state; two-way bindable (`bind:open`). */
|
|
9
10
|
open?: boolean;
|
|
10
11
|
/** Open the dialog initially for uncontrolled usage. */
|
|
11
12
|
defaultOpen?: boolean;
|
|
13
|
+
/** Called after the dialog opens or closes (including native Escape). */
|
|
14
|
+
onOpenChange?: (open: boolean) => void;
|
|
15
|
+
/** Let Escape and a backdrop click close the dialog. Defaults to `true`. */
|
|
12
16
|
closeOnBackdrop?: boolean;
|
|
17
|
+
/** Dialog content; compose with `<ModalHeader>`, `<ModalBody>`, `<ModalFooter>`. */
|
|
13
18
|
children?: Snippet;
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
let {
|
|
17
22
|
defaultOpen = false,
|
|
18
23
|
open = $bindable(),
|
|
24
|
+
onOpenChange,
|
|
19
25
|
closeOnBackdrop = true,
|
|
20
26
|
class: klass,
|
|
21
27
|
children,
|
|
@@ -23,28 +29,21 @@
|
|
|
23
29
|
}: Props = $props();
|
|
24
30
|
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
25
31
|
if (open === undefined) open = defaultOpen;
|
|
26
|
-
let dialog = $state<HTMLDialogElement>();
|
|
27
|
-
let api = $state<ModalApi | null>(null);
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
onOpenChange
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return () => {
|
|
38
|
-
handle.destroy();
|
|
39
|
-
api = null;
|
|
40
|
-
};
|
|
41
|
-
});
|
|
33
|
+
const modal = useEnhancer(enhanceModal, () => ({
|
|
34
|
+
closeOnBackdrop,
|
|
35
|
+
defaultOpen: untrack(() => open),
|
|
36
|
+
onOpenChange: (next) => {
|
|
37
|
+
open = next;
|
|
38
|
+
onOpenChange?.(next);
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
42
41
|
|
|
43
42
|
$effect(() => {
|
|
44
|
-
if (open != null) api?.setOpen(open);
|
|
43
|
+
if (open != null) modal.api?.setOpen(open);
|
|
45
44
|
});
|
|
46
45
|
</script>
|
|
47
46
|
|
|
48
|
-
<dialog {...rest}
|
|
47
|
+
<dialog {...rest} class={['hl-modal', klass]} data-hl-modal {@attach modal.attach}>
|
|
49
48
|
{@render children?.()}
|
|
50
49
|
</dialog>
|
|
@@ -5,7 +5,11 @@ interface Props extends HTMLDialogAttributes {
|
|
|
5
5
|
open?: boolean;
|
|
6
6
|
/** Open the dialog initially for uncontrolled usage. */
|
|
7
7
|
defaultOpen?: boolean;
|
|
8
|
+
/** Called after the dialog opens or closes (including native Escape). */
|
|
9
|
+
onOpenChange?: (open: boolean) => void;
|
|
10
|
+
/** Let Escape and a backdrop click close the dialog. Defaults to `true`. */
|
|
8
11
|
closeOnBackdrop?: boolean;
|
|
12
|
+
/** Dialog content; compose with `<ModalHeader>`, `<ModalBody>`, `<ModalFooter>`. */
|
|
9
13
|
children?: Snippet;
|
|
10
14
|
}
|
|
11
15
|
declare const Modal: import("svelte").Component<Props, {}, "open">;
|
|
@@ -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 dialog content. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const ModalBody: 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
|
+
/** Footer content, typically actions. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const ModalFooter: 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
|
+
/** Dialog title; the enhancer labels the dialog with this section. */
|
|
4
5
|
children?: Snippet;
|
|
5
6
|
}
|
|
6
7
|
declare const ModalHeader: import("svelte").Component<Props, {}, "">;
|
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
|
|
4
4
|
interface Props extends Omit<HTMLAttributes<HTMLElement>, 'onchange'> {
|
|
5
|
+
/** Current page (1-based). */
|
|
5
6
|
page: number;
|
|
7
|
+
/** Total number of pages. */
|
|
6
8
|
count: number;
|
|
9
|
+
/** Called with the requested page when the user navigates. */
|
|
7
10
|
onPageChange?: (page: number) => void;
|
|
8
11
|
/** Pages to show on each side of the current page. Defaults to 1. */
|
|
9
12
|
siblingCount?: number;
|
|
10
13
|
/** Render Previous/Next controls. Defaults to true. */
|
|
11
14
|
showControls?: boolean;
|
|
15
|
+
/** Visible label of the Previous control. */
|
|
12
16
|
prevLabel?: string;
|
|
17
|
+
/** Visible label of the Next control. */
|
|
13
18
|
nextLabel?: string;
|
|
14
19
|
}
|
|
15
20
|
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
2
|
interface Props extends Omit<HTMLAttributes<HTMLElement>, 'onchange'> {
|
|
3
|
+
/** Current page (1-based). */
|
|
3
4
|
page: number;
|
|
5
|
+
/** Total number of pages. */
|
|
4
6
|
count: number;
|
|
7
|
+
/** Called with the requested page when the user navigates. */
|
|
5
8
|
onPageChange?: (page: number) => void;
|
|
6
9
|
/** Pages to show on each side of the current page. Defaults to 1. */
|
|
7
10
|
siblingCount?: number;
|
|
8
11
|
/** Render Previous/Next controls. Defaults to true. */
|
|
9
12
|
showControls?: boolean;
|
|
13
|
+
/** Visible label of the Previous control. */
|
|
10
14
|
prevLabel?: string;
|
|
15
|
+
/** Visible label of the Next control. */
|
|
11
16
|
nextLabel?: string;
|
|
12
17
|
}
|
|
13
18
|
declare const Pagination: import("svelte").Component<Props, {}, "">;
|
|
@@ -1,42 +1,59 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { enhancePopover, type
|
|
2
|
+
import { enhancePopover, type EnhancePopoverOptions } 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 { useEnhancer } from '../useEnhancer.svelte.js';
|
|
6
7
|
|
|
7
8
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
9
|
+
/**
|
|
10
|
+
* Open state; two-way bindable (`bind:open`). The browser's light-dismiss
|
|
11
|
+
* (Escape/outside click) closes it and updates the binding.
|
|
12
|
+
*/
|
|
10
13
|
open?: boolean;
|
|
11
14
|
/** Show the popover initially for uncontrolled usage. */
|
|
12
15
|
defaultOpen?: boolean;
|
|
16
|
+
/** Called after the popover shows or hides. */
|
|
17
|
+
onOpenChange?: (open: boolean) => void;
|
|
18
|
+
/** Preferred placement relative to the invoker. Defaults to `bottom`. */
|
|
19
|
+
placement?: EnhancePopoverOptions['placement'];
|
|
20
|
+
/** Open on hover/focus of the invoker instead of on click. */
|
|
21
|
+
hover?: boolean;
|
|
22
|
+
/** Popover content. Point a `<button popovertarget={id}>` at this element's `id`. */
|
|
13
23
|
children?: Snippet;
|
|
14
24
|
}
|
|
15
25
|
|
|
16
|
-
let {
|
|
26
|
+
let {
|
|
27
|
+
defaultOpen = false,
|
|
28
|
+
open = $bindable(),
|
|
29
|
+
onOpenChange,
|
|
30
|
+
placement,
|
|
31
|
+
hover = false,
|
|
32
|
+
id,
|
|
33
|
+
children,
|
|
34
|
+
...rest
|
|
35
|
+
}: Props = $props();
|
|
17
36
|
// svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
|
|
18
37
|
if (open === undefined) open = defaultOpen;
|
|
19
|
-
|
|
20
|
-
|
|
38
|
+
// An id is required so invokers can target the popover before hydration.
|
|
39
|
+
const generatedId = $props.id();
|
|
40
|
+
const popoverId = $derived(id ?? `hl-popover-${generatedId}`);
|
|
21
41
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
api = null;
|
|
32
|
-
};
|
|
33
|
-
});
|
|
42
|
+
const popover = useEnhancer(enhancePopover, () => ({
|
|
43
|
+
placement,
|
|
44
|
+
triggerEvent: hover ? ('hover' as const) : ('click' as const),
|
|
45
|
+
defaultOpen: untrack(() => open),
|
|
46
|
+
onOpenChange: (next) => {
|
|
47
|
+
open = next;
|
|
48
|
+
onOpenChange?.(next);
|
|
49
|
+
},
|
|
50
|
+
}));
|
|
34
51
|
|
|
35
52
|
$effect(() => {
|
|
36
|
-
if (open != null) api?.setOpen(open);
|
|
53
|
+
if (open != null) popover.api?.setOpen(open);
|
|
37
54
|
});
|
|
38
55
|
</script>
|
|
39
56
|
|
|
40
|
-
<div {...rest} data-hl-popover popover="auto" role="dialog"
|
|
57
|
+
<div {...rest} id={popoverId} data-hl-popover popover="auto" role="dialog" {@attach popover.attach}>
|
|
41
58
|
{@render children?.()}
|
|
42
59
|
</div>
|