@xds/svelte 1.0.1 → 1.2.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 (207) hide show
  1. .diffend-unextracted-0 +2 -1
  2. package/dist/Accordion.svelte +7 -2
  3. package/dist/Avatar.svelte +10 -2
  4. package/dist/AvatarStack.svelte +11 -1
  5. package/dist/Badge.svelte +14 -3
  6. package/dist/Banner.svelte +6 -1
  7. package/dist/Breadcrumb.svelte +53 -0
  8. package/dist/Breadcrumb.svelte.d.ts +11 -0
  9. package/dist/Button.svelte +30 -2
  10. package/dist/Button.svelte.d.ts +10 -1
  11. package/dist/Card.svelte +16 -2
  12. package/dist/Checkbox.svelte +62 -10
  13. package/dist/Checkbox.svelte.d.ts +14 -3
  14. package/dist/Chip.svelte +3 -1
  15. package/dist/ChipBar.svelte +3 -2
  16. package/dist/Combobox.svelte +194 -0
  17. package/dist/Combobox.svelte.d.ts +37 -0
  18. package/dist/CountBadge.svelte +4 -2
  19. package/dist/DatePicker.svelte +16 -5
  20. package/dist/DateRangePicker.svelte +6 -1
  21. package/dist/Dialog.svelte +9 -2
  22. package/dist/Divider.svelte +7 -3
  23. package/dist/EmptyState.svelte +15 -3
  24. package/dist/Icon.svelte +11 -2
  25. package/dist/IconButton.svelte +30 -2
  26. package/dist/IconButton.svelte.d.ts +10 -1
  27. package/dist/Labels.svelte +29 -0
  28. package/dist/Labels.svelte.d.ts +17 -0
  29. package/dist/Link.svelte +86 -0
  30. package/dist/Link.svelte.d.ts +26 -0
  31. package/dist/MediaCard.svelte +4 -1
  32. package/dist/Menu.svelte +21 -2
  33. package/dist/Pagination.svelte +108 -0
  34. package/dist/Pagination.svelte.d.ts +14 -0
  35. package/dist/PlaceRow.svelte +6 -1
  36. package/dist/Popover.svelte +91 -0
  37. package/dist/Popover.svelte.d.ts +21 -0
  38. package/dist/PopoverSurface.svelte +77 -0
  39. package/dist/PopoverSurface.svelte.d.ts +21 -0
  40. package/dist/ProgressBar.svelte +3 -1
  41. package/dist/RadioGroup.svelte +23 -8
  42. package/dist/RadioGroup.svelte.d.ts +4 -2
  43. package/dist/SearchField.svelte +65 -18
  44. package/dist/SearchField.svelte.d.ts +14 -4
  45. package/dist/SectionHeader.svelte +7 -2
  46. package/dist/SegmentedControl.svelte +21 -7
  47. package/dist/SegmentedControl.svelte.d.ts +3 -2
  48. package/dist/Select.svelte +64 -12
  49. package/dist/Select.svelte.d.ts +9 -2
  50. package/dist/Sidebar.svelte +3 -0
  51. package/dist/Skeleton.svelte +10 -2
  52. package/dist/Slider.svelte +23 -7
  53. package/dist/Slider.svelte.d.ts +2 -2
  54. package/dist/Spinner.svelte +3 -2
  55. package/dist/Switch.svelte +53 -9
  56. package/dist/Switch.svelte.d.ts +13 -3
  57. package/dist/Table.svelte +92 -0
  58. package/dist/Table.svelte.d.ts +17 -0
  59. package/dist/Tabs.svelte +21 -6
  60. package/dist/Tabs.svelte.d.ts +2 -1
  61. package/dist/Text.svelte +3 -1
  62. package/dist/TextField.svelte +59 -14
  63. package/dist/TextField.svelte.d.ts +13 -3
  64. package/dist/Thumbnail.svelte +7 -1
  65. package/dist/TimePicker.svelte +222 -0
  66. package/dist/TimePicker.svelte.d.ts +20 -0
  67. package/dist/Toast.svelte +12 -2
  68. package/dist/ToastQueue.svelte +57 -0
  69. package/dist/ToastQueue.svelte.d.ts +20 -0
  70. package/dist/Tooltip.svelte +9 -2
  71. package/dist/TooltipOverlay.svelte +9 -2
  72. package/dist/base.d.ts +14 -0
  73. package/dist/base.js +27 -0
  74. package/dist/controllable.svelte.d.ts +28 -0
  75. package/dist/controllable.svelte.js +41 -0
  76. package/dist/index.d.ts +12 -2
  77. package/dist/index.js +12 -0
  78. package/dist/labels.svelte.d.ts +13 -0
  79. package/dist/labels.svelte.js +24 -0
  80. package/dist/modal-popover.svelte.js +5 -1
  81. package/dist/presence.svelte.js +5 -2
  82. package/dist/preview/Component.svelte +8 -3
  83. package/dist/preview/Preview.svelte +8 -2
  84. package/dist/preview/Preview.svelte.d.ts +2 -0
  85. package/dist/preview/components.d.ts +9 -2
  86. package/dist/preview/components.js +18 -1
  87. package/dist/preview/index.d.ts +1 -0
  88. package/dist/root.d.ts +4 -2
  89. package/eject/files/Accordion.svelte +100 -0
  90. package/eject/files/AccordionPanel.svelte +48 -0
  91. package/eject/files/Avatar.svelte +51 -0
  92. package/eject/files/AvatarStack.svelte +61 -0
  93. package/eject/files/Badge.svelte +52 -0
  94. package/eject/files/Banner.svelte +94 -0
  95. package/eject/files/Breadcrumb.svelte +52 -0
  96. package/eject/files/Button.svelte +126 -0
  97. package/eject/files/Card.svelte +112 -0
  98. package/eject/files/Checkbox.svelte +121 -0
  99. package/eject/files/Chip.svelte +51 -0
  100. package/eject/files/ChipBar.svelte +39 -0
  101. package/eject/files/Combobox.svelte +198 -0
  102. package/eject/files/CountBadge.svelte +51 -0
  103. package/eject/files/DatePicker.svelte +213 -0
  104. package/eject/files/DateRangePicker.svelte +294 -0
  105. package/eject/files/Dialog.svelte +119 -0
  106. package/eject/files/Divider.svelte +27 -0
  107. package/eject/files/EmptyState.svelte +52 -0
  108. package/eject/files/Icon.svelte +51 -0
  109. package/eject/files/IconButton.svelte +99 -0
  110. package/eject/files/Link.svelte +85 -0
  111. package/eject/files/ListRow.svelte +33 -0
  112. package/eject/files/MediaCard.svelte +117 -0
  113. package/eject/files/Menu.svelte +183 -0
  114. package/eject/files/Pagination.svelte +109 -0
  115. package/eject/files/PlaceRow.svelte +75 -0
  116. package/eject/files/Popover.svelte +100 -0
  117. package/eject/files/PopoverSurface.svelte +85 -0
  118. package/eject/files/ProgressBar.svelte +38 -0
  119. package/eject/files/RadioGroup.svelte +133 -0
  120. package/eject/files/SearchField.svelte +154 -0
  121. package/eject/files/SectionHeader.svelte +67 -0
  122. package/eject/files/SegmentedControl.svelte +85 -0
  123. package/eject/files/Select.svelte +276 -0
  124. package/eject/files/Sidebar.svelte +130 -0
  125. package/eject/files/SidebarRailButton.svelte +32 -0
  126. package/eject/files/Skeleton.svelte +55 -0
  127. package/eject/files/Slider.svelte +136 -0
  128. package/eject/files/Spinner.svelte +41 -0
  129. package/eject/files/Switch.svelte +105 -0
  130. package/eject/files/Table.svelte +90 -0
  131. package/eject/files/Tabs.svelte +85 -0
  132. package/eject/files/Text.svelte +43 -0
  133. package/eject/files/TextField.svelte +222 -0
  134. package/eject/files/Thumbnail.svelte +88 -0
  135. package/eject/files/TimePicker.svelte +237 -0
  136. package/eject/files/Toast.svelte +98 -0
  137. package/eject/files/ToastQueue.svelte +61 -0
  138. package/eject/files/Tooltip.svelte +51 -0
  139. package/eject/files/TooltipOverlay.svelte +88 -0
  140. package/eject/files/accordion.css +89 -0
  141. package/eject/files/accordion.ts +67 -0
  142. package/eject/files/avatar-stack.ts +57 -0
  143. package/eject/files/avatar.ts +42 -0
  144. package/eject/files/badge.ts +30 -0
  145. package/eject/files/banner.ts +71 -0
  146. package/eject/files/base.css +38 -0
  147. package/eject/files/breadcrumb.css +51 -0
  148. package/eject/files/breadcrumb.ts +42 -0
  149. package/eject/files/button.css +241 -0
  150. package/eject/files/button.ts +106 -0
  151. package/eject/files/card.ts +58 -0
  152. package/eject/files/checkbox.ts +52 -0
  153. package/eject/files/chip-bar.ts +16 -0
  154. package/eject/files/chip.ts +35 -0
  155. package/eject/files/combobox.css +269 -0
  156. package/eject/files/combobox.ts +85 -0
  157. package/eject/files/count-badge.ts +32 -0
  158. package/eject/files/date-picker.css +375 -0
  159. package/eject/files/date-picker.ts +280 -0
  160. package/eject/files/date-range-picker.ts +338 -0
  161. package/eject/files/dialog.css +139 -0
  162. package/eject/files/dialog.ts +15 -0
  163. package/eject/files/divider.ts +5 -0
  164. package/eject/files/empty-state.ts +22 -0
  165. package/eject/files/icon.ts +36 -0
  166. package/eject/files/link.css +64 -0
  167. package/eject/files/link.ts +63 -0
  168. package/eject/files/list-row.ts +66 -0
  169. package/eject/files/media-card.ts +66 -0
  170. package/eject/files/menu.css +192 -0
  171. package/eject/files/menu.ts +84 -0
  172. package/eject/files/overlay.css +40 -0
  173. package/eject/files/pagination.css +106 -0
  174. package/eject/files/pagination.ts +68 -0
  175. package/eject/files/parts.ts +17 -0
  176. package/eject/files/popover.css +101 -0
  177. package/eject/files/popover.ts +37 -0
  178. package/eject/files/progress-bar.ts +26 -0
  179. package/eject/files/radio-group.css +184 -0
  180. package/eject/files/radio-group.ts +30 -0
  181. package/eject/files/section-header.ts +32 -0
  182. package/eject/files/segmented-control.ts +33 -0
  183. package/eject/files/select.css +347 -0
  184. package/eject/files/select.ts +77 -0
  185. package/eject/files/sidebar.ts +75 -0
  186. package/eject/files/skeleton.ts +51 -0
  187. package/eject/files/slider.css +160 -0
  188. package/eject/files/slider.ts +80 -0
  189. package/eject/files/spinner.ts +22 -0
  190. package/eject/files/switch.ts +45 -0
  191. package/eject/files/table.css +107 -0
  192. package/eject/files/table.ts +84 -0
  193. package/eject/files/tabs.css +120 -0
  194. package/eject/files/tabs.ts +37 -0
  195. package/eject/files/text-field.css +225 -0
  196. package/eject/files/text-field.ts +64 -0
  197. package/eject/files/text.ts +38 -0
  198. package/eject/files/thumbnail.ts +51 -0
  199. package/eject/files/time-picker.ts +113 -0
  200. package/eject/files/toast-queue.ts +64 -0
  201. package/eject/files/toast.ts +31 -0
  202. package/eject/files/tooltip.css +111 -0
  203. package/eject/files/tooltip.ts +21 -0
  204. package/eject/manifest.json +1053 -0
  205. package/package.json +12 -4
  206. package/styles.css +1064 -169
  207. package/tailwind.css +1295 -218
