@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,109 @@
|
|
|
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
|
+
Moves through a list split into pages: a step back, the first and the last pages, the page
|
|
8
|
+
shown with an ellipsis for those left out, and a step on. A navigation landmark; the page shown
|
|
9
|
+
is marked as the current page. Without `value` it keeps its own, from `defaultValue`.
|
|
10
|
+
-->
|
|
11
|
+
<script module lang="ts">
|
|
12
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
13
|
+
import type { PaginationBaseProps } from "./pagination.ts";
|
|
14
|
+
|
|
15
|
+
export type PaginationProps = PaginationBaseProps &
|
|
16
|
+
RootProps & {
|
|
17
|
+
/** Called with the page to show, from 1. */
|
|
18
|
+
onChange?: (value: number) => void;
|
|
19
|
+
};
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { controllable, rootAttributes, useLabels } from "@xds/svelte/base";
|
|
24
|
+
import Icon from "./Icon.svelte";
|
|
25
|
+
import {
|
|
26
|
+
clampPage,
|
|
27
|
+
PAGINATION_PARTS,
|
|
28
|
+
PAGINATION_STEPS,
|
|
29
|
+
paginationEntries,
|
|
30
|
+
} from "./pagination.ts";
|
|
31
|
+
import { classes, rootPart } from "./parts.ts";
|
|
32
|
+
|
|
33
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
34
|
+
let {
|
|
35
|
+
count,
|
|
36
|
+
defaultValue,
|
|
37
|
+
label,
|
|
38
|
+
previousLabel,
|
|
39
|
+
nextLabel,
|
|
40
|
+
onChange,
|
|
41
|
+
class: className,
|
|
42
|
+
style,
|
|
43
|
+
...rest
|
|
44
|
+
}: PaginationProps = $props();
|
|
45
|
+
|
|
46
|
+
const control = controllable<number | undefined, number>(
|
|
47
|
+
() => rest,
|
|
48
|
+
"value",
|
|
49
|
+
() => rest.value,
|
|
50
|
+
() => defaultValue ?? 1,
|
|
51
|
+
() => onChange,
|
|
52
|
+
);
|
|
53
|
+
const labels = useLabels();
|
|
54
|
+
const page = $derived(clampPage(control.current ?? 1, count));
|
|
55
|
+
const last = $derived(Math.max(1, Math.floor(count)));
|
|
56
|
+
const entries = $derived(paginationEntries(page, count));
|
|
57
|
+
const go = (next: number) => {
|
|
58
|
+
if (next !== page && next >= 1 && next <= last) control.set(next);
|
|
59
|
+
};
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<nav
|
|
63
|
+
{...rootAttributes(rest)}
|
|
64
|
+
aria-label={label ?? labels().pagination}
|
|
65
|
+
class={classes(rootPart("Pagination"), className)}
|
|
66
|
+
{style}
|
|
67
|
+
>
|
|
68
|
+
<ul class={PAGINATION_PARTS.list}>
|
|
69
|
+
<li>
|
|
70
|
+
<button
|
|
71
|
+
type="button"
|
|
72
|
+
class={PAGINATION_PARTS.step}
|
|
73
|
+
aria-label={previousLabel ?? labels().previousPage}
|
|
74
|
+
aria-disabled={page <= 1 ? true : undefined}
|
|
75
|
+
onclick={() => go(page - 1)}
|
|
76
|
+
>
|
|
77
|
+
<Icon name={PAGINATION_STEPS.previous} size={PAGINATION_STEPS.size} />
|
|
78
|
+
</button>
|
|
79
|
+
</li>
|
|
80
|
+
<!-- A gap is known by where it is; a page by its number. -->
|
|
81
|
+
{#each entries as entry, index (entry === "gap" ? `gap-${index}` : entry)}
|
|
82
|
+
<li>
|
|
83
|
+
{#if entry === "gap"}
|
|
84
|
+
<span class={PAGINATION_PARTS.gap} aria-hidden="true">…</span>
|
|
85
|
+
{:else}
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
class={PAGINATION_PARTS.page}
|
|
89
|
+
aria-current={entry === page ? "page" : undefined}
|
|
90
|
+
onclick={() => go(entry)}
|
|
91
|
+
>
|
|
92
|
+
{entry}
|
|
93
|
+
</button>
|
|
94
|
+
{/if}
|
|
95
|
+
</li>
|
|
96
|
+
{/each}
|
|
97
|
+
<li>
|
|
98
|
+
<button
|
|
99
|
+
type="button"
|
|
100
|
+
class={PAGINATION_PARTS.step}
|
|
101
|
+
aria-label={nextLabel ?? labels().nextPage}
|
|
102
|
+
aria-disabled={page >= last ? true : undefined}
|
|
103
|
+
onclick={() => go(page + 1)}
|
|
104
|
+
>
|
|
105
|
+
<Icon name={PAGINATION_STEPS.next} size={PAGINATION_STEPS.size} />
|
|
106
|
+
</button>
|
|
107
|
+
</li>
|
|
108
|
+
</ul>
|
|
109
|
+
</nav>
|
|
@@ -0,0 +1,75 @@
|
|
|
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 ListRow that says what kind of current item its selected state is. A Sidebar's rows are the
|
|
8
|
+
places of an app, so its selected row is the current page. Only for this package's own
|
|
9
|
+
components: the index does not export it.
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
13
|
+
import Icon from "./Icon.svelte";
|
|
14
|
+
import {
|
|
15
|
+
LIST_ROW_PARTS,
|
|
16
|
+
listRowClass,
|
|
17
|
+
listRowDescriptionClass,
|
|
18
|
+
listRowTitleClass,
|
|
19
|
+
} from "./list-row.ts";
|
|
20
|
+
import type { ListRowProps } from "./ListRow.svelte";
|
|
21
|
+
import { classes } from "./parts.ts";
|
|
22
|
+
|
|
23
|
+
let {
|
|
24
|
+
title,
|
|
25
|
+
description,
|
|
26
|
+
chevron,
|
|
27
|
+
selected,
|
|
28
|
+
compact,
|
|
29
|
+
disabled,
|
|
30
|
+
leading,
|
|
31
|
+
trailing,
|
|
32
|
+
onPress,
|
|
33
|
+
class: className,
|
|
34
|
+
style,
|
|
35
|
+
current: kind,
|
|
36
|
+
...rest
|
|
37
|
+
}: ListRowProps & { current: "true" | "page" } = $props();
|
|
38
|
+
|
|
39
|
+
const current = $derived(selected ? kind : undefined);
|
|
40
|
+
const row = $derived(
|
|
41
|
+
classes(listRowClass({ compact, selected, pressable: onPress !== undefined }), className),
|
|
42
|
+
);
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
{#snippet content()}
|
|
46
|
+
{@render leading?.()}
|
|
47
|
+
<span class={LIST_ROW_PARTS.text}>
|
|
48
|
+
<span class={listRowTitleClass({ compact, selected, disabled })}>{title}</span>
|
|
49
|
+
{#if description}
|
|
50
|
+
<span class={listRowDescriptionClass(compact)}>{description}</span>
|
|
51
|
+
{/if}
|
|
52
|
+
</span>
|
|
53
|
+
{@render trailing?.()}
|
|
54
|
+
{#if chevron}
|
|
55
|
+
<Icon name="chevron-right" size="sm" class={LIST_ROW_PARTS.chevron} />
|
|
56
|
+
{/if}
|
|
57
|
+
{/snippet}
|
|
58
|
+
|
|
59
|
+
{#if onPress}
|
|
60
|
+
<button
|
|
61
|
+
{...rootAttributes(rest)}
|
|
62
|
+
aria-current={current}
|
|
63
|
+
type="button"
|
|
64
|
+
{disabled}
|
|
65
|
+
onclick={() => onPress()}
|
|
66
|
+
class={row}
|
|
67
|
+
{style}
|
|
68
|
+
>
|
|
69
|
+
{@render content()}
|
|
70
|
+
</button>
|
|
71
|
+
{:else}
|
|
72
|
+
<div {...rootAttributes(rest)} aria-current={current} class={row} {style}>
|
|
73
|
+
{@render content()}
|
|
74
|
+
</div>
|
|
75
|
+
{/if}
|
|
@@ -0,0 +1,100 @@
|
|
|
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 opens beside the control that opens it, for details or a short task that do not
|
|
8
|
+
need the whole screen: a press outside, Escape or its close button closes it, and the focus goes
|
|
9
|
+
back to the trigger. It is a dialog named by its title, and not modal: the page stays as it is
|
|
10
|
+
behind it. Without `open` it keeps its own, from `defaultOpen`.
|
|
11
|
+
-->
|
|
12
|
+
<script module lang="ts">
|
|
13
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
14
|
+
import type { Snippet } from "svelte";
|
|
15
|
+
import type { PopoverBaseProps } from "./popover.ts";
|
|
16
|
+
|
|
17
|
+
/** Its root is the surface, while it is open, not its trigger. */
|
|
18
|
+
export type PopoverProps = PopoverBaseProps &
|
|
19
|
+
RootProps & {
|
|
20
|
+
/** The control that opens it: a Button or an IconButton. */
|
|
21
|
+
trigger: Snippet;
|
|
22
|
+
/** Called with whether it is open, as it opens and closes. */
|
|
23
|
+
onOpenChange?: (open: boolean) => void;
|
|
24
|
+
/** What it holds: a few lines of text, a short form, actions. */
|
|
25
|
+
children?: Snippet;
|
|
26
|
+
};
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<script lang="ts">
|
|
30
|
+
import {
|
|
31
|
+
controllable,
|
|
32
|
+
leaveEscapeToFields,
|
|
33
|
+
provideTrigger,
|
|
34
|
+
readCssPx,
|
|
35
|
+
space,
|
|
36
|
+
type TriggerProps,
|
|
37
|
+
} from "@xds/svelte/base";
|
|
38
|
+
import * as popover from "@zag-js/popover";
|
|
39
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
40
|
+
import { POPOVER_PARTS } from "./popover.ts";
|
|
41
|
+
import PopoverSurface from "./PopoverSurface.svelte";
|
|
42
|
+
|
|
43
|
+
// `open` stays in the rest, where whether it is given at all can be asked.
|
|
44
|
+
let {
|
|
45
|
+
title,
|
|
46
|
+
placement,
|
|
47
|
+
closeLabel,
|
|
48
|
+
defaultOpen,
|
|
49
|
+
onOpenChange,
|
|
50
|
+
trigger,
|
|
51
|
+
children,
|
|
52
|
+
class: className,
|
|
53
|
+
style,
|
|
54
|
+
...rest
|
|
55
|
+
}: PopoverProps = $props();
|
|
56
|
+
|
|
57
|
+
const control = controllable<boolean | undefined, boolean>(
|
|
58
|
+
() => rest,
|
|
59
|
+
"open",
|
|
60
|
+
() => rest.open,
|
|
61
|
+
() => defaultOpen ?? false,
|
|
62
|
+
() => onOpenChange,
|
|
63
|
+
);
|
|
64
|
+
const id = $props.id();
|
|
65
|
+
let content = $state<HTMLElement>();
|
|
66
|
+
const service = useMachine(popover.machine, () => ({
|
|
67
|
+
id,
|
|
68
|
+
// The app's id names the surface, and the trigger's aria-controls points there.
|
|
69
|
+
ids: rest.id === undefined ? undefined : { content: rest.id },
|
|
70
|
+
open: control.current ?? false,
|
|
71
|
+
onOpenChange: (details: popover.OpenChangeDetails) => control.set(details.open),
|
|
72
|
+
positioning: {
|
|
73
|
+
placement: placement ?? "bottom",
|
|
74
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
75
|
+
},
|
|
76
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
77
|
+
// The surface itself rather than its first control: a screen reader then reads the title
|
|
78
|
+
// first, and the close button is the next stop.
|
|
79
|
+
initialFocusEl: () => content ?? null,
|
|
80
|
+
}));
|
|
81
|
+
const api = $derived(popover.connect(service, normalizeProps));
|
|
82
|
+
// Added to the control's own class; the trigger looks pressed while it is open.
|
|
83
|
+
provideTrigger(
|
|
84
|
+
() => mergeProps(api.getTriggerProps(), { class: POPOVER_PARTS.trigger }) as TriggerProps,
|
|
85
|
+
);
|
|
86
|
+
// What the app gives the root, without `open`, which is the machine's.
|
|
87
|
+
const { open: _open, ...attributes } = $derived(rest);
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
{@render trigger()}
|
|
91
|
+
<PopoverSurface
|
|
92
|
+
api={() => api}
|
|
93
|
+
{title}
|
|
94
|
+
{closeLabel}
|
|
95
|
+
class={className}
|
|
96
|
+
{style}
|
|
97
|
+
{attributes}
|
|
98
|
+
{children}
|
|
99
|
+
bind:content
|
|
100
|
+
/>
|
|
@@ -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
|
+
What a Popover draws while it is open: the surface, with its title, its close button and its
|
|
8
|
+
content. A component of its own so that the controls in it get none of the trigger props the
|
|
9
|
+
Popover gives its trigger. Only for Popover: the index does not export it.
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import {
|
|
13
|
+
createPresence,
|
|
14
|
+
Portal,
|
|
15
|
+
resetTrigger,
|
|
16
|
+
rootAttributes,
|
|
17
|
+
useLabels,
|
|
18
|
+
} from "@xds/svelte/base";
|
|
19
|
+
import type * as popover from "@zag-js/popover";
|
|
20
|
+
import { mergeProps, type PropTypes } from "@zag-js/svelte";
|
|
21
|
+
import type { Snippet } from "svelte";
|
|
22
|
+
import IconButton from "./IconButton.svelte";
|
|
23
|
+
import { classes } from "./parts.ts";
|
|
24
|
+
import { POPOVER_PARTS } from "./popover.ts";
|
|
25
|
+
|
|
26
|
+
let {
|
|
27
|
+
api,
|
|
28
|
+
title,
|
|
29
|
+
closeLabel,
|
|
30
|
+
class: className,
|
|
31
|
+
style,
|
|
32
|
+
attributes,
|
|
33
|
+
children,
|
|
34
|
+
content = $bindable(),
|
|
35
|
+
}: {
|
|
36
|
+
api: () => popover.Api<PropTypes>;
|
|
37
|
+
title: string;
|
|
38
|
+
closeLabel: string | undefined;
|
|
39
|
+
class: string | undefined;
|
|
40
|
+
style: string | undefined;
|
|
41
|
+
attributes: Record<string, unknown>;
|
|
42
|
+
children: Snippet | undefined;
|
|
43
|
+
content: HTMLElement | undefined;
|
|
44
|
+
} = $props();
|
|
45
|
+
|
|
46
|
+
// Nothing inside opens an overlay from a control outside it.
|
|
47
|
+
resetTrigger();
|
|
48
|
+
const labels = useLabels();
|
|
49
|
+
const present = createPresence(
|
|
50
|
+
() => api().open,
|
|
51
|
+
() => [content],
|
|
52
|
+
);
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
{#if present()}
|
|
56
|
+
<Portal>
|
|
57
|
+
<div {...api().getPositionerProps()} class={POPOVER_PARTS.positioner}>
|
|
58
|
+
<!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
|
|
59
|
+
<section
|
|
60
|
+
{...mergeProps(api().getContentProps(), {
|
|
61
|
+
...rootAttributes(attributes),
|
|
62
|
+
class: classes("{{prefix}}-popover", className),
|
|
63
|
+
style,
|
|
64
|
+
})}
|
|
65
|
+
bind:this={content}
|
|
66
|
+
hidden={false}
|
|
67
|
+
>
|
|
68
|
+
<div class={POPOVER_PARTS.header}>
|
|
69
|
+
<h2 {...api().getTitleProps()} class={POPOVER_PARTS.title}>{title}</h2>
|
|
70
|
+
<IconButton
|
|
71
|
+
icon="x"
|
|
72
|
+
label={closeLabel ?? labels().close}
|
|
73
|
+
variant="ghost"
|
|
74
|
+
size="sm"
|
|
75
|
+
class={POPOVER_PARTS.close}
|
|
76
|
+
onPress={() => api().setOpen(false)}
|
|
77
|
+
/>
|
|
78
|
+
</div>
|
|
79
|
+
{#if children}
|
|
80
|
+
<div class={POPOVER_PARTS.body}>{@render children()}</div>
|
|
81
|
+
{/if}
|
|
82
|
+
</section>
|
|
83
|
+
</div>
|
|
84
|
+
</Portal>
|
|
85
|
+
{/if}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
How far along something is, from 0 to 1. For work of unknown length use a Spinner. `label` says
|
|
8
|
+
what is progressing; a screen reader reads it with the percentage.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
12
|
+
import type { ProgressBarBaseProps } from "./progress-bar.ts";
|
|
13
|
+
|
|
14
|
+
export type ProgressBarProps = ProgressBarBaseProps & RootProps;
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
19
|
+
import { classes, rootPart } from "./parts.ts";
|
|
20
|
+
import { progressBarClass, progressBarFillClass, progressPercent } from "./progress-bar.ts";
|
|
21
|
+
|
|
22
|
+
let { value, label, class: className, style, ...rest }: ProgressBarProps = $props();
|
|
23
|
+
|
|
24
|
+
const percent = $derived(progressPercent(value));
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<div
|
|
28
|
+
{...rootAttributes(rest)}
|
|
29
|
+
role="progressbar"
|
|
30
|
+
aria-label={label}
|
|
31
|
+
aria-valuemin={0}
|
|
32
|
+
aria-valuemax={100}
|
|
33
|
+
aria-valuenow={percent}
|
|
34
|
+
class={classes(rootPart("ProgressBar"), progressBarClass, className)}
|
|
35
|
+
{style}
|
|
36
|
+
>
|
|
37
|
+
<div class={progressBarFillClass} style:width="{percent}%"></div>
|
|
38
|
+
</div>
|
|
@@ -0,0 +1,133 @@
|
|
|
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 choice among a few, applied later with the form it belongs to. For a choice that takes
|
|
8
|
+
effect at once among two to four options, a SegmentedControl is the usual pick.
|
|
9
|
+
|
|
10
|
+
The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
|
|
11
|
+
options are native radio buttons, hidden and drawn beside, in a group named by the legend: the
|
|
12
|
+
arrow keys move between them, and the error is tied to the group and announced. Without
|
|
13
|
+
`value` it keeps its own choice, from `defaultValue`, and a reset of its form puts that back;
|
|
14
|
+
given `value`, even as `undefined`, it shows the app's.
|
|
15
|
+
-->
|
|
16
|
+
<script module lang="ts">
|
|
17
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
18
|
+
import type { RadioGroupBaseProps } from "./radio-group.ts";
|
|
19
|
+
|
|
20
|
+
export type { RadioOption } from "./radio-group.ts";
|
|
21
|
+
|
|
22
|
+
export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> &
|
|
23
|
+
RootProps & {
|
|
24
|
+
onChange?: (value: Value) => void;
|
|
25
|
+
};
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<script lang="ts" generics="Value extends string = string">
|
|
29
|
+
import { controllable, followFormReset, keepChecked, rootAttributes } from "@xds/svelte/base";
|
|
30
|
+
import { classes } from "./parts.ts";
|
|
31
|
+
|
|
32
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
33
|
+
let {
|
|
34
|
+
label,
|
|
35
|
+
options,
|
|
36
|
+
defaultValue,
|
|
37
|
+
disabled,
|
|
38
|
+
error,
|
|
39
|
+
name,
|
|
40
|
+
onChange,
|
|
41
|
+
class: className,
|
|
42
|
+
style,
|
|
43
|
+
...rest
|
|
44
|
+
}: RadioGroupProps<Value> = $props();
|
|
45
|
+
|
|
46
|
+
const control = controllable<Value | undefined, Value>(
|
|
47
|
+
() => rest,
|
|
48
|
+
"value",
|
|
49
|
+
() => rest.value,
|
|
50
|
+
() => defaultValue,
|
|
51
|
+
() => onChange,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const id = $props.id();
|
|
55
|
+
const labelId = `${id}-label`;
|
|
56
|
+
const errorId = `${id}-error`;
|
|
57
|
+
const invalid = $derived(error !== undefined);
|
|
58
|
+
let group = $state<HTMLDivElement>();
|
|
59
|
+
followFormReset(() => group, control);
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<div
|
|
63
|
+
{...rootAttributes(rest)}
|
|
64
|
+
bind:this={group}
|
|
65
|
+
role="radiogroup"
|
|
66
|
+
aria-labelledby={labelId}
|
|
67
|
+
aria-describedby={invalid ? errorId : undefined}
|
|
68
|
+
aria-invalid={invalid ? "true" : undefined}
|
|
69
|
+
aria-disabled={disabled ? "true" : undefined}
|
|
70
|
+
aria-orientation="vertical"
|
|
71
|
+
class={classes("{{prefix}}-radio-group", className)}
|
|
72
|
+
{style}
|
|
73
|
+
>
|
|
74
|
+
<span id={labelId} class="{{prefix}}-radio-group__label">{label}</span>
|
|
75
|
+
<div class="{{prefix}}-radio-group__options">
|
|
76
|
+
{#each options as option, index (option.value)}
|
|
77
|
+
<label class="{{prefix}}-radio-group__option">
|
|
78
|
+
<!-- The description is inside the pressable row, so the row's text would name the radio
|
|
79
|
+
together with it. The label alone names it; the description describes it.
|
|
80
|
+
aria-invalid is on each radio as well as the group, so it is heard on the radio that
|
|
81
|
+
has focus. -->
|
|
82
|
+
<!-- svelte-ignore a11y_role_supports_aria_props_implicit -->
|
|
83
|
+
<input
|
|
84
|
+
type="radio"
|
|
85
|
+
class="{{prefix}}-radio-group__input sr-only"
|
|
86
|
+
name={name ?? id}
|
|
87
|
+
value={option.value}
|
|
88
|
+
checked={option.value === control.current}
|
|
89
|
+
defaultChecked={option.value === (control.controlled ? control.current : defaultValue)}
|
|
90
|
+
{disabled}
|
|
91
|
+
aria-labelledby={`${id}-${index}`}
|
|
92
|
+
aria-describedby={[
|
|
93
|
+
option.description ? `${id}-${index}-description` : undefined,
|
|
94
|
+
invalid ? errorId : undefined,
|
|
95
|
+
]
|
|
96
|
+
.filter(Boolean)
|
|
97
|
+
.join(" ") || undefined}
|
|
98
|
+
aria-invalid={invalid ? "true" : undefined}
|
|
99
|
+
onchange={() => {
|
|
100
|
+
control.set(option.value);
|
|
101
|
+
// The browser moved the dot already; where the owner kept the old value, it goes
|
|
102
|
+
// back, on every radio of the group.
|
|
103
|
+
for (const input of group?.querySelectorAll("input") ?? []) {
|
|
104
|
+
keepChecked(input, () => input.value === control.current);
|
|
105
|
+
}
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
<span class="{{prefix}}-radio-group__row">
|
|
109
|
+
<span class="{{prefix}}-radio-group__circle-line">
|
|
110
|
+
<span class="{{prefix}}-radio-group__circle"
|
|
111
|
+
><span class="{{prefix}}-radio-group__dot"></span></span
|
|
112
|
+
>
|
|
113
|
+
</span>
|
|
114
|
+
<span class="{{prefix}}-radio-group__words">
|
|
115
|
+
<span id={`${id}-${index}`} class="{{prefix}}-radio-group__text">{option.label}</span>
|
|
116
|
+
{#if option.description}
|
|
117
|
+
<span id={`${id}-${index}-description`} class="{{prefix}}-radio-group__description"
|
|
118
|
+
>{option.description}</span
|
|
119
|
+
>
|
|
120
|
+
{/if}
|
|
121
|
+
</span>
|
|
122
|
+
</span>
|
|
123
|
+
</label>
|
|
124
|
+
{/each}
|
|
125
|
+
</div>
|
|
126
|
+
<!-- The region is there before the error is, so that the error is announced when it appears.
|
|
127
|
+
Empty, it takes no room. -->
|
|
128
|
+
<div aria-live="polite">
|
|
129
|
+
{#if invalid}
|
|
130
|
+
<span id={errorId} class="{{prefix}}-radio-group__error">{error}</span>
|
|
131
|
+
{/if}
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
@@ -0,0 +1,154 @@
|
|
|
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 text field for a query: TextField's box as a pill, with a search icon in front and, while
|
|
8
|
+
there is a value, a control that clears it. Escape clears too. A read-only field has neither.
|
|
9
|
+
|
|
10
|
+
Use it to filter or search what is on the screen. For a value that is saved with a form, use a
|
|
11
|
+
TextField, which has a visible label. Without `value` it keeps its own query, from
|
|
12
|
+
`defaultValue`, and a reset of its form puts that back.
|
|
13
|
+
|
|
14
|
+
`focus()`, `blur()` and `element()` on the instance reach the native input.
|
|
15
|
+
-->
|
|
16
|
+
<script module lang="ts">
|
|
17
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
18
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
19
|
+
import type { SearchFieldBaseProps } from "./text-field.ts";
|
|
20
|
+
|
|
21
|
+
export type SearchFieldProps = SearchFieldBaseProps &
|
|
22
|
+
RootProps & {
|
|
23
|
+
onChange?: (value: string) => void;
|
|
24
|
+
/** Called with the query on Enter, or on the search key of a software keyboard. */
|
|
25
|
+
onSubmit?: (value: string) => void;
|
|
26
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
27
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
28
|
+
};
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<script lang="ts">
|
|
32
|
+
import {
|
|
33
|
+
controllable,
|
|
34
|
+
followFormReset,
|
|
35
|
+
keepValue,
|
|
36
|
+
rootAttributes,
|
|
37
|
+
useLabels,
|
|
38
|
+
} from "@xds/svelte/base";
|
|
39
|
+
import Icon from "./Icon.svelte";
|
|
40
|
+
import { classes, rootPart } from "./parts.ts";
|
|
41
|
+
|
|
42
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
43
|
+
let {
|
|
44
|
+
defaultValue = "",
|
|
45
|
+
readOnly,
|
|
46
|
+
label,
|
|
47
|
+
placeholder,
|
|
48
|
+
disabled,
|
|
49
|
+
clearLabel,
|
|
50
|
+
onChange,
|
|
51
|
+
onSubmit,
|
|
52
|
+
onFocus,
|
|
53
|
+
onBlur,
|
|
54
|
+
class: className,
|
|
55
|
+
style,
|
|
56
|
+
...rest
|
|
57
|
+
}: SearchFieldProps = $props();
|
|
58
|
+
|
|
59
|
+
const labels = useLabels();
|
|
60
|
+
|
|
61
|
+
const control = controllable(
|
|
62
|
+
() => rest,
|
|
63
|
+
"value",
|
|
64
|
+
() => rest.value ?? "",
|
|
65
|
+
() => defaultValue,
|
|
66
|
+
() => onChange,
|
|
67
|
+
);
|
|
68
|
+
let input = $state<HTMLInputElement>();
|
|
69
|
+
followFormReset(() => input, control);
|
|
70
|
+
// Nothing to clear in a field that cannot be changed.
|
|
71
|
+
const clearable = $derived(control.current !== "" && !disabled && !readOnly);
|
|
72
|
+
|
|
73
|
+
/** Moves the focus to the native input. */
|
|
74
|
+
export function focus(options?: FocusOptions) {
|
|
75
|
+
input?.focus(options);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Takes the focus from the native input. */
|
|
79
|
+
export function blur() {
|
|
80
|
+
input?.blur();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The native input, once it is on the page. */
|
|
84
|
+
export function element(): HTMLInputElement | undefined {
|
|
85
|
+
return input;
|
|
86
|
+
}
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<!-- TextField's box, so its part as well as its own. -->
|
|
90
|
+
<div
|
|
91
|
+
{...rootAttributes(rest)}
|
|
92
|
+
class={classes("{{prefix}}-text-field", rootPart("SearchField"), className)}
|
|
93
|
+
{style}
|
|
94
|
+
>
|
|
95
|
+
<div
|
|
96
|
+
class="{{prefix}}-text-field__control {{prefix}}-text-field__control--pill {{prefix}}-text-field__group"
|
|
97
|
+
>
|
|
98
|
+
<span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--leading"
|
|
99
|
+
><Icon name="search" size="sm" /></span
|
|
100
|
+
>
|
|
101
|
+
<!-- Escape clears only while there is something to clear; an empty field lets Escape
|
|
102
|
+
through to whatever it sits in, such as a dialog. -->
|
|
103
|
+
<input
|
|
104
|
+
bind:this={input}
|
|
105
|
+
type="text"
|
|
106
|
+
role="searchbox"
|
|
107
|
+
class="{{prefix}}-text-field__input"
|
|
108
|
+
aria-label={label}
|
|
109
|
+
enterkeyhint="search"
|
|
110
|
+
{placeholder}
|
|
111
|
+
value={control.current}
|
|
112
|
+
defaultValue={control.controlled ? control.current : defaultValue}
|
|
113
|
+
readonly={readOnly}
|
|
114
|
+
{disabled}
|
|
115
|
+
data-uses-escape={clearable ? "" : undefined}
|
|
116
|
+
oninput={(event) => {
|
|
117
|
+
control.set(event.currentTarget.value);
|
|
118
|
+
if (!(event instanceof InputEvent && event.isComposing))
|
|
119
|
+
keepValue(event.currentTarget, () => control.current);
|
|
120
|
+
}}
|
|
121
|
+
oncompositionend={(event) => keepValue(event.currentTarget, () => control.current)}
|
|
122
|
+
onkeydown={(event) => {
|
|
123
|
+
// While a composition is open, Enter and Escape belong to the input method.
|
|
124
|
+
if (event.isComposing) return;
|
|
125
|
+
if (event.key === "Enter" && onSubmit) {
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
onSubmit(control.current);
|
|
128
|
+
}
|
|
129
|
+
if (event.key === "Escape" && clearable) {
|
|
130
|
+
event.stopPropagation();
|
|
131
|
+
control.set("");
|
|
132
|
+
}
|
|
133
|
+
}}
|
|
134
|
+
onfocus={onFocus}
|
|
135
|
+
onblur={onBlur}
|
|
136
|
+
/>
|
|
137
|
+
{#if clearable}
|
|
138
|
+
<span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--trailing">
|
|
139
|
+
<button
|
|
140
|
+
type="button"
|
|
141
|
+
aria-label={clearLabel ?? labels().clear}
|
|
142
|
+
onclick={() => {
|
|
143
|
+
control.set("");
|
|
144
|
+
// The control is about to disappear, and focus would be lost with it.
|
|
145
|
+
input?.focus();
|
|
146
|
+
}}
|
|
147
|
+
class="-me-1 flex size-xds-target-min cursor-pointer items-center justify-center rounded-xds-full hover:text-xds-field-text focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-xds-border-focus focus-visible:outline-solid"
|
|
148
|
+
>
|
|
149
|
+
<Icon name="circle-x" size="sm" />
|
|
150
|
+
</button>
|
|
151
|
+
</span>
|
|
152
|
+
{/if}
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|