@human-kit/ui 1.0.0-beta.7 → 1.0.0-beta.9

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 (203) hide show
  1. package/dist/FOCUS_STATE_CONTRACT.md +15 -4
  2. package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
  3. package/dist/avatar/README.md +52 -0
  4. package/dist/avatar/count/avatar-count.svelte +56 -0
  5. package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
  6. package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
  7. package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
  8. package/dist/avatar/group/avatar-group.svelte +65 -0
  9. package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
  10. package/dist/avatar/group/context.d.ts +15 -0
  11. package/dist/avatar/group/context.js +15 -0
  12. package/dist/avatar/image/avatar-image.svelte +104 -0
  13. package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
  14. package/dist/avatar/index.d.ts +22 -0
  15. package/dist/avatar/index.js +10 -0
  16. package/dist/avatar/index.parts.d.ts +5 -0
  17. package/dist/avatar/index.parts.js +5 -0
  18. package/dist/avatar/root/avatar-root.svelte +79 -0
  19. package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
  20. package/dist/avatar/root/context.d.ts +14 -0
  21. package/dist/avatar/root/context.js +15 -0
  22. package/dist/avatar/types.d.ts +84 -0
  23. package/dist/avatar/types.js +1 -0
  24. package/dist/breadcrumbs/README.md +65 -0
  25. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
  26. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
  27. package/dist/breadcrumbs/index.d.ts +23 -0
  28. package/dist/breadcrumbs/index.js +10 -0
  29. package/dist/breadcrumbs/index.parts.d.ts +6 -0
  30. package/dist/breadcrumbs/index.parts.js +6 -0
  31. package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
  32. package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
  33. package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
  34. package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
  35. package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
  36. package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
  37. package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
  38. package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
  39. package/dist/breadcrumbs/root/context.d.ts +19 -0
  40. package/dist/breadcrumbs/root/context.js +15 -0
  41. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
  42. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
  43. package/dist/breadcrumbs/types.d.ts +80 -0
  44. package/dist/breadcrumbs/types.js +1 -0
  45. package/dist/combobox/popover/combobox-popover.svelte +4 -56
  46. package/dist/dialog/root/dialog-root.svelte +15 -2
  47. package/dist/drawer/root/drawer-root.svelte +15 -2
  48. package/dist/index.d.ts +16 -0
  49. package/dist/index.js +15 -0
  50. package/dist/internal/localized-strings.d.ts +72 -0
  51. package/dist/internal/localized-strings.js +72 -0
  52. package/dist/internal/number-precision.d.ts +9 -0
  53. package/dist/internal/number-precision.js +27 -0
  54. package/dist/menu/root/focus-state.d.ts +2 -2
  55. package/dist/menu/root/focus-state.js +8 -32
  56. package/dist/menu/root/menu-state.svelte.js +5 -1
  57. package/dist/numberfield/root/number-utils.js +1 -20
  58. package/dist/popover/root/focus-state.d.ts +2 -2
  59. package/dist/popover/root/focus-state.js +7 -34
  60. package/dist/primitives/aria-hide-outside.d.ts +13 -0
  61. package/dist/primitives/aria-hide-outside.js +7 -1
  62. package/dist/primitives/contain-wheel.d.ts +9 -0
  63. package/dist/primitives/contain-wheel.js +41 -0
  64. package/dist/primitives/floating.d.ts +6 -0
  65. package/dist/primitives/floating.js +26 -5
  66. package/dist/primitives/focus-trap.d.ts +2 -0
  67. package/dist/primitives/focus-trap.js +7 -1
  68. package/dist/primitives/keyboard-navigation.d.ts +6 -0
  69. package/dist/primitives/keyboard-navigation.js +2 -1
  70. package/dist/primitives/presence.svelte.js +6 -1
  71. package/dist/primitives/trigger-focus-state.d.ts +29 -0
  72. package/dist/primitives/trigger-focus-state.js +57 -0
  73. package/dist/progress/README.md +54 -0
  74. package/dist/progress/index.d.ts +21 -0
  75. package/dist/progress/index.js +9 -0
  76. package/dist/progress/index.parts.d.ts +5 -0
  77. package/dist/progress/index.parts.js +5 -0
  78. package/dist/progress/indicator/progress-indicator.svelte +37 -0
  79. package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
  80. package/dist/progress/label/progress-label.svelte +34 -0
  81. package/dist/progress/label/progress-label.svelte.d.ts +4 -0
  82. package/dist/progress/root/context.d.ts +26 -0
  83. package/dist/progress/root/context.js +15 -0
  84. package/dist/progress/root/progress-root.svelte +136 -0
  85. package/dist/progress/root/progress-root.svelte.d.ts +4 -0
  86. package/dist/progress/root/progress-utils.d.ts +12 -0
  87. package/dist/progress/root/progress-utils.js +41 -0
  88. package/dist/progress/track/progress-track.svelte +27 -0
  89. package/dist/progress/track/progress-track.svelte.d.ts +4 -0
  90. package/dist/progress/types.d.ts +81 -0
  91. package/dist/progress/types.js +1 -0
  92. package/dist/progress/value/progress-value.svelte +36 -0
  93. package/dist/progress/value/progress-value.svelte.d.ts +4 -0
  94. package/dist/select/README.md +129 -0
  95. package/dist/select/index.d.ts +30 -0
  96. package/dist/select/index.js +16 -0
  97. package/dist/select/index.parts.d.ts +8 -0
  98. package/dist/select/index.parts.js +9 -0
  99. package/dist/select/item/select-item.svelte +68 -0
  100. package/dist/select/item/select-item.svelte.d.ts +10 -0
  101. package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
  102. package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
  103. package/dist/select/label/select-label.svelte +46 -0
  104. package/dist/select/label/select-label.svelte.d.ts +4 -0
  105. package/dist/select/list/select-list.svelte +241 -0
  106. package/dist/select/list/select-list.svelte.d.ts +62 -0
  107. package/dist/select/popover/select-popover.svelte +80 -0
  108. package/dist/select/popover/select-popover.svelte.d.ts +9 -0
  109. package/dist/select/root/context.d.ts +106 -0
  110. package/dist/select/root/context.js +22 -0
  111. package/dist/select/root/select-root.svelte +544 -0
  112. package/dist/select/root/select-root.svelte.d.ts +25 -0
  113. package/dist/select/trigger/select-trigger.svelte +192 -0
  114. package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
  115. package/dist/select/types.d.ts +133 -0
  116. package/dist/select/types.js +1 -0
  117. package/dist/select/value/select-value.svelte +61 -0
  118. package/dist/select/value/select-value.svelte.d.ts +4 -0
  119. package/dist/separator/README.md +35 -0
  120. package/dist/separator/index.d.ts +7 -0
  121. package/dist/separator/index.js +3 -0
  122. package/dist/separator/separator.svelte +254 -0
  123. package/dist/separator/separator.svelte.d.ts +45 -0
  124. package/dist/separator/types.d.ts +1 -0
  125. package/dist/separator/types.js +1 -0
  126. package/dist/slider/README.md +61 -0
  127. package/dist/slider/fill/slider-fill.svelte +40 -0
  128. package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
  129. package/dist/slider/index.d.ts +9 -0
  130. package/dist/slider/index.js +8 -0
  131. package/dist/slider/index.parts.d.ts +6 -0
  132. package/dist/slider/index.parts.js +6 -0
  133. package/dist/slider/label/slider-label.svelte +44 -0
  134. package/dist/slider/label/slider-label.svelte.d.ts +4 -0
  135. package/dist/slider/output/slider-output.svelte +46 -0
  136. package/dist/slider/output/slider-output.svelte.d.ts +4 -0
  137. package/dist/slider/root/context.d.ts +106 -0
  138. package/dist/slider/root/context.js +15 -0
  139. package/dist/slider/root/slider-root.svelte +545 -0
  140. package/dist/slider/root/slider-root.svelte.d.ts +4 -0
  141. package/dist/slider/root/slider-utils.d.ts +57 -0
  142. package/dist/slider/root/slider-utils.js +88 -0
  143. package/dist/slider/thumb/slider-thumb.svelte +276 -0
  144. package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
  145. package/dist/slider/track/slider-track.svelte +60 -0
  146. package/dist/slider/track/slider-track.svelte.d.ts +4 -0
  147. package/dist/slider/types.d.ts +144 -0
  148. package/dist/slider/types.js +1 -0
  149. package/dist/toast/README.md +75 -0
  150. package/dist/toast/action/toast-action.svelte +42 -0
  151. package/dist/toast/action/toast-action.svelte.d.ts +4 -0
  152. package/dist/toast/close/toast-close.svelte +41 -0
  153. package/dist/toast/close/toast-close.svelte.d.ts +4 -0
  154. package/dist/toast/content/toast-content.svelte +24 -0
  155. package/dist/toast/content/toast-content.svelte.d.ts +4 -0
  156. package/dist/toast/description/toast-description.svelte +41 -0
  157. package/dist/toast/description/toast-description.svelte.d.ts +4 -0
  158. package/dist/toast/index.d.ts +34 -0
  159. package/dist/toast/index.js +15 -0
  160. package/dist/toast/index.parts.d.ts +9 -0
  161. package/dist/toast/index.parts.js +9 -0
  162. package/dist/toast/positioner/toast-positioner.svelte +75 -0
  163. package/dist/toast/positioner/toast-positioner.svelte.d.ts +4 -0
  164. package/dist/toast/provider/context.d.ts +36 -0
  165. package/dist/toast/provider/context.js +22 -0
  166. package/dist/toast/provider/toast-manager.svelte.d.ts +113 -0
  167. package/dist/toast/provider/toast-manager.svelte.js +210 -0
  168. package/dist/toast/provider/toast-provider.svelte +98 -0
  169. package/dist/toast/provider/toast-provider.svelte.d.ts +4 -0
  170. package/dist/toast/root/context.d.ts +18 -0
  171. package/dist/toast/root/context.js +15 -0
  172. package/dist/toast/root/toast-root.svelte +296 -0
  173. package/dist/toast/root/toast-root.svelte.d.ts +4 -0
  174. package/dist/toast/title/toast-title.svelte +38 -0
  175. package/dist/toast/title/toast-title.svelte.d.ts +4 -0
  176. package/dist/toast/types.d.ts +100 -0
  177. package/dist/toast/types.js +1 -0
  178. package/dist/toast/viewport/toast-viewport.svelte +389 -0
  179. package/dist/toast/viewport/toast-viewport.svelte.d.ts +4 -0
  180. package/dist/tooltip/README.md +53 -0
  181. package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
  182. package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
  183. package/dist/tooltip/content/tooltip-content.svelte +148 -0
  184. package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
  185. package/dist/tooltip/index.d.ts +8 -0
  186. package/dist/tooltip/index.js +7 -0
  187. package/dist/tooltip/index.parts.d.ts +5 -0
  188. package/dist/tooltip/index.parts.js +5 -0
  189. package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
  190. package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
  191. package/dist/tooltip/root/context.d.ts +46 -0
  192. package/dist/tooltip/root/context.js +22 -0
  193. package/dist/tooltip/root/safe-polygon.d.ts +26 -0
  194. package/dist/tooltip/root/safe-polygon.js +66 -0
  195. package/dist/tooltip/root/tooltip-group.d.ts +26 -0
  196. package/dist/tooltip/root/tooltip-group.js +41 -0
  197. package/dist/tooltip/root/tooltip-root.svelte +454 -0
  198. package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
  199. package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
  200. package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
  201. package/dist/tooltip/types.d.ts +105 -0
  202. package/dist/tooltip/types.js +1 -0
  203. package/package.json +41 -1
