@hydrateless/svelte 0.7.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.
Files changed (155) hide show
  1. package/README.md +173 -38
  2. package/dist/components/Accordion.svelte +28 -17
  3. package/dist/components/Accordion.svelte.d.ts +3 -0
  4. package/dist/components/AccordionItem.svelte +17 -11
  5. package/dist/components/AccordionItem.svelte.d.ts +5 -3
  6. package/dist/components/Alert.svelte +4 -0
  7. package/dist/components/Alert.svelte.d.ts +4 -0
  8. package/dist/components/Avatar.svelte +5 -0
  9. package/dist/components/Avatar.svelte.d.ts +5 -0
  10. package/dist/components/AvatarGroup.svelte +1 -0
  11. package/dist/components/AvatarGroup.svelte.d.ts +1 -0
  12. package/dist/components/Badge.svelte +4 -0
  13. package/dist/components/Badge.svelte.d.ts +4 -0
  14. package/dist/components/Breadcrumb.svelte +1 -0
  15. package/dist/components/Breadcrumb.svelte.d.ts +1 -0
  16. package/dist/components/BreadcrumbItem.svelte +3 -0
  17. package/dist/components/BreadcrumbItem.svelte.d.ts +3 -0
  18. package/dist/components/Button.svelte +7 -0
  19. package/dist/components/Button.svelte.d.ts +7 -0
  20. package/dist/components/Card.svelte +2 -0
  21. package/dist/components/Card.svelte.d.ts +2 -0
  22. package/dist/components/CardBody.svelte +1 -0
  23. package/dist/components/CardBody.svelte.d.ts +1 -0
  24. package/dist/components/CardDescription.svelte +1 -0
  25. package/dist/components/CardDescription.svelte.d.ts +1 -0
  26. package/dist/components/CardFooter.svelte +1 -0
  27. package/dist/components/CardFooter.svelte.d.ts +1 -0
  28. package/dist/components/CardHeader.svelte +1 -0
  29. package/dist/components/CardHeader.svelte.d.ts +1 -0
  30. package/dist/components/CardTitle.svelte +1 -0
  31. package/dist/components/CardTitle.svelte.d.ts +1 -0
  32. package/dist/components/Checkbox.svelte +24 -2
  33. package/dist/components/Checkbox.svelte.d.ts +2 -0
  34. package/dist/components/Combobox.svelte +37 -26
  35. package/dist/components/Combobox.svelte.d.ts +12 -3
  36. package/dist/components/ComboboxInput.svelte +21 -2
  37. package/dist/components/ComboboxInput.svelte.d.ts +1 -0
  38. package/dist/components/ComboboxList.svelte +4 -1
  39. package/dist/components/ComboboxList.svelte.d.ts +1 -0
  40. package/dist/components/ComboboxOption.svelte +6 -2
  41. package/dist/components/ComboboxOption.svelte.d.ts +4 -0
  42. package/dist/components/Command.svelte +36 -9
  43. package/dist/components/Command.svelte.d.ts +12 -5
  44. package/dist/components/CommandEmpty.svelte +1 -0
  45. package/dist/components/CommandEmpty.svelte.d.ts +1 -0
  46. package/dist/components/CommandGroup.svelte +1 -0
  47. package/dist/components/CommandGroup.svelte.d.ts +1 -0
  48. package/dist/components/CommandItem.svelte +2 -0
  49. package/dist/components/CommandItem.svelte.d.ts +2 -0
  50. package/dist/components/CommandList.svelte +1 -0
  51. package/dist/components/CommandList.svelte.d.ts +1 -0
  52. package/dist/components/Disclosure.svelte +50 -6
  53. package/dist/components/Disclosure.svelte.d.ts +15 -2
  54. package/dist/components/Drawer.svelte +32 -21
  55. package/dist/components/Drawer.svelte.d.ts +8 -1
  56. package/dist/components/DrawerBody.svelte +1 -0
  57. package/dist/components/DrawerBody.svelte.d.ts +1 -0
  58. package/dist/components/DrawerFooter.svelte +1 -0
  59. package/dist/components/DrawerFooter.svelte.d.ts +1 -0
  60. package/dist/components/DrawerHeader.svelte +1 -0
  61. package/dist/components/DrawerHeader.svelte.d.ts +1 -0
  62. package/dist/components/Dropdown.svelte +49 -24
  63. package/dist/components/Dropdown.svelte.d.ts +15 -2
  64. package/dist/components/DropdownGroup.svelte +19 -0
  65. package/dist/components/DropdownGroup.svelte.d.ts +11 -0
  66. package/dist/components/DropdownItem.svelte +28 -4
  67. package/dist/components/DropdownItem.svelte.d.ts +11 -2
  68. package/dist/components/DropdownMenu.svelte +14 -2
  69. package/dist/components/DropdownMenu.svelte.d.ts +1 -0
  70. package/dist/components/DropdownSeparator.svelte +3 -2
  71. package/dist/components/DropdownTrigger.svelte +14 -2
  72. package/dist/components/DropdownTrigger.svelte.d.ts +1 -0
  73. package/dist/components/Field.svelte +45 -5
  74. package/dist/components/Field.svelte.d.ts +16 -0
  75. package/dist/components/FieldError.svelte +4 -3
  76. package/dist/components/FieldError.svelte.d.ts +1 -0
  77. package/dist/components/FieldHelp.svelte +4 -3
  78. package/dist/components/FieldHelp.svelte.d.ts +1 -0
  79. package/dist/components/FieldLabel.svelte +4 -3
  80. package/dist/components/FieldLabel.svelte.d.ts +1 -0
  81. package/dist/components/Fieldset.svelte +2 -0
  82. package/dist/components/Fieldset.svelte.d.ts +2 -0
  83. package/dist/components/Input.svelte +22 -6
  84. package/dist/components/Input.svelte.d.ts +3 -0
  85. package/dist/components/Kbd.svelte +1 -0
  86. package/dist/components/Kbd.svelte.d.ts +1 -0
  87. package/dist/components/Menu.svelte +43 -6
  88. package/dist/components/Menu.svelte.d.ts +19 -2
  89. package/dist/components/MenuItem.svelte +49 -18
  90. package/dist/components/MenuItem.svelte.d.ts +12 -7
  91. package/dist/components/MenuSubmenu.svelte +30 -0
  92. package/dist/components/MenuSubmenu.svelte.d.ts +17 -0
  93. package/dist/components/Modal.svelte +23 -19
  94. package/dist/components/Modal.svelte.d.ts +6 -0
  95. package/dist/components/ModalBody.svelte +1 -0
  96. package/dist/components/ModalBody.svelte.d.ts +1 -0
  97. package/dist/components/ModalFooter.svelte +1 -0
  98. package/dist/components/ModalFooter.svelte.d.ts +1 -0
  99. package/dist/components/ModalHeader.svelte +1 -0
  100. package/dist/components/ModalHeader.svelte.d.ts +1 -0
  101. package/dist/components/Pagination.svelte +5 -0
  102. package/dist/components/Pagination.svelte.d.ts +5 -0
  103. package/dist/components/Popover.svelte +41 -18
  104. package/dist/components/Popover.svelte.d.ts +14 -2
  105. package/dist/components/Progress.svelte +4 -0
  106. package/dist/components/Progress.svelte.d.ts +4 -0
  107. package/dist/components/Radio.svelte +2 -0
  108. package/dist/components/Radio.svelte.d.ts +2 -0
  109. package/dist/components/RadioGroup.svelte +34 -4
  110. package/dist/components/RadioGroup.svelte.d.ts +10 -1
  111. package/dist/components/SegmentedControl.svelte +35 -7
  112. package/dist/components/SegmentedControl.svelte.d.ts +13 -2
  113. package/dist/components/Select.svelte +16 -5
  114. package/dist/components/Select.svelte.d.ts +4 -0
  115. package/dist/components/Separator.svelte +2 -0
  116. package/dist/components/Separator.svelte.d.ts +2 -0
  117. package/dist/components/Skeleton.svelte +6 -3
  118. package/dist/components/Skeleton.svelte.d.ts +4 -1
  119. package/dist/components/SkipLink.svelte +1 -0
  120. package/dist/components/SkipLink.svelte.d.ts +1 -0
  121. package/dist/components/Slider.svelte +23 -2
  122. package/dist/components/Slider.svelte.d.ts +1 -0
  123. package/dist/components/Spinner.svelte +2 -0
  124. package/dist/components/Spinner.svelte.d.ts +2 -0
  125. package/dist/components/Switch.svelte +25 -2
  126. package/dist/components/Switch.svelte.d.ts +2 -0
  127. package/dist/components/Tab.svelte +16 -2
  128. package/dist/components/Tab.svelte.d.ts +1 -0
  129. package/dist/components/TabList.svelte +1 -0
  130. package/dist/components/TabList.svelte.d.ts +1 -0
  131. package/dist/components/TabPanel.svelte +8 -1
  132. package/dist/components/TabPanel.svelte.d.ts +1 -0
  133. package/dist/components/Table.svelte +30 -0
  134. package/dist/components/Table.svelte.d.ts +17 -0
  135. package/dist/components/Tabs.svelte +41 -19
  136. package/dist/components/Tabs.svelte.d.ts +6 -1
  137. package/dist/components/Textarea.svelte +26 -6
  138. package/dist/components/Textarea.svelte.d.ts +5 -0
  139. package/dist/components/ToastRegion.svelte +18 -2
  140. package/dist/components/ToastRegion.svelte.d.ts +8 -1
  141. package/dist/components/Toc.svelte +19 -8
  142. package/dist/components/Toc.svelte.d.ts +6 -0
  143. package/dist/components/Tooltip.svelte +59 -20
  144. package/dist/components/Tooltip.svelte.d.ts +16 -7
  145. package/dist/context.d.ts +84 -8
  146. package/dist/context.js +60 -11
  147. package/dist/index.d.ts +8 -4
  148. package/dist/index.js +6 -4
  149. package/dist/toast.d.ts +12 -7
  150. package/dist/toast.js +20 -11
  151. package/dist/useEnhancer.svelte.d.ts +40 -0
  152. package/dist/useEnhancer.svelte.js +58 -0
  153. package/package.json +4 -4
  154. package/dist/actions.d.ts +0 -25
  155. 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, type TabsApi } from '@hydrateless/enhancers';
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
- /** Initial value for uncontrolled usage. */
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
- let host = $state<HTMLDivElement>();
26
- let api = $state<TabsApi | null>(null);
33
+ // svelte-ignore state_referenced_locally -- seeds the uncontrolled initial value once
34
+ if (value === undefined) value = defaultValue;
27
35
 
