@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,67 @@
|
|
|
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 title row of a group of content. The title is a heading at `level`; the action is a quiet
|
|
8
|
+
button with a chevron at its end edge, which points the other way in a right-to-left layout.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
12
|
+
import type { SectionHeaderBaseProps } from "./section-header.ts";
|
|
13
|
+
|
|
14
|
+
export type SectionHeaderProps = SectionHeaderBaseProps &
|
|
15
|
+
RootProps & {
|
|
16
|
+
/** A link-like action at the end, such as "See all". */
|
|
17
|
+
action?: { label: string; onPress: () => void };
|
|
18
|
+
};
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
23
|
+
import Button from "./Button.svelte";
|
|
24
|
+
import Icon from "./Icon.svelte";
|
|
25
|
+
import { classes, rootPart } from "./parts.ts";
|
|
26
|
+
import { SECTION_HEADER_PARTS } from "./section-header.ts";
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
title,
|
|
30
|
+
description,
|
|
31
|
+
icon,
|
|
32
|
+
level = 2,
|
|
33
|
+
action,
|
|
34
|
+
class: className,
|
|
35
|
+
style,
|
|
36
|
+
...rest
|
|
37
|
+
}: SectionHeaderProps = $props();
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<div
|
|
41
|
+
{...rootAttributes(rest)}
|
|
42
|
+
class={classes(rootPart("SectionHeader"), SECTION_HEADER_PARTS.root, className)}
|
|
43
|
+
{style}
|
|
44
|
+
>
|
|
45
|
+
<div class={SECTION_HEADER_PARTS.lead}>
|
|
46
|
+
{#if icon}
|
|
47
|
+
<span class={SECTION_HEADER_PARTS.icon}><Icon name={icon} size="md" /></span>
|
|
48
|
+
{/if}
|
|
49
|
+
<div class={SECTION_HEADER_PARTS.text}>
|
|
50
|
+
<svelte:element this={`h${level}`} class={SECTION_HEADER_PARTS.title}>{title}</svelte:element>
|
|
51
|
+
{#if description}
|
|
52
|
+
<p class={SECTION_HEADER_PARTS.description}>{description}</p>
|
|
53
|
+
{/if}
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
{#if action}
|
|
57
|
+
<span class={SECTION_HEADER_PARTS.action}>
|
|
58
|
+
<Button variant="ghost" size="sm" onPress={() => action.onPress()}
|
|
59
|
+
>{action.label}<Icon
|
|
60
|
+
name="chevron-right"
|
|
61
|
+
size="sm"
|
|
62
|
+
class={SECTION_HEADER_PARTS.chevron}
|
|
63
|
+
/></Button
|
|
64
|
+
>
|
|
65
|
+
</span>
|
|
66
|
+
{/if}
|
|
67
|
+
</div>
|
|
@@ -0,0 +1,85 @@
|
|
|
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 choice between a few views or modes, all visible at once. The selected segment is outlined as
|
|
8
|
+
well as filled, so the choice does not depend on telling two greys apart.
|
|
9
|
+
|
|
10
|
+
It is a group of native radio buttons, so the arrow keys move between segments. Without
|
|
11
|
+
`value` it keeps its own choice, from `defaultValue` or else the first segment.
|
|
12
|
+
-->
|
|
13
|
+
<script module lang="ts">
|
|
14
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
15
|
+
import type { SegmentedControlBaseProps } from "./segmented-control.ts";
|
|
16
|
+
|
|
17
|
+
export type SegmentedControlProps<Value extends string> = SegmentedControlBaseProps<Value> &
|
|
18
|
+
RootProps & {
|
|
19
|
+
onChange?: (value: Value) => void;
|
|
20
|
+
};
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<script lang="ts" generics="Value extends string">
|
|
24
|
+
import { controllable, keepChecked, rootAttributes } from "@xds/svelte/base";
|
|
25
|
+
import { classes, rootPart } from "./parts.ts";
|
|
26
|
+
import {
|
|
27
|
+
segmentedControlClass,
|
|
28
|
+
segmentedControlOptionClass,
|
|
29
|
+
segmentedControlSegmentClass,
|
|
30
|
+
} from "./segmented-control.ts";
|
|
31
|
+
|
|
32
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
33
|
+
let {
|
|
34
|
+
options,
|
|
35
|
+
defaultValue,
|
|
36
|
+
"aria-label": ariaLabel,
|
|
37
|
+
fullWidth,
|
|
38
|
+
onChange,
|
|
39
|
+
class: className,
|
|
40
|
+
style,
|
|
41
|
+
...rest
|
|
42
|
+
}: SegmentedControlProps<Value> = $props();
|
|
43
|
+
|
|
44
|
+
const control = controllable<Value | undefined, Value>(
|
|
45
|
+
() => rest,
|
|
46
|
+
"value",
|
|
47
|
+
() => rest.value,
|
|
48
|
+
() => defaultValue ?? options[0]?.value,
|
|
49
|
+
() => onChange,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const name = $props.id();
|
|
53
|
+
let group = $state<HTMLDivElement>();
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<div
|
|
57
|
+
{...rootAttributes(rest)}
|
|
58
|
+
bind:this={group}
|
|
59
|
+
aria-label={ariaLabel}
|
|
60
|
+
role="radiogroup"
|
|
61
|
+
class={classes(rootPart("SegmentedControl"), segmentedControlClass(fullWidth), className)}
|
|
62
|
+
{style}
|
|
63
|
+
>
|
|
64
|
+
{#each options as option (option.value)}
|
|
65
|
+
<label class={segmentedControlOptionClass(fullWidth)}>
|
|
66
|
+
<input
|
|
67
|
+
type="radio"
|
|
68
|
+
{name}
|
|
69
|
+
value={option.value}
|
|
70
|
+
class="peer sr-only"
|
|
71
|
+
checked={option.value === control.current}
|
|
72
|
+
defaultChecked={option.value === control.current}
|
|
73
|
+
onchange={() => {
|
|
74
|
+
control.set(option.value);
|
|
75
|
+
// The browser moved the dot already; where the owner kept the old value, it goes
|
|
76
|
+
// back, on every radio of the group.
|
|
77
|
+
for (const input of group?.querySelectorAll("input") ?? []) {
|
|
78
|
+
keepChecked(input, () => input.value === control.current);
|
|
79
|
+
}
|
|
80
|
+
}}
|
|
81
|
+
/>
|
|
82
|
+
<span class={segmentedControlSegmentClass}>{option.label}</span>
|
|
83
|
+
</label>
|
|
84
|
+
{/each}
|
|
85
|
+
</div>
|
|
@@ -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>
|