@@ -0,0 +1,84 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes, HTMLImgAttributes } from 'svelte/elements';
3
+ import type { AvatarStatus } from './root/context.js';
4
+ export type { AvatarContext, AvatarStatus } from './root/context.js';
5
+ export type { AvatarGroupContext } from './group/context.js';
6
+ export type AvatarGroupProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'role'> & {
7
+ /** The avatars, and an `Avatar.Count` for the ones past `max`. */
8
+ children?: Snippet;
9
+ /** The CSS class names of the element. */
10
+ class?: string;
11
+ /**
12
+ * The count of avatars on the screen. The ones past it render nothing, and `Avatar.Count`
13
+ * says how many they are. Without it, every avatar is on the screen.
14
+ */
15
+ max?: number;
16
+ /**
17
+ * The name of the group, such as "Assignees". A group with no name is a group a screen
18
+ * reader cannot tell apart from the content around it.
19
+ */
20
+ 'aria-label'?: string;
21
+ /** The group element. Use `bind:element` to read it. */
22
+ element?: HTMLDivElement | null;
23
+ };
24
+ export type AvatarCountState = {
25
+ /** The count of avatars past `max`. */
26
+ overflow: number;
27
+ /** The count of avatars in the group. */
28
+ count: number;
29
+ /** The limit of the group. */
30
+ max: number;
31
+ };
32
+ export type AvatarCountProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class' | 'aria-label'> & {
33
+ /** The content in place of `+N`. It gets the overflow, the count and the limit. */
34
+ children?: Snippet<[AvatarCountState]>;
35
+ /** The CSS class names of the element. */
36
+ class?: string;
37
+ /** The name for the screen reader. Without it, "N more" in the locale of `LocaleProvider`. */
38
+ 'aria-label'?: string;
39
+ /** The count element, while it is on the screen. Use `bind:element` to read it. */
40
+ element?: HTMLSpanElement | null;
41
+ };
42
+ export type AvatarRootProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
43
+ /** `Avatar.Image` and `Avatar.Fallback`. */
44
+ children?: Snippet;
45
+ /** The CSS class names of the element. */
46
+ class?: string;
47
+ /** The root element. Use `bind:element` to read it. */
48
+ element?: HTMLSpanElement | null;
49
+ /** Called when the image starts to load, loads, or fails. */
50
+ onStatusChange?: (status: AvatarStatus) => void;
51
+ };
52
+ export type AvatarImageProps = Omit<HTMLImgAttributes, 'class' | 'src' | 'alt' | 'loading'> & {
53
+ /** The address of the image. Without it, the fallback shows. */
54
+ src?: string | null;
55
+ /**
56
+ * `lazy` starts the load when the avatar comes into view, and not on mount. Use it on a long
57
+ * list of avatars, thus the ones below the fold do not all load at once.
58
+ */
59
+ loading?: 'eager' | 'lazy';
60
+ /**
61
+ * The text in place of the image. Give the name of the person or the thing. Give an empty
62
+ * string when the name is beside the avatar already, thus a screen reader does not read it
63
+ * twice.
64
+ */
65
+ alt: string;
66
+ /** The CSS class names of the element. */
67
+ class?: string;
68
+ /** The image element, once the image is on the screen. Use `bind:element` to read it. */
69
+ element?: HTMLImageElement | null;
70
+ };
71
+ export type AvatarFallbackProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
72
+ /** The content in place of the image, such as initials or an icon. */
73
+ children?: Snippet;
74
+ /** The CSS class names of the element. */
75
+ class?: string;
76
+ /**
77
+ * The time in milliseconds before the fallback shows while the image loads. A fallback that
78
+ * flashes before a fast image is noise: 300 or 600 hides it on a good connection. It shows at
79
+ * once when the image fails, or when there is no image.
80
+ */
81
+ delay?: number;
82
+ /** The fallback element, while it is on the screen. Use `bind:element` to read it. */
83
+ element?: HTMLSpanElement | null;
84
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ # Breadcrumbs
2
+
3
+ ## Description
4
+
5
+ `Breadcrumbs` is the trail of pages above the one the user is on. It is a `<nav>` landmark named "Breadcrumb" with an ordered list of links, and the last one says it is the current page.
6
+
7
+ ## Anatomy
8
+
9
+ - `Breadcrumbs.Root`
10
+ - `Breadcrumbs.List`
11
+ - `Breadcrumbs.Item`
12
+ - `Breadcrumbs.Link`
13
+ - `Breadcrumbs.Ellipsis`
14
+ - `Breadcrumbs.Separator`
15
+
16
+ ```svelte
17
+ <Breadcrumbs.Root>
18
+ <Breadcrumbs.List>
19
+ <Breadcrumbs.Item>
20
+ <Breadcrumbs.Link href="/">Home</Breadcrumbs.Link>
21
+ <Breadcrumbs.Separator />
22
+ </Breadcrumbs.Item>
23
+ <Breadcrumbs.Item>
24
+ <Breadcrumbs.Link href="/docs">Docs</Breadcrumbs.Link>
25
+ <Breadcrumbs.Separator />
26
+ </Breadcrumbs.Item>
27
+ <Breadcrumbs.Item>
28
+ <Breadcrumbs.Link current>Breadcrumbs</Breadcrumbs.Link>
29
+ </Breadcrumbs.Item>
30
+ </Breadcrumbs.List>
31
+ </Breadcrumbs.Root>
32
+ ```
33
+
34
+ ## Usage guidelines
35
+
36
+ - Set `current` on the last link. It can keep its `href`: a link to the page the user is on is a way to reload it.
37
+ - Put the separator in the item, after the link, on every item but the last.
38
+ - Give the root an `aria-label` when the page has two sets of breadcrumbs.
39
+ - Use `disabled` for a page the user cannot open now. The text stays, the link goes.
40
+ - Give `maxItems` to fold a long trail, and put a `Breadcrumbs.Ellipsis` after the first item.
41
+
42
+ ## API reference
43
+
44
+ - `Breadcrumbs.Root`
45
+ - `aria-label?: string` ("Breadcrumb", localized)
46
+ - `maxItems?: number`, `expanded?: boolean` (bindable), `onExpandedChange?: (expanded: boolean) => void`
47
+ - `element?: HTMLElement | null` (bindable)
48
+ - `Breadcrumbs.List`, `Breadcrumbs.Item`
49
+ - `element` (bindable)
50
+ - `Breadcrumbs.Link`
51
+ - `href?: string`, `current?: boolean`, `disabled?: boolean`
52
+ - `element?: HTMLAnchorElement | HTMLSpanElement | null` (bindable)
53
+ - `Breadcrumbs.Ellipsis`
54
+ - `children` (three dots without children), `itemClass?: string`, `separator?: Snippet`, `aria-label?: string` ("Show N more pages", localized)
55
+ - `Breadcrumbs.Separator`
56
+ - `children` (a slash without children)
57
+
58
+ ## Accessibility
59
+
60
+ - `Breadcrumbs.Root` is a `<nav>` with `aria-label="Breadcrumb"`, in the locale of `LocaleProvider`. A screen reader user finds it in the list of landmarks.
61
+ - `Breadcrumbs.List` is an `<ol>` of `<li>`: a screen reader says the count and the position of each page. It has `role="list"` in writing, for the browsers that drop a list with `list-style: none`.
62
+ - `Breadcrumbs.Link` with `current` has `aria-current="page"`. Without an `href`, or with `disabled`, it is a `<span>`: not a link, and not a tab stop.
63
+ - `Breadcrumbs.Separator` is `aria-hidden`. The list already separates the items.
64
+ - `Breadcrumbs.Ellipsis` is a button named "Show N more pages". After the press, the focus lands on the first page that comes into view.
65
+ - The keyboard moves through the links with `Tab`. Breadcrumbs are links on a page, not a widget with arrow keys.
@@ -0,0 +1,62 @@
1
+ <script lang="ts">
2
+ import { readable } from 'svelte/store';
3
+ import { ButtonRoot } from '../../button/index.js';
4
+ import { resolveLocalizedString } from '../../internal/localized-strings';
5
+ import { useLocaleContextOptional } from '../../locale-provider/context';
6
+ import type { BreadcrumbsEllipsisProps } from '../types.js';
7
+ import { useBreadcrumbsContext } from '../root/context';
8
+
9
+ /**
10
+ * Breadcrumbs.Ellipsis — the button that stands for the folded middle of a long trail.
11
+ *
12
+ * Put it in the list after the first item. It renders only while the trail is folded, as an
13
+ * `<li>` with a button named "Show N more pages", in the locale of `LocaleProvider`. A press
14
+ * unfolds the trail, and the focus moves to the first page that comes into view: the button
15
+ * is gone, and a focus left on nothing is a focus lost.
16
+ */
17
+ let {
18
+ children,
19
+ class: className = '',
20
+ itemClass = '',
21
+ separator,
22
+ 'aria-label': ariaLabelProp,
23
+ element = $bindable<HTMLButtonElement | null>(null),
24
+ onclick,
25
+ ...restProps
26
+ }: BreadcrumbsEllipsisProps = $props();
27
+
28
+ const breadcrumbs = useBreadcrumbsContext('Breadcrumbs.Ellipsis');
29
+
30
+ const localeContext = useLocaleContextOptional();
31
+ const emptyLocaleStore = readable<string | undefined>(undefined);
32
+ const localeStore = localeContext?.locale ?? emptyLocaleStore;
33
+ const ariaLabel = $derived(
34
+ ariaLabelProp ??
35
+ resolveLocalizedString($localeStore, 'breadcrumbs.showMore', {
36
+ count: breadcrumbs.hiddenCount
37
+ })
38
+ );
39
+
40
+ function handleClick(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
41
+ onclick?.(event);
42
+ if (event.defaultPrevented) return;
43
+ breadcrumbs.expand();
44
+ }
45
+ </script>
46
+
47
+ {#if breadcrumbs.collapsed}
48
+ <li class={itemClass} data-breadcrumbs-ellipsis="true">
49
+ <ButtonRoot
50
+ {...restProps}
51
+ bind:element
52
+ class={className}
53
+ type="button"
54
+ aria-label={ariaLabel}
55
+ data-breadcrumbs-ellipsis-button="true"
56
+ onclick={handleClick}
57
+ >
58
+ {#if children}{@render children()}{:else}…{/if}
59
+ </ButtonRoot>
60
+ {@render separator?.()}
61
+ </li>
62
+ {/if}
@@ -0,0 +1,4 @@
1
+ import type { BreadcrumbsEllipsisProps } from '../types.js';
2
+ declare const BreadcrumbsEllipsis: import("svelte").Component<BreadcrumbsEllipsisProps, {}, "element">;
3
+ type BreadcrumbsEllipsis = ReturnType<typeof BreadcrumbsEllipsis>;
4
+ export default BreadcrumbsEllipsis;
@@ -0,0 +1,23 @@
1
+ import type { ComponentProps } from 'svelte';
2
+ import type BreadcrumbsEllipsisComponent from './ellipsis/breadcrumbs-ellipsis.svelte';
3
+ import type BreadcrumbsItemComponent from './item/breadcrumbs-item.svelte';
4
+ import type BreadcrumbsLinkComponent from './link/breadcrumbs-link.svelte';
5
+ import type BreadcrumbsListComponent from './list/breadcrumbs-list.svelte';
6
+ import type BreadcrumbsRootComponent from './root/breadcrumbs-root.svelte';
7
+ import type BreadcrumbsSeparatorComponent from './separator/breadcrumbs-separator.svelte';
8
+ export * as Breadcrumbs from './index.parts.js';
9
+ export { default as BreadcrumbsRoot } from './root/breadcrumbs-root.svelte';
10
+ export { default as BreadcrumbsList } from './list/breadcrumbs-list.svelte';
11
+ export { default as BreadcrumbsItem } from './item/breadcrumbs-item.svelte';
12
+ export { default as BreadcrumbsLink } from './link/breadcrumbs-link.svelte';
13
+ export { default as BreadcrumbsEllipsis } from './ellipsis/breadcrumbs-ellipsis.svelte';
14
+ export { default as BreadcrumbsSeparator } from './separator/breadcrumbs-separator.svelte';
15
+ export type BreadcrumbsRootProps = ComponentProps<typeof BreadcrumbsRootComponent>;
16
+ export type BreadcrumbsListProps = ComponentProps<typeof BreadcrumbsListComponent>;
17
+ export type BreadcrumbsItemProps = ComponentProps<typeof BreadcrumbsItemComponent>;
18
+ export type BreadcrumbsLinkProps = ComponentProps<typeof BreadcrumbsLinkComponent>;
19
+ export type BreadcrumbsEllipsisProps = ComponentProps<typeof BreadcrumbsEllipsisComponent>;
20
+ export { getBreadcrumbsContext, setBreadcrumbsContext, useBreadcrumbsContext, type BreadcrumbsContext } from './root/context.js';
21
+ export type BreadcrumbsSeparatorProps = ComponentProps<typeof BreadcrumbsSeparatorComponent>;
22
+ import * as BreadcrumbsParts from './index.parts.js';
23
+ export default BreadcrumbsParts;
@@ -0,0 +1,10 @@
1
+ export * as Breadcrumbs from './index.parts.js';
2
+ export { default as BreadcrumbsRoot } from './root/breadcrumbs-root.svelte';
3
+ export { default as BreadcrumbsList } from './list/breadcrumbs-list.svelte';
4
+ export { default as BreadcrumbsItem } from './item/breadcrumbs-item.svelte';
5
+ export { default as BreadcrumbsLink } from './link/breadcrumbs-link.svelte';
6
+ export { default as BreadcrumbsEllipsis } from './ellipsis/breadcrumbs-ellipsis.svelte';
7
+ export { default as BreadcrumbsSeparator } from './separator/breadcrumbs-separator.svelte';
8
+ export { getBreadcrumbsContext, setBreadcrumbsContext, useBreadcrumbsContext } from './root/context.js';
9
+ import * as BreadcrumbsParts from './index.parts.js';
10
+ export default BreadcrumbsParts;
@@ -0,0 +1,6 @@
1
+ export { default as Root } from './root/breadcrumbs-root.svelte';
2
+ export { default as List } from './list/breadcrumbs-list.svelte';
3
+ export { default as Item } from './item/breadcrumbs-item.svelte';
4
+ export { default as Link } from './link/breadcrumbs-link.svelte';
5
+ export { default as Ellipsis } from './ellipsis/breadcrumbs-ellipsis.svelte';
6
+ export { default as Separator } from './separator/breadcrumbs-separator.svelte';
@@ -0,0 +1,6 @@
1
+ export { default as Root } from './root/breadcrumbs-root.svelte';
2
+ export { default as List } from './list/breadcrumbs-list.svelte';
3
+ export { default as Item } from './item/breadcrumbs-item.svelte';
4
+ export { default as Link } from './link/breadcrumbs-link.svelte';
5
+ export { default as Ellipsis } from './ellipsis/breadcrumbs-ellipsis.svelte';
6
+ export { default as Separator } from './separator/breadcrumbs-separator.svelte';
@@ -0,0 +1,42 @@
1
+ <script lang="ts">
2
+ import type { BreadcrumbsItemProps } from '../types.js';
3
+ import { useBreadcrumbsContext } from '../root/context';
4
+
5
+ /**
6
+ * Breadcrumbs.Item — one page of the trail.
7
+ *
8
+ * It is an `<li>` with a `Breadcrumbs.Link` in it, and a `Breadcrumbs.Separator` after the
9
+ * link on every item but the last. The separator is in the item, not between two items,
10
+ * thus the list holds items only and its count is the count of pages. In a folded trail, an
11
+ * item of the middle renders nothing until the trail unfolds.
12
+ */
13
+ let {
14
+ children,
15
+ class: className = '',
16
+ element = $bindable<HTMLLIElement | null>(null),
17
+ ...restProps
18
+ }: BreadcrumbsItemProps = $props();
19
+
20
+ const breadcrumbs = useBreadcrumbsContext('Breadcrumbs.Item');
21
+ // Registered at creation, not in an effect: the place in the trail must be known before the
22
+ // first render, or a folded item would paint once and go.
23
+ const id = $props.id();
24
+ const unregister = breadcrumbs.register(id);
25
+ $effect(() => unregister);
26
+ const hidden = $derived(breadcrumbs.isHidden(id));
27
+
28
+ let itemRef: HTMLLIElement | null = $state(null);
29
+
30
+ $effect(() => {
31
+ element = itemRef;
32
+ return () => {
33
+ element = null;
34
+ };
35
+ });
36
+ </script>
37
+
38
+ {#if !hidden}
39
+ <li {...restProps} bind:this={itemRef} class={className} data-breadcrumbs-item="true">
40
+ {@render children?.()}
41
+ </li>
42
+ {/if}
@@ -0,0 +1,4 @@
1
+ import type { BreadcrumbsItemProps } from '../types.js';
2
+ declare const BreadcrumbsItem: import("svelte").Component<BreadcrumbsItemProps, {}, "element">;
3
+ type BreadcrumbsItem = ReturnType<typeof BreadcrumbsItem>;
4
+ export default BreadcrumbsItem;
@@ -0,0 +1,47 @@
1
+ <script lang="ts">
2
+ import type { BreadcrumbsLinkProps } from '../types.js';
3
+
4
+ /**
5
+ * Breadcrumbs.Link — the page, as a link.
6
+ *
7
+ * It is an `<a>` with an `href`, and a `<span>` without one. `current` marks the page the
8
+ * user is on with `aria-current="page"`. `disabled` takes the `href` away: a link with no
9
+ * address is out of the tab order on its own, with no `tabindex` to manage.
10
+ */
11
+ let {
12
+ children,
13
+ class: className = '',
14
+ href,
15
+ current = false,
16
+ disabled = false,
17
+ element = $bindable<HTMLAnchorElement | HTMLSpanElement | null>(null),
18
+ ...restProps
19
+ }: BreadcrumbsLinkProps = $props();
20
+
21
+ let linkRef: HTMLAnchorElement | HTMLSpanElement | null = $state(null);
22
+ const isLink = $derived(Boolean(href) && !disabled);
23
+
24
+ $effect(() => {
25
+ element = linkRef;
26
+ return () => {
27
+ element = null;
28
+ };
29
+ });
30
+ </script>
31
+
32
+ <!-- Without an address, the text is not a link: a span says so, where an anchor with no href
33
+ still reads as a link to some screen readers. -->
34
+ <svelte:element
35
+ this={isLink ? 'a' : 'span'}
36
+ {...restProps}
37
+ bind:this={linkRef}
38
+ href={isLink ? href : undefined}
39
+ aria-current={current ? 'page' : undefined}
40
+ aria-disabled={disabled ? 'true' : undefined}
41
+ class={className}
42
+ data-breadcrumbs-link="true"
43
+ data-current={current || undefined}
44
+ data-disabled={disabled || undefined}
45
+ >
46
+ {@render children?.()}
47
+ </svelte:element>
@@ -0,0 +1,4 @@
1
+ import type { BreadcrumbsLinkProps } from '../types.js';
2
+ declare const BreadcrumbsLink: import("svelte").Component<BreadcrumbsLinkProps, {}, "element">;
3
+ type BreadcrumbsLink = ReturnType<typeof BreadcrumbsLink>;
4
+ export default BreadcrumbsLink;
@@ -0,0 +1,31 @@
1
+ <script lang="ts">
2
+ import type { BreadcrumbsListProps } from '../types.js';
3
+
4
+ /**
5
+ * Breadcrumbs.List — the ordered list of the trail.
6
+ *
7
+ * It is an `<ol>`: the order of the items is the order of the pages, from the root of the
8
+ * site to the page the user is on, and a screen reader says how many there are. The role is
9
+ * on it in writing: some browsers drop the list from the accessibility tree when its
10
+ * `list-style` is `none`, which every trail sets.
11
+ */
12
+ let {
13
+ children,
14
+ class: className = '',
15
+ element = $bindable<HTMLOListElement | null>(null),
16
+ ...restProps
17
+ }: BreadcrumbsListProps = $props();
18
+
19
+ let listRef: HTMLOListElement | null = $state(null);
20
+
21
+ $effect(() => {
22
+ element = listRef;
23
+ return () => {
24
+ element = null;
25
+ };
26
+ });
27
+ </script>
28
+
29
+ <ol {...restProps} bind:this={listRef} role="list" class={className} data-breadcrumbs-list="true">
30
+ {@render children?.()}
31
+ </ol>
@@ -0,0 +1,4 @@
1
+ import type { BreadcrumbsListProps } from '../types.js';
2
+ declare const BreadcrumbsList: import("svelte").Component<BreadcrumbsListProps, {}, "element">;
3
+ type BreadcrumbsList = ReturnType<typeof BreadcrumbsList>;
4
+ export default BreadcrumbsList;
@@ -0,0 +1,112 @@
1
+ <script lang="ts">
2
+ import { tick } from 'svelte';
3
+ import { readable } from 'svelte/store';
4
+ import { resolveLocalizedString } from '../../internal/localized-strings';
5
+ import { useLocaleContextOptional } from '../../locale-provider/context';
6
+ import type { BreadcrumbsRootProps } from '../types.js';
7
+ import { setBreadcrumbsContext, type BreadcrumbsContext } from './context';
8
+
9
+ /**
10
+ * Breadcrumbs.Root — the trail of pages above the one the user is on.
11
+ *
12
+ * It is a `<nav>` landmark named "Breadcrumb", in the locale of `LocaleProvider`: a screen
13
+ * reader user finds it in the list of landmarks, apart from the main navigation. Put a
14
+ * `Breadcrumbs.List` in it.
15
+ *
16
+ * `maxItems` folds the middle of a long trail: the first item and the last `maxItems - 1`
17
+ * stay in view, and a `Breadcrumbs.Ellipsis` in the list stands for the rest until a press
18
+ * unfolds them.
19
+ */
20
+ let {
21
+ children,
22
+ class: className = '',
23
+ 'aria-label': ariaLabelProp,
24
+ maxItems,
25
+ expanded = $bindable(false),
26
+ onExpandedChange,
27
+ element = $bindable<HTMLElement | null>(null),
28
+ ...restProps
29
+ }: BreadcrumbsRootProps = $props();
30
+
31
+ const localeContext = useLocaleContextOptional();
32
+ const emptyLocaleStore = readable<string | undefined>(undefined);
33
+ const localeStore = localeContext?.locale ?? emptyLocaleStore;
34
+ const ariaLabel = $derived(
35
+ ariaLabelProp ?? resolveLocalizedString($localeStore, 'breadcrumbs.label')
36
+ );
37
+
38
+ let navRef: HTMLElement | null = $state(null);
39
+ let ids = $state<string[]>([]);
40
+
41
+ // Fewer than two in view would hide the current page, or the root of the site.
42
+ const limit = $derived(maxItems === undefined ? Infinity : Math.max(2, Math.floor(maxItems)));
43
+ const collapsed = $derived(!expanded && ids.length > limit);
44
+ // The folded middle: after the first item, before the last `limit - 1`.
45
+ const hiddenEnd = $derived(collapsed ? ids.length - (limit - 1) : 0);
46
+ const hiddenCount = $derived(collapsed ? hiddenEnd - 1 : 0);
47
+
48
+ async function expand() {
49
+ if (expanded) return;
50
+ expanded = true;
51
+ onExpandedChange?.(true);
52
+ // The button that had the focus is gone: the first page that came into view takes it.
53
+ await tick();
54
+ const items = Array.from(
55
+ navRef?.querySelectorAll<HTMLElement>('[data-breadcrumbs-item]') ?? []
56
+ ).slice(1);
57
+ for (const item of items) {
58
+ const target = item.querySelector<HTMLElement>('a[href], button, [tabindex]');
59
+ if (target) {
60
+ target.focus();
61
+ return;
62
+ }
63
+ }
64
+ }
65
+
66
+ const context: BreadcrumbsContext = {
67
+ get count() {
68
+ return ids.length;
69
+ },
70
+ get maxItems() {
71
+ return limit;
72
+ },
73
+ get collapsed() {
74
+ return collapsed;
75
+ },
76
+ get hiddenCount() {
77
+ return hiddenCount;
78
+ },
79
+ register(id) {
80
+ ids = [...ids, id];
81
+ return () => {
82
+ ids = ids.filter((candidate) => candidate !== id);
83
+ };
84
+ },
85
+ isHidden(id) {
86
+ if (!collapsed) return false;
87
+ const index = ids.indexOf(id);
88
+ return index > 0 && index < hiddenEnd;
89
+ },
90
+ expand
91
+ };
92
+
93
+ setBreadcrumbsContext(context);
94
+
95
+ $effect(() => {
96
+ element = navRef;
97
+ return () => {
98
+ element = null;
99
+ };
100
+ });
101
+ </script>
102
+
103
+ <nav
104
+ {...restProps}
105
+ bind:this={navRef}
106
+ aria-label={ariaLabel}
107
+ class={className}
108
+ data-breadcrumbs-root="true"
109
+ data-collapsed={collapsed || undefined}
110
+ >
111
+ {@render children?.()}
112
+ </nav>
@@ -0,0 +1,4 @@
1
+ import type { BreadcrumbsRootProps } from '../types.js';
2
+ declare const BreadcrumbsRoot: import("svelte").Component<BreadcrumbsRootProps, {}, "element" | "expanded">;
3
+ type BreadcrumbsRoot = ReturnType<typeof BreadcrumbsRoot>;
4
+ export default BreadcrumbsRoot;
@@ -0,0 +1,19 @@
1
+ export type BreadcrumbsContext = {
2
+ /** The count of items in the trail, on the screen or not. */
3
+ readonly count: number;
4
+ /** The count of items past which the middle of the trail folds. `Infinity` without a limit. */
5
+ readonly maxItems: number;
6
+ /** True while the middle of the trail is out of view. */
7
+ readonly collapsed: boolean;
8
+ /** The count of items out of view. */
9
+ readonly hiddenCount: number;
10
+ /** Registers an item, and answers a function that unregisters it. */
11
+ register: (id: string) => () => void;
12
+ /** True for an item in the folded middle of the trail. */
13
+ isHidden: (id: string) => boolean;
14
+ /** Unfolds the trail, and moves the focus to the first item that comes into view. */
15
+ expand: () => void;
16
+ };
17
+ export declare function setBreadcrumbsContext(context: BreadcrumbsContext): void;
18
+ export declare function getBreadcrumbsContext(): BreadcrumbsContext | undefined;
19
+ export declare function useBreadcrumbsContext(part?: string): BreadcrumbsContext;
@@ -0,0 +1,15 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ const KEY = Symbol('breadcrumbs');
3
+ export function setBreadcrumbsContext(context) {
4
+ setContext(KEY, context);
5
+ }
6
+ export function getBreadcrumbsContext() {
7
+ return getContext(KEY);
8
+ }
9
+ export function useBreadcrumbsContext(part = 'Breadcrumbs') {
10
+ const context = getBreadcrumbsContext();
11
+ if (!context) {
12
+ throw new Error(`${part} must be used within Breadcrumbs.Root.`);
13
+ }
14
+ return context;
15
+ }
@@ -0,0 +1,35 @@
1
+ <script lang="ts">
2
+ import type { BreadcrumbsSeparatorProps } from '../types.js';
3
+
4
+ /**
5
+ * Breadcrumbs.Separator — the sign between two pages of the trail.
6
+ *
7
+ * It is hidden from the screen reader: the list already separates the items, and a slash
8
+ * read aloud between each two is noise. Put it in the item, after the link.
9
+ */
10
+ let {
11
+ children,
12
+ class: className = '',
13
+ element = $bindable<HTMLSpanElement | null>(null),
14
+ ...restProps
15
+ }: BreadcrumbsSeparatorProps = $props();
16
+
17
+ let separatorRef: HTMLSpanElement | null = $state(null);
18
+
19
+ $effect(() => {
20
+ element = separatorRef;
21
+ return () => {
22
+ element = null;
23
+ };
24
+ });
25
+ </script>
26
+
27
+ <span
28
+ {...restProps}
29
+ bind:this={separatorRef}
30
+ aria-hidden="true"
31
+ class={className}
32
+ data-breadcrumbs-separator="true"
33
+ >
34
+ {#if children}{@render children()}{:else}/{/if}
35
+ </span>
@@ -0,0 +1,4 @@
1
+ import type { BreadcrumbsSeparatorProps } from '../types.js';
2
+ declare const BreadcrumbsSeparator: import("svelte").Component<BreadcrumbsSeparatorProps, {}, "element">;
3
+ type BreadcrumbsSeparator = ReturnType<typeof BreadcrumbsSeparator>;
4
+ export default BreadcrumbsSeparator;