@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,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
|
+
Items whose bodies open and close under their titles, separated by hairlines. The chevron turns
|
|
8
|
+
over when an item is open, so the state does not depend on color. Opening and closing animate
|
|
9
|
+
the height, and do not for people who ask for less motion.
|
|
10
|
+
|
|
11
|
+
Each title is a heading holding a button that says whether its body is expanded and which body
|
|
12
|
+
it controls. A closed body is hidden, but the browser's find in page still opens it.
|
|
13
|
+
-->
|
|
14
|
+
<script module lang="ts">
|
|
15
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
16
|
+
import type { Snippet } from "svelte";
|
|
17
|
+
import type { AccordionBaseProps, AccordionItemBase } from "./accordion.ts";
|
|
18
|
+
|
|
19
|
+
export type AccordionItem<Value extends string = string> = AccordionItemBase<Value> & {
|
|
20
|
+
/** The body, shown under the title while the item is open: text, or a snippet. */
|
|
21
|
+
content: string | Snippet;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type AccordionProps<Value extends string = string> = AccordionBaseProps<Value> &
|
|
25
|
+
RootProps & {
|
|
26
|
+
items: readonly AccordionItem<Value>[];
|
|
27
|
+
onChange: (expanded: Value[]) => void;
|
|
28
|
+
};
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<script lang="ts" generics="Value extends string = string">
|
|
32
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
33
|
+
import * as accordion from "@zag-js/accordion";
|
|
34
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
35
|
+
import { ACCORDION_PARTS, focusTitleOnClick } from "./accordion.ts";
|
|
36
|
+
import AccordionPanel from "./AccordionPanel.svelte";
|
|
37
|
+
import Icon from "./Icon.svelte";
|
|
38
|
+
import { classes } from "./parts.ts";
|
|
39
|
+
|
|
40
|
+
let {
|
|
41
|
+
items,
|
|
42
|
+
expanded,
|
|
43
|
+
multiple = false,
|
|
44
|
+
onChange,
|
|
45
|
+
class: className,
|
|
46
|
+
style,
|
|
47
|
+
...rest
|
|
48
|
+
}: AccordionProps<Value> = $props();
|
|
49
|
+
|
|
50
|
+
const id = $props.id();
|
|
51
|
+
const service = useMachine(accordion.machine, () => ({
|
|
52
|
+
id,
|
|
53
|
+
value: [...expanded],
|
|
54
|
+
onValueChange: (details: accordion.ValueChangeDetails) => onChange(details.value as Value[]),
|
|
55
|
+
multiple,
|
|
56
|
+
collapsible: true,
|
|
57
|
+
hiddenUntilFound: true,
|
|
58
|
+
}));
|
|
59
|
+
const api = $derived(accordion.connect(service, normalizeProps));
|
|
60
|
+
// Merged, so that the app's style joins any the machine writes on the root.
|
|
61
|
+
const root = $derived(
|
|
62
|
+
mergeProps(api.getRootProps(), {
|
|
63
|
+
...rootAttributes(rest),
|
|
64
|
+
class: classes("{{prefix}}-accordion", className),
|
|
65
|
+
style,
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
const body = (value: Value) => {
|
|
69
|
+
// The panel hides itself once it has finished closing; see AccordionPanel.
|
|
70
|
+
const { hidden: _hidden, ...attributes } = api.getItemContentProps({ value });
|
|
71
|
+
return attributes;
|
|
72
|
+
};
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<div {...root}>
|
|
76
|
+
{#each items as item (item.value)}
|
|
77
|
+
<div {...api.getItemProps({ value: item.value })} class="{{prefix}}-accordion__item">
|
|
78
|
+
<h3 {...api.getItemHeaderProps({ value: item.value })} class="{{prefix}}-accordion__heading">
|
|
79
|
+
<button
|
|
80
|
+
{...mergeProps(api.getItemTriggerProps({ value: item.value }), {
|
|
81
|
+
// Runs before Zag's handler.
|
|
82
|
+
onclick: focusTitleOnClick,
|
|
83
|
+
})}
|
|
84
|
+
class="{{prefix}}-accordion__trigger group"
|
|
85
|
+
>
|
|
86
|
+
<span class={ACCORDION_PARTS.text}>
|
|
87
|
+
<span class={ACCORDION_PARTS.title}>{item.title}</span>
|
|
88
|
+
{#if item.description}
|
|
89
|
+
<span class={ACCORDION_PARTS.description}>{item.description}</span>
|
|
90
|
+
{/if}
|
|
91
|
+
</span>
|
|
92
|
+
<Icon name="chevron-down" size="sm" class={ACCORDION_PARTS.chevron} />
|
|
93
|
+
</button>
|
|
94
|
+
</h3>
|
|
95
|
+
<AccordionPanel open={api.value.includes(item.value)} attributes={body(item.value)}>
|
|
96
|
+
{#if typeof item.content === "string"}{item.content}{:else}{@render item.content()}{/if}
|
|
97
|
+
</AccordionPanel>
|
|
98
|
+
</div>
|
|
99
|
+
{/each}
|
|
100
|
+
</div>
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
An Accordion item's body. Its height moves between zero and the height of what it holds, and
|
|
8
|
+
it is hidden only once it has finished closing. Only for Accordion: the index does not export
|
|
9
|
+
it.
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { untrack, type Snippet } from "svelte";
|
|
13
|
+
import type { Attachment } from "svelte/attachments";
|
|
14
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
15
|
+
import { setPanelOpen } from "./accordion.ts";
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
open,
|
|
19
|
+
attributes,
|
|
20
|
+
children,
|
|
21
|
+
}: { open: boolean; attributes: HTMLAttributes<HTMLDivElement>; children: Snippet } = $props();
|
|
22
|
+
|
|
23
|
+
let rendered = false;
|
|
24
|
+
// A page rendered on the server shows the panel before the attachment can run, so a closed one
|
|
25
|
+
// starts hidden. Read once so setPanelOpen owns `hidden` from then on.
|
|
26
|
+
const closedAtFirst = untrack(() => !open);
|
|
27
|
+
// Again on each toggle; the next one takes over from this one.
|
|
28
|
+
const toggle: Attachment<HTMLDivElement> = (panel) => {
|
|
29
|
+
const stop = setPanelOpen(panel, open, rendered);
|
|
30
|
+
rendered = true;
|
|
31
|
+
return stop;
|
|
32
|
+
};
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<!-- A group: a region is a landmark, and a page of accordions would fill the list of landmarks.
|
|
36
|
+
A closed one is left out of the accessibility tree as soon as it starts closing;
|
|
37
|
+
`hidden="until-found"` alone leaves the empty group in it. A group, not a fieldset: it is the
|
|
38
|
+
body of a disclosure, not a set of form fields. -->
|
|
39
|
+
<div
|
|
40
|
+
{...attributes}
|
|
41
|
+
{@attach toggle}
|
|
42
|
+
hidden={closedAtFirst || undefined}
|
|
43
|
+
role="group"
|
|
44
|
+
aria-hidden={open ? undefined : "true"}
|
|
45
|
+
class="{{prefix}}-accordion__panel"
|
|
46
|
+
>
|
|
47
|
+
<div class="{{prefix}}-accordion__body">{@render children()}</div>
|
|
48
|
+
</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
|
+
Stands for a person or a team by a picture, or by their initials when there is none. Assistive
|
|
8
|
+
technology gets the full name either way. The small size has room for one letter.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
12
|
+
import type { AvatarBaseProps } from "./avatar.ts";
|
|
13
|
+
|
|
14
|
+
export type { AvatarSize } from "./avatar.ts";
|
|
15
|
+
|
|
16
|
+
export type AvatarProps = AvatarBaseProps & RootProps;
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
import { createPicture, rootAttributes, useDefaults } from "@xds/svelte/base";
|
|
21
|
+
import { avatarClass, avatarInitials, pictureClass } from "./avatar.ts";
|
|
22
|
+
import { classes, rootPart } from "./parts.ts";
|
|
23
|
+
|
|
24
|
+
let { name, src, size: ownSize, class: className, style, ...rest }: AvatarProps = $props();
|
|
25
|
+
|
|
26
|
+
const defaults = useDefaults("Avatar");
|
|
27
|
+
const size = $derived(ownSize ?? defaults().size);
|
|
28
|
+
|
|
29
|
+
const picture = createPicture(() => src);
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<span
|
|
33
|
+
{...rootAttributes(rest)}
|
|
34
|
+
role="img"
|
|
35
|
+
aria-label={name}
|
|
36
|
+
class={classes(rootPart("Avatar"), avatarClass(size), className)}
|
|
37
|
+
{style}
|
|
38
|
+
>{avatarInitials(name, size)}{#if picture.loaded() !== false && src}
|
|
39
|
+
{@const address = src}
|
|
40
|
+
<!-- The name is on the avatar itself; a second one on the picture would be read twice. -->
|
|
41
|
+
<img
|
|
42
|
+
{@attach picture.sync(address)}
|
|
43
|
+
src={address}
|
|
44
|
+
alt=""
|
|
45
|
+
aria-hidden="true"
|
|
46
|
+
class={pictureClass(picture.loaded() === true)}
|
|
47
|
+
onload={() => picture.onLoad(address)}
|
|
48
|
+
onerror={() => picture.onError(address)}
|
|
49
|
+
/>
|
|
50
|
+
{/if}</span
|
|
51
|
+
>
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
Several people in the room of one. Assistive technology gets one image named after everyone in
|
|
8
|
+
it, including those who did not fit.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
12
|
+
import type { AvatarStackBaseProps } from "./avatar-stack.ts";
|
|
13
|
+
|
|
14
|
+
export type AvatarStackProps = AvatarStackBaseProps & RootProps;
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import { rootAttributes, useDefaults } from "@xds/svelte/base";
|
|
19
|
+
import {
|
|
20
|
+
avatarStack,
|
|
21
|
+
avatarStackClass,
|
|
22
|
+
avatarStackItemClass,
|
|
23
|
+
avatarStackRestClass,
|
|
24
|
+
} from "./avatar-stack.ts";
|
|
25
|
+
import Avatar from "./Avatar.svelte";
|
|
26
|
+
import { classes, rootPart } from "./parts.ts";
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
people,
|
|
30
|
+
max,
|
|
31
|
+
size: ownSize,
|
|
32
|
+
label,
|
|
33
|
+
class: className,
|
|
34
|
+
style,
|
|
35
|
+
...rest
|
|
36
|
+
}: AvatarStackProps = $props();
|
|
37
|
+
|
|
38
|
+
const defaults = useDefaults("AvatarStack");
|
|
39
|
+
// Resolved here, built-in default included, so that the avatars take the stack's size rather
|
|
40
|
+
// than an Avatar default of their own.
|
|
41
|
+
const size = $derived(ownSize ?? defaults().size ?? "md");
|
|
42
|
+
|
|
43
|
+
const stack = $derived(avatarStack(people, max, label));
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<span
|
|
47
|
+
{...rootAttributes(rest)}
|
|
48
|
+
role="img"
|
|
49
|
+
aria-label={stack.name}
|
|
50
|
+
class={classes(rootPart("AvatarStack"), avatarStackClass, className)}
|
|
51
|
+
{style}
|
|
52
|
+
>
|
|
53
|
+
{#each stack.shown as person, index (index)}
|
|
54
|
+
<span aria-hidden="true" class={avatarStackItemClass(size)}>
|
|
55
|
+
<Avatar name={person.name} src={person.src} {size} />
|
|
56
|
+
</span>
|
|
57
|
+
{/each}
|
|
58
|
+
{#if stack.rest > 0}
|
|
59
|
+
<span aria-hidden="true" class={avatarStackRestClass(size)}>+{stack.rest}</span>
|
|
60
|
+
{/if}
|
|
61
|
+
</span>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
|
|
3
|
+
as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
4
|
+
-->
|
|
5
|
+
<!--
|
|
6
|
+
@component
|
|
7
|
+
A short status or category. The words carry the meaning; the color only reinforces it, so a
|
|
8
|
+
badge still reads for someone who cannot tell the tones apart. `dot` adds a small mark for live
|
|
9
|
+
states such as "connected", and `icon` a drawing in front of the words.
|
|
10
|
+
-->
|
|
11
|
+
<script module lang="ts">
|
|
12
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
13
|
+
import type { Snippet } from "svelte";
|
|
14
|
+
import type { BadgeBaseProps } from "./badge.ts";
|
|
15
|
+
|
|
16
|
+
export type { BadgeTone } from "./badge.ts";
|
|
17
|
+
|
|
18
|
+
export type BadgeProps = BadgeBaseProps &
|
|
19
|
+
RootProps & {
|
|
20
|
+
children: Snippet;
|
|
21
|
+
};
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<script lang="ts">
|
|
25
|
+
import { rootAttributes, useDefaults } from "@xds/svelte/base";
|
|
26
|
+
import { badgeClass, badgeDotClass } from "./badge.ts";
|
|
27
|
+
import Icon from "./Icon.svelte";
|
|
28
|
+
import { classes, rootPart } from "./parts.ts";
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
tone: ownTone,
|
|
32
|
+
dot,
|
|
33
|
+
icon,
|
|
34
|
+
class: className,
|
|
35
|
+
style,
|
|
36
|
+
children,
|
|
37
|
+
...rest
|
|
38
|
+
}: BadgeProps = $props();
|
|
39
|
+
|
|
40
|
+
const defaults = useDefaults("Badge");
|
|
41
|
+
const tone = $derived(ownTone ?? defaults().tone);
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<span
|
|
45
|
+
{...rootAttributes(rest)}
|
|
46
|
+
class={classes(rootPart("Badge"), badgeClass(tone), className)}
|
|
47
|
+
{style}
|
|
48
|
+
>{#if dot}<span aria-hidden="true" class={badgeDotClass}></span>{/if}{#if icon}<Icon
|
|
49
|
+
name={icon}
|
|
50
|
+
size="xs"
|
|
51
|
+
/>{/if}{@render children()}</span
|
|
52
|
+
>
|
|
@@ -0,0 +1,94 @@
|
|
|
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 message about the whole view or a section of it. Each tone has its own icon shape, so the tone
|
|
8
|
+
does not depend on color. Problems (`warning`, `danger`) interrupt a screen reader; `info` and
|
|
9
|
+
`success` wait their turn.
|
|
10
|
+
-->
|
|
11
|
+
<script module lang="ts">
|
|
12
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
13
|
+
import type { Snippet } from "svelte";
|
|
14
|
+
import type { BannerBaseProps } from "./banner.ts";
|
|
15
|
+
|
|
16
|
+
export type { BannerTone } from "./banner.ts";
|
|
17
|
+
|
|
18
|
+
export type BannerProps = BannerBaseProps &
|
|
19
|
+
RootProps & {
|
|
20
|
+
/** What the person can do about the message. Drawn under it as a small secondary button. */
|
|
21
|
+
action?: { label: string; onPress: () => void };
|
|
22
|
+
/**
|
|
23
|
+
* Shows a close control. The banner does not hide itself: the handler decides what happens
|
|
24
|
+
* to it.
|
|
25
|
+
*/
|
|
26
|
+
onDismiss?: () => void;
|
|
27
|
+
children: Snippet;
|
|
28
|
+
};
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<script lang="ts">
|
|
32
|
+
import { rootAttributes, useDefaults, useLabels } from "@xds/svelte/base";
|
|
33
|
+
import {
|
|
34
|
+
BANNER_PARTS,
|
|
35
|
+
bannerClass,
|
|
36
|
+
bannerIconClass,
|
|
37
|
+
bannerIconPath,
|
|
38
|
+
bannerRole,
|
|
39
|
+
} from "./banner.ts";
|
|
40
|
+
import Button from "./Button.svelte";
|
|
41
|
+
import IconButton from "./IconButton.svelte";
|
|
42
|
+
import { classes, rootPart } from "./parts.ts";
|
|
43
|
+
|
|
44
|
+
let {
|
|
45
|
+
tone: ownTone,
|
|
46
|
+
title,
|
|
47
|
+
dismissLabel,
|
|
48
|
+
action,
|
|
49
|
+
onDismiss,
|
|
50
|
+
class: className,
|
|
51
|
+
style,
|
|
52
|
+
children,
|
|
53
|
+
...rest
|
|
54
|
+
}: BannerProps = $props();
|
|
55
|
+
|
|
56
|
+
const defaults = useDefaults("Banner");
|
|
57
|
+
const labels = useLabels();
|
|
58
|
+
const tone = $derived(ownTone ?? defaults().tone);
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<div
|
|
62
|
+
{...rootAttributes(rest)}
|
|
63
|
+
role={bannerRole(tone)}
|
|
64
|
+
class={classes(rootPart("Banner"), bannerClass(tone), className)}
|
|
65
|
+
{style}
|
|
66
|
+
>
|
|
67
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" class={bannerIconClass(tone)}>
|
|
68
|
+
<path fill="currentColor" d={bannerIconPath(tone)} />
|
|
69
|
+
</svg>
|
|
70
|
+
<div class={BANNER_PARTS.body}>
|
|
71
|
+
{#if title}
|
|
72
|
+
<p class={BANNER_PARTS.title}>{title}</p>
|
|
73
|
+
{/if}
|
|
74
|
+
<div>{@render children()}</div>
|
|
75
|
+
{#if action}
|
|
76
|
+
<div class={BANNER_PARTS.action}>
|
|
77
|
+
<Button variant="secondary" size="sm" onPress={() => action.onPress()}
|
|
78
|
+
>{action.label}</Button
|
|
79
|
+
>
|
|
80
|
+
</div>
|
|
81
|
+
{/if}
|
|
82
|
+
</div>
|
|
83
|
+
{#if onDismiss}
|
|
84
|
+
<div class={BANNER_PARTS.dismiss}>
|
|
85
|
+
<IconButton
|
|
86
|
+
icon="x"
|
|
87
|
+
label={dismissLabel ?? labels().dismiss}
|
|
88
|
+
variant="ghost"
|
|
89
|
+
size="sm"
|
|
90
|
+
onPress={() => onDismiss()}
|
|
91
|
+
/>
|
|
92
|
+
</div>
|
|
93
|
+
{/if}
|
|
94
|
+
</div>
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
Where the current view sits in the app: the places above it, each a link, then the view
|
|
8
|
+
itself. A navigation landmark; the current place is marked as the page.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
12
|
+
import type { BreadcrumbBaseProps } from "./breadcrumb.ts";
|
|
13
|
+
|
|
14
|
+
export type { BreadcrumbItem } from "./breadcrumb.ts";
|
|
15
|
+
export type BreadcrumbProps = BreadcrumbBaseProps & RootProps;
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { rootAttributes, useLabels } from "@xds/svelte/base";
|
|
20
|
+
import { BREADCRUMB_PARTS, BREADCRUMB_SEPARATOR } from "./breadcrumb.ts";
|
|
21
|
+
import Icon from "./Icon.svelte";
|
|
22
|
+
import Link from "./Link.svelte";
|
|
23
|
+
import { classes, rootPart } from "./parts.ts";
|
|
24
|
+
|
|
25
|
+
let { items, label, class: className, style, ...rest }: BreadcrumbProps = $props();
|
|
26
|
+
const labels = useLabels();
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<nav
|
|
30
|
+
{...rootAttributes(rest)}
|
|
31
|
+
aria-label={label ?? labels().breadcrumb}
|
|
32
|
+
class={classes(rootPart("Breadcrumb"), className)}
|
|
33
|
+
{style}
|
|
34
|
+
>
|
|
35
|
+
<ol class={BREADCRUMB_PARTS.list}>
|
|
36
|
+
<!-- Two places of a trail can share a label, so a place is known by where it is. -->
|
|
37
|
+
{#each items as item, index (index)}
|
|
38
|
+
<li class={BREADCRUMB_PARTS.item}>
|
|
39
|
+
{#if index === items.length - 1}
|
|
40
|
+
<span aria-current="page" class={BREADCRUMB_PARTS.current}>{item.label}</span>
|
|
41
|
+
{:else}
|
|
42
|
+
<Link href={item.href} onPress={item.onPress}>{item.label}</Link>
|
|
43
|
+
<Icon
|
|
44
|
+
name={BREADCRUMB_SEPARATOR.name}
|
|
45
|
+
size={BREADCRUMB_SEPARATOR.size}
|
|
46
|
+
class={BREADCRUMB_PARTS.separator}
|
|
47
|
+
/>
|
|
48
|
+
{/if}
|
|
49
|
+
</li>
|
|
50
|
+
{/each}
|
|
51
|
+
</ol>
|
|
52
|
+
</nav>
|
|
@@ -0,0 +1,126 @@
|
|
|
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 native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach it
|
|
8
|
+
through context.
|
|
9
|
+
|
|
10
|
+
`focus()`, `blur()` and `element()` on the instance reach the native button.
|
|
11
|
+
-->
|
|
12
|
+
<script module lang="ts">
|
|
13
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
14
|
+
import type { Snippet } from "svelte";
|
|
15
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
16
|
+
import type { ButtonBaseProps } from "./button.ts";
|
|
17
|
+
|
|
18
|
+
export type { ButtonVariant, ControlSize } from "./button.ts";
|
|
19
|
+
|
|
20
|
+
export type ButtonProps = ButtonBaseProps &
|
|
21
|
+
RootProps & {
|
|
22
|
+
onPress?: () => void;
|
|
23
|
+
onFocus?: FocusEventHandler<HTMLButtonElement>;
|
|
24
|
+
onBlur?: FocusEventHandler<HTMLButtonElement>;
|
|
25
|
+
/** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
|
|
26
|
+
children?: Snippet;
|
|
27
|
+
};
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<script lang="ts">
|
|
31
|
+
import { rootAttributes, useDefaults, withTrigger } from "@xds/svelte/base";
|
|
32
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
33
|
+
import { BUTTON_ICON, buttonClass, isHeld } from "./button.ts";
|
|
34
|
+
import Icon from "./Icon.svelte";
|
|
35
|
+
import { classes } from "./parts.ts";
|
|
36
|
+
import Spinner from "./Spinner.svelte";
|
|
37
|
+
|
|
38
|
+
let {
|
|
39
|
+
variant: ownVariant,
|
|
40
|
+
size: ownSize,
|
|
41
|
+
iconStart,
|
|
42
|
+
iconEnd,
|
|
43
|
+
selected,
|
|
44
|
+
disabled,
|
|
45
|
+
loading,
|
|
46
|
+
fullWidth = false,
|
|
47
|
+
type = "button",
|
|
48
|
+
onPress,
|
|
49
|
+
onFocus,
|
|
50
|
+
onBlur,
|
|
51
|
+
"aria-label": ariaLabel,
|
|
52
|
+
class: className,
|
|
53
|
+
style,
|
|
54
|
+
children,
|
|
55
|
+
...rest
|
|
56
|
+
}: ButtonProps = $props();
|
|
57
|
+
|
|
58
|
+
const defaults = useDefaults("Button");
|
|
59
|
+
const variant = $derived(ownVariant ?? defaults().variant ?? "secondary");
|
|
60
|
+
const size = $derived(ownSize ?? defaults().size ?? "md");
|
|
61
|
+
|
|
62
|
+
const icon = $derived(BUTTON_ICON[size]);
|
|
63
|
+
const held = $derived(isHeld({ variant, selected, disabled }));
|
|
64
|
+
const attributes = withTrigger(
|
|
65
|
+
(): HTMLButtonAttributes => ({
|
|
66
|
+
type,
|
|
67
|
+
// The recipe gives the root part, `{{prefix}}-button`.
|
|
68
|
+
class: classes(
|
|
69
|
+
buttonClass({
|
|
70
|
+
variant,
|
|
71
|
+
size,
|
|
72
|
+
iconOnly: children === undefined && (iconStart !== undefined || iconEnd !== undefined),
|
|
73
|
+
fullWidth,
|
|
74
|
+
}),
|
|
75
|
+
className,
|
|
76
|
+
),
|
|
77
|
+
style,
|
|
78
|
+
disabled,
|
|
79
|
+
// Loading keeps the button focusable, so focus is not lost while it waits.
|
|
80
|
+
"aria-disabled": loading ? "true" : undefined,
|
|
81
|
+
"data-pending": loading ? "" : undefined,
|
|
82
|
+
"aria-pressed": selected === undefined ? undefined : selected ? "true" : "false",
|
|
83
|
+
"aria-label": ariaLabel,
|
|
84
|
+
onclick: (event) => {
|
|
85
|
+
// The press was taken already: block keyboard Enter/Space form submit or reset too.
|
|
86
|
+
if (loading) {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
onPress?.();
|
|
91
|
+
},
|
|
92
|
+
onfocus: onFocus,
|
|
93
|
+
onblur: onBlur,
|
|
94
|
+
}),
|
|
95
|
+
() => loading === true,
|
|
96
|
+
);
|
|
97
|
+
let button = $state<HTMLButtonElement>();
|
|
98
|
+
|
|
99
|
+
/** Moves the focus to the native button. */
|
|
100
|
+
export function focus(options?: FocusOptions) {
|
|
101
|
+
button?.focus(options);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Takes the focus from the native button. */
|
|
105
|
+
export function blur() {
|
|
106
|
+
button?.blur();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The native button, once it is on the page. */
|
|
110
|
+
export function element(): HTMLButtonElement | undefined {
|
|
111
|
+
return button;
|
|
112
|
+
}
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<!-- The app's id gives way to the one an overlay gives its trigger, which the overlay's own
|
|
116
|
+
parts point at. -->
|
|
117
|
+
<button {...rootAttributes(rest)} {...attributes()} bind:this={button}
|
|
118
|
+
>{#if loading}{#if iconStart}
|
|
119
|
+
<!-- Where the icon was, so the button keeps its width. -->
|
|
120
|
+
<span class={icon.box}><Spinner size="sm" /></span>
|
|
121
|
+
{:else}<Spinner size="sm" />{/if}{:else if iconStart}<Icon
|
|
122
|
+
name={iconStart}
|
|
123
|
+
size={icon.size}
|
|
124
|
+
filled={held}
|
|
125
|
+
/>{/if}{@render children?.()}{#if iconEnd}<Icon name={iconEnd} size={icon.size} />{/if}</button
|
|
126
|
+
>
|