28
- $effect(() => {
29
- if (!host) return;
30
- const handle = enhanceTabs(host, {
31
- activation,
32
- orientation,
33
- defaultValue: untrack(() => value ?? defaultValue),
34
- onValueChange: (next) => (value = next),
35
- });
36
- api = handle.api;
37
- return () => {
38
- handle.destroy();
39
- api = null;
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 bind:this={host}>
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
- /** Initial value for uncontrolled usage. */
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 { fieldBindings } from '../context.js';
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 { value = $bindable(), size, invalid = false, class: klass, ...rest }: Props = $props();
12
- const field = fieldBindings();
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-invalid={invalid || undefined}
22
- aria-invalid={invalid || undefined}
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
- let { ...rest }: HTMLAttributes<HTMLDivElement> = $props();
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
- declare const ToastRegion: import("svelte").Component<HTMLAttributes<HTMLDivElement>, {}, "">;
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
- $effect(() => {
15
- if (!host) return;
16
- return enhanceToc(host.ownerDocument, { contentSelector, headings, scrollSpy }).destroy;
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 bind:this={host}></nav>
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,36 +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 text shown on hover/focus. */
7
- label?: string;
8
- /** Richer hint content; overrides `label` when provided. */
9
- tip?: Snippet;
10
- id?: string;
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 { label, tip, id, children }: Props = $props();
16
- const generatedId = `hl-tip-${Math.random().toString(36).slice(2, 8)}`;
17
- const tipId = $derived(id ?? generatedId);
18
- let host = $state<HTMLSpanElement>();
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();
36
+ // SSR-safe: $props.id() is stable across server and client renders.
37
+ const generatedId = $props.id();
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
+ );
19
59
 
20
60
  $effect(() => {
21
- if (!host) return;
22
- const trigger = host.querySelector<HTMLElement>(':scope > :first-child');
23
- if (trigger) {
24
- trigger.setAttribute('data-hl-tooltip', tipId);
25
- trigger.setAttribute('aria-describedby', tipId);
26
- }
27
- return enhanceTooltip(host).destroy;
61
+ if (open != null) tooltip.api?.setOpen(open);
28
62
  });
29
63
  </script>
30
64
 
31
- <span bind:this={host} style="position:relative;display:inline-block">
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
+ >
32
71
  {@render children?.()}
33
72
  <span id={tipId} role="tooltip" hidden
34
- >{#if tip}{@render tip()}{:else}{label}{/if}</span
73
+ >{#if typeof content === 'function'}{@render content()}{:else}{content}{/if}</span
35
74
  >
36
75
  </span>
@@ -1,13 +1,22 @@
1
+ import { type EnhanceTooltipOptions } from '@hydrateless/enhancers';
1
2
  import type { Snippet } from 'svelte';
2
- interface Props {
3
- /** The hint text shown on hover/focus. */
4
- label?: string;
5
- /** Richer hint content; overrides `label` when provided. */
6
- tip?: Snippet;
7
- id?: string;
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
- /** Shared field state a Field provides to its controls (ids and validity flags). */
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} to the descendant controls of a Field. */
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
- /** Returns attributes (`id`, `aria-describedby`, `aria-invalid`) for a field control. */
14
- export declare function fieldBindings(): Record<string, string | boolean | undefined>;
15
- /** Shared state a RadioGroup provides to its radios (name, selected value, and a setter). */
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} to the descendant radios of a group. */
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} to the descendant controls of a Field. */
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
- /** Returns attributes (`id`, `aria-describedby`, `aria-invalid`) for a field control. */
12
- export function fieldBindings() {
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: ctx.id,
19
- 'aria-describedby': describedBy || undefined,
20
- 'aria-invalid': ctx.invalid || undefined,
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} to the descendant radios of a group. */
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 { accordion, disclosure, tabs, dropdown, modal, drawer, popover, tooltip, toc, menu, combobox, command, } from './actions.js';
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, ComboboxApi, Disposer, DrawerApi, DropdownApi, EnhancerHandle, ModalApi, PopoverApi, TabsApi, ToastApi, 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';