@@ -0,0 +1,66 @@
1
+ // Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ /** ListRow's props in every framework, short of `leading`, `trailing` and `onPress`. */
5
+ export type ListRowBaseProps = {
6
+ title: string;
7
+ description?: string;
8
+ /** Draws a chevron at the far end, for a row that leads somewhere else. */
9
+ chevron?: boolean;
10
+ /** The row that is the current choice, such as the open page in a sidebar. */
11
+ selected?: boolean;
12
+ /** A shorter row with smaller text, for dense lists such as a sidebar or a menu. */
13
+ compact?: boolean;
14
+ disabled?: boolean;
15
+ };
16
+
17
+ // The selected title is heavier, so the choice does not depend on the tint alone.
18
+ const TITLE = {
19
+ regular: { rest: "text-xds-body", selected: "text-xds-body-strong" },
20
+ compact: { rest: "text-xds-detail", selected: "text-xds-label" },
21
+ } as const;
22
+
23
+ /**
24
+ * The fills and the focus ring of a pressable row, at rest and selected. A collapsed Sidebar
25
+ * draws its icon-only rows with them too. The ring is inside the row, where a list that clips
26
+ * its rows still shows it.
27
+ */
28
+ export const PRESSABLE_ROW = {
29
+ rest: "hover:bg-xds-list-row-background-hover active:bg-xds-list-row-background-pressed disabled:hover:bg-transparent",
30
+ selected:
31
+ "hover:bg-xds-list-row-background-selected-hover active:bg-xds-list-row-background-selected-hover disabled:hover:bg-xds-list-row-background-selected",
32
+ focus:
33
+ "focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:-outline-offset-(--xds-focus-offset) focus-visible:outline-xds-border-focus",
34
+ } as const;
35
+
36
+ /** The row: a `div`, or a `button` with `pressable`. */
37
+ export function listRowClass(options: {
38
+ compact?: boolean | undefined;
39
+ selected?: boolean | undefined;
40
+ pressable?: boolean | undefined;
41
+ }): string {
42
+ const { compact = false, selected = false, pressable = false } = options;
43
+ const row = `flex w-full items-center gap-3 px-4 text-start ${compact ? "min-h-xds-list-row-compact py-1" : "min-h-xds-list-row py-2"}${selected ? " bg-xds-list-row-background-selected" : ""}`;
44
+ if (!pressable) return row;
45
+ return `${row} cursor-pointer transition-colors duration-(--xds-motion-duration-fast) ${selected ? PRESSABLE_ROW.selected : PRESSABLE_ROW.rest} ${PRESSABLE_ROW.focus} disabled:cursor-not-allowed`;
46
+ }
47
+
48
+ export function listRowTitleClass(options: {
49
+ compact?: boolean | undefined;
50
+ selected?: boolean | undefined;
51
+ disabled?: boolean | undefined;
52
+ }): string {
53
+ const { compact = false, selected = false, disabled = false } = options;
54
+ return `${TITLE[compact ? "compact" : "regular"][selected ? "selected" : "rest"]} ${disabled ? "text-xds-text-secondary" : "text-xds-text-primary"}`;
55
+ }
56
+
57
+ export function listRowDescriptionClass(compact = false): string {
58
+ return `text-xds-text-secondary ${compact ? "text-xds-footnote" : "text-xds-detail"}`;
59
+ }
60
+
61
+ export const LIST_ROW_PARTS = {
62
+ /** The title and the description, between `leading` and `trailing`. */
63
+ text: "flex min-w-0 flex-1 flex-col gap-0.5",
64
+ /** It points onward, so it mirrors in a right-to-left layout. */
65
+ chevron: "text-xds-text-tertiary rtl:-scale-x-100",
66
+ } as const;
@@ -0,0 +1,66 @@
1
+ // Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ import type { ThumbnailRatio } from "@xds/svelte/base";
5
+
6
+ export type MediaCardLayout = "vertical" | "horizontal";
7
+
8
+ /** MediaCard's props in every framework, short of `leading`, `action` and `onPress`. */
9
+ export type MediaCardBaseProps = {
10
+ /** `vertical` puts the thumbnail on top; `horizontal` at the start, at 40% of the width. */
11
+ layout?: MediaCardLayout;
12
+ /** The picture, as a Thumbnail's. */
13
+ src?: string | undefined;
14
+ /** Describes the picture. Defaults to an empty string: the title already says what it is. */
15
+ alt?: string;
16
+ ratio?: ThumbnailRatio;
17
+ /** Short text on the picture's bottom end corner, such as a duration. */
18
+ badge?: string;
19
+ /** How much was watched, from 0 to 1. */
20
+ progress?: number;
21
+ /** At most two lines, then an ellipsis. */
22
+ title: string;
23
+ /** Short details, one line each, such as a channel name and "3 days ago". */
24
+ meta?: readonly string[];
25
+ };
26
+
27
+ /** The ids of the title and of each detail, which together name the card. */
28
+ export function mediaCardIds(id: string, meta: readonly string[] = []) {
29
+ const title = `${id}-title`;
30
+ const details = meta.map((_, index) => `${id}-meta-${index}`);
31
+ return { title, details, names: [title, ...details].join(" ") };
32
+ }
33
+
34
+ /**
35
+ * The thumbnail and the text. On a pressable card it sits above the button, which draws the
36
+ * fills under it, and is see-through to the pointer, so a press anywhere but on the action
37
+ * lands on the button.
38
+ */
39
+ export function mediaCardContentClass(options: {
40
+ horizontal: boolean;
41
+ pressable: boolean;
42
+ }): string {
43
+ const { horizontal, pressable } = options;
44
+ return `relative flex gap-3 ${horizontal ? "items-start" : "flex-col"}${pressable ? " pointer-events-none" : ""}`;
45
+ }
46
+
47
+ export function mediaCardThumbnailClass(horizontal: boolean): string {
48
+ return horizontal ? "w-2/5 shrink-0" : "block";
49
+ }
50
+
51
+ export const MEDIA_CARD_PARTS = {
52
+ /** A card that is not pressable: a group named by its text. */
53
+ group: "flex flex-col",
54
+ /** A pressable card: the box around the button and the content. */
55
+ pressable: "relative flex flex-col rounded-xds-lg p-2",
56
+ /** Covers the whole pressable card, under the content. */
57
+ button:
58
+ "absolute inset-0 cursor-pointer rounded-xds-lg transition-colors duration-(--xds-motion-duration-fast) hover:bg-xds-card-background-hover focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-offset-(--xds-focus-offset) focus-visible:outline-xds-border-focus active:bg-xds-card-background-pressed",
59
+ /** Beside the thumbnail, or under it: `leading`, the text and the action. */
60
+ body: "flex min-w-0 flex-1 items-start gap-3",
61
+ leading: "flex shrink-0",
62
+ text: "flex min-w-0 flex-1 flex-col gap-0.5",
63
+ title: "line-clamp-2 text-xds-body-strong text-xds-text-primary",
64
+ meta: "truncate text-xds-detail text-xds-text-secondary",
65
+ action: "pointer-events-auto flex shrink-0",
66
+ } as const;
@@ -0,0 +1,192 @@
1
+ /*
2
+ * Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ * as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ */
5
+ /*
6
+ * Menu: Zag's menu machine. The list stays in the body, hidden while closed once it has
7
+ * animated out.
8
+ *
9
+ * Parts: `.{{prefix}}-menu__trigger` (added to the Button or IconButton that opens it),
10
+ * `.{{prefix}}-menu__underlay` (over the page while the menu is open), `.{{prefix}}-menu__positioner` (placed by
11
+ * Zag), `.{{prefix}}-menu` (the surface, role="menu"), `.{{prefix}}-menu__item` with `.{{prefix}}-menu__item--danger`,
12
+ * `.{{prefix}}-menu__item-icon`, `.{{prefix}}-menu__separator`.
13
+ * States: `[aria-expanded="true"]` on the trigger while open, `[data-highlighted]` on the row
14
+ * the arrow keys or the pointer are on (focus stays on the menu, so it is the only sign of it),
15
+ * `:active` while pressed, `[data-disabled]`, `[data-side]` on the surface for the side it
16
+ * opened on, and `[data-state="closed"]` on it while it animates out.
17
+ */
18
+ @layer components {
19
+ /* The trigger stays pressed while its menu is open, which ties the menu to the control it
20
+ came from. The underlay is over it, so the pointer does not turn it back to its hover
21
+ fill. */
22
+ .{{prefix}}-menu__trigger[aria-expanded="true"] {
23
+ background-color: var(--button-bg-pressed);
24
+ transform: scale(var(--xds-motion-press-scale));
25
+ will-change: transform;
26
+ }
27
+
28
+ @media (prefers-reduced-motion: reduce) {
29
+ .{{prefix}}-menu__trigger[aria-expanded="true"] {
30
+ transform: none;
31
+ }
32
+ }
33
+
34
+ /* Over the page and under the open menu: a press outside lands here and only closes the
35
+ menu, and nothing on the page reacts to the pointer meanwhile. Rendered before the
36
+ positioner, it is under it at the same level. Inside a dialog it is above the dialog,
37
+ which was rendered earlier. */
38
+ .{{prefix}}-menu__underlay {
39
+ position: fixed;
40
+ inset: 0;
41
+ z-index: calc(var(--{{prefix}}-layer-overlay) + var(--layer-index, 0));
42
+ }
43
+
44
+ .{{prefix}}-menu__positioner {
45
+ z-index: calc(var(--{{prefix}}-layer-overlay) + var(--layer-index, 0));
46
+ }
47
+
48
+ .{{prefix}}-menu {
49
+ display: flex;
50
+ flex-direction: column;
51
+ /* Four times `space.12`: wide enough that a menu of short words does not look like a
52
+ stack of chips. Beyond that it is as wide as its longest row. */
53
+ min-width: calc(4 * var(--xds-space-12));
54
+ max-width: calc(100svw - 2 * var(--xds-space-4));
55
+ max-height: var(--available-height);
56
+ padding: var(--xds-space-1);
57
+ overflow-y: auto;
58
+ overscroll-behavior: contain;
59
+ scroll-padding-block: var(--xds-space-1);
60
+ scrollbar-width: thin;
61
+ border: var(--xds-border-width-thin) solid var(--xds-color-menu-border);
62
+ border-radius: var(--xds-radius-md);
63
+ background: var(--xds-color-menu-background);
64
+ box-shadow: var(--xds-shadow-raised);
65
+ outline: none;
66
+ transform-origin: var(--transform-origin);
67
+ }
68
+
69
+ /* It grows in from the trigger's side. */
70
+ .{{prefix}}-menu[data-side="bottom"] {
71
+ animation: {{prefix}}-menu-enter-down var(--xds-motion-duration-fast) var(--xds-motion-easing-enter);
72
+ }
73
+
74
+ .{{prefix}}-menu[data-side="top"] {
75
+ animation: {{prefix}}-menu-enter-up var(--xds-motion-duration-fast) var(--xds-motion-easing-enter);
76
+ }
77
+
78
+ /* After the rules above, which it replaces. A closing menu takes no more presses. */
79
+ .{{prefix}}-menu[data-state="closed"] {
80
+ animation: {{prefix}}-overlay-exit var(--xds-motion-duration-fast) var(--xds-motion-easing-exit)
81
+ forwards;
82
+ pointer-events: none;
83
+ }
84
+
85
+ @media (prefers-reduced-motion: reduce) {
86
+ .{{prefix}}-menu[data-side],
87
+ .{{prefix}}-menu[data-state="closed"] {
88
+ animation: none;
89
+ }
90
+ }
91
+
92
+ /* A row of a menu looks like a compact list row. A compact row is shorter than a finger
93
+ needs, so on a touch screen it grows to the smallest pressable size. The padding above and
94
+ below only shows on a row of two lines. */
95
+ .{{prefix}}-menu__item {
96
+ position: relative;
97
+ display: flex;
98
+ align-items: center;
99
+ justify-content: flex-start;
100
+ gap: var(--xds-space-2);
101
+ width: 100%;
102
+ min-height: max(var(--xds-size-list-row-compact), var(--xds-size-target-min));
103
+ padding: var(--xds-space-1) var(--xds-space-2);
104
+ border-radius: var(--xds-radius-sm);
105
+ white-space: nowrap;
106
+ font-size: var(--xds-typography-detail-size);
107
+ font-weight: var(--xds-typography-detail-weight);
108
+ line-height: var(--xds-typography-detail-line-height);
109
+ color: var(--xds-color-menu-text);
110
+ outline: none;
111
+ cursor: pointer;
112
+ touch-action: manipulation;
113
+ -webkit-tap-highlight-color: transparent;
114
+ transition: background-color var(--xds-motion-duration-fast) var(--xds-motion-easing-standard);
115
+ }
116
+
117
+ .{{prefix}}-menu__item-icon {
118
+ color: var(--xds-color-menu-icon);
119
+ }
120
+
121
+ /* The pointer moves the same highlight as the arrow keys, so one rule draws both. The
122
+ highlight is a fill, which shows inside the menu where a focus ring would be clipped. */
123
+ .{{prefix}}-menu__item[data-highlighted] {
124
+ background: var(--xds-color-menu-item-background-hover);
125
+ }
126
+
127
+ /* A press that drags does not select the row's text. */
128
+ .{{prefix}}-menu__item:active {
129
+ background: var(--xds-color-menu-item-background-pressed);
130
+ user-select: none;
131
+ }
132
+
133
+ .{{prefix}}-menu__item--danger,
134
+ .{{prefix}}-menu__item--danger .{{prefix}}-menu__item-icon {
135
+ color: var(--xds-color-menu-danger-text);
136
+ }
137
+
138
+ .{{prefix}}-menu__item--danger[data-highlighted],
139
+ .{{prefix}}-menu__item--danger:active {
140
+ background: var(--xds-color-menu-danger-background-hover);
141
+ }
142
+
143
+ /* Recolored, not faded, like a disabled button. */
144
+ .{{prefix}}-menu__item[data-disabled],
145
+ .{{prefix}}-menu__item[data-disabled] .{{prefix}}-menu__item-icon {
146
+ color: var(--xds-color-menu-text-disabled);
147
+ }
148
+
149
+ .{{prefix}}-menu__item[data-disabled] {
150
+ cursor: not-allowed;
151
+ pointer-events: none;
152
+ }
153
+
154
+ .{{prefix}}-menu__separator {
155
+ flex-shrink: 0;
156
+ height: var(--xds-border-width-thin);
157
+ margin-block: var(--xds-space-1);
158
+ background: var(--xds-color-menu-border);
159
+ }
160
+
161
+ /* Forced colors draw every fill in the page's color, so the row under the pointer or the
162
+ keyboard takes the system's highlight. The browser draws a backplate in the page's color behind text in forced colors,
163
+ which would hide the highlight's text, so these keep their colors, which are the system's. */
164
+ @media (forced-colors: active) {
165
+ .{{prefix}}-menu__item[data-highlighted],
166
+ .{{prefix}}-menu__item--danger[data-highlighted] {
167
+ forced-color-adjust: none;
168
+ background-color: Highlight;
169
+ color: HighlightText;
170
+ }
171
+
172
+ .{{prefix}}-menu__item[data-highlighted] * {
173
+ color: inherit;
174
+ }
175
+ }
176
+ }
177
+
178
+ /* Literal offsets and scales: a custom property inside a keyframe keeps WebKit from running the
179
+ animation on the compositor. */
180
+ @keyframes {{prefix}}-menu-enter-down {
181
+ from {
182
+ opacity: 0;
183
+ transform: translate3d(0, -0.25rem, 0) scale(0.9);
184
+ }
185
+ }
186
+
187
+ @keyframes {{prefix}}-menu-enter-up {
188
+ from {
189
+ opacity: 0;
190
+ transform: translate3d(0, 0.25rem, 0) scale(0.9);
191
+ }
192
+ }
@@ -0,0 +1,84 @@
1
+ // Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ import type { IconName } from "@xds/svelte/base";
5
+
6
+ export type MenuItem =
7
+ | "separator"
8
+ | {
9
+ label: string;
10
+ icon?: IconName;
11
+ onSelect: () => void;
12
+ /** An action that destroys something. Drawn in the danger color. */
13
+ danger?: boolean;
14
+ disabled?: boolean;
15
+ /** The current choice among its neighbours. Marked with a check at the end of the row. */
16
+ selected?: boolean;
17
+ };
18
+
19
+ /** Menu's props in every framework, short of its trigger. */
20
+ export type MenuBaseProps = {
21
+ /** Names the menu for assistive technology. */
22
+ label: string;
23
+ items: readonly MenuItem[];
24
+ /** The edge of the trigger the menu lines up with. */
25
+ align?: "start" | "end";
26
+ };
27
+
28
+ /** The class of a row of the menu. The highlight and the disabled look come from attributes. */
29
+ export function menuItemClass(danger = false): string {
30
+ return danger ? "{{prefix}}-menu__item {{prefix}}-menu__item--danger" : "{{prefix}}-menu__item";
31
+ }
32
+
33
+ /**
34
+ * The box to place a menu against: its trigger's box before the transform that scales the
35
+ * trigger about its center while the menu is open, so the menu stays where it opened.
36
+ */
37
+ export function layoutRect(element: HTMLElement): {
38
+ x: number;
39
+ y: number;
40
+ width: number;
41
+ height: number;
42
+ } {
43
+ const box = element.getBoundingClientRect();
44
+ const style = getComputedStyle(element);
45
+ const width = Number.parseFloat(style.width);
46
+ const height = Number.parseFloat(style.height);
47
+ return {
48
+ x: box.x + (box.width - width) / 2,
49
+ y: box.y + (box.height - height) / 2,
50
+ width,
51
+ height,
52
+ };
53
+ }
54
+
55
+ /**
56
+ * Whether a press on a menu's trigger opens the menu as the button goes down rather than on
57
+ * the click: the main button of a mouse, without Control (which asks for the context menu on a
58
+ * Mac), on an enabled trigger. The pressed trigger then takes the focus, so the focus that
59
+ * comes back to it when the menu closes shows no keyboard ring. Touch and pen open it on the
60
+ * click, as Zag does.
61
+ */
62
+ export function opensOnPress(event: {
63
+ pointerType: string;
64
+ button: number;
65
+ ctrlKey: boolean;
66
+ currentTarget: EventTarget | null;
67
+ }): boolean {
68
+ return (
69
+ event.pointerType === "mouse" &&
70
+ event.button === 0 &&
71
+ !event.ctrlKey &&
72
+ !(event.currentTarget instanceof Element && event.currentTarget.matches(":disabled"))
73
+ );
74
+ }
75
+
76
+ /**
77
+ * The value of the first item that can be chosen, by position as the rows are: where the
78
+ * highlight goes when a screen reader or a script opens the menu with a click, as the keyboard
79
+ * puts it there, so the next key works the list at once.
80
+ */
81
+ export function firstMenuValue(items: readonly MenuItem[]): string | undefined {
82
+ const first = items.findIndex((item) => item !== "separator" && !item.disabled);
83
+ return first >= 0 ? String(first) : undefined;
84
+ }
@@ -0,0 +1,40 @@
1
+ /*
2
+ * Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ * as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ */
5
+ /*
6
+ * What every overlay shares: the level it is drawn on and how it leaves.
7
+ *
8
+ * The level: a dialog's scrim and the dialog, a menu, a select's list, a tooltip. Zag puts
9
+ * `--layer-index` on each layer it opens (0 for the first, 1 for one opened from it), and an
10
+ * overlay adds it, so the later one is on top. The design tokens have no z-index: only the web
11
+ * needs one. A toast needs none, as it is in the top layer.
12
+ */
13
+ :root {
14
+ --{{prefix}}-layer-overlay: 100000;
15
+ }
16
+
17
+ /* How every overlay leaves: a menu, a select's list, a tooltip and a dialog fade and shrink a
18
+ little, a dialog's scrim fades. Each starts it on `[data-state="closed"]`, and its component
19
+ keeps it on the page until it ends. Each holds the last frame (`forwards`): a framework may
20
+ paint once more before it removes the overlay, which would otherwise show again for that
21
+ frame. Both ends are set: WebKit does not run a transform animation that starts from an
22
+ implicit `none`.
23
+ The scale is a literal because a custom property inside a keyframe keeps WebKit from running
24
+ the animation on the compositor. */
25
+ @keyframes {{prefix}}-overlay-exit {
26
+ from {
27
+ opacity: 1;
28
+ transform: scale(1);
29
+ }
30
+ to {
31
+ opacity: 0;
32
+ transform: scale(0.95);
33
+ }
34
+ }
35
+
36
+ @keyframes {{prefix}}-fade-out {
37
+ to {
38
+ opacity: 0;
39
+ }
40
+ }
@@ -0,0 +1,106 @@
1
+ /*
2
+ * Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ * as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ */
5
+ /*
6
+ * Pagination: a `<nav>` holding a row of native buttons, the step back, the pages and the step
7
+ * on, with an ellipsis where pages are left out.
8
+ *
9
+ * Parts: `.{{prefix}}-pagination` (the root), `__list`, `__page` (`aria-current="page"` on the page
10
+ * shown), `__gap` and `__step`. A step with no page to go to has `aria-disabled="true"`, which
11
+ * keeps it in the tab order, so the focus stays on it once it reaches the end.
12
+ */
13
+ @layer components {
14
+ .{{prefix}}-pagination__list {
15
+ display: flex;
16
+ align-items: center;
17
+ gap: var(--xds-space-1);
18
+ margin: 0;
19
+ padding: 0;
20
+ list-style: none;
21
+ }
22
+
23
+ .{{prefix}}-pagination__list > li {
24
+ display: flex;
25
+ }
26
+
27
+ .{{prefix}}-pagination__page,
28
+ .{{prefix}}-pagination__step,
29
+ .{{prefix}}-pagination__gap {
30
+ display: inline-flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ min-width: var(--xds-size-control-sm);
34
+ height: var(--xds-size-control-sm);
35
+ font-size: var(--xds-typography-label-size);
36
+ font-weight: var(--xds-typography-label-weight);
37
+ line-height: var(--xds-typography-label-line-height);
38
+ font-variant-numeric: tabular-nums;
39
+ }
40
+
41
+ .{{prefix}}-pagination__page,
42
+ .{{prefix}}-pagination__step {
43
+ padding-inline: var(--xds-space-2);
44
+ /* Transparent until it is the page shown, so the outline never changes its size. */
45
+ border: var(--xds-border-width-thin) solid transparent;
46
+ border-radius: var(--xds-radius-md);
47
+ background-color: transparent;
48
+ color: var(--xds-color-pagination-text);
49
+ outline: none;
50
+ cursor: pointer;
51
+ user-select: none;
52
+ -webkit-tap-highlight-color: transparent;
53
+ transition-property: background-color, border-color;
54
+ transition-duration: var(--xds-motion-duration-fast);
55
+ transition-timing-function: var(--xds-motion-easing-standard);
56
+ }
57
+
58
+ .{{prefix}}-pagination__step {
59
+ padding-inline: 0;
60
+ }
61
+
62
+ .{{prefix}}-pagination__step svg {
63
+ pointer-events: none;
64
+ }
65
+
66
+ /* They point back and on, so they turn with the reading direction. */
67
+ .{{prefix}}-pagination__step svg:dir(rtl) {
68
+ transform: scaleX(-1);
69
+ }
70
+
71
+ @media (hover: hover) {
72
+ .{{prefix}}-pagination__page:not([aria-current]):hover,
73
+ .{{prefix}}-pagination__step:not([aria-disabled="true"]):hover {
74
+ background-color: var(--xds-color-pagination-background-hover);
75
+ }
76
+ }
77
+
78
+ .{{prefix}}-pagination__page:not([aria-current]):active,
79
+ .{{prefix}}-pagination__step:not([aria-disabled="true"]):active {
80
+ background-color: var(--xds-color-pagination-background-pressed);
81
+ }
82
+
83
+ /* The page shown: an outline as well as a tint, so it does not depend on color. */
84
+ .{{prefix}}-pagination__page[aria-current="page"] {
85
+ border-color: var(--xds-color-pagination-border-current);
86
+ background-color: var(--xds-color-pagination-background-current);
87
+ color: var(--xds-color-pagination-text-current);
88
+ cursor: default;
89
+ }
90
+
91
+ .{{prefix}}-pagination__step[aria-disabled="true"] {
92
+ color: var(--xds-color-pagination-text-disabled);
93
+ cursor: not-allowed;
94
+ }
95
+
96
+ .{{prefix}}-pagination__gap {
97
+ color: var(--xds-color-pagination-gap);
98
+ }
99
+
100
+ .{{prefix}}-pagination__page:focus-visible,
101
+ .{{prefix}}-pagination__step:focus-visible {
102
+ box-shadow:
103
+ 0 0 0 var(--xds-focus-offset) var(--xds-color-background-base),
104
+ 0 0 0 calc(var(--xds-focus-width) + var(--xds-focus-offset)) var(--xds-color-border-focus);
105
+ }
106
+ }
@@ -0,0 +1,68 @@
1
+ // Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ /** Pagination's props in every framework, short of its change handler. */
5
+ export type PaginationBaseProps = {
6
+ /** How many pages there are. */
7
+ count: number;
8
+ /**
9
+ * The page shown, from 1. Given at all, even as `undefined`, the app keeps it and changes it
10
+ * in `onChange`; otherwise the pagination keeps its own, from `defaultValue`.
11
+ */
12
+ value?: number;
13
+ /** The page shown first when the pagination keeps its own. Defaults to 1. */
14
+ defaultValue?: number;
15
+ /**
16
+ * Names the pagination's navigation landmark for assistive technology: `pagination` from the
17
+ * closest `Labels`, "Pagination" in English, unless it is given.
18
+ */
19
+ label?: string;
20
+ /** Names the step back a page: `previousPage` from the closest `Labels` unless it is given. */
21
+ previousLabel?: string;
22
+ /** Names the step on a page: `nextPage` from the closest `Labels` unless it is given. */
23
+ nextLabel?: string;
24
+ };
25
+
26
+ /** A page, by its number from 1, or a gap that stands for the pages left out. */
27
+ export type PaginationEntry = number | "gap";
28
+
29
+ /**
30
+ * The pages a Pagination shows between its steps: the first, the last, and the one shown, with
31
+ * a gap for each run of pages left out. Never more than five, so the row keeps its width from
32
+ * page to page and fits a phone held upright with the steps beside it. Near either end the
33
+ * three pages there are shown, so a gap never stands for a single page beside the one shown.
34
+ */
35
+ export function paginationEntries(value: number, count: number): PaginationEntry[] {
36
+ const last = Math.max(0, Math.floor(count));
37
+ if (last <= 5) return Array.from({ length: last }, (_, index) => index + 1);
38
+ const page = clampPage(value, last);
39
+ if (page <= 3) return [1, 2, 3, "gap", last];
40
+ if (page >= last - 2) return [1, "gap", last - 2, last - 1, last];
41
+ return [1, "gap", page, "gap", last];
42
+ }
43
+
44
+ /** The page shown, kept between the first and the last: an app may give one past the end. */
45
+ export function clampPage(value: number, count: number): number {
46
+ return Math.min(Math.max(1, Math.floor(value)), Math.max(1, Math.floor(count)));
47
+ }
48
+
49
+ /**
50
+ * The classes of a Pagination's parts beside its root, `{{prefix}}-pagination`, a `<nav>`: the row,
51
+ * a page, a gap, and the steps back and on.
52
+ */
53
+ export const PAGINATION_PARTS = {
54
+ list: "{{prefix}}-pagination__list",
55
+ page: "{{prefix}}-pagination__page",
56
+ gap: "{{prefix}}-pagination__gap",
57
+ step: "{{prefix}}-pagination__step",
58
+ } as const;
59
+
60
+ /**
61
+ * The steps' chevrons, which point back and on, so they mirror in a right-to-left layout. `sm`
62
+ * is the icon of a small control.
63
+ */
64
+ export const PAGINATION_STEPS = {
65
+ previous: "chevron-left",
66
+ next: "chevron-right",
67
+ size: "sm",
68
+ } as const;
@@ -0,0 +1,17 @@
1
+ // Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ /**
5
+ * The class on the root element of every web component, `{{prefix}}-` and its name in kebab case
6
+ * (`{{prefix}}-icon-button`). It is the component's stable handle for an app's own styles, beside the
7
+ * part classes of the components drawn with a stylesheet (`{{prefix}}-dialog__title`) and the state
8
+ * attributes (`aria-*`, `data-state`). A published library names it after itself.
9
+ */
10
+ export function rootPart(component: string): string {
11
+ return `{{prefix}}-${component.replace(/[A-Z]/g, (letter, index: number) => `${index ? "-" : ""}${letter.toLowerCase()}`)}`;
12
+ }
13
+
14
+ /** Joins the classes that are given, skipping those that are not. */
15
+ export function classes(...names: (string | false | null | undefined)[]): string {
16
+ return names.filter(Boolean).join(" ");
17
+ }