@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,160 @@
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
+ * Slider: Zag's slider machine, with one thumb.
7
+ *
8
+ * Parts: `.{{prefix}}-slider` (a grid: the label and the value on one line, the track under them),
9
+ * `__label`, `__output`, `__control` (the pressable band, which Zag measures to turn a press into
10
+ * a value), `__track` (the line), `__range` (the fill), `__thumb`.
11
+ * States: `[data-disabled]` on the root, `:focus-visible` and `[data-dragging]` on the thumb.
12
+ * Zag places the thumb and the ends of the fill with its own inline styles.
13
+ */
14
+ @layer components {
15
+ .{{prefix}}-slider {
16
+ display: grid;
17
+ grid-template-areas:
18
+ "label output"
19
+ "track track";
20
+ grid-template-columns: 1fr auto;
21
+ row-gap: var(--xds-space-1);
22
+ column-gap: var(--xds-space-2);
23
+ width: 100%;
24
+ }
25
+
26
+ .{{prefix}}-slider__label {
27
+ grid-area: label;
28
+ width: fit-content;
29
+ font-size: var(--xds-typography-label-size);
30
+ font-weight: var(--xds-typography-label-weight);
31
+ line-height: var(--xds-typography-label-line-height);
32
+ }
33
+
34
+ .{{prefix}}-slider__output {
35
+ grid-area: output;
36
+ align-self: end;
37
+ font-size: var(--xds-typography-detail-size);
38
+ font-weight: var(--xds-typography-detail-weight);
39
+ line-height: var(--xds-typography-detail-line-height);
40
+ font-variant-numeric: tabular-nums;
41
+ color: var(--xds-color-text-secondary);
42
+ }
43
+
44
+ /* The pressable band, as tall as the smallest pressable area, and inset by half a thumb at
45
+ each end so the thumb is centered on the value. It is as wide as the slider besides, so
46
+ the far end reaches half a thumb past the slider's edge. */
47
+ .{{prefix}}-slider__control {
48
+ grid-area: track;
49
+ width: 100%;
50
+ height: max(var(--xds-size-target-min), var(--xds-size-slider-thumb));
51
+ margin-inline: calc(var(--xds-size-slider-thumb) / 2);
52
+ cursor: pointer;
53
+ }
54
+
55
+ .{{prefix}}-slider__track {
56
+ height: 100%;
57
+ }
58
+
59
+ /* The line runs past the band's insets, to where the thumb's edge is at either extreme. */
60
+ .{{prefix}}-slider__track::before {
61
+ content: "";
62
+ position: absolute;
63
+ inset-inline: calc(var(--xds-size-slider-thumb) / -2);
64
+ top: 50%;
65
+ height: var(--xds-size-slider-track);
66
+ translate: 0 -50%;
67
+ border-radius: var(--xds-radius-full);
68
+ background: var(--xds-color-slider-track);
69
+ }
70
+
71
+ /* Zag sizes the fill from the start of the inset band; the padding reaches back over the
72
+ inset, so the fill starts where the line does. */
73
+ .{{prefix}}-slider__range {
74
+ top: 50%;
75
+ box-sizing: content-box;
76
+ height: var(--xds-size-slider-track);
77
+ margin-inline-start: calc(var(--xds-size-slider-thumb) / -2);
78
+ padding-inline-start: calc(var(--xds-size-slider-thumb) / 2);
79
+ translate: 0 -50%;
80
+ border-radius: var(--xds-radius-full);
81
+ background: var(--xds-color-slider-fill);
82
+ pointer-events: none;
83
+ }
84
+
85
+ /* Zag centers the thumb on the value across; this centers it on the line. */
86
+ .{{prefix}}-slider__thumb {
87
+ top: 50%;
88
+ z-index: 2;
89
+ box-sizing: border-box;
90
+ width: var(--xds-size-slider-thumb);
91
+ height: var(--xds-size-slider-thumb);
92
+ translate: 0 -50%;
93
+ border: var(--xds-border-width-thick) solid var(--xds-color-slider-thumb-border);
94
+ border-radius: var(--xds-radius-full);
95
+ background: var(--xds-color-slider-thumb);
96
+ outline: none;
97
+ cursor: grab;
98
+ transition: border-color var(--xds-motion-duration-fast) var(--xds-motion-easing-standard);
99
+ }
100
+
101
+ .{{prefix}}-slider__thumb[data-dragging] {
102
+ cursor: grabbing;
103
+ }
104
+
105
+ .{{prefix}}-slider__thumb:focus-visible {
106
+ z-index: 10;
107
+ outline: var(--xds-focus-width) solid var(--xds-color-border-focus);
108
+ outline-offset: var(--xds-focus-offset);
109
+ }
110
+
111
+ /* Disabled is recolored, not faded: the fill and the thumb's ring turn grey, and so do the
112
+ label and the value. */
113
+ .{{prefix}}-slider[data-disabled] {
114
+ cursor: not-allowed;
115
+ pointer-events: none;
116
+ }
117
+
118
+ .{{prefix}}-slider[data-disabled] .{{prefix}}-slider__label,
119
+ .{{prefix}}-slider[data-disabled] .{{prefix}}-slider__output {
120
+ color: var(--xds-color-text-disabled);
121
+ cursor: not-allowed;
122
+ }
123
+
124
+ .{{prefix}}-slider[data-disabled] .{{prefix}}-slider__range {
125
+ background: var(--xds-color-slider-disabled-fill);
126
+ }
127
+
128
+ .{{prefix}}-slider[data-disabled] .{{prefix}}-slider__thumb {
129
+ border-color: var(--xds-color-slider-disabled-fill);
130
+ cursor: default;
131
+ }
132
+
133
+ .{{prefix}}-slider[data-disabled] .{{prefix}}-slider__control {
134
+ cursor: default;
135
+ }
136
+
137
+ /* Forced colors draw every fill in the page's color: the line and the thumb's edge take the
138
+ text's, and the part before the thumb the system's highlight. */
139
+ @media (forced-colors: active) {
140
+ .{{prefix}}-slider__track::before {
141
+ background: CanvasText;
142
+ }
143
+
144
+ .{{prefix}}-slider__range {
145
+ background: Highlight;
146
+ }
147
+
148
+ .{{prefix}}-slider__thumb {
149
+ border-color: CanvasText;
150
+ background: Canvas;
151
+ }
152
+
153
+ .{{prefix}}-slider[data-disabled] .{{prefix}}-slider__track::before,
154
+ .{{prefix}}-slider[data-disabled] .{{prefix}}-slider__range,
155
+ .{{prefix}}-slider[data-disabled] .{{prefix}}-slider__thumb {
156
+ border-color: GrayText;
157
+ background: GrayText;
158
+ }
159
+ }
160
+ }
@@ -0,0 +1,80 @@
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 { focusWithoutRing } from "@xds/svelte/base";
5
+
6
+ /** Slider's props in every framework, short of `onChange`. */
7
+ export type SliderBaseProps = {
8
+ /** Shown above the track, and names the slider for assistive technology. */
9
+ label: string;
10
+ /** Leave it out for a slider that keeps its own value, from `defaultValue`. */
11
+ value?: number;
12
+ /** The first value of a slider that keeps its own, without `value`. Defaults to `min`. */
13
+ defaultValue?: number;
14
+ /** Defaults to 0. */
15
+ min?: number;
16
+ /** Defaults to 100. */
17
+ max?: number;
18
+ /** The values snap to multiples of it from `min`. Defaults to 1. */
19
+ step?: number;
20
+ disabled?: boolean;
21
+ /** Shows the current value at the end of the label's line. */
22
+ showValue?: boolean;
23
+ /** The name the value is submitted under with a form. */
24
+ name?: string;
25
+ /** Formats the displayed value in a fixed locale (useful for SSR). */
26
+ locale?: string;
27
+ };
28
+
29
+ /** The value as it is shown beside the label and read out: a number in the chosen or reader's locale. */
30
+ export function sliderValueText(value: number, locale?: string): string {
31
+ // Outside the browser (SSR), fall back to en-US unless an explicit locale is given so server and
32
+ // client can align deterministically.
33
+ const tag = locale ?? (typeof navigator === "undefined" ? "en-US" : navigator.language);
34
+ return new Intl.NumberFormat(tag).format(value);
35
+ }
36
+
37
+ /**
38
+ * How far Page Up, Page Down and a shifted arrow key move the thumb: a tenth of the range,
39
+ * rounded to a whole number of steps and never less than one.
40
+ */
41
+ export function sliderPageSize(options: { min: number; max: number; step: number }): number {
42
+ const { min, max, step } = options;
43
+ const steps = Math.max(Math.round((max - min) / 10 / step), 1);
44
+ // Rounded to the step's decimals, so that 3 steps of 0.1 are 0.3.
45
+ const decimals = String(step).split(".")[1]?.length ?? 0;
46
+ return Number((steps * step).toFixed(decimals));
47
+ }
48
+
49
+ /**
50
+ * Where Up or Down moves the thumb of a horizontal slider, as they move a native range input:
51
+ * a step, or `pageSize` with Shift, within the range. Undefined for any other key. Zag's
52
+ * horizontal slider leaves the two keys to the page.
53
+ */
54
+ export function sliderArrowValue(
55
+ event: { key: string; shiftKey: boolean },
56
+ options: { value: number; min: number; max: number; step: number; pageSize: number },
57
+ ): number | undefined {
58
+ const direction = event.key === "ArrowUp" ? 1 : event.key === "ArrowDown" ? -1 : 0;
59
+ if (direction === 0) return undefined;
60
+ const { value, min, max, step, pageSize } = options;
61
+ const delta = event.shiftKey ? pageSize : step;
62
+ const decimals = Math.max(
63
+ String(step).split(".")[1]?.length ?? 0,
64
+ String(delta).split(".")[1]?.length ?? 0,
65
+ );
66
+ const next = Number((value + direction * delta).toFixed(decimals));
67
+ return Math.min(max, Math.max(min, next));
68
+ }
69
+
70
+ /**
71
+ * For a press on a slider's track or thumb, ahead of Zag's handler. Zag keeps the press from
72
+ * focusing anything, then focuses the thumb from a script; focused here first, the thumb shows
73
+ * no keyboard ring.
74
+ */
75
+ export function focusThumbOnPress(
76
+ event: { button: number },
77
+ thumb: HTMLElement | null | undefined,
78
+ ): void {
79
+ if (event.button === 0) focusWithoutRing(thumb);
80
+ }
@@ -0,0 +1,22 @@
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
+ const SIZE = {
5
+ sm: "size-xds-spinner-sm",
6
+ md: "size-xds-spinner-md",
7
+ lg: "size-xds-spinner-lg",
8
+ } as const;
9
+
10
+ export type SpinnerSize = keyof typeof SIZE;
11
+
12
+ export type SpinnerBaseProps = {
13
+ size?: SpinnerSize;
14
+ /** Announces the spinner. Leave it out next to text that already says what is happening. */
15
+ label?: string;
16
+ };
17
+
18
+ /** The class of the spinner's ring. Its wrapper is `inline-flex shrink-0`. */
19
+ export function spinnerClass(size: SpinnerSize = "md"): string {
20
+ // People who ask for less motion get a slow pulse instead of a spin, not a frozen ring.
21
+ return `${SIZE[size]} animate-spin motion-reduce:animate-pulse`;
22
+ }
@@ -0,0 +1,45 @@
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
+ /** Switch's props in every framework, short of `onChange`. */
5
+ export type SwitchBaseProps = {
6
+ /** Leave it out for a switch that keeps its own state, from `defaultChecked`. */
7
+ checked?: boolean;
8
+ /** Whether a switch that keeps its own state starts on. */
9
+ defaultChecked?: boolean;
10
+ /** Shown beside the switch. Pressing it toggles too. */
11
+ label?: string;
12
+ /** Names the switch for assistive technology when there is no visible label. */
13
+ "aria-label"?: string;
14
+ disabled?: boolean;
15
+ };
16
+
17
+ // The focus ring of a control that is drawn next to a visually hidden native input.
18
+ export const PEER_FOCUS =
19
+ "peer-focus-visible:outline-solid peer-focus-visible:outline-(length:--xds-focus-width) peer-focus-visible:outline-offset-(--xds-focus-offset) peer-focus-visible:outline-xds-border-focus";
20
+
21
+ /**
22
+ * The label around a Switch's input, which is also a Checkbox's: pressing any of it toggles.
23
+ * The input inside is `peer sr-only`, and the parts after it follow its state.
24
+ */
25
+ export const switchClass =
26
+ "relative inline-flex min-h-xds-target-min w-fit cursor-pointer items-center gap-2 has-disabled:cursor-not-allowed";
27
+
28
+ /**
29
+ * Forced colors draw every fill in the page's color, which would leave a switch blank: the
30
+ * track takes an edge in the text's color, the system's highlight when on, and the thumb the
31
+ * text's color, or the highlight's when on. A disabled one is gray.
32
+ */
33
+ const FORCED_COLORS =
34
+ "forced-colors:border forced-colors:border-[CanvasText] forced-colors:p-px forced-colors:*:bg-[CanvasText] forced-colors:peer-checked:border-[Highlight] forced-colors:peer-checked:bg-[Highlight] forced-colors:peer-checked:*:bg-[HighlightText] forced-colors:peer-disabled:border-[GrayText] forced-colors:peer-disabled:*:bg-[GrayText]";
35
+
36
+ /** The track, drawn beside the hidden input. */
37
+ export const switchTrackClass = `flex h-xds-switch-height w-xds-switch-width shrink-0 rounded-full bg-xds-switch-track p-0.5 transition-colors duration-(--xds-motion-duration-fast) peer-checked:bg-xds-switch-track-on peer-disabled:bg-xds-switch-disabled-track peer-checked:*:translate-x-[calc(var(--xds-size-switch-width)-var(--xds-size-switch-height))] peer-disabled:*:bg-xds-switch-disabled-thumb ${FORCED_COLORS} ${PEER_FOCUS}`;
38
+
39
+ /** The thumb inside the track. */
40
+ export const switchThumbClass =
41
+ "aspect-square h-full rounded-full bg-xds-switch-thumb transition-transform duration-(--xds-motion-duration-fast) ease-(--xds-motion-easing-standard) motion-reduce:transition-none";
42
+
43
+ /** The visible label after the track, which is also a Checkbox's. */
44
+ export const switchLabelClass =
45
+ "text-xds-body text-xds-text-primary peer-disabled:text-xds-text-secondary";
@@ -0,0 +1,107 @@
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
+ * Table: a native `<table>` in a frame that scrolls sideways when its columns do not fit.
7
+ *
8
+ * Parts: `.{{prefix}}-table` (the root, the frame), `__table`, `__header` (a `<th>`, with `aria-sort`
9
+ * on the one the rows are sorted by), `__sort` (the button of a sortable header), `__row`,
10
+ * `__cell`, `__cell--end` (a cell of a column aligned to the end) and `__empty`.
11
+ */
12
+ @layer components {
13
+ .{{prefix}}-table {
14
+ overflow-x: auto;
15
+ border: var(--xds-border-width-thin) solid var(--xds-color-table-border);
16
+ /* A card's corners: a table is a card of rows. */
17
+ border-radius: var(--xds-radius-lg);
18
+ background-color: var(--xds-color-table-background);
19
+ }
20
+
21
+ .{{prefix}}-table__table {
22
+ width: 100%;
23
+ border-collapse: collapse;
24
+ color: var(--xds-color-table-text);
25
+ font-size: var(--xds-typography-body-size);
26
+ font-weight: var(--xds-typography-body-weight);
27
+ line-height: var(--xds-typography-body-line-height);
28
+ }
29
+
30
+ .{{prefix}}-table__header,
31
+ .{{prefix}}-table__cell,
32
+ .{{prefix}}-table__empty {
33
+ padding: var(--xds-space-2) var(--xds-space-3);
34
+ text-align: start;
35
+ vertical-align: middle;
36
+ }
37
+
38
+ .{{prefix}}-table__header {
39
+ background-color: var(--xds-color-table-header-background);
40
+ color: var(--xds-color-table-header-text);
41
+ font-size: var(--xds-typography-label-size);
42
+ font-weight: var(--xds-typography-label-weight);
43
+ line-height: var(--xds-typography-label-line-height);
44
+ white-space: nowrap;
45
+ }
46
+
47
+ .{{prefix}}-table__header[aria-sort] {
48
+ color: var(--xds-color-table-header-text-hover);
49
+ }
50
+
51
+ /* Rows apart by a line between them, which the frame's outline closes at the ends. */
52
+ .{{prefix}}-table__row + .{{prefix}}-table__row > *,
53
+ thead + tbody > .{{prefix}}-table__row:first-child > * {
54
+ border-top: var(--xds-border-width-thin) solid var(--xds-color-table-border);
55
+ }
56
+
57
+ .{{prefix}}-table__cell--end {
58
+ text-align: end;
59
+ font-variant-numeric: tabular-nums;
60
+ }
61
+
62
+ /* As wide as the header's text, with the arrow after it, and the header's own type. */
63
+ .{{prefix}}-table__sort {
64
+ display: inline-flex;
65
+ align-items: center;
66
+ gap: var(--xds-space-1);
67
+ margin: 0;
68
+ padding: 0;
69
+ border: none;
70
+ border-radius: var(--xds-radius-sm);
71
+ background: none;
72
+ color: inherit;
73
+ font: inherit;
74
+ text-align: inherit;
75
+ outline: none;
76
+ cursor: pointer;
77
+ user-select: none;
78
+ -webkit-tap-highlight-color: transparent;
79
+ }
80
+
81
+ /* A header aligned to the end has its arrow before its text, so the text lines up with the numbers. */
82
+ .{{prefix}}-table__cell--end > .{{prefix}}-table__sort {
83
+ flex-direction: row-reverse;
84
+ }
85
+
86
+ .{{prefix}}-table__sort svg {
87
+ flex-shrink: 0;
88
+ pointer-events: none;
89
+ }
90
+
91
+ @media (hover: hover) {
92
+ .{{prefix}}-table__sort:hover {
93
+ color: var(--xds-color-table-header-text-hover);
94
+ }
95
+ }
96
+
97
+ .{{prefix}}-table__sort:focus-visible {
98
+ box-shadow:
99
+ 0 0 0 var(--xds-focus-offset) var(--xds-color-table-header-background),
100
+ 0 0 0 calc(var(--xds-focus-width) + var(--xds-focus-offset)) var(--xds-color-border-focus);
101
+ }
102
+
103
+ .{{prefix}}-table__empty {
104
+ color: var(--xds-color-text-secondary);
105
+ text-align: center;
106
+ }
107
+ }
@@ -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
+ /** A column of a Table. */
5
+ export type TableColumn = {
6
+ /** Names the column, for `sort`. */
7
+ key: string;
8
+ /** The column's header. */
9
+ label: string;
10
+ /** `end` for numbers, so that their digits line up. `start` unless set. */
11
+ align?: "start" | "end";
12
+ /** Its header is a button that asks for the rows sorted by it, through `onSortChange`. */
13
+ sortable?: boolean;
14
+ };
15
+
16
+ /** A row of a Table: its values, one for each column, in the columns' order. */
17
+ export type TableRow = {
18
+ /** Tells the row from the others. */
19
+ id: string;
20
+ cells: readonly string[];
21
+ };
22
+
23
+ export type SortDirection = "ascending" | "descending";
24
+
25
+ /** The column the rows are sorted by, by its `key`, and in which order. */
26
+ export type TableSort = { column: string; direction: SortDirection };
27
+
28
+ /** Table's props in every framework, short of `onSortChange`. */
29
+ export type TableBaseProps = {
30
+ /** Names the table for assistive technology. */
31
+ label: string;
32
+ columns: readonly TableColumn[];
33
+ /** Shown in the order given: the table does not sort them. */
34
+ rows: readonly TableRow[];
35
+ /** The column the app sorted the rows by, which its header shows. */
36
+ sort?: TableSort | undefined;
37
+ /** Said in the table while it has no rows. */
38
+ empty?: string;
39
+ };
40
+
41
+ /**
42
+ * The sort a press on a sortable column's header asks for: ascending, or the other way for
43
+ * the column the rows are sorted by already.
44
+ */
45
+ export function nextSort(sort: TableSort | undefined, column: string): TableSort {
46
+ return {
47
+ column,
48
+ direction:
49
+ sort?.column === column && sort.direction === "ascending" ? "descending" : "ascending",
50
+ };
51
+ }
52
+
53
+ /** The order of a column's rows, or none for a column they are not sorted by. */
54
+ export function columnSort(sort: TableSort | undefined, column: string): SortDirection | undefined {
55
+ return sort?.column === column ? sort.direction : undefined;
56
+ }
57
+
58
+ /**
59
+ * The arrow at the end of a sortable column's header: up while the rows are sorted ascending
60
+ * by it, down while descending, and both ways while they are sorted by another column.
61
+ */
62
+ export function sortIcon(direction: SortDirection | undefined) {
63
+ return direction === "ascending"
64
+ ? "arrow-up"
65
+ : direction === "descending"
66
+ ? "arrow-down"
67
+ : "arrow-up-down";
68
+ }
69
+
70
+ /**
71
+ * The classes of a Table's parts beside its root, `{{prefix}}-table`, the frame that scrolls sideways
72
+ * when the columns do not fit: the `<table>`, a header cell, the button of a sortable one, a
73
+ * row, a cell, and the cell that says the table is empty. A cell of a column aligned to the end
74
+ * takes `end` too.
75
+ */
76
+ export const TABLE_PARTS = {
77
+ table: "{{prefix}}-table__table",
78
+ header: "{{prefix}}-table__header",
79
+ sort: "{{prefix}}-table__sort",
80
+ row: "{{prefix}}-table__row",
81
+ cell: "{{prefix}}-table__cell",
82
+ empty: "{{prefix}}-table__empty",
83
+ end: "{{prefix}}-table__cell--end",
84
+ } as const;
@@ -0,0 +1,120 @@
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
+ * Tabs: Zag's tabs machine, the row alone (the app shows the view).
7
+ *
8
+ * Parts: `.{{prefix}}-tabs` (the root, which scrolls), `__list`, `__tab`, `__indicator`. `.{{prefix}}-tabs--full-width`
9
+ * shares the width between the tabs.
10
+ * States: `[aria-selected="true"]`, `:hover` and `:focus-visible` on a tab; `[data-instant]` and
11
+ * `[hidden]` on the indicator, which Zag places with `--left` and `--width`.
12
+ */
13
+ @layer components {
14
+ /* The root is what scrolls, so the hairline under the row stays put while the tabs move.
15
+ It is drawn as a shadow inside the box, which lets the selected tab's bar cover it. */
16
+ .{{prefix}}-tabs {
17
+ display: flex;
18
+ flex-direction: column;
19
+ overflow-x: auto;
20
+ scrollbar-width: none;
21
+ box-shadow: inset 0 calc(-1 * var(--xds-border-width-thin)) 0 var(--xds-color-tabs-border);
22
+ }
23
+
24
+ .{{prefix}}-tabs::-webkit-scrollbar {
25
+ display: none;
26
+ }
27
+
28
+ /* As wide as its tabs, and never narrower than the row. */
29
+ .{{prefix}}-tabs__list {
30
+ position: relative;
31
+ display: flex;
32
+ width: max-content;
33
+ min-width: 100%;
34
+ }
35
+
36
+ .{{prefix}}-tabs--full-width .{{prefix}}-tabs__list {
37
+ width: 100%;
38
+ }
39
+
40
+ .{{prefix}}-tabs__tab {
41
+ position: relative;
42
+ z-index: 1;
43
+ display: flex;
44
+ flex: none;
45
+ align-items: center;
46
+ justify-content: center;
47
+ gap: var(--xds-space-2);
48
+ height: var(--xds-size-tab);
49
+ padding-inline: var(--xds-space-4);
50
+ white-space: nowrap;
51
+ text-align: center;
52
+ font-size: var(--xds-typography-label-size);
53
+ font-weight: var(--xds-typography-label-weight);
54
+ line-height: var(--xds-typography-label-line-height);
55
+ color: var(--xds-color-tabs-text);
56
+ outline: none;
57
+ cursor: pointer;
58
+ touch-action: manipulation;
59
+ -webkit-tap-highlight-color: transparent;
60
+ transition: color var(--xds-motion-duration-fast) var(--xds-motion-easing-standard);
61
+ }
62
+
63
+ .{{prefix}}-tabs--full-width .{{prefix}}-tabs__tab {
64
+ flex: 1 1 0;
65
+ }
66
+
67
+ /* Under the pointer a tab takes a color of its own. */
68
+ @media (hover: hover) {
69
+ .{{prefix}}-tabs__tab:not([aria-selected="true"]):hover {
70
+ color: var(--xds-color-tabs-text-hover);
71
+ }
72
+ }
73
+
74
+ .{{prefix}}-tabs__tab[aria-selected="true"] {
75
+ color: var(--xds-color-tabs-text-selected);
76
+ }
77
+
78
+ /* Inside the tab, because the row clips whatever is drawn outside it. */
79
+ .{{prefix}}-tabs__tab:focus-visible {
80
+ outline: var(--xds-focus-width) solid var(--xds-color-border-focus);
81
+ outline-offset: calc(-1 * var(--xds-focus-offset));
82
+ }
83
+
84
+ /* A bar across the bottom edge of the selected tab, over the hairline and under the tabs'
85
+ focus rings. It slides to the tab that is selected next; Zag marks the moves that should
86
+ not slide, such as the first placing. */
87
+ .{{prefix}}-tabs__indicator {
88
+ bottom: 0;
89
+ width: var(--width);
90
+ height: var(--xds-border-width-thick);
91
+ background: var(--xds-color-tabs-indicator);
92
+ transition-property: left, width;
93
+ transition-duration: var(--xds-motion-duration-normal);
94
+ transition-timing-function: var(--xds-motion-easing-standard);
95
+ }
96
+
97
+ .{{prefix}}-tabs__indicator[data-instant] {
98
+ transition: none;
99
+ }
100
+
101
+ /* Zag hides the bar until it has measured the selected tab, which a page rendered on the
102
+ server shows first: the tab draws the same bar inside itself until then. */
103
+ .{{prefix}}-tabs__list:has(> .{{prefix}}-tabs__indicator[hidden]) > .{{prefix}}-tabs__tab[aria-selected="true"] {
104
+ box-shadow: inset 0 calc(-1 * var(--xds-border-width-thick)) 0 var(--xds-color-tabs-indicator);
105
+ }
106
+
107
+ @media (prefers-reduced-motion: reduce) {
108
+ .{{prefix}}-tabs__indicator {
109
+ transition: none;
110
+ }
111
+ }
112
+
113
+ /* Forced colors draw every fill in the page's color, which would hide the bar under the
114
+ selected tab: it takes the system's highlight. */
115
+ @media (forced-colors: active) {
116
+ .{{prefix}}-tabs__indicator {
117
+ background: Highlight;
118
+ }
119
+ }
120
+ }
@@ -0,0 +1,37 @@
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
+ /** Tabs' props in every framework, short of `onChange`. */
7
+ export type TabsBaseProps<Value extends string> = {
8
+ items: readonly { value: Value; label: string; icon?: IconName }[];
9
+ /** The selected tab. Leave it out for tabs that keep their own, from `defaultValue`. */
10
+ value?: Value;
11
+ /** The first tab of tabs that keep their own, without `value`. Defaults to the first. */
12
+ defaultValue?: Value;
13
+ /** Says what the tabs switch between, for assistive technology. */
14
+ label: string;
15
+ /** The tabs share the width equally instead of being as wide as their labels. */
16
+ fullWidth?: boolean;
17
+ };
18
+
19
+ /** The classes of the row's root, which is what scrolls. */
20
+ export function tabsClass(fullWidth = false): string {
21
+ return fullWidth ? "{{prefix}}-tabs {{prefix}}-tabs--full-width" : "{{prefix}}-tabs";
22
+ }
23
+
24
+ /**
25
+ * A tab's tabindex. Zag makes the selected tab the row's one stop for Tab and Shift+Tab. A tab
26
+ * can have the focus without being selected, after a press that ended off it or from a script,
27
+ * and the stop would then be another tab of the same row. While a tab has the focus it is the
28
+ * stop, so that Tab and Shift+Tab leave the row from it.
29
+ */
30
+ export function tabStopIndex<ZagTabIndex>(
31
+ focusedValue: string | null,
32
+ value: string,
33
+ zagTabIndex: ZagTabIndex,
34
+ ): ZagTabIndex | 0 | -1 {
35
+ if (focusedValue === null) return zagTabIndex;
36
+ return focusedValue === value ? 0 : -1;
37
+ }