@xds/svelte 1.1.0 → 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.
- package/dist/Breadcrumb.svelte +53 -0
- package/dist/Breadcrumb.svelte.d.ts +11 -0
- package/dist/Checkbox.svelte +11 -3
- package/dist/Checkbox.svelte.d.ts +2 -1
- package/dist/Combobox.svelte +194 -0
- package/dist/Combobox.svelte.d.ts +37 -0
- package/dist/DatePicker.svelte +5 -4
- package/dist/Link.svelte +86 -0
- package/dist/Link.svelte.d.ts +26 -0
- package/dist/Menu.svelte +8 -1
- package/dist/Pagination.svelte +108 -0
- package/dist/Pagination.svelte.d.ts +14 -0
- package/dist/Popover.svelte +91 -0
- package/dist/Popover.svelte.d.ts +21 -0
- package/dist/PopoverSurface.svelte +77 -0
- package/dist/PopoverSurface.svelte.d.ts +21 -0
- package/dist/Select.svelte +40 -8
- package/dist/Select.svelte.d.ts +6 -0
- package/dist/Table.svelte +92 -0
- package/dist/Table.svelte.d.ts +17 -0
- package/dist/TimePicker.svelte +222 -0
- package/dist/TimePicker.svelte.d.ts +20 -0
- package/dist/ToastQueue.svelte +57 -0
- package/dist/ToastQueue.svelte.d.ts +20 -0
- package/dist/base.d.ts +14 -0
- package/dist/base.js +27 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +11 -0
- package/dist/modal-popover.svelte.js +5 -1
- package/dist/presence.svelte.js +5 -2
- package/dist/preview/Component.svelte +6 -3
- package/dist/preview/Preview.svelte +8 -2
- package/dist/preview/Preview.svelte.d.ts +2 -0
- package/dist/preview/components.d.ts +9 -2
- package/dist/preview/components.js +18 -2
- package/dist/preview/index.d.ts +1 -0
- package/eject/files/Accordion.svelte +100 -0
- package/eject/files/AccordionPanel.svelte +48 -0
- package/eject/files/Avatar.svelte +51 -0
- package/eject/files/AvatarStack.svelte +61 -0
- package/eject/files/Badge.svelte +52 -0
- package/eject/files/Banner.svelte +94 -0
- package/eject/files/Breadcrumb.svelte +52 -0
- package/eject/files/Button.svelte +126 -0
- package/eject/files/Card.svelte +112 -0
- package/eject/files/Checkbox.svelte +121 -0
- package/eject/files/Chip.svelte +51 -0
- package/eject/files/ChipBar.svelte +39 -0
- package/eject/files/Combobox.svelte +198 -0
- package/eject/files/CountBadge.svelte +51 -0
- package/eject/files/DatePicker.svelte +213 -0
- package/eject/files/DateRangePicker.svelte +294 -0
- package/eject/files/Dialog.svelte +119 -0
- package/eject/files/Divider.svelte +27 -0
- package/eject/files/EmptyState.svelte +52 -0
- package/eject/files/Icon.svelte +51 -0
- package/eject/files/IconButton.svelte +99 -0
- package/eject/files/Link.svelte +85 -0
- package/eject/files/ListRow.svelte +33 -0
- package/eject/files/MediaCard.svelte +117 -0
- package/eject/files/Menu.svelte +183 -0
- package/eject/files/Pagination.svelte +109 -0
- package/eject/files/PlaceRow.svelte +75 -0
- package/eject/files/Popover.svelte +100 -0
- package/eject/files/PopoverSurface.svelte +85 -0
- package/eject/files/ProgressBar.svelte +38 -0
- package/eject/files/RadioGroup.svelte +133 -0
- package/eject/files/SearchField.svelte +154 -0
- package/eject/files/SectionHeader.svelte +67 -0
- package/eject/files/SegmentedControl.svelte +85 -0
- package/eject/files/Select.svelte +276 -0
- package/eject/files/Sidebar.svelte +130 -0
- package/eject/files/SidebarRailButton.svelte +32 -0
- package/eject/files/Skeleton.svelte +55 -0
- package/eject/files/Slider.svelte +136 -0
- package/eject/files/Spinner.svelte +41 -0
- package/eject/files/Switch.svelte +105 -0
- package/eject/files/Table.svelte +90 -0
- package/eject/files/Tabs.svelte +85 -0
- package/eject/files/Text.svelte +43 -0
- package/eject/files/TextField.svelte +222 -0
- package/eject/files/Thumbnail.svelte +88 -0
- package/eject/files/TimePicker.svelte +237 -0
- package/eject/files/Toast.svelte +98 -0
- package/eject/files/ToastQueue.svelte +61 -0
- package/eject/files/Tooltip.svelte +51 -0
- package/eject/files/TooltipOverlay.svelte +88 -0
- package/eject/files/accordion.css +89 -0
- package/eject/files/accordion.ts +67 -0
- package/eject/files/avatar-stack.ts +57 -0
- package/eject/files/avatar.ts +42 -0
- package/eject/files/badge.ts +30 -0
- package/eject/files/banner.ts +71 -0
- package/eject/files/base.css +38 -0
- package/eject/files/breadcrumb.css +51 -0
- package/eject/files/breadcrumb.ts +42 -0
- package/eject/files/button.css +241 -0
- package/eject/files/button.ts +106 -0
- package/eject/files/card.ts +58 -0
- package/eject/files/checkbox.ts +52 -0
- package/eject/files/chip-bar.ts +16 -0
- package/eject/files/chip.ts +35 -0
- package/eject/files/combobox.css +269 -0
- package/eject/files/combobox.ts +85 -0
- package/eject/files/count-badge.ts +32 -0
- package/eject/files/date-picker.css +375 -0
- package/eject/files/date-picker.ts +280 -0
- package/eject/files/date-range-picker.ts +338 -0
- package/eject/files/dialog.css +139 -0
- package/eject/files/dialog.ts +15 -0
- package/eject/files/divider.ts +5 -0
- package/eject/files/empty-state.ts +22 -0
- package/eject/files/icon.ts +36 -0
- package/eject/files/link.css +64 -0
- package/eject/files/link.ts +63 -0
- package/eject/files/list-row.ts +66 -0
- package/eject/files/media-card.ts +66 -0
- package/eject/files/menu.css +192 -0
- package/eject/files/menu.ts +84 -0
- package/eject/files/overlay.css +40 -0
- package/eject/files/pagination.css +106 -0
- package/eject/files/pagination.ts +68 -0
- package/eject/files/parts.ts +17 -0
- package/eject/files/popover.css +101 -0
- package/eject/files/popover.ts +37 -0
- package/eject/files/progress-bar.ts +26 -0
- package/eject/files/radio-group.css +184 -0
- package/eject/files/radio-group.ts +30 -0
- package/eject/files/section-header.ts +32 -0
- package/eject/files/segmented-control.ts +33 -0
- package/eject/files/select.css +347 -0
- package/eject/files/select.ts +77 -0
- package/eject/files/sidebar.ts +75 -0
- package/eject/files/skeleton.ts +51 -0
- package/eject/files/slider.css +160 -0
- package/eject/files/slider.ts +80 -0
- package/eject/files/spinner.ts +22 -0
- package/eject/files/switch.ts +45 -0
- package/eject/files/table.css +107 -0
- package/eject/files/table.ts +84 -0
- package/eject/files/tabs.css +120 -0
- package/eject/files/tabs.ts +37 -0
- package/eject/files/text-field.css +225 -0
- package/eject/files/text-field.ts +64 -0
- package/eject/files/text.ts +38 -0
- package/eject/files/thumbnail.ts +51 -0
- package/eject/files/time-picker.ts +113 -0
- package/eject/files/toast-queue.ts +64 -0
- package/eject/files/toast.ts +31 -0
- package/eject/files/tooltip.css +111 -0
- package/eject/files/tooltip.ts +21 -0
- package/eject/manifest.json +1053 -0
- package/package.json +12 -4
- package/styles.css +1064 -169
- package/tailwind.css +1295 -218
|
@@ -0,0 +1,269 @@
|
|
|
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
|
+
* Combobox: Zag's combobox machine. A text field whose list of options, narrowed down by what is
|
|
7
|
+
* typed, opens under it with a Menu's surface; the list is rendered into the body.
|
|
8
|
+
*
|
|
9
|
+
* Parts: `.{{prefix}}-combobox` (the column), `__label`, `__control` (the box), `__input`, `__icon`,
|
|
10
|
+
* `__footer`, `__description`, `__error`; in the list, `__positioner`, `__content` (the surface,
|
|
11
|
+
* which scrolls), `__list` (the list box), `__item`, `__item-words`, `__item-label`,
|
|
12
|
+
* `__item-description`, and `__empty`, said when nothing matches.
|
|
13
|
+
* States: `:focus`, `:disabled` and `[aria-invalid="true"]` on the input, which the box follows
|
|
14
|
+
* through `:has()`; `[data-highlighted]` and `:active` on an item; `[data-side]` on the content.
|
|
15
|
+
* The positioner stacks by `--{{prefix}}-layer-overlay` and Zag's `--layer-index`.
|
|
16
|
+
*/
|
|
17
|
+
@layer components {
|
|
18
|
+
.{{prefix}}-combobox {
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
gap: var(--xds-space-1);
|
|
22
|
+
width: 100%;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.{{prefix}}-combobox__label {
|
|
26
|
+
width: fit-content;
|
|
27
|
+
font-size: var(--xds-typography-label-size);
|
|
28
|
+
font-weight: var(--xds-typography-label-weight);
|
|
29
|
+
line-height: var(--xds-typography-label-line-height);
|
|
30
|
+
color: var(--xds-color-text-primary);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.{{prefix}}-combobox:has(.{{prefix}}-combobox__input:disabled) .{{prefix}}-combobox__label {
|
|
34
|
+
opacity: 0.5;
|
|
35
|
+
cursor: not-allowed;
|
|
36
|
+
pointer-events: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* ------------------------------------------------------------ the field */
|
|
40
|
+
|
|
41
|
+
/* A text field's box, with the chevrons at the end that say a list opens from it. */
|
|
42
|
+
.{{prefix}}-combobox__control {
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
gap: var(--xds-space-2);
|
|
46
|
+
min-height: var(--xds-size-control-md);
|
|
47
|
+
padding-inline-end: var(--xds-space-3);
|
|
48
|
+
border: var(--xds-border-width-thin) solid var(--xds-color-field-border);
|
|
49
|
+
border-radius: var(--xds-radius-md);
|
|
50
|
+
background-color: var(--xds-color-field-background);
|
|
51
|
+
color: var(--xds-color-field-text);
|
|
52
|
+
transition-property: background-color, border-color, box-shadow;
|
|
53
|
+
transition-duration: var(--xds-motion-duration-fast);
|
|
54
|
+
transition-timing-function: var(--xds-motion-easing-standard);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.{{prefix}}-combobox__control:has(> .{{prefix}}-combobox__input:focus) {
|
|
58
|
+
border-color: var(--xds-color-field-border-focus);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* Thicker as well as red, so the state does not depend on telling colors apart. Focused, it
|
|
62
|
+
keeps the red border and outline and drops the inner line. */
|
|
63
|
+
.{{prefix}}-combobox__control:has(> .{{prefix}}-combobox__input[aria-invalid="true"]) {
|
|
64
|
+
border-color: var(--xds-color-field-border-invalid);
|
|
65
|
+
box-shadow: inset 0 0 0 var(--xds-border-width-thin) var(--xds-color-field-border-invalid);
|
|
66
|
+
outline: var(--xds-border-width-thin) solid var(--xds-color-danger-default);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.{{prefix}}-combobox__control:has(> .{{prefix}}-combobox__input[aria-invalid="true"]:focus) {
|
|
70
|
+
box-shadow: none;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* After the error, which it outranks. */
|
|
74
|
+
@media (hover: hover) {
|
|
75
|
+
.{{prefix}}-combobox__control:hover:not(:has(:focus)) {
|
|
76
|
+
border-color: var(--xds-color-text-primary);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.{{prefix}}-combobox__control:has(> .{{prefix}}-combobox__input:disabled) {
|
|
81
|
+
opacity: 0.5;
|
|
82
|
+
cursor: not-allowed;
|
|
83
|
+
pointer-events: none;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.{{prefix}}-combobox__input {
|
|
87
|
+
flex: 1 1 0%;
|
|
88
|
+
min-width: 0;
|
|
89
|
+
align-self: stretch;
|
|
90
|
+
padding-block: 0;
|
|
91
|
+
padding-inline: var(--xds-space-3) 0;
|
|
92
|
+
border: none;
|
|
93
|
+
background: transparent;
|
|
94
|
+
color: inherit;
|
|
95
|
+
/* 16px on every screen: below that, iOS zooms the page when the field takes focus. */
|
|
96
|
+
font-size: var(--xds-typography-body-size);
|
|
97
|
+
line-height: var(--xds-typography-body-line-height);
|
|
98
|
+
outline-style: none;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.{{prefix}}-combobox__input::placeholder {
|
|
102
|
+
color: var(--xds-color-field-placeholder);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.{{prefix}}-combobox__icon {
|
|
106
|
+
flex: none;
|
|
107
|
+
color: var(--xds-color-field-placeholder);
|
|
108
|
+
pointer-events: none;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* One line under the box, as under a TextField: the help or the error. Empty, it takes no
|
|
112
|
+
room, and the error stays mounted as a live region. */
|
|
113
|
+
.{{prefix}}-combobox__footer {
|
|
114
|
+
display: flex;
|
|
115
|
+
align-items: baseline;
|
|
116
|
+
gap: var(--xds-space-3);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.{{prefix}}-combobox__footer:not(:has(> :not(:empty))) {
|
|
120
|
+
position: absolute;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.{{prefix}}-combobox__description,
|
|
124
|
+
.{{prefix}}-combobox__error {
|
|
125
|
+
font-size: var(--xds-typography-detail-size);
|
|
126
|
+
line-height: var(--xds-typography-detail-line-height);
|
|
127
|
+
overflow-wrap: break-word;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.{{prefix}}-combobox__description {
|
|
131
|
+
color: var(--xds-color-text-secondary);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.{{prefix}}-combobox__error {
|
|
135
|
+
color: var(--xds-color-status-danger);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.{{prefix}}-combobox__error:empty {
|
|
139
|
+
position: absolute;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* ------------------------------------------------------------ the list */
|
|
143
|
+
|
|
144
|
+
/* Zag sets the position, and the width: the field's. */
|
|
145
|
+
.{{prefix}}-combobox__positioner {
|
|
146
|
+
z-index: calc(var(--{{prefix}}-layer-overlay) + var(--layer-index, 0));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* A menu's surface. It scrolls when the window has no room for all of it. */
|
|
150
|
+
.{{prefix}}-combobox__content {
|
|
151
|
+
max-height: min(var(--available-height), 20rem);
|
|
152
|
+
overflow-y: auto;
|
|
153
|
+
overscroll-behavior: contain;
|
|
154
|
+
scroll-padding-block: var(--xds-space-1);
|
|
155
|
+
scrollbar-width: thin;
|
|
156
|
+
scrollbar-color: color-mix(in oklab, var(--xds-color-text-primary) 15%, transparent)
|
|
157
|
+
transparent;
|
|
158
|
+
padding: var(--xds-space-1);
|
|
159
|
+
border: var(--xds-border-width-thin) solid var(--xds-color-menu-border);
|
|
160
|
+
border-radius: var(--xds-radius-md);
|
|
161
|
+
background: var(--xds-color-menu-background);
|
|
162
|
+
box-shadow: var(--xds-shadow-raised);
|
|
163
|
+
outline: none;
|
|
164
|
+
transform-origin: var(--transform-origin);
|
|
165
|
+
animation: {{prefix}}-combobox-enter var(--xds-motion-duration-fast) var(--xds-motion-easing-enter);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.{{prefix}}-combobox__content[data-side="top"] {
|
|
169
|
+
animation-name: {{prefix}}-combobox-enter-above;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@media (prefers-reduced-motion: reduce) {
|
|
173
|
+
.{{prefix}}-combobox__content {
|
|
174
|
+
animation: none;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.{{prefix}}-combobox__list {
|
|
179
|
+
outline: none;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* A compact list row, at least the smallest pressable size on a touch screen. */
|
|
183
|
+
.{{prefix}}-combobox__item {
|
|
184
|
+
display: flex;
|
|
185
|
+
align-items: center;
|
|
186
|
+
gap: var(--xds-space-2);
|
|
187
|
+
min-height: max(var(--xds-size-list-row-compact), var(--xds-size-target-min));
|
|
188
|
+
padding: var(--xds-space-1) var(--xds-space-2);
|
|
189
|
+
border-radius: var(--xds-radius-sm);
|
|
190
|
+
white-space: nowrap;
|
|
191
|
+
font-size: var(--xds-typography-detail-size);
|
|
192
|
+
font-weight: var(--xds-typography-detail-weight);
|
|
193
|
+
line-height: var(--xds-typography-detail-line-height);
|
|
194
|
+
color: var(--xds-color-menu-text);
|
|
195
|
+
cursor: pointer;
|
|
196
|
+
touch-action: manipulation;
|
|
197
|
+
transition: background-color var(--xds-motion-duration-fast) var(--xds-motion-easing-standard);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* The keys and the pointer move one highlight, which the focus does not: it stays in the
|
|
201
|
+
field, where the person types. */
|
|
202
|
+
.{{prefix}}-combobox__item[data-highlighted] {
|
|
203
|
+
background: var(--xds-color-menu-item-background-hover);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.{{prefix}}-combobox__item:active {
|
|
207
|
+
background: var(--xds-color-menu-item-background-pressed);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.{{prefix}}-combobox__item-words {
|
|
211
|
+
display: flex;
|
|
212
|
+
flex: 1 1 0%;
|
|
213
|
+
flex-direction: column;
|
|
214
|
+
min-width: 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.{{prefix}}-combobox__item-label,
|
|
218
|
+
.{{prefix}}-combobox__item-description {
|
|
219
|
+
overflow: hidden;
|
|
220
|
+
text-overflow: ellipsis;
|
|
221
|
+
white-space: nowrap;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.{{prefix}}-combobox__item-description {
|
|
225
|
+
font-size: var(--xds-typography-footnote-size);
|
|
226
|
+
font-weight: var(--xds-typography-footnote-weight);
|
|
227
|
+
line-height: var(--xds-typography-footnote-line-height);
|
|
228
|
+
color: var(--xds-color-text-secondary);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/* In the place of the rows, as quiet as a row's help line. */
|
|
232
|
+
.{{prefix}}-combobox__empty {
|
|
233
|
+
padding: var(--xds-space-2);
|
|
234
|
+
font-size: var(--xds-typography-detail-size);
|
|
235
|
+
line-height: var(--xds-typography-detail-line-height);
|
|
236
|
+
color: var(--xds-color-text-secondary);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/* Forced colors draw every fill in the page's color, so the highlighted row takes the system's
|
|
240
|
+
highlight, as a Select's does. The browser draws a backplate in the page's color behind text in
|
|
241
|
+
forced colors, which would hide the highlight's text, so these keep their colors, which are the
|
|
242
|
+
system's. */
|
|
243
|
+
@media (forced-colors: active) {
|
|
244
|
+
.{{prefix}}-combobox__item[data-highlighted] {
|
|
245
|
+
forced-color-adjust: none;
|
|
246
|
+
background-color: Highlight;
|
|
247
|
+
color: HighlightText;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.{{prefix}}-combobox__item[data-highlighted] * {
|
|
251
|
+
color: inherit;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/* As a Select's list, from the side of the field it opens on. */
|
|
257
|
+
@keyframes {{prefix}}-combobox-enter {
|
|
258
|
+
from {
|
|
259
|
+
opacity: 0;
|
|
260
|
+
transform: translate3d(0, -0.25rem, 0) scale(0.95);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
@keyframes {{prefix}}-combobox-enter-above {
|
|
265
|
+
from {
|
|
266
|
+
opacity: 0;
|
|
267
|
+
transform: translate3d(0, 0.25rem, 0) scale(0.95);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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 { SelectOption } from "@xds/svelte/base";
|
|
5
|
+
|
|
6
|
+
/** Combobox's props in every framework, short of `onChange`. */
|
|
7
|
+
export type ComboboxBaseProps<Value extends string = string> = {
|
|
8
|
+
/** Always visible, like a TextField's. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** The options to choose from, which what the person types narrows down. */
|
|
11
|
+
options: readonly SelectOption<Value>[];
|
|
12
|
+
/**
|
|
13
|
+
* The chosen option, `undefined` while nothing is chosen. Leave it out for a combobox that
|
|
14
|
+
* keeps its own choice, from `defaultValue`: it is controlled whenever `value` is given, even
|
|
15
|
+
* as `undefined`.
|
|
16
|
+
*/
|
|
17
|
+
value?: Value | undefined;
|
|
18
|
+
/** The first choice of a combobox that keeps its own, without `value`. */
|
|
19
|
+
defaultValue?: Value | undefined;
|
|
20
|
+
/** Shown in the field while it is empty. */
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
/** Help shown under the field. Replaced by `error` while there is one. */
|
|
23
|
+
description?: string;
|
|
24
|
+
/** What is wrong and how to fix it. Clear it when the choice changes. */
|
|
25
|
+
error?: string | undefined;
|
|
26
|
+
/** The name the choice is submitted under with a form. */
|
|
27
|
+
name?: string;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Said in the list when no option matches what was typed, in place of `noMatches` from the
|
|
31
|
+
* closest Labels.
|
|
32
|
+
*/
|
|
33
|
+
emptyLabel?: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const COMBOBOX_PARTS = {
|
|
37
|
+
label: "{{prefix}}-combobox__label",
|
|
38
|
+
control: "{{prefix}}-combobox__control",
|
|
39
|
+
input: "{{prefix}}-combobox__input",
|
|
40
|
+
icon: "{{prefix}}-combobox__icon",
|
|
41
|
+
footer: "{{prefix}}-combobox__footer",
|
|
42
|
+
description: "{{prefix}}-combobox__description",
|
|
43
|
+
error: "{{prefix}}-combobox__error",
|
|
44
|
+
positioner: "{{prefix}}-combobox__positioner",
|
|
45
|
+
content: "{{prefix}}-combobox__content",
|
|
46
|
+
list: "{{prefix}}-combobox__list",
|
|
47
|
+
item: "{{prefix}}-combobox__item",
|
|
48
|
+
itemWords: "{{prefix}}-combobox__item-words",
|
|
49
|
+
itemLabel: "{{prefix}}-combobox__item-label",
|
|
50
|
+
itemDescription: "{{prefix}}-combobox__item-description",
|
|
51
|
+
empty: "{{prefix}}-combobox__empty",
|
|
52
|
+
} as const;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Text as a combobox compares it: in lower case, without accents and with runs of white space
|
|
56
|
+
* as one, so that "sao paulo" finds "São Paulo".
|
|
57
|
+
*/
|
|
58
|
+
export function foldText(text: string): string {
|
|
59
|
+
return text
|
|
60
|
+
.normalize("NFD")
|
|
61
|
+
.replace(/\p{Diacritic}/gu, "")
|
|
62
|
+
.toLocaleLowerCase()
|
|
63
|
+
.replace(/\s+/g, " ")
|
|
64
|
+
.trim();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The options whose label holds what was typed, in their own order, those whose label starts
|
|
69
|
+
* with it first. With nothing typed, every option.
|
|
70
|
+
*/
|
|
71
|
+
export function matchOptions<Option extends { label: string }>(
|
|
72
|
+
options: readonly Option[],
|
|
73
|
+
query: string,
|
|
74
|
+
): Option[] {
|
|
75
|
+
const wanted = foldText(query);
|
|
76
|
+
if (wanted === "") return [...options];
|
|
77
|
+
const starting: Option[] = [];
|
|
78
|
+
const holding: Option[] = [];
|
|
79
|
+
for (const option of options) {
|
|
80
|
+
const label = foldText(option.label);
|
|
81
|
+
if (label.startsWith(wanted)) starting.push(option);
|
|
82
|
+
else if (label.includes(wanted)) holding.push(option);
|
|
83
|
+
}
|
|
84
|
+
return [...starting, ...holding];
|
|
85
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
/** CountBadge's props in every framework, short of the child it sits on. */
|
|
5
|
+
export type CountBadgeBaseProps = {
|
|
6
|
+
/** Zero or less draws no badge. */
|
|
7
|
+
count: number;
|
|
8
|
+
/** The largest number shown. A larger count reads "99+". */
|
|
9
|
+
max?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Says what is counted, such as "3 unread notifications". Without it assistive technology
|
|
12
|
+
* reads the number alone.
|
|
13
|
+
*/
|
|
14
|
+
label?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** The badge, laid out inline or, with `onChild`, on the top end corner of a child. */
|
|
18
|
+
export function countBadgeClass(onChild: boolean): string {
|
|
19
|
+
// Pushed out from the corner by a quarter of its own height, so it overlaps the corner
|
|
20
|
+
// instead of covering the child. `end` follows the layout direction.
|
|
21
|
+
return onChild
|
|
22
|
+
? "absolute end-[calc(var(--xds-size-count-badge)/-4)] top-[calc(var(--xds-size-count-badge)/-4)] inline-flex h-xds-count-badge min-w-xds-count-badge shrink-0 select-none items-center justify-center whitespace-nowrap rounded-full bg-xds-badge-count-background px-1 text-xds-badge-count-text text-xds-footnote"
|
|
23
|
+
: "inline-flex h-xds-count-badge min-w-xds-count-badge shrink-0 select-none items-center justify-center whitespace-nowrap rounded-full bg-xds-badge-count-background px-1 text-xds-badge-count-text text-xds-footnote";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The box around a child that a badge sits on. */
|
|
27
|
+
export const countBadgeAnchorClass = "relative inline-flex w-fit shrink-0";
|
|
28
|
+
|
|
29
|
+
/** What the badge reads: the count, or "99+" past `max`. */
|
|
30
|
+
export function countBadgeText(count: number, max = 99): string {
|
|
31
|
+
return count > max ? `${max}+` : String(count);
|
|
32
|
+
}
|