@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.
- .diffend-unextracted-0 +2 -1
- package/dist/Accordion.svelte +7 -2
- package/dist/Avatar.svelte +10 -2
- package/dist/AvatarStack.svelte +11 -1
- package/dist/Badge.svelte +14 -3
- package/dist/Banner.svelte +6 -1
- package/dist/Breadcrumb.svelte +53 -0
- package/dist/Breadcrumb.svelte.d.ts +11 -0
- package/dist/Button.svelte +30 -2
- package/dist/Button.svelte.d.ts +10 -1
- package/dist/Card.svelte +16 -2
- package/dist/Checkbox.svelte +62 -10
- package/dist/Checkbox.svelte.d.ts +14 -3
- package/dist/Chip.svelte +3 -1
- package/dist/ChipBar.svelte +3 -2
- package/dist/Combobox.svelte +194 -0
- package/dist/Combobox.svelte.d.ts +37 -0
- package/dist/CountBadge.svelte +4 -2
- package/dist/DatePicker.svelte +16 -5
- package/dist/DateRangePicker.svelte +6 -1
- package/dist/Dialog.svelte +9 -2
- package/dist/Divider.svelte +7 -3
- package/dist/EmptyState.svelte +15 -3
- package/dist/Icon.svelte +11 -2
- package/dist/IconButton.svelte +30 -2
- package/dist/IconButton.svelte.d.ts +10 -1
- package/dist/Labels.svelte +29 -0
- package/dist/Labels.svelte.d.ts +17 -0
- package/dist/Link.svelte +86 -0
- package/dist/Link.svelte.d.ts +26 -0
- package/dist/MediaCard.svelte +4 -1
- package/dist/Menu.svelte +21 -2
- package/dist/Pagination.svelte +108 -0
- package/dist/Pagination.svelte.d.ts +14 -0
- package/dist/PlaceRow.svelte +6 -1
- 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/ProgressBar.svelte +3 -1
- package/dist/RadioGroup.svelte +23 -8
- package/dist/RadioGroup.svelte.d.ts +4 -2
- package/dist/SearchField.svelte +65 -18
- package/dist/SearchField.svelte.d.ts +14 -4
- package/dist/SectionHeader.svelte +7 -2
- package/dist/SegmentedControl.svelte +21 -7
- package/dist/SegmentedControl.svelte.d.ts +3 -2
- package/dist/Select.svelte +64 -12
- package/dist/Select.svelte.d.ts +9 -2
- package/dist/Sidebar.svelte +3 -0
- package/dist/Skeleton.svelte +10 -2
- package/dist/Slider.svelte +23 -7
- package/dist/Slider.svelte.d.ts +2 -2
- package/dist/Spinner.svelte +3 -2
- package/dist/Switch.svelte +53 -9
- package/dist/Switch.svelte.d.ts +13 -3
- package/dist/Table.svelte +92 -0
- package/dist/Table.svelte.d.ts +17 -0
- package/dist/Tabs.svelte +21 -6
- package/dist/Tabs.svelte.d.ts +2 -1
- package/dist/Text.svelte +3 -1
- package/dist/TextField.svelte +59 -14
- package/dist/TextField.svelte.d.ts +13 -3
- package/dist/Thumbnail.svelte +7 -1
- package/dist/TimePicker.svelte +222 -0
- package/dist/TimePicker.svelte.d.ts +20 -0
- package/dist/Toast.svelte +12 -2
- package/dist/ToastQueue.svelte +57 -0
- package/dist/ToastQueue.svelte.d.ts +20 -0
- package/dist/Tooltip.svelte +9 -2
- package/dist/TooltipOverlay.svelte +9 -2
- package/dist/base.d.ts +14 -0
- package/dist/base.js +27 -0
- package/dist/controllable.svelte.d.ts +28 -0
- package/dist/controllable.svelte.js +41 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +12 -0
- package/dist/labels.svelte.d.ts +13 -0
- package/dist/labels.svelte.js +24 -0
- package/dist/modal-popover.svelte.js +5 -1
- package/dist/presence.svelte.js +5 -2
- package/dist/preview/Component.svelte +8 -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 -1
- package/dist/preview/index.d.ts +1 -0
- package/dist/root.d.ts +4 -2
- 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,276 @@
|
|
|
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
|
+
@component
|
|
7
|
+
A field for choosing one option from a list too long to show at once. Closed, it looks like a
|
|
8
|
+
TextField; pressed, it opens the list under itself with a Menu's surface, as wide as the field.
|
|
9
|
+
Choosing an option calls `onChange` and closes the list; a press outside or Escape closes it
|
|
10
|
+
too.
|
|
11
|
+
|
|
12
|
+
The field is a button that says it opens a list box and whether the list is open. In the list
|
|
13
|
+
the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
|
|
14
|
+
selected for assistive technology and marked with a check. Without `value` it keeps its own
|
|
15
|
+
choice, from `defaultValue`.
|
|
16
|
+
|
|
17
|
+
With `multiple`, any number of options can be chosen: choosing one adds it or takes it away, the
|
|
18
|
+
list stays open, and `onValuesChange` gets them all. The list box says that several can be
|
|
19
|
+
chosen.
|
|
20
|
+
-->
|
|
21
|
+
<script module lang="ts">
|
|
22
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
23
|
+
import type { SelectBaseProps } from "./select.ts";
|
|
24
|
+
|
|
25
|
+
export type { SelectOption } from "./select.ts";
|
|
26
|
+
|
|
27
|
+
export type SelectProps<Value extends string = string> = SelectBaseProps<Value> &
|
|
28
|
+
RootProps & {
|
|
29
|
+
onChange?: (value: Value) => void;
|
|
30
|
+
/** Called with the chosen options of a select with `multiple`, in the options' order. */
|
|
31
|
+
onValuesChange?: (values: Value[]) => void;
|
|
32
|
+
};
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<script lang="ts" generics="Value extends string = string">
|
|
36
|
+
import {
|
|
37
|
+
controllable,
|
|
38
|
+
createItemPropsCache,
|
|
39
|
+
createPresence,
|
|
40
|
+
keepListKeys,
|
|
41
|
+
modalPopover,
|
|
42
|
+
Portal,
|
|
43
|
+
readCssPx,
|
|
44
|
+
rootAttributes,
|
|
45
|
+
space,
|
|
46
|
+
underlayLayerStyle,
|
|
47
|
+
} from "@xds/svelte/base";
|
|
48
|
+
import * as select from "@zag-js/select";
|
|
49
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
50
|
+
import type { HTMLAttributes, HTMLLabelAttributes } from "svelte/elements";
|
|
51
|
+
import Icon from "./Icon.svelte";
|
|
52
|
+
import { classes } from "./parts.ts";
|
|
53
|
+
import { orderedValues, type SelectOption, selectedLabels, selectOptionIds } from "./select.ts";
|
|
54
|
+
|
|
55
|
+
type KeyHandler = (event: KeyboardEvent) => void;
|
|
56
|
+
|
|
57
|
+
// `value` and `values` stay in the rest, where whether they are given at all can be asked.
|
|
58
|
+
let {
|
|
59
|
+
label,
|
|
60
|
+
options,
|
|
61
|
+
defaultValue,
|
|
62
|
+
placeholder,
|
|
63
|
+
description,
|
|
64
|
+
error,
|
|
65
|
+
name,
|
|
66
|
+
disabled,
|
|
67
|
+
onChange,
|
|
68
|
+
multiple = false,
|
|
69
|
+
defaultValues,
|
|
70
|
+
onValuesChange,
|
|
71
|
+
class: className,
|
|
72
|
+
style,
|
|
73
|
+
...rest
|
|
74
|
+
}: SelectProps<Value> = $props();
|
|
75
|
+
|
|
76
|
+
const control = controllable<Value | undefined, Value>(
|
|
77
|
+
() => rest,
|
|
78
|
+
"value",
|
|
79
|
+
() => rest.value,
|
|
80
|
+
() => defaultValue,
|
|
81
|
+
() => onChange,
|
|
82
|
+
);
|
|
83
|
+
const value = $derived(control.current);
|
|
84
|
+
const valuesControl = controllable<readonly Value[], Value[]>(
|
|
85
|
+
() => rest,
|
|
86
|
+
"values",
|
|
87
|
+
() => rest.values ?? [],
|
|
88
|
+
() => defaultValues ?? [],
|
|
89
|
+
() => onValuesChange,
|
|
90
|
+
);
|
|
91
|
+
const values = $derived(valuesControl.current);
|
|
92
|
+
|
|
93
|
+
const id = $props.id();
|
|
94
|
+
const valueId = `${id}-value`;
|
|
95
|
+
const descriptionId = `${id}-description`;
|
|
96
|
+
const errorId = `${id}-error`;
|
|
97
|
+
const invalid = $derived(error !== undefined);
|
|
98
|
+
const collection = $derived(
|
|
99
|
+
select.collection<SelectOption<Value>>({
|
|
100
|
+
items: [...options],
|
|
101
|
+
itemToValue: (option) => option.value,
|
|
102
|
+
itemToString: (option) => option.label,
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
const service = useMachine(select.machine, () => ({
|
|
106
|
+
id,
|
|
107
|
+
collection,
|
|
108
|
+
value: multiple ? [...values] : value === undefined ? [] : [value],
|
|
109
|
+
onValueChange: (details: select.ValueChangeDetails<SelectOption<Value>>) => {
|
|
110
|
+
if (multiple) {
|
|
111
|
+
valuesControl.set(orderedValues(options, details.value as Value[]));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const next = details.value[0];
|
|
115
|
+
if (next !== undefined) control.set(next as Value);
|
|
116
|
+
},
|
|
117
|
+
multiple,
|
|
118
|
+
// Several are chosen one after another, so the list stays until the person closes it.
|
|
119
|
+
closeOnSelect: !multiple,
|
|
120
|
+
disabled,
|
|
121
|
+
invalid,
|
|
122
|
+
name,
|
|
123
|
+
positioning: {
|
|
124
|
+
placement: "bottom-start" as const,
|
|
125
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
126
|
+
sameWidth: true,
|
|
127
|
+
// The list keeps this far from the window's edges.
|
|
128
|
+
overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
|
|
129
|
+
},
|
|
130
|
+
}));
|
|
131
|
+
const api = $derived(select.connect(service, normalizeProps));
|
|
132
|
+
// The rows' props as they last were while they draw the same, so that a step of the highlight
|
|
133
|
+
// sets the attributes and the handlers of the two rows it moves between, not of every row.
|
|
134
|
+
const keep = createItemPropsCache();
|
|
135
|
+
// Zag's key handlers read whether a search by typing is under way when the field renders, and
|
|
136
|
+
// a search ends on a timer, which renders nothing: long after a search, Space would still
|
|
137
|
+
// search for a space instead of opening the list or choosing. A handler taken from the
|
|
138
|
+
// machine when the key comes reads it then.
|
|
139
|
+
const current = () => select.connect(service, normalizeProps);
|
|
140
|
+
// A span: the field is a button, which a <label> cannot point at. A press on it still focuses
|
|
141
|
+
// the field.
|
|
142
|
+
const labelProps = $derived.by(() => {
|
|
143
|
+
const { for: _, ...rest } = api.getLabelProps() as HTMLLabelAttributes;
|
|
144
|
+
return rest as HTMLAttributes<HTMLSpanElement>;
|
|
145
|
+
});
|
|
146
|
+
// A button that opens a list box, rather than Zag's combobox: named by the chosen option and
|
|
147
|
+
// then the label, and described by the help or the error. The error is said there, so the
|
|
148
|
+
// button itself does not claim to be invalid or required.
|
|
149
|
+
const triggerProps = $derived.by(() => {
|
|
150
|
+
const {
|
|
151
|
+
role: _role,
|
|
152
|
+
"aria-invalid": _invalid,
|
|
153
|
+
"aria-required": _required,
|
|
154
|
+
onkeydown: _onKeyDown,
|
|
155
|
+
...rest
|
|
156
|
+
} = api.getTriggerProps();
|
|
157
|
+
return {
|
|
158
|
+
...rest,
|
|
159
|
+
// Home and End leave a closed field to the page; Zag would choose the first or the last
|
|
160
|
+
// option.
|
|
161
|
+
onkeydown: (event: KeyboardEvent) => {
|
|
162
|
+
if (!api.open && (event.key === "Home" || event.key === "End")) return;
|
|
163
|
+
(current().getTriggerProps().onkeydown as KeyHandler | undefined)?.(event);
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
let positioner = $state<HTMLDivElement>();
|
|
168
|
+
let surface = $state<HTMLDivElement>();
|
|
169
|
+
modalPopover(
|
|
170
|
+
() => api.open,
|
|
171
|
+
() => positioner,
|
|
172
|
+
);
|
|
173
|
+
const present = createPresence(
|
|
174
|
+
() => api.open,
|
|
175
|
+
() => [surface],
|
|
176
|
+
);
|
|
177
|
+
const content = $derived.by(() => {
|
|
178
|
+
const { onkeydown: _onKeyDown, ...rest } = api.getContentProps();
|
|
179
|
+
return mergeProps(rest, {
|
|
180
|
+
onkeydown: (event: KeyboardEvent) => {
|
|
181
|
+
keepListKeys(event, surface, ".{{prefix}}-select__item:not([data-disabled])", (value) =>
|
|
182
|
+
api.setHighlightedValue(value),
|
|
183
|
+
);
|
|
184
|
+
(current().getContentProps().onkeydown as KeyHandler | undefined)?.(event);
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
</script>
|
|
189
|
+
|
|
190
|
+
<!-- Merged, so that the app's style joins any the machine writes on the root. -->
|
|
191
|
+
<div
|
|
192
|
+
{...mergeProps(api.getRootProps(), {
|
|
193
|
+
...rootAttributes(rest),
|
|
194
|
+
class: classes("{{prefix}}-select", className),
|
|
195
|
+
style,
|
|
196
|
+
})}
|
|
197
|
+
>
|
|
198
|
+
<span {...labelProps} class="{{prefix}}-select__label">{label}</span>
|
|
199
|
+
<button
|
|
200
|
+
{...triggerProps}
|
|
201
|
+
aria-labelledby={`${valueId} ${labelProps.id}`}
|
|
202
|
+
aria-describedby={invalid ? errorId : description ? descriptionId : undefined}
|
|
203
|
+
class="{{prefix}}-select__trigger"
|
|
204
|
+
>
|
|
205
|
+
<!-- The chosen option's label alone: the list's rows also hold a description and a check,
|
|
206
|
+
which do not belong in the field. -->
|
|
207
|
+
<span {...api.getValueTextProps()} id={valueId} class="{{prefix}}-select__value"
|
|
208
|
+
>{(multiple ? selectedLabels(options, values) : api.valueAsString) || placeholder}</span
|
|
209
|
+
>
|
|
210
|
+
<Icon name="chevrons-up-down" size="sm" class="text-xds-field-placeholder" />
|
|
211
|
+
</button>
|
|
212
|
+
<!-- One line under the box: the help, or the error in its place. The error stays mounted as
|
|
213
|
+
a live region so assistive technology announces it when it appears. -->
|
|
214
|
+
<div class="{{prefix}}-select__footer">
|
|
215
|
+
{#if !invalid && description}
|
|
216
|
+
<span id={descriptionId} class="{{prefix}}-select__description">{description}</span>
|
|
217
|
+
{/if}
|
|
218
|
+
<span id={errorId} class="{{prefix}}-select__error" aria-live="polite">{error}</span>
|
|
219
|
+
</div>
|
|
220
|
+
<!-- What a form submits; in a select of one, the first option stands for no choice. Zag's props
|
|
221
|
+
hide the select from assistive technology, which uses the trigger. -->
|
|
222
|
+
<select {...api.getHiddenSelectProps()}>
|
|
223
|
+
{#if !multiple}
|
|
224
|
+
<option value=""></option>
|
|
225
|
+
{/if}
|
|
226
|
+
{#each options as option (option.value)}
|
|
227
|
+
<option value={option.value}>{option.label}</option>
|
|
228
|
+
{/each}
|
|
229
|
+
</select>
|
|
230
|
+
<Portal>
|
|
231
|
+
{#if api.open}
|
|
232
|
+
<!-- Takes a press outside, which then only closes the list. The focus stays in the list
|
|
233
|
+
until the list hands it back to the field. -->
|
|
234
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
235
|
+
<div
|
|
236
|
+
class="{{prefix}}-select__underlay"
|
|
237
|
+
style:--layer-index={underlayLayerStyle(api.getPositionerProps().style)?.["--layer-index"]}
|
|
238
|
+
onmousedown={(event) => event.preventDefault()}
|
|
239
|
+
></div>
|
|
240
|
+
{/if}
|
|
241
|
+
<div {...api.getPositionerProps()} bind:this={positioner} class="{{prefix}}-select__positioner">
|
|
242
|
+
<!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
|
|
243
|
+
<div {...content} bind:this={surface} hidden={!present()} class="{{prefix}}-select__content">
|
|
244
|
+
<div {...api.getListProps()} class="{{prefix}}-select__list">
|
|
245
|
+
{#each collection.items as option, index (option.value)}
|
|
246
|
+
{@const ids = selectOptionIds(id, index)}
|
|
247
|
+
<!-- Named by its label alone, as the field shows it; the help line describes it. -->
|
|
248
|
+
<div
|
|
249
|
+
{...keep(`item:${option.value}`, api.getItemProps({ item: option }))}
|
|
250
|
+
aria-labelledby={ids.label}
|
|
251
|
+
aria-describedby={option.description ? ids.description : undefined}
|
|
252
|
+
class="{{prefix}}-select__item"
|
|
253
|
+
>
|
|
254
|
+
<span class="{{prefix}}-select__item-words">
|
|
255
|
+
<span
|
|
256
|
+
{...keep(`text:${option.value}`, api.getItemTextProps({ item: option }))}
|
|
257
|
+
id={ids.label}
|
|
258
|
+
class="{{prefix}}-select__item-label">{option.label}</span
|
|
259
|
+
>
|
|
260
|
+
{#if option.description}
|
|
261
|
+
<span id={ids.description} class="{{prefix}}-select__item-description"
|
|
262
|
+
>{option.description}</span
|
|
263
|
+
>
|
|
264
|
+
{/if}
|
|
265
|
+
</span>
|
|
266
|
+
<!-- Unnamed, unlike a Menu's: the option itself reports that it is selected. -->
|
|
267
|
+
{#if api.getItemState({ item: option }).selected}
|
|
268
|
+
<Icon name="check" size="sm" />
|
|
269
|
+
{/if}
|
|
270
|
+
</div>
|
|
271
|
+
{/each}
|
|
272
|
+
</div>
|
|
273
|
+
</div>
|
|
274
|
+
</div>
|
|
275
|
+
</Portal>
|
|
276
|
+
</div>
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
@component
|
|
7
|
+
The top-level places of an app used with a pointer: the counterpart of TabBar on touch. Each row
|
|
8
|
+
is a compact list row; the current one is selected, its title heavier and its icon filled, so
|
|
9
|
+
the place does not depend on the tint alone.
|
|
10
|
+
|
|
11
|
+
It is navigation named by `label`, and the current row says it is the current page. Collapsed,
|
|
12
|
+
the rows keep their names, and show them in a Tooltip under a pointer and on keyboard focus.
|
|
13
|
+
-->
|
|
14
|
+
<script module lang="ts">
|
|
15
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
16
|
+
import type { Snippet } from "svelte";
|
|
17
|
+
import type { SidebarBaseProps } from "./sidebar.ts";
|
|
18
|
+
|
|
19
|
+
export type { SidebarItem, SidebarSection } from "./sidebar.ts";
|
|
20
|
+
|
|
21
|
+
export type SidebarProps<Value extends string = string> = SidebarBaseProps<Value> &
|
|
22
|
+
RootProps & {
|
|
23
|
+
onChange: (value: Value) => void;
|
|
24
|
+
/** At the top, such as the app's name. It has to fit the rail itself while collapsed. */
|
|
25
|
+
header?: Snippet;
|
|
26
|
+
/** At the bottom, such as an account row. It has to fit the rail itself while collapsed. */
|
|
27
|
+
footer?: Snippet;
|
|
28
|
+
};
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<script lang="ts" generics="Value extends string = string">
|
|
32
|
+
import { rootAttributes, tooltipEndSide } from "@xds/svelte/base";
|
|
33
|
+
import Icon from "./Icon.svelte";
|
|
34
|
+
import { classes, rootPart } from "./parts.ts";
|
|
35
|
+
import PlaceRow from "./PlaceRow.svelte";
|
|
36
|
+
import {
|
|
37
|
+
SIDEBAR_PARTS,
|
|
38
|
+
sidebarClass,
|
|
39
|
+
sidebarCount,
|
|
40
|
+
sidebarIconClass,
|
|
41
|
+
sidebarSectionClass,
|
|
42
|
+
sidebarTitleClass,
|
|
43
|
+
} from "./sidebar.ts";
|
|
44
|
+
import SidebarRailButton from "./SidebarRailButton.svelte";
|
|
45
|
+
import TooltipOverlay from "./TooltipOverlay.svelte";
|
|
46
|
+
|
|
47
|
+
let {
|
|
48
|
+
sections,
|
|
49
|
+
value,
|
|
50
|
+
label,
|
|
51
|
+
collapsed = false,
|
|
52
|
+
onChange,
|
|
53
|
+
header,
|
|
54
|
+
footer,
|
|
55
|
+
class: className,
|
|
56
|
+
style,
|
|
57
|
+
...rest
|
|
58
|
+
}: SidebarProps<Value> = $props();
|
|
59
|
+
|
|
60
|
+
const id = $props.id();
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<nav
|
|
64
|
+
{...rootAttributes(rest)}
|
|
65
|
+
aria-label={label}
|
|
66
|
+
class={classes(rootPart("Sidebar"), sidebarClass(collapsed), className)}
|
|
67
|
+
{style}
|
|
68
|
+
>
|
|
69
|
+
{#if header}
|
|
70
|
+
<div class={SIDEBAR_PARTS.edge}>{@render header()}</div>
|
|
71
|
+
{/if}
|
|
72
|
+
<!-- The places scroll when there are more than fit; the header and footer stay. -->
|
|
73
|
+
<div class={SIDEBAR_PARTS.places}>
|
|
74
|
+
{#each sections as section, index (index)}
|
|
75
|
+
<!-- A section has nothing but its position to tell it apart: titles are optional. -->
|
|
76
|
+
{@const title = `${id}-${index}`}
|
|
77
|
+
<div class={sidebarSectionClass(index, collapsed)}>
|
|
78
|
+
{#if section.title}
|
|
79
|
+
<p id={title} class={sidebarTitleClass(collapsed)}>{section.title}</p>
|
|
80
|
+
{/if}
|
|
81
|
+
{#if collapsed && index > 0}
|
|
82
|
+
<div aria-hidden="true" class={SIDEBAR_PARTS.rule}></div>
|
|
83
|
+
{/if}
|
|
84
|
+
<ul aria-labelledby={section.title ? title : undefined} class={SIDEBAR_PARTS.list}>
|
|
85
|
+
{#each section.items as item (item.value)}
|
|
86
|
+
{@const selected = item.value === value}
|
|
87
|
+
<li class={SIDEBAR_PARTS.item}>
|
|
88
|
+
{#if collapsed}
|
|
89
|
+
<TooltipOverlay label={item.label} placement={tooltipEndSide}>
|
|
90
|
+
<SidebarRailButton
|
|
91
|
+
label={item.label}
|
|
92
|
+
icon={item.icon}
|
|
93
|
+
{selected}
|
|
94
|
+
onPress={() => onChange(item.value)}
|
|
95
|
+
/>
|
|
96
|
+
</TooltipOverlay>
|
|
97
|
+
{:else}
|
|
98
|
+
{@const count = sidebarCount(item.count)}
|
|
99
|
+
<PlaceRow
|
|
100
|
+
compact
|
|
101
|
+
current="page"
|
|
102
|
+
{selected}
|
|
103
|
+
onPress={() => onChange(item.value)}
|
|
104
|
+
title={item.label}
|
|
105
|
+
>
|
|
106
|
+
{#snippet leading()}
|
|
107
|
+
<Icon
|
|
108
|
+
name={item.icon}
|
|
109
|
+
size="md"
|
|
110
|
+
filled={selected}
|
|
111
|
+
class={sidebarIconClass(selected)}
|
|
112
|
+
/>
|
|
113
|
+
{/snippet}
|
|
114
|
+
{#snippet trailing()}
|
|
115
|
+
{#if count}
|
|
116
|
+
<span class={SIDEBAR_PARTS.count}>{count}</span>
|
|
117
|
+
{/if}
|
|
118
|
+
{/snippet}
|
|
119
|
+
</PlaceRow>
|
|
120
|
+
{/if}
|
|
121
|
+
</li>
|
|
122
|
+
{/each}
|
|
123
|
+
</ul>
|
|
124
|
+
</div>
|
|
125
|
+
{/each}
|
|
126
|
+
</div>
|
|
127
|
+
{#if footer}
|
|
128
|
+
<div class={SIDEBAR_PARTS.edge}>{@render footer()}</div>
|
|
129
|
+
{/if}
|
|
130
|
+
</nav>
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
@component
|
|
7
|
+
A row of a collapsed Sidebar. It is the trigger of the Tooltip that names it. Only for Sidebar:
|
|
8
|
+
the index does not export it.
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import { type IconName, withTrigger } from "@xds/svelte/base";
|
|
12
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
13
|
+
import Icon from "./Icon.svelte";
|
|
14
|
+
import { sidebarRailButtonClass } from "./sidebar.ts";
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
label,
|
|
18
|
+
icon,
|
|
19
|
+
selected,
|
|
20
|
+
onPress,
|
|
21
|
+
}: { label: string; icon: IconName; selected: boolean; onPress: () => void } = $props();
|
|
22
|
+
|
|
23
|
+
const attributes = withTrigger((): HTMLButtonAttributes => ({
|
|
24
|
+
type: "button",
|
|
25
|
+
class: sidebarRailButtonClass(selected),
|
|
26
|
+
"aria-label": label,
|
|
27
|
+
"aria-current": selected ? "page" : undefined,
|
|
28
|
+
onclick: () => onPress(),
|
|
29
|
+
}));
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<button {...attributes()}><Icon name={icon} size="md" filled={selected} /></button>
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
@component
|
|
7
|
+
Holds the place of content that is loading, in the shape the content will have. It pulses, and
|
|
8
|
+
stands still for people who ask for less motion.
|
|
9
|
+
|
|
10
|
+
It is hidden from assistive technology: the screen that shows skeletons says that it is
|
|
11
|
+
loading, once, instead of every placeholder saying so.
|
|
12
|
+
-->
|
|
13
|
+
<script module lang="ts">
|
|
14
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
15
|
+
import type { SkeletonBaseProps } from "./skeleton.ts";
|
|
16
|
+
|
|
17
|
+
export type SkeletonProps = SkeletonBaseProps & RootProps;
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import { rootAttributes, useDefaults } from "@xds/svelte/base";
|
|
22
|
+
import { classes, rootPart } from "./parts.ts";
|
|
23
|
+
import { skeletonClass, skeletonSize } from "./skeleton.ts";
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
shape: ownShape,
|
|
27
|
+
width,
|
|
28
|
+
height,
|
|
29
|
+
class: className,
|
|
30
|
+
style,
|
|
31
|
+
...rest
|
|
32
|
+
}: SkeletonProps = $props();
|
|
33
|
+
|
|
34
|
+
const defaults = useDefaults("Skeleton");
|
|
35
|
+
const shape = $derived(ownShape ?? defaults().shape);
|
|
36
|
+
|
|
37
|
+
const box = $derived(skeletonSize({ shape, width, height }));
|
|
38
|
+
// The app's `style` comes after the computed box dimensions so it wins when overriding width/height.
|
|
39
|
+
const combinedStyle = $derived(
|
|
40
|
+
[
|
|
41
|
+
box.width !== undefined ? `width:${box.width}` : "",
|
|
42
|
+
box.height !== undefined ? `height:${box.height}` : "",
|
|
43
|
+
style ?? "",
|
|
44
|
+
]
|
|
45
|
+
.filter(Boolean)
|
|
46
|
+
.join(";"),
|
|
47
|
+
);
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<span
|
|
51
|
+
{...rootAttributes(rest)}
|
|
52
|
+
aria-hidden="true"
|
|
53
|
+
class={classes(rootPart("Skeleton"), skeletonClass(shape), className)}
|
|
54
|
+
style={combinedStyle || undefined}
|
|
55
|
+
></span>
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
@component
|
|
7
|
+
Picks a number in a range by dragging the thumb, or by pressing the track where it should go.
|
|
8
|
+
The values snap to `step`.
|
|
9
|
+
|
|
10
|
+
It is a slider named by its label with its value, minimum and maximum, and each arrow key moves
|
|
11
|
+
it one step. Without `value` it keeps its own, from `defaultValue` or else `min`.
|
|
12
|
+
-->
|
|
13
|
+
<script module lang="ts">
|
|
14
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
15
|
+
import type { SliderBaseProps } from "./slider.ts";
|
|
16
|
+
|
|
17
|
+
export type SliderProps = SliderBaseProps &
|
|
18
|
+
RootProps & {
|
|
19
|
+
onChange?: (value: number) => void;
|
|
20
|
+
};
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<script lang="ts">
|
|
24
|
+
import { controllable, rootAttributes } from "@xds/svelte/base";
|
|
25
|
+
import * as slider from "@zag-js/slider";
|
|
26
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
27
|
+
import { classes } from "./parts.ts";
|
|
28
|
+
import {
|
|
29
|
+
focusThumbOnPress,
|
|
30
|
+
sliderArrowValue,
|
|
31
|
+
sliderPageSize,
|
|
32
|
+
sliderValueText,
|
|
33
|
+
} from "./slider.ts";
|
|
34
|
+
|
|
35
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
36
|
+
let {
|
|
37
|
+
label,
|
|
38
|
+
defaultValue,
|
|
39
|
+
min = 0,
|
|
40
|
+
max = 100,
|
|
41
|
+
step = 1,
|
|
42
|
+
disabled,
|
|
43
|
+
showValue,
|
|
44
|
+
name,
|
|
45
|
+
locale,
|
|
46
|
+
onChange,
|
|
47
|
+
class: className,
|
|
48
|
+
style,
|
|
49
|
+
...rest
|
|
50
|
+
}: SliderProps = $props();
|
|
51
|
+
|
|
52
|
+
const position = controllable(
|
|
53
|
+
() => rest,
|
|
54
|
+
"value",
|
|
55
|
+
() => rest.value ?? min,
|
|
56
|
+
() => defaultValue ?? min,
|
|
57
|
+
() => onChange,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const id = $props.id();
|
|
61
|
+
const pageSize = $derived(sliderPageSize({ min, max, step }));
|
|
62
|
+
const service = useMachine(slider.machine, () => ({
|
|
63
|
+
id,
|
|
64
|
+
name,
|
|
65
|
+
value: [position.current],
|
|
66
|
+
// One thumb, so one number.
|
|
67
|
+
onValueChange: (details: slider.ValueChangeDetails) => position.set(details.value[0] ?? min),
|
|
68
|
+
min,
|
|
69
|
+
max,
|
|
70
|
+
step,
|
|
71
|
+
largeStep: pageSize,
|
|
72
|
+
disabled,
|
|
73
|
+
// The thumb's center is on the value, at the ends too; the band is inset to make room.
|
|
74
|
+
thumbAlignment: "center" as const,
|
|
75
|
+
getAriaValueText: (details: { value: number }) => sliderValueText(details.value, locale),
|
|
76
|
+
}));
|
|
77
|
+
const api = $derived(slider.connect(service, normalizeProps));
|
|
78
|
+
let thumbElement = $state<HTMLDivElement>();
|
|
79
|
+
const thumb = $derived(
|
|
80
|
+
mergeProps(api.getThumbProps({ index: 0 }), {
|
|
81
|
+
// Up and Down move a horizontal slider too, as they move a native range input.
|
|
82
|
+
onkeydown: (event: KeyboardEvent) => {
|
|
83
|
+
if (disabled) return;
|
|
84
|
+
const next = sliderArrowValue(event, {
|
|
85
|
+
value: api.value[0] ?? min,
|
|
86
|
+
min,
|
|
87
|
+
max,
|
|
88
|
+
step,
|
|
89
|
+
pageSize,
|
|
90
|
+
});
|
|
91
|
+
if (next !== undefined) {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
api.setThumbValue(0, next);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
const control = $derived(
|
|
99
|
+
mergeProps(api.getControlProps(), {
|
|
100
|
+
// No focus ring after a press. This handler runs before Zag's.
|
|
101
|
+
onpointerdown: (event: PointerEvent) => {
|
|
102
|
+
if (!disabled) focusThumbOnPress(event, thumbElement);
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
</script>
|
|
107
|
+
|
|
108
|
+
<!-- A group named by the label, around the label, the value and the slider. Not a fieldset:
|
|
109
|
+
that is for a set of fields, and this is one slider and its label. The app's style is merged
|
|
110
|
+
with the one the machine writes on the root. -->
|
|
111
|
+
<div
|
|
112
|
+
{...mergeProps(api.getRootProps(), {
|
|
113
|
+
...rootAttributes(rest),
|
|
114
|
+
class: classes("{{prefix}}-slider", className),
|
|
115
|
+
style,
|
|
116
|
+
})}
|
|
117
|
+
role="group"
|
|
118
|
+
aria-labelledby={api.getLabelProps().id}
|
|
119
|
+
>
|
|
120
|
+
<!-- Zag's props give it `for`, the hidden input's id. -->
|
|
121
|
+
<label {...api.getLabelProps()} class="{{prefix}}-slider__label">{label}</label>
|
|
122
|
+
{#if showValue}
|
|
123
|
+
<!-- Read when asked for, not at every step: the slider itself announces its value. -->
|
|
124
|
+
<output {...api.getValueTextProps()} aria-live="off" class="{{prefix}}-slider__output"
|
|
125
|
+
>{sliderValueText(api.value[0] ?? position.current, locale)}</output
|
|
126
|
+
>
|
|
127
|
+
{/if}
|
|
128
|
+
<div {...control} class="{{prefix}}-slider__control">
|
|
129
|
+
<div {...api.getTrackProps()} class="{{prefix}}-slider__track">
|
|
130
|
+
<div {...api.getRangeProps()} class="{{prefix}}-slider__range"></div>
|
|
131
|
+
</div>
|
|
132
|
+
<div {...thumb} bind:this={thumbElement} class="{{prefix}}-slider__thumb">
|
|
133
|
+
<input {...api.getHiddenInputProps({ index: 0 })} />
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
@component
|
|
7
|
+
Says that something is in progress and how long is unknown. Takes the color of the text around
|
|
8
|
+
it. With `label` it is announced; without one it is decoration next to text that already says
|
|
9
|
+
what is happening.
|
|
10
|
+
-->
|
|
11
|
+
<script module lang="ts">
|
|
12
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
13
|
+
import type { SpinnerBaseProps } from "./spinner.ts";
|
|
14
|
+
|
|
15
|
+
export type SpinnerProps = SpinnerBaseProps & RootProps;
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { rootAttributes, useDefaults } from "@xds/svelte/base";
|
|
20
|
+
import { classes, rootPart } from "./parts.ts";
|
|
21
|
+
import { spinnerClass } from "./spinner.ts";
|
|
22
|
+
|
|
23
|
+
let { size: ownSize, label, class: className, style, ...rest }: SpinnerProps = $props();
|
|
24
|
+
|
|
25
|
+
const defaults = useDefaults("Spinner");
|
|
26
|
+
const size = $derived(ownSize ?? defaults().size);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<span
|
|
30
|
+
{...rootAttributes(rest)}
|
|
31
|
+
class={classes(rootPart("Spinner"), "inline-flex shrink-0", className)}
|
|
32
|
+
{style}
|
|
33
|
+
role={label ? "status" : undefined}
|
|
34
|
+
aria-label={label || undefined}
|
|
35
|
+
aria-hidden={label ? undefined : "true"}
|
|
36
|
+
>
|
|
37
|
+
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" class={spinnerClass(size)}>
|
|
38
|
+
<circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="3" opacity="0.25" />
|
|
39
|
+
<path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" stroke-width="3" stroke-linecap="round" />
|
|
40
|
+
</svg>
|
|
41
|
+
</span>
|