@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,112 @@
|
|
|
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 surface that groups related content. A hairline outline and a trace of shadow lift it off the
|
|
8
|
+
page; in dark mode, where shadows barely show, the lighter fill does that. `title` renders as a
|
|
9
|
+
heading; `actions` sit across from it.
|
|
10
|
+
-->
|
|
11
|
+
<script module lang="ts">
|
|
12
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
13
|
+
import type { Snippet } from "svelte";
|
|
14
|
+
import type { CardBaseProps } from "./card.ts";
|
|
15
|
+
|
|
16
|
+
export type CardProps = CardBaseProps &
|
|
17
|
+
RootProps & {
|
|
18
|
+
/** Sit across from the title. A pressable card takes none: it is one button already. */
|
|
19
|
+
actions?: Snippet;
|
|
20
|
+
/** A picture or a drawing at the top, running edge to edge above the padding. */
|
|
21
|
+
media?: Snippet;
|
|
22
|
+
/** Makes the whole card one button. Put no other control inside it then. */
|
|
23
|
+
onPress?: () => void;
|
|
24
|
+
children?: Snippet;
|
|
25
|
+
};
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<script lang="ts">
|
|
29
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
30
|
+
import { CARD_PARTS, cardClass, cardMediaClass } from "./card.ts";
|
|
31
|
+
import { classes, rootPart } from "./parts.ts";
|
|
32
|
+
|
|
33
|
+
let {
|
|
34
|
+
title,
|
|
35
|
+
description,
|
|
36
|
+
flush,
|
|
37
|
+
selected,
|
|
38
|
+
actions,
|
|
39
|
+
media,
|
|
40
|
+
onPress,
|
|
41
|
+
class: className,
|
|
42
|
+
style,
|
|
43
|
+
children,
|
|
44
|
+
...rest
|
|
45
|
+
}: CardProps = $props();
|
|
46
|
+
|
|
47
|
+
const pressable = $derived(onPress !== undefined);
|
|
48
|
+
// A button may hold only phrasing content, so inside one the parts are spans. Its heading
|
|
49
|
+
// would not be reachable as a heading anyway: a button reads as its text.
|
|
50
|
+
const tags = $derived(
|
|
51
|
+
pressable
|
|
52
|
+
? { header: "span", box: "span", title: "span", line: "span" }
|
|
53
|
+
: { header: "header", box: "div", title: "h2", line: "p" },
|
|
54
|
+
);
|
|
55
|
+
const surface = $derived(
|
|
56
|
+
classes(rootPart("Card"), cardClass({ selected, flush, pressable }), className),
|
|
57
|
+
);
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
{#snippet parts()}
|
|
61
|
+
{#if media}
|
|
62
|
+
<svelte:element this={tags.box} class={cardMediaClass(flush)}>{@render media()}</svelte:element>
|
|
63
|
+
{/if}
|
|
64
|
+
{#if title || description || (actions && !pressable)}
|
|
65
|
+
<svelte:element this={tags.header} class={CARD_PARTS.header}>
|
|
66
|
+
<svelte:element this={tags.box} class={CARD_PARTS.heading}>
|
|
67
|
+
{#if title}
|
|
68
|
+
<svelte:element this={tags.title} class={CARD_PARTS.title}>{title}</svelte:element>
|
|
69
|
+
{/if}
|
|
70
|
+
{#if description}
|
|
71
|
+
<svelte:element this={tags.line} class={CARD_PARTS.description}
|
|
72
|
+
>{description}</svelte:element
|
|
73
|
+
>
|
|
74
|
+
{/if}
|
|
75
|
+
</svelte:element>
|
|
76
|
+
{#if actions && !pressable}
|
|
77
|
+
<div class={CARD_PARTS.actions}>{@render actions()}</div>
|
|
78
|
+
{/if}
|
|
79
|
+
</svelte:element>
|
|
80
|
+
{/if}
|
|
81
|
+
{@render children?.()}
|
|
82
|
+
{/snippet}
|
|
83
|
+
|
|
84
|
+
{#snippet content()}
|
|
85
|
+
{#if flush}
|
|
86
|
+
<svelte:element this={tags.box} class={CARD_PARTS.flush}>{@render parts()}</svelte:element>
|
|
87
|
+
{:else}
|
|
88
|
+
{@render parts()}
|
|
89
|
+
{/if}
|
|
90
|
+
{/snippet}
|
|
91
|
+
|
|
92
|
+
{#if pressable}
|
|
93
|
+
<button
|
|
94
|
+
{...rootAttributes(rest)}
|
|
95
|
+
type="button"
|
|
96
|
+
onclick={() => onPress?.()}
|
|
97
|
+
aria-pressed={selected === undefined ? undefined : selected ? "true" : "false"}
|
|
98
|
+
class={surface}
|
|
99
|
+
{style}
|
|
100
|
+
>
|
|
101
|
+
{@render content()}
|
|
102
|
+
</button>
|
|
103
|
+
{:else}
|
|
104
|
+
<section
|
|
105
|
+
{...rootAttributes(rest)}
|
|
106
|
+
aria-current={selected ? "true" : undefined}
|
|
107
|
+
class={surface}
|
|
108
|
+
{style}
|
|
109
|
+
>
|
|
110
|
+
{@render content()}
|
|
111
|
+
</section>
|
|
112
|
+
{/if}
|
|
@@ -0,0 +1,121 @@
|
|
|
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 that is applied later, with the form it belongs to. A native checkbox: the input is
|
|
8
|
+
hidden and the box is drawn beside it. Without `checked` it keeps its own state, from
|
|
9
|
+
`defaultChecked`, and a reset of its form puts that back. With `indeterminate` it shows a dash
|
|
10
|
+
and is reported as mixed.
|
|
11
|
+
|
|
12
|
+
`focus()`, `blur()` and `element()` on the instance reach the native checkbox.
|
|
13
|
+
-->
|
|
14
|
+
<script module lang="ts">
|
|
15
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
16
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
17
|
+
import type { CheckboxBaseProps } from "./checkbox.ts";
|
|
18
|
+
|
|
19
|
+
export type CheckboxProps = CheckboxBaseProps &
|
|
20
|
+
RootProps & {
|
|
21
|
+
onChange?: (checked: boolean) => void;
|
|
22
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
23
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
24
|
+
};
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script lang="ts">
|
|
28
|
+
import { controllable, followFormReset, keepChecked, rootAttributes } from "@xds/svelte/base";
|
|
29
|
+
import {
|
|
30
|
+
checkboxBoxClass,
|
|
31
|
+
checkboxClass,
|
|
32
|
+
checkboxLabelClass,
|
|
33
|
+
checkboxMark,
|
|
34
|
+
checkboxMarkClass,
|
|
35
|
+
} from "./checkbox.ts";
|
|
36
|
+
import { classes, rootPart } from "./parts.ts";
|
|
37
|
+
|
|
38
|
+
// `checked` stays in the rest, where whether it is given at all can be asked.
|
|
39
|
+
let {
|
|
40
|
+
defaultChecked = false,
|
|
41
|
+
indeterminate = false,
|
|
42
|
+
label,
|
|
43
|
+
"aria-label": ariaLabel,
|
|
44
|
+
name,
|
|
45
|
+
disabled,
|
|
46
|
+
onChange,
|
|
47
|
+
onFocus,
|
|
48
|
+
onBlur,
|
|
49
|
+
class: className,
|
|
50
|
+
style,
|
|
51
|
+
...rest
|
|
52
|
+
}: CheckboxProps = $props();
|
|
53
|
+
|
|
54
|
+
const control = controllable(
|
|
55
|
+
() => rest,
|
|
56
|
+
"checked",
|
|
57
|
+
() => rest.checked ?? false,
|
|
58
|
+
() => defaultChecked,
|
|
59
|
+
() => onChange,
|
|
60
|
+
);
|
|
61
|
+
let input = $state<HTMLInputElement>();
|
|
62
|
+
followFormReset(() => input, control);
|
|
63
|
+
// A property of the native input, with no attribute: it is what reports the box as mixed.
|
|
64
|
+
$effect(() => {
|
|
65
|
+
if (input) input.indeterminate = indeterminate;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/** Moves the focus to the native checkbox. */
|
|
69
|
+
export function focus(options?: FocusOptions) {
|
|
70
|
+
input?.focus(options);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Takes the focus from the native checkbox. */
|
|
74
|
+
export function blur() {
|
|
75
|
+
input?.blur();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The native checkbox, once it is on the page. */
|
|
79
|
+
export function element(): HTMLInputElement | undefined {
|
|
80
|
+
return input;
|
|
81
|
+
}
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<label
|
|
85
|
+
{...rootAttributes(rest)}
|
|
86
|
+
class={classes(rootPart("Checkbox"), checkboxClass, className)}
|
|
87
|
+
{style}
|
|
88
|
+
>
|
|
89
|
+
<input
|
|
90
|
+
bind:this={input}
|
|
91
|
+
type="checkbox"
|
|
92
|
+
aria-label={ariaLabel}
|
|
93
|
+
class="peer sr-only"
|
|
94
|
+
checked={control.current}
|
|
95
|
+
defaultChecked={control.controlled ? control.current : defaultChecked}
|
|
96
|
+
{disabled}
|
|
97
|
+
name={name || undefined}
|
|
98
|
+
onchange={(event) => {
|
|
99
|
+
// A press clears it on the input; it stays until the app clears it.
|
|
100
|
+
event.currentTarget.indeterminate = indeterminate;
|
|
101
|
+
control.set(event.currentTarget.checked);
|
|
102
|
+
keepChecked(event.currentTarget, () => control.current);
|
|
103
|
+
}}
|
|
104
|
+
onfocus={onFocus}
|
|
105
|
+
onblur={onBlur}
|
|
106
|
+
/>
|
|
107
|
+
<span class={checkboxBoxClass}>
|
|
108
|
+
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class={checkboxMarkClass}>
|
|
109
|
+
<path
|
|
110
|
+
d={checkboxMark(indeterminate)}
|
|
111
|
+
stroke="currentColor"
|
|
112
|
+
stroke-width="2"
|
|
113
|
+
stroke-linecap="round"
|
|
114
|
+
stroke-linejoin="round"
|
|
115
|
+
/>
|
|
116
|
+
</svg>
|
|
117
|
+
</span>
|
|
118
|
+
{#if label}
|
|
119
|
+
<span class={checkboxLabelClass}>{label}</span>
|
|
120
|
+
{/if}
|
|
121
|
+
</label>
|
|
@@ -0,0 +1,51 @@
|
|
|
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 that filters what is shown. Unlike a Badge it is pressed. A selected chip is tinted,
|
|
8
|
+
outlined and marked with a check, so the state does not depend on color.
|
|
9
|
+
|
|
10
|
+
It is a toggle button: assistive technology hears whether it is pressed.
|
|
11
|
+
-->
|
|
12
|
+
<script module lang="ts">
|
|
13
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
14
|
+
import type { ChipBaseProps } from "./chip.ts";
|
|
15
|
+
|
|
16
|
+
export type ChipProps = ChipBaseProps &
|
|
17
|
+
RootProps & {
|
|
18
|
+
onPress?: () => void;
|
|
19
|
+
};
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
24
|
+
import { chipClass, chipIcon } from "./chip.ts";
|
|
25
|
+
import Icon from "./Icon.svelte";
|
|
26
|
+
import { classes, rootPart } from "./parts.ts";
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
label,
|
|
30
|
+
selected,
|
|
31
|
+
iconStart,
|
|
32
|
+
disabled,
|
|
33
|
+
onPress,
|
|
34
|
+
class: className,
|
|
35
|
+
style,
|
|
36
|
+
...rest
|
|
37
|
+
}: ChipProps = $props();
|
|
38
|
+
|
|
39
|
+
const icon = $derived(chipIcon({ selected, iconStart }));
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<button
|
|
43
|
+
{...rootAttributes(rest)}
|
|
44
|
+
type="button"
|
|
45
|
+
aria-pressed={selected ? "true" : "false"}
|
|
46
|
+
{disabled}
|
|
47
|
+
onclick={() => onPress?.()}
|
|
48
|
+
class={classes(rootPart("Chip"), chipClass(selected), className)}
|
|
49
|
+
{style}
|
|
50
|
+
>{#if icon}<Icon name={icon} size="sm" />{/if}{label}</button
|
|
51
|
+
>
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
One row of chips. It scrolls sideways when the chips do not fit and never wraps, so the content
|
|
8
|
+
under it stays where it is.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
12
|
+
import type { Snippet } from "svelte";
|
|
13
|
+
import type { ChipBarBaseProps } from "./chip-bar.ts";
|
|
14
|
+
|
|
15
|
+
export type ChipBarProps = ChipBarBaseProps &
|
|
16
|
+
RootProps & {
|
|
17
|
+
/** The chips. Which of them are selected is the app's business: the bar holds no state. */
|
|
18
|
+
children: Snippet;
|
|
19
|
+
};
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
24
|
+
import { chipBarClass } from "./chip-bar.ts";
|
|
25
|
+
import { classes, rootPart } from "./parts.ts";
|
|
26
|
+
|
|
27
|
+
let { label, class: className, style, children, ...rest }: ChipBarProps = $props();
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<!-- A group, not a fieldset: a fieldset cannot be a scrolling flex row in every browser. -->
|
|
31
|
+
<div
|
|
32
|
+
{...rootAttributes(rest)}
|
|
33
|
+
role="group"
|
|
34
|
+
aria-label={label}
|
|
35
|
+
class={classes(rootPart("ChipBar"), chipBarClass, className)}
|
|
36
|
+
{style}
|
|
37
|
+
>
|
|
38
|
+
{@render children()}
|
|
39
|
+
</div>
|
|
@@ -0,0 +1,198 @@
|
|
|
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 by typing part of its name. As the person types, the
|
|
8
|
+
options whose label holds what was typed open under it, those that start with it first, and the
|
|
9
|
+
first is highlighted, so Enter chooses it. Choosing an option calls `onChange`, puts its label in
|
|
10
|
+
the field and closes the list. Text that names no option goes back to the chosen option's label
|
|
11
|
+
when the field is left. When nothing matches, the list says so. Without `value` it keeps its own
|
|
12
|
+
choice, from `defaultValue`.
|
|
13
|
+
-->
|
|
14
|
+
<script module lang="ts">
|
|
15
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
16
|
+
import type { ComboboxBaseProps } from "./combobox.ts";
|
|
17
|
+
|
|
18
|
+
export type ComboboxProps<Value extends string = string> = ComboboxBaseProps<Value> &
|
|
19
|
+
RootProps & {
|
|
20
|
+
onChange?: (value: Value) => void;
|
|
21
|
+
};
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<script lang="ts" generics="Value extends string = string">
|
|
25
|
+
import {
|
|
26
|
+
controllable,
|
|
27
|
+
createItemPropsCache,
|
|
28
|
+
followFormReset,
|
|
29
|
+
Portal,
|
|
30
|
+
readCssPx,
|
|
31
|
+
rootAttributes,
|
|
32
|
+
type SelectOption,
|
|
33
|
+
selectOptionIds,
|
|
34
|
+
space,
|
|
35
|
+
useLabels,
|
|
36
|
+
} from "@xds/svelte/base";
|
|
37
|
+
import * as combobox from "@zag-js/combobox";
|
|
38
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
39
|
+
import { COMBOBOX_PARTS as PARTS, matchOptions } from "./combobox.ts";
|
|
40
|
+
import Icon from "./Icon.svelte";
|
|
41
|
+
import { classes } from "./parts.ts";
|
|
42
|
+
|
|
43
|
+
let {
|
|
44
|
+
label,
|
|
45
|
+
options,
|
|
46
|
+
defaultValue,
|
|
47
|
+
placeholder,
|
|
48
|
+
description,
|
|
49
|
+
error,
|
|
50
|
+
name,
|
|
51
|
+
disabled,
|
|
52
|
+
onChange,
|
|
53
|
+
emptyLabel,
|
|
54
|
+
class: className,
|
|
55
|
+
style,
|
|
56
|
+
...rest
|
|
57
|
+
}: ComboboxProps<Value> = $props();
|
|
58
|
+
|
|
59
|
+
const labels = useLabels();
|
|
60
|
+
const control = controllable<Value | undefined, Value>(
|
|
61
|
+
() => rest,
|
|
62
|
+
"value",
|
|
63
|
+
() => rest.value,
|
|
64
|
+
() => defaultValue,
|
|
65
|
+
() => onChange,
|
|
66
|
+
);
|
|
67
|
+
const value = $derived(control.current);
|
|
68
|
+
let root = $state<HTMLDivElement>();
|
|
69
|
+
followFormReset(() => root, control);
|
|
70
|
+
|
|
71
|
+
const id = $props.id();
|
|
72
|
+
const descriptionId = `${id}-description`;
|
|
73
|
+
const errorId = `${id}-error`;
|
|
74
|
+
const invalid = $derived(error !== undefined);
|
|
75
|
+
// What the person typed, which narrows the list. Choosing an option puts its label in the field
|
|
76
|
+
// without narrowing it, so the list opens on every option again.
|
|
77
|
+
let query = $state("");
|
|
78
|
+
const shown = $derived(matchOptions(options, query));
|
|
79
|
+
const collection = $derived(
|
|
80
|
+
combobox.collection<SelectOption<Value>>({
|
|
81
|
+
items: shown,
|
|
82
|
+
itemToValue: (option) => option.value,
|
|
83
|
+
itemToString: (option) => option.label,
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
const service = useMachine(combobox.machine, () => ({
|
|
87
|
+
id,
|
|
88
|
+
collection,
|
|
89
|
+
value: value === undefined ? [] : [value],
|
|
90
|
+
onValueChange: (details: combobox.ValueChangeDetails<SelectOption<Value>>) => {
|
|
91
|
+
const next = details.value[0];
|
|
92
|
+
if (next !== undefined) control.set(next as Value);
|
|
93
|
+
},
|
|
94
|
+
onInputValueChange: (details: combobox.InputValueChangeDetails) => {
|
|
95
|
+
if (details.reason === "input-change") query = details.inputValue;
|
|
96
|
+
},
|
|
97
|
+
onOpenChange: (details: combobox.OpenChangeDetails) => {
|
|
98
|
+
if (!details.open) query = "";
|
|
99
|
+
},
|
|
100
|
+
// The first match is highlighted as the person types, so Enter chooses it.
|
|
101
|
+
inputBehavior: "autohighlight" as const,
|
|
102
|
+
selectionBehavior: "replace" as const,
|
|
103
|
+
openOnClick: true,
|
|
104
|
+
disabled,
|
|
105
|
+
invalid,
|
|
106
|
+
placeholder,
|
|
107
|
+
positioning: {
|
|
108
|
+
placement: "bottom-start" as const,
|
|
109
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
110
|
+
sameWidth: true,
|
|
111
|
+
overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
|
|
112
|
+
},
|
|
113
|
+
}));
|
|
114
|
+
const api = $derived(combobox.connect(service, normalizeProps));
|
|
115
|
+
// The rows' props as they last were while they draw the same, so that a step of the highlight
|
|
116
|
+
// sets the attributes and the handlers of the two rows it moves between, not of every row.
|
|
117
|
+
const keep = createItemPropsCache();
|
|
118
|
+
// Zag puts the chosen label back only when the list closes by a press outside; after Escape,
|
|
119
|
+
// text that names no option would stay in a field that has left it.
|
|
120
|
+
const input = $derived(
|
|
121
|
+
mergeProps(api.getInputProps(), {
|
|
122
|
+
onblur: () => {
|
|
123
|
+
const chosen = options.find((option) => option.value === value)?.label ?? "";
|
|
124
|
+
const now = combobox.connect(service, normalizeProps);
|
|
125
|
+
if (now.inputValue !== chosen) now.setInputValue(chosen, "script");
|
|
126
|
+
},
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<!-- Merged, so that the app's style joins any the machine writes on the root. -->
|
|
132
|
+
<div
|
|
133
|
+
bind:this={root}
|
|
134
|
+
{...mergeProps(api.getRootProps(), {
|
|
135
|
+
...rootAttributes(rest),
|
|
136
|
+
class: classes("{{prefix}}-combobox", className),
|
|
137
|
+
style,
|
|
138
|
+
})}
|
|
139
|
+
>
|
|
140
|
+
<label {...api.getLabelProps()} class={PARTS.label}>{label}</label>
|
|
141
|
+
<div {...api.getControlProps()} class={PARTS.control}>
|
|
142
|
+
<input
|
|
143
|
+
{...input}
|
|
144
|
+
aria-describedby={invalid ? errorId : description ? descriptionId : undefined}
|
|
145
|
+
class={PARTS.input}
|
|
146
|
+
/>
|
|
147
|
+
<Icon name="chevrons-up-down" size="sm" class={PARTS.icon} />
|
|
148
|
+
</div>
|
|
149
|
+
<div class={PARTS.footer}>
|
|
150
|
+
{#if !invalid && description}
|
|
151
|
+
<span id={descriptionId} class={PARTS.description}>{description}</span>
|
|
152
|
+
{/if}
|
|
153
|
+
<span id={errorId} class={PARTS.error} aria-live="polite">{error}</span>
|
|
154
|
+
</div>
|
|
155
|
+
<!-- What a form submits: the option's value, where the field holds its label. -->
|
|
156
|
+
{#if name !== undefined}
|
|
157
|
+
<input type="hidden" {name} value={value ?? ""} />
|
|
158
|
+
{/if}
|
|
159
|
+
<Portal>
|
|
160
|
+
<div {...api.getPositionerProps()} class={PARTS.positioner}>
|
|
161
|
+
<!-- Zag hides it while closed. It goes at once, with no animation out: it comes and goes as
|
|
162
|
+
the person types. -->
|
|
163
|
+
<div {...api.getContentProps()} class={PARTS.content}>
|
|
164
|
+
{#if shown.length === 0}
|
|
165
|
+
<div {...api.getEmptyProps()} class={PARTS.empty}>{emptyLabel ?? labels().noMatches}</div>
|
|
166
|
+
{:else}
|
|
167
|
+
<div {...api.getListProps()} class={PARTS.list}>
|
|
168
|
+
{#each shown as option, index (option.value)}
|
|
169
|
+
{@const ids = selectOptionIds(id, index)}
|
|
170
|
+
<div
|
|
171
|
+
{...keep(`item:${option.value}`, api.getItemProps({ item: option }))}
|
|
172
|
+
aria-labelledby={ids.label}
|
|
173
|
+
aria-describedby={option.description ? ids.description : undefined}
|
|
174
|
+
class={PARTS.item}
|
|
175
|
+
>
|
|
176
|
+
<span class={PARTS.itemWords}>
|
|
177
|
+
<span
|
|
178
|
+
{...keep(`text:${option.value}`, api.getItemTextProps({ item: option }))}
|
|
179
|
+
id={ids.label}
|
|
180
|
+
class={PARTS.itemLabel}>{option.label}</span
|
|
181
|
+
>
|
|
182
|
+
{#if option.description}
|
|
183
|
+
<span id={ids.description} class={PARTS.itemDescription}
|
|
184
|
+
>{option.description}</span
|
|
185
|
+
>
|
|
186
|
+
{/if}
|
|
187
|
+
</span>
|
|
188
|
+
{#if api.getItemState({ item: option }).selected}
|
|
189
|
+
<Icon name="check" size="sm" />
|
|
190
|
+
{/if}
|
|
191
|
+
</div>
|
|
192
|
+
{/each}
|
|
193
|
+
</div>
|
|
194
|
+
{/if}
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
</Portal>
|
|
198
|
+
</div>
|
|
@@ -0,0 +1,51 @@
|
|
|
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 count of something waiting: unread messages, items in a cart. On its own it is laid out
|
|
8
|
+
inline; around a child it sits on the child's top end corner.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
12
|
+
import type { Snippet } from "svelte";
|
|
13
|
+
import type { CountBadgeBaseProps } from "./count-badge.ts";
|
|
14
|
+
|
|
15
|
+
export type CountBadgeProps = CountBadgeBaseProps &
|
|
16
|
+
RootProps & {
|
|
17
|
+
/** What the count belongs to: an icon, an avatar, a button. The badge sits on its corner. */
|
|
18
|
+
children?: Snippet;
|
|
19
|
+
};
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
24
|
+
import { countBadgeAnchorClass, countBadgeClass, countBadgeText } from "./count-badge.ts";
|
|
25
|
+
import { classes, rootPart } from "./parts.ts";
|
|
26
|
+
|
|
27
|
+
let { count, max, label, class: className, style, children, ...rest }: CountBadgeProps = $props();
|
|
28
|
+
|
|
29
|
+
// The root is the anchor around the child, or the badge itself when there is none.
|
|
30
|
+
const root = $derived(classes(rootPart("CountBadge"), className));
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
{#snippet badge(onChild: boolean)}
|
|
34
|
+
{#if count > 0}
|
|
35
|
+
<span
|
|
36
|
+
{...onChild ? {} : rootAttributes(rest)}
|
|
37
|
+
role={label ? "img" : undefined}
|
|
38
|
+
aria-label={label || undefined}
|
|
39
|
+
class={classes(countBadgeClass(onChild), !onChild && root)}
|
|
40
|
+
style={onChild ? undefined : style}>{countBadgeText(count, max)}</span
|
|
41
|
+
>
|
|
42
|
+
{/if}
|
|
43
|
+
{/snippet}
|
|
44
|
+
|
|
45
|
+
{#if children}
|
|
46
|
+
<span {...rootAttributes(rest)} class={classes(countBadgeAnchorClass, root)} {style}
|
|
47
|
+
>{@render children()}{@render badge(true)}</span
|
|
48
|
+
>
|
|
49
|
+
{:else}
|
|
50
|
+
{@render badge(false)}
|
|
51
|
+
{/if}
|