@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,222 @@
|
|
|
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 labelled text field, of one line or several. The label, the description and the error message
|
|
8
|
+
are tied to the input for assistive technology, and the error is announced when it appears.
|
|
9
|
+
|
|
10
|
+
An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
|
|
11
|
+
the person edits the value. Without `value` it keeps its own text, from `defaultValue`, and a
|
|
12
|
+
reset of its form puts that back.
|
|
13
|
+
|
|
14
|
+
`focus()`, `blur()` and `element()` on the instance reach the native input or text area.
|
|
15
|
+
-->
|
|
16
|
+
<script module lang="ts">
|
|
17
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
18
|
+
import type { Snippet } from "svelte";
|
|
19
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
20
|
+
import type { TextFieldBaseProps } from "./text-field.ts";
|
|
21
|
+
|
|
22
|
+
export type TextFieldProps = TextFieldBaseProps &
|
|
23
|
+
RootProps & {
|
|
24
|
+
onChange?: (value: string) => void;
|
|
25
|
+
onFocus?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
26
|
+
onBlur?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
27
|
+
/**
|
|
28
|
+
* Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
|
|
29
|
+
* unless it sets its own.
|
|
30
|
+
*/
|
|
31
|
+
leading?: Snippet;
|
|
32
|
+
/** Inside the box, after the text: an icon, a unit, a small button. */
|
|
33
|
+
trailing?: Snippet;
|
|
34
|
+
};
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<script lang="ts">
|
|
38
|
+
import { controllable, followFormReset, keepValue, rootAttributes } from "@xds/svelte/base";
|
|
39
|
+
import { untrack } from "svelte";
|
|
40
|
+
import type { Attachment } from "svelte/attachments";
|
|
41
|
+
import { classes } from "./parts.ts";
|
|
42
|
+
|
|
43
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
44
|
+
let {
|
|
45
|
+
label,
|
|
46
|
+
defaultValue = "",
|
|
47
|
+
readOnly,
|
|
48
|
+
description,
|
|
49
|
+
error,
|
|
50
|
+
placeholder,
|
|
51
|
+
multiline,
|
|
52
|
+
rows = 3,
|
|
53
|
+
maxLength,
|
|
54
|
+
name,
|
|
55
|
+
type = "text",
|
|
56
|
+
inputMode,
|
|
57
|
+
autoComplete,
|
|
58
|
+
autoFocus,
|
|
59
|
+
required,
|
|
60
|
+
disabled,
|
|
61
|
+
onChange,
|
|
62
|
+
onFocus,
|
|
63
|
+
onBlur,
|
|
64
|
+
leading,
|
|
65
|
+
trailing,
|
|
66
|
+
class: className,
|
|
67
|
+
style,
|
|
68
|
+
...rest
|
|
69
|
+
}: TextFieldProps = $props();
|
|
70
|
+
|
|
71
|
+
const control = controllable(
|
|
72
|
+
() => rest,
|
|
73
|
+
"value",
|
|
74
|
+
() => rest.value ?? "",
|
|
75
|
+
() => defaultValue,
|
|
76
|
+
() => onChange,
|
|
77
|
+
);
|
|
78
|
+
let input = $state<HTMLInputElement | HTMLTextAreaElement>();
|
|
79
|
+
followFormReset(() => input, control);
|
|
80
|
+
|
|
81
|
+
/** Moves the focus to the native input or text area. */
|
|
82
|
+
export function focus(options?: FocusOptions) {
|
|
83
|
+
input?.focus(options);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Takes the focus from the native input or text area. */
|
|
87
|
+
export function blur() {
|
|
88
|
+
input?.blur();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The native input or text area, once it is on the page. */
|
|
92
|
+
export function element(): HTMLInputElement | HTMLTextAreaElement | undefined {
|
|
93
|
+
return input;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const id = $props.id();
|
|
97
|
+
const descriptionId = `${id}-description`;
|
|
98
|
+
const errorId = `${id}-error`;
|
|
99
|
+
const invalid = $derived(error !== undefined);
|
|
100
|
+
const describedBy = $derived(invalid ? errorId : description ? descriptionId : undefined);
|
|
101
|
+
|
|
102
|
+
// Once the field is on the page.
|
|
103
|
+
const settle: Attachment<HTMLInputElement | HTMLTextAreaElement> = (input) => {
|
|
104
|
+
// The value is set as a property, which leaves a text area's caret after the last line,
|
|
105
|
+
// and keyboard focus would then scroll to it. React renders the first value as the text
|
|
106
|
+
// area's own text, with the caret before the first line.
|
|
107
|
+
if (input instanceof HTMLTextAreaElement) input.setSelectionRange(0, 0);
|
|
108
|
+
if (untrack(() => autoFocus)) input.focus();
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const syncValidity: Attachment<HTMLInputElement | HTMLTextAreaElement> = (input) => {
|
|
112
|
+
input.setCustomValidity(error ?? "");
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
function oninput(event: Event & { currentTarget: HTMLInputElement | HTMLTextAreaElement }) {
|
|
116
|
+
control.set(event.currentTarget.value);
|
|
117
|
+
// While a composition is open the text belongs to the input method; it ends with
|
|
118
|
+
// compositionend.
|
|
119
|
+
if (!(event instanceof InputEvent && event.isComposing))
|
|
120
|
+
keepValue(event.currentTarget, () => control.current);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function oncompositionend(
|
|
124
|
+
event: CompositionEvent & { currentTarget: HTMLInputElement | HTMLTextAreaElement },
|
|
125
|
+
) {
|
|
126
|
+
keepValue(event.currentTarget, () => control.current);
|
|
127
|
+
}
|
|
128
|
+
</script>
|
|
129
|
+
|
|
130
|
+
<!-- The input draws the box itself until something sits inside the box beside the text. -->
|
|
131
|
+
{#snippet field(box: boolean)}
|
|
132
|
+
{#if multiline}
|
|
133
|
+
<textarea
|
|
134
|
+
{@attach settle}
|
|
135
|
+
{@attach syncValidity}
|
|
136
|
+
{rows}
|
|
137
|
+
{id}
|
|
138
|
+
class={box
|
|
139
|
+
? "{{prefix}}-text-field__input {{prefix}}-text-field__control"
|
|
140
|
+
: "{{prefix}}-text-field__input"}
|
|
141
|
+
bind:this={input}
|
|
142
|
+
value={control.current}
|
|
143
|
+
defaultValue={control.controlled ? control.current : defaultValue}
|
|
144
|
+
{placeholder}
|
|
145
|
+
{name}
|
|
146
|
+
maxlength={maxLength}
|
|
147
|
+
inputmode={inputMode}
|
|
148
|
+
autocomplete={autoComplete as HTMLTextAreaElement["autocomplete"]}
|
|
149
|
+
readonly={readOnly}
|
|
150
|
+
{required}
|
|
151
|
+
{disabled}
|
|
152
|
+
aria-invalid={invalid ? "true" : undefined}
|
|
153
|
+
aria-errormessage={invalid ? errorId : undefined}
|
|
154
|
+
aria-describedby={describedBy}
|
|
155
|
+
{oninput}
|
|
156
|
+
{oncompositionend}
|
|
157
|
+
onfocus={onFocus}
|
|
158
|
+
onblur={onBlur}></textarea>
|
|
159
|
+
{:else}
|
|
160
|
+
<input
|
|
161
|
+
{@attach settle}
|
|
162
|
+
{@attach syncValidity}
|
|
163
|
+
{type}
|
|
164
|
+
{id}
|
|
165
|
+
class={box
|
|
166
|
+
? "{{prefix}}-text-field__input {{prefix}}-text-field__control"
|
|
167
|
+
: "{{prefix}}-text-field__input"}
|
|
168
|
+
bind:this={input}
|
|
169
|
+
value={control.current}
|
|
170
|
+
defaultValue={control.controlled ? control.current : defaultValue}
|
|
171
|
+
{placeholder}
|
|
172
|
+
{name}
|
|
173
|
+
maxlength={maxLength}
|
|
174
|
+
inputmode={inputMode}
|
|
175
|
+
autocomplete={autoComplete as HTMLInputElement["autocomplete"]}
|
|
176
|
+
readonly={readOnly}
|
|
177
|
+
{required}
|
|
178
|
+
{disabled}
|
|
179
|
+
aria-invalid={invalid ? "true" : undefined}
|
|
180
|
+
aria-errormessage={invalid ? errorId : undefined}
|
|
181
|
+
aria-describedby={describedBy}
|
|
182
|
+
{oninput}
|
|
183
|
+
{oncompositionend}
|
|
184
|
+
onfocus={onFocus}
|
|
185
|
+
onblur={onBlur}
|
|
186
|
+
/>
|
|
187
|
+
{/if}
|
|
188
|
+
{/snippet}
|
|
189
|
+
|
|
190
|
+
<div {...rootAttributes(rest)} class={classes("{{prefix}}-text-field", className)} {style}>
|
|
191
|
+
<label for={id} class="{{prefix}}-text-field__label">{label}</label>
|
|
192
|
+
{#if leading || trailing}
|
|
193
|
+
<div class="{{prefix}}-text-field__control {{prefix}}-text-field__group">
|
|
194
|
+
{#if leading}
|
|
195
|
+
<span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--leading"
|
|
196
|
+
>{@render leading()}</span
|
|
197
|
+
>
|
|
198
|
+
{/if}
|
|
199
|
+
{@render field(false)}
|
|
200
|
+
{#if trailing}
|
|
201
|
+
<span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--trailing"
|
|
202
|
+
>{@render trailing()}</span
|
|
203
|
+
>
|
|
204
|
+
{/if}
|
|
205
|
+
</div>
|
|
206
|
+
{:else}
|
|
207
|
+
{@render field(true)}
|
|
208
|
+
{/if}
|
|
209
|
+
<!-- One line under the box: the help or the error at the start edge, the count at the end.
|
|
210
|
+
The error is a live region, so it is announced when it appears. -->
|
|
211
|
+
<div class="{{prefix}}-text-field__footer">
|
|
212
|
+
{#if !invalid && description}
|
|
213
|
+
<span id={descriptionId} class="{{prefix}}-text-field__description">{description}</span>
|
|
214
|
+
{/if}
|
|
215
|
+
<span id={errorId} class="{{prefix}}-text-field__error" aria-live="polite">{error}</span>
|
|
216
|
+
{#if maxLength !== undefined}
|
|
217
|
+
<span class="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums"
|
|
218
|
+
>{control.current.length}/{maxLength}</span
|
|
219
|
+
>
|
|
220
|
+
{/if}
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
@@ -0,0 +1,88 @@
|
|
|
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 picture in a fixed shape, for a video, an article or a product. It fills the width it is
|
|
8
|
+
given and takes its height from `ratio`, and crops the picture to fill it.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
12
|
+
import type { ThumbnailBaseProps } from "./thumbnail.ts";
|
|
13
|
+
|
|
14
|
+
export type { ThumbnailRatio } from "./thumbnail.ts";
|
|
15
|
+
|
|
16
|
+
export type ThumbnailProps = ThumbnailBaseProps & RootProps;
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
import { createPicture, pictureClass, rootAttributes, useDefaults } from "@xds/svelte/base";
|
|
21
|
+
import Badge from "./Badge.svelte";
|
|
22
|
+
import Icon from "./Icon.svelte";
|
|
23
|
+
import { classes, rootPart } from "./parts.ts";
|
|
24
|
+
import {
|
|
25
|
+
THUMBNAIL_PARTS,
|
|
26
|
+
thumbnailBadgeClass,
|
|
27
|
+
thumbnailClass,
|
|
28
|
+
thumbnailWatched,
|
|
29
|
+
} from "./thumbnail.ts";
|
|
30
|
+
|
|
31
|
+
let {
|
|
32
|
+
src,
|
|
33
|
+
alt,
|
|
34
|
+
ratio: ownRatio,
|
|
35
|
+
badge,
|
|
36
|
+
progress,
|
|
37
|
+
class: className,
|
|
38
|
+
style,
|
|
39
|
+
...rest
|
|
40
|
+
}: ThumbnailProps = $props();
|
|
41
|
+
|
|
42
|
+
const defaults = useDefaults("Thumbnail");
|
|
43
|
+
const ratio = $derived(ownRatio ?? defaults().ratio);
|
|
44
|
+
|
|
45
|
+
const picture = createPicture(() => src);
|
|
46
|
+
const watched = $derived(thumbnailWatched(progress));
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<span
|
|
50
|
+
{...rootAttributes(rest)}
|
|
51
|
+
class={classes(rootPart("Thumbnail"), thumbnailClass(ratio), className)}
|
|
52
|
+
{style}
|
|
53
|
+
>
|
|
54
|
+
<!-- The placeholder is the picture's stand-in for assistive technology too, so the description
|
|
55
|
+
is on the box that always shows, not on the picture that may not. -->
|
|
56
|
+
<span
|
|
57
|
+
class={THUMBNAIL_PARTS.placeholder}
|
|
58
|
+
role={alt ? "img" : undefined}
|
|
59
|
+
aria-label={alt || undefined}
|
|
60
|
+
aria-hidden={alt ? undefined : "true"}
|
|
61
|
+
>
|
|
62
|
+
{#if picture.loaded() !== true}
|
|
63
|
+
<Icon name="image" size="lg" />
|
|
64
|
+
{/if}
|
|
65
|
+
{#if picture.loaded() !== false && src}
|
|
66
|
+
{@const address = src}
|
|
67
|
+
<img
|
|
68
|
+
{@attach picture.sync(address)}
|
|
69
|
+
src={address}
|
|
70
|
+
alt=""
|
|
71
|
+
aria-hidden="true"
|
|
72
|
+
class={pictureClass(picture.loaded() === true)}
|
|
73
|
+
onload={() => picture.onLoad(address)}
|
|
74
|
+
onerror={() => picture.onError(address)}
|
|
75
|
+
/>
|
|
76
|
+
{/if}
|
|
77
|
+
</span>
|
|
78
|
+
{#if badge}
|
|
79
|
+
<span class={thumbnailBadgeClass(watched)}><Badge tone="overlay">{badge}</Badge></span>
|
|
80
|
+
{/if}
|
|
81
|
+
{#if watched > 0}
|
|
82
|
+
<!-- Decoration: what was watched is for the eye, and a list that needs it said says it in
|
|
83
|
+
words. -->
|
|
84
|
+
<span aria-hidden="true" class={THUMBNAIL_PARTS.track}>
|
|
85
|
+
<span class={THUMBNAIL_PARTS.fill} style:width="{watched * 100}%"></span>
|
|
86
|
+
</span>
|
|
87
|
+
{/if}
|
|
88
|
+
</span>
|
|
@@ -0,0 +1,237 @@
|
|
|
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 a time of day. Closed, it looks like a Select with a clock: the chosen time
|
|
8
|
+
on the locale's own clock ("9:30 AM", "09:30"). Pressed, it opens the times from `min` to `max`,
|
|
9
|
+
`step` minutes apart, under itself, with the chosen one in view; choosing one calls `onChange`
|
|
10
|
+
with it as `HH:MM` and closes the list.
|
|
11
|
+
|
|
12
|
+
The field is a button that says it opens a list box, as a Select's does: the arrow keys move,
|
|
13
|
+
typing the hour jumps to it, and Enter chooses. Without `value` it keeps its own choice, from
|
|
14
|
+
`defaultValue`.
|
|
15
|
+
-->
|
|
16
|
+
<script module lang="ts">
|
|
17
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
18
|
+
import type { IsoTime, TimePickerBaseProps } from "./time-picker.ts";
|
|
19
|
+
|
|
20
|
+
export type { IsoTime } from "./time-picker.ts";
|
|
21
|
+
|
|
22
|
+
export type TimePickerProps = TimePickerBaseProps &
|
|
23
|
+
RootProps & {
|
|
24
|
+
/** Called with the chosen time, as `HH:MM` on a 24-hour clock. */
|
|
25
|
+
onChange?: (value: IsoTime) => void;
|
|
26
|
+
};
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<script lang="ts">
|
|
30
|
+
import {
|
|
31
|
+
controllable,
|
|
32
|
+
createItemPropsCache,
|
|
33
|
+
createPresence,
|
|
34
|
+
followFormReset,
|
|
35
|
+
keepListKeys,
|
|
36
|
+
modalPopover,
|
|
37
|
+
Portal,
|
|
38
|
+
readCssPx,
|
|
39
|
+
rootAttributes,
|
|
40
|
+
space,
|
|
41
|
+
underlayLayerStyle,
|
|
42
|
+
} from "@xds/svelte/base";
|
|
43
|
+
import * as select from "@zag-js/select";
|
|
44
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
45
|
+
import type { HTMLAttributes, HTMLLabelAttributes } from "svelte/elements";
|
|
46
|
+
import Icon from "./Icon.svelte";
|
|
47
|
+
import { classes } from "./parts.ts";
|
|
48
|
+
import type { SelectOption } from "./select.ts";
|
|
49
|
+
import { timeOptions, timePickerIds, timePickerLocale } from "./time-picker.ts";
|
|
50
|
+
|
|
51
|
+
type KeyHandler = (event: KeyboardEvent) => void;
|
|
52
|
+
|
|
53
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
54
|
+
let {
|
|
55
|
+
label,
|
|
56
|
+
defaultValue,
|
|
57
|
+
min,
|
|
58
|
+
max,
|
|
59
|
+
step,
|
|
60
|
+
placeholder,
|
|
61
|
+
description,
|
|
62
|
+
error,
|
|
63
|
+
name,
|
|
64
|
+
disabled,
|
|
65
|
+
locale,
|
|
66
|
+
onChange,
|
|
67
|
+
class: className,
|
|
68
|
+
style,
|
|
69
|
+
...rest
|
|
70
|
+
}: TimePickerProps = $props();
|
|
71
|
+
|
|
72
|
+
const control = controllable<IsoTime | undefined, IsoTime>(
|
|
73
|
+
() => rest,
|
|
74
|
+
"value",
|
|
75
|
+
() => rest.value,
|
|
76
|
+
() => defaultValue,
|
|
77
|
+
() => onChange,
|
|
78
|
+
);
|
|
79
|
+
const value = $derived(control.current);
|
|
80
|
+
let root = $state<HTMLDivElement>();
|
|
81
|
+
followFormReset(() => root, control);
|
|
82
|
+
|
|
83
|
+
const id = $props.id();
|
|
84
|
+
const ids = timePickerIds(id);
|
|
85
|
+
const invalid = $derived(error !== undefined);
|
|
86
|
+
const options = $derived(timeOptions({ min, max, step, value }, timePickerLocale(locale)));
|
|
87
|
+
const collection = $derived(
|
|
88
|
+
select.collection<SelectOption<IsoTime>>({
|
|
89
|
+
items: options,
|
|
90
|
+
itemToValue: (option) => option.value,
|
|
91
|
+
itemToString: (option) => option.label,
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
const service = useMachine(select.machine, () => ({
|
|
95
|
+
id,
|
|
96
|
+
collection,
|
|
97
|
+
value: value === undefined ? [] : [value],
|
|
98
|
+
onValueChange: (details: select.ValueChangeDetails<SelectOption<IsoTime>>) => {
|
|
99
|
+
const next = details.value[0];
|
|
100
|
+
if (next !== undefined) control.set(next);
|
|
101
|
+
},
|
|
102
|
+
disabled,
|
|
103
|
+
invalid,
|
|
104
|
+
positioning: {
|
|
105
|
+
placement: "bottom-start" as const,
|
|
106
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
107
|
+
sameWidth: true,
|
|
108
|
+
overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
|
|
109
|
+
},
|
|
110
|
+
}));
|
|
111
|
+
const api = $derived(select.connect(service, normalizeProps));
|
|
112
|
+
// The rows' props as they last were while they draw the same, so that a step of the highlight
|
|
113
|
+
// sets the attributes and the handlers of the two rows it moves between, not of every row.
|
|
114
|
+
const keep = createItemPropsCache();
|
|
115
|
+
// As in Select: a handler taken from the machine when the key comes reads whether a search by
|
|
116
|
+
// typing is still under way.
|
|
117
|
+
const current = () => select.connect(service, normalizeProps);
|
|
118
|
+
// A span: the field is a button, which a <label> cannot point at.
|
|
119
|
+
const labelProps = $derived.by(() => {
|
|
120
|
+
const { for: _, ...rest } = api.getLabelProps() as HTMLLabelAttributes;
|
|
121
|
+
return rest as HTMLAttributes<HTMLSpanElement>;
|
|
122
|
+
});
|
|
123
|
+
const triggerProps = $derived.by(() => {
|
|
124
|
+
const {
|
|
125
|
+
role: _role,
|
|
126
|
+
"aria-invalid": _invalid,
|
|
127
|
+
"aria-required": _required,
|
|
128
|
+
onkeydown: _onKeyDown,
|
|
129
|
+
...rest
|
|
130
|
+
} = api.getTriggerProps();
|
|
131
|
+
return {
|
|
132
|
+
...rest,
|
|
133
|
+
onkeydown: (event: KeyboardEvent) => {
|
|
134
|
+
if (!api.open && (event.key === "Home" || event.key === "End")) return;
|
|
135
|
+
(current().getTriggerProps().onkeydown as KeyHandler | undefined)?.(event);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
let positioner = $state<HTMLDivElement>();
|
|
140
|
+
let surface = $state<HTMLDivElement>();
|
|
141
|
+
modalPopover(
|
|
142
|
+
() => api.open,
|
|
143
|
+
() => positioner,
|
|
144
|
+
);
|
|
145
|
+
const present = createPresence(
|
|
146
|
+
() => api.open,
|
|
147
|
+
() => [surface],
|
|
148
|
+
);
|
|
149
|
+
const content = $derived.by(() => {
|
|
150
|
+
const { onkeydown: _onKeyDown, ...rest } = api.getContentProps();
|
|
151
|
+
return mergeProps(rest, {
|
|
152
|
+
onkeydown: (event: KeyboardEvent) => {
|
|
153
|
+
keepListKeys(
|
|
154
|
+
event,
|
|
155
|
+
surface,
|
|
156
|
+
".{{prefix}}-time-picker__item:not([data-disabled])",
|
|
157
|
+
(value) => api.setHighlightedValue(value),
|
|
158
|
+
);
|
|
159
|
+
(current().getContentProps().onkeydown as KeyHandler | undefined)?.(event);
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
</script>
|
|
164
|
+
|
|
165
|
+
<!-- Merged, so that the app's style joins any the machine writes on the root. -->
|
|
166
|
+
<div
|
|
167
|
+
bind:this={root}
|
|
168
|
+
{...mergeProps(api.getRootProps(), {
|
|
169
|
+
...rootAttributes(rest),
|
|
170
|
+
class: classes("{{prefix}}-time-picker", className),
|
|
171
|
+
style,
|
|
172
|
+
})}
|
|
173
|
+
>
|
|
174
|
+
<span {...labelProps} class="{{prefix}}-time-picker__label">{label}</span>
|
|
175
|
+
<button
|
|
176
|
+
{...triggerProps}
|
|
177
|
+
aria-labelledby={`${ids.value} ${labelProps.id}`}
|
|
178
|
+
aria-describedby={invalid ? ids.error : description ? ids.description : undefined}
|
|
179
|
+
class="{{prefix}}-time-picker__trigger"
|
|
180
|
+
>
|
|
181
|
+
<span {...api.getValueTextProps()} id={ids.value} class="{{prefix}}-time-picker__value"
|
|
182
|
+
>{api.valueAsString || placeholder}</span
|
|
183
|
+
>
|
|
184
|
+
<Icon name="clock" size="sm" class="text-xds-field-placeholder" />
|
|
185
|
+
</button>
|
|
186
|
+
<div class="{{prefix}}-time-picker__footer">
|
|
187
|
+
{#if !invalid && description}
|
|
188
|
+
<span id={ids.description} class="{{prefix}}-time-picker__description">{description}</span>
|
|
189
|
+
{/if}
|
|
190
|
+
<span id={ids.error} class="{{prefix}}-time-picker__error" aria-live="polite">{error}</span>
|
|
191
|
+
</div>
|
|
192
|
+
<!-- What a form submits: the time as HH:MM, where the field shows it on the locale's clock. -->
|
|
193
|
+
{#if name !== undefined}
|
|
194
|
+
<input type="hidden" {name} value={value ?? ""} />
|
|
195
|
+
{/if}
|
|
196
|
+
<Portal>
|
|
197
|
+
{#if api.open}
|
|
198
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
199
|
+
<div
|
|
200
|
+
class="{{prefix}}-time-picker__underlay"
|
|
201
|
+
style:--layer-index={underlayLayerStyle(api.getPositionerProps().style)?.["--layer-index"]}
|
|
202
|
+
onmousedown={(event) => event.preventDefault()}
|
|
203
|
+
></div>
|
|
204
|
+
{/if}
|
|
205
|
+
<div
|
|
206
|
+
{...api.getPositionerProps()}
|
|
207
|
+
bind:this={positioner}
|
|
208
|
+
class="{{prefix}}-time-picker__positioner"
|
|
209
|
+
>
|
|
210
|
+
<div
|
|
211
|
+
{...content}
|
|
212
|
+
bind:this={surface}
|
|
213
|
+
hidden={!present()}
|
|
214
|
+
class="{{prefix}}-time-picker__content"
|
|
215
|
+
>
|
|
216
|
+
<div {...api.getListProps()} class="{{prefix}}-time-picker__list">
|
|
217
|
+
{#each collection.items as option (option.value)}
|
|
218
|
+
<div
|
|
219
|
+
{...keep(`item:${option.value}`, api.getItemProps({ item: option }))}
|
|
220
|
+
class="{{prefix}}-time-picker__item"
|
|
221
|
+
>
|
|
222
|
+
<span class="{{prefix}}-time-picker__item-words">
|
|
223
|
+
<span
|
|
224
|
+
{...keep(`text:${option.value}`, api.getItemTextProps({ item: option }))}
|
|
225
|
+
class="{{prefix}}-time-picker__item-label">{option.label}</span
|
|
226
|
+
>
|
|
227
|
+
</span>
|
|
228
|
+
{#if api.getItemState({ item: option }).selected}
|
|
229
|
+
<Icon name="check" size="sm" />
|
|
230
|
+
{/if}
|
|
231
|
+
</div>
|
|
232
|
+
{/each}
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
</Portal>
|
|
237
|
+
</div>
|
|
@@ -0,0 +1,98 @@
|
|
|
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 short message about what just happened, which leaves on its own. It sits at the bottom center
|
|
8
|
+
of the window, above everything else, and is announced politely without taking focus. The time
|
|
9
|
+
does not run while the pointer is over it or focus is inside it.
|
|
10
|
+
|
|
11
|
+
Do not put the only way to do something in a toast: it is gone in a few seconds.
|
|
12
|
+
-->
|
|
13
|
+
<script module lang="ts">
|
|
14
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
15
|
+
import type { ToastBaseProps } from "./toast.ts";
|
|
16
|
+
|
|
17
|
+
/** Its root is the toast, while it is open, not the region it appears in. */
|
|
18
|
+
export type ToastProps = ToastBaseProps &
|
|
19
|
+
RootProps & {
|
|
20
|
+
/** Called when the time is up and after the action. Set `open` to false in it. */
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<script lang="ts">
|
|
26
|
+
import { motion, readCssMs, rootAttributes } from "@xds/svelte/base";
|
|
27
|
+
import type { Attachment } from "svelte/attachments";
|
|
28
|
+
import { classes, rootPart } from "./parts.ts";
|
|
29
|
+
import { TOAST_PARTS } from "./toast.ts";
|
|
30
|
+
|
|
31
|
+
let {
|
|
32
|
+
open,
|
|
33
|
+
message,
|
|
34
|
+
action,
|
|
35
|
+
duration,
|
|
36
|
+
onClose,
|
|
37
|
+
class: className,
|
|
38
|
+
style,
|
|
39
|
+
...rest
|
|
40
|
+
}: ToastProps = $props();
|
|
41
|
+
|
|
42
|
+
let regionElement = $state<HTMLDivElement>();
|
|
43
|
+
// The toast the pointer is over and the one focus is in. A toast that closed under the pointer
|
|
44
|
+
// gets no event to say that the pointer left, so only one still in the page counts.
|
|
45
|
+
let hovered = $state<Element>();
|
|
46
|
+
let focused = $state<Element>();
|
|
47
|
+
const inPage = (toast: Element | undefined) => toast?.isConnected === true;
|
|
48
|
+
|
|
49
|
+
// The region is in the top layer for as long as the component is mounted, empty or not: a
|
|
50
|
+
// screen reader only announces what is added to a region it already knows.
|
|
51
|
+
const showRegion: Attachment<HTMLDivElement> = (region) => {
|
|
52
|
+
regionElement = region;
|
|
53
|
+
if (!region.showPopover) return;
|
|
54
|
+
region.showPopover();
|
|
55
|
+
return () => {
|
|
56
|
+
if (region.isConnected && region.matches(":popover-open")) region.hidePopover();
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
$effect(() => {
|
|
61
|
+
// Touch `message` so a replacement toast restarts the timer.
|
|
62
|
+
void message;
|
|
63
|
+
const ms =
|
|
64
|
+
duration ?? readCssMs(regionElement, "--xds-motion-duration-toast", motion.duration.toast);
|
|
65
|
+
if (!open || inPage(hovered) || inPage(focused) || ms <= 0) return;
|
|
66
|
+
// `onClose` is read when the time is up, so a new function does not restart it.
|
|
67
|
+
const timer = setTimeout(() => onClose(), ms);
|
|
68
|
+
return () => clearTimeout(timer);
|
|
69
|
+
});
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<div {@attach showRegion} role="status" popover="manual" class={TOAST_PARTS.region}>
|
|
73
|
+
{#if open}
|
|
74
|
+
<!-- Hover and focus only pause the timer; the action inside is a real button. -->
|
|
75
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
76
|
+
<div
|
|
77
|
+
{...rootAttributes(rest)}
|
|
78
|
+
onpointerenter={(event) => (hovered = event.currentTarget)}
|
|
79
|
+
onpointerleave={() => (hovered = undefined)}
|
|
80
|
+
onfocusin={(event) => (focused = event.currentTarget)}
|
|
81
|
+
onfocusout={() => (focused = undefined)}
|
|
82
|
+
class={classes(rootPart("Toast"), TOAST_PARTS.toast, className)}
|
|
83
|
+
{style}
|
|
84
|
+
>
|
|
85
|
+
<span class={TOAST_PARTS.message}>{message}</span>
|
|
86
|
+
{#if action}
|
|
87
|
+
<button
|
|
88
|
+
type="button"
|
|
89
|
+
onclick={() => {
|
|
90
|
+
action.onPress();
|
|
91
|
+
onClose();
|
|
92
|
+
}}
|
|
93
|
+
class={TOAST_PARTS.action}>{action.label}</button
|
|
94
|
+
>
|
|
95
|
+
{/if}
|
|
96
|
+
</div>
|
|
97
|
+
{/if}
|
|
98
|
+
</div>
|