@xds/svelte 1.0.1 → 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.
- .diffend-unextracted-0 +2 -1
- package/dist/Accordion.svelte +7 -2
- package/dist/Avatar.svelte +10 -2
- package/dist/AvatarStack.svelte +11 -1
- package/dist/Badge.svelte +14 -3
- package/dist/Banner.svelte +6 -1
- package/dist/Breadcrumb.svelte +53 -0
- package/dist/Breadcrumb.svelte.d.ts +11 -0
- package/dist/Button.svelte +30 -2
- package/dist/Button.svelte.d.ts +10 -1
- package/dist/Card.svelte +16 -2
- package/dist/Checkbox.svelte +62 -10
- package/dist/Checkbox.svelte.d.ts +14 -3
- package/dist/Chip.svelte +3 -1
- package/dist/ChipBar.svelte +3 -2
- package/dist/Combobox.svelte +194 -0
- package/dist/Combobox.svelte.d.ts +37 -0
- package/dist/CountBadge.svelte +4 -2
- package/dist/DatePicker.svelte +16 -5
- package/dist/DateRangePicker.svelte +6 -1
- package/dist/Dialog.svelte +9 -2
- package/dist/Divider.svelte +7 -3
- package/dist/EmptyState.svelte +15 -3
- package/dist/Icon.svelte +11 -2
- package/dist/IconButton.svelte +30 -2
- package/dist/IconButton.svelte.d.ts +10 -1
- package/dist/Labels.svelte +29 -0
- package/dist/Labels.svelte.d.ts +17 -0
- package/dist/Link.svelte +86 -0
- package/dist/Link.svelte.d.ts +26 -0
- package/dist/MediaCard.svelte +4 -1
- package/dist/Menu.svelte +21 -2
- package/dist/Pagination.svelte +108 -0
- package/dist/Pagination.svelte.d.ts +14 -0
- package/dist/PlaceRow.svelte +6 -1
- 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/ProgressBar.svelte +3 -1
- package/dist/RadioGroup.svelte +23 -8
- package/dist/RadioGroup.svelte.d.ts +4 -2
- package/dist/SearchField.svelte +65 -18
- package/dist/SearchField.svelte.d.ts +14 -4
- package/dist/SectionHeader.svelte +7 -2
- package/dist/SegmentedControl.svelte +21 -7
- package/dist/SegmentedControl.svelte.d.ts +3 -2
- package/dist/Select.svelte +64 -12
- package/dist/Select.svelte.d.ts +9 -2
- package/dist/Sidebar.svelte +3 -0
- package/dist/Skeleton.svelte +10 -2
- package/dist/Slider.svelte +23 -7
- package/dist/Slider.svelte.d.ts +2 -2
- package/dist/Spinner.svelte +3 -2
- package/dist/Switch.svelte +53 -9
- package/dist/Switch.svelte.d.ts +13 -3
- package/dist/Table.svelte +92 -0
- package/dist/Table.svelte.d.ts +17 -0
- package/dist/Tabs.svelte +21 -6
- package/dist/Tabs.svelte.d.ts +2 -1
- package/dist/Text.svelte +3 -1
- package/dist/TextField.svelte +59 -14
- package/dist/TextField.svelte.d.ts +13 -3
- package/dist/Thumbnail.svelte +7 -1
- package/dist/TimePicker.svelte +222 -0
- package/dist/TimePicker.svelte.d.ts +20 -0
- package/dist/Toast.svelte +12 -2
- package/dist/ToastQueue.svelte +57 -0
- package/dist/ToastQueue.svelte.d.ts +20 -0
- package/dist/Tooltip.svelte +9 -2
- package/dist/TooltipOverlay.svelte +9 -2
- package/dist/base.d.ts +14 -0
- package/dist/base.js +27 -0
- package/dist/controllable.svelte.d.ts +28 -0
- package/dist/controllable.svelte.js +41 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +12 -0
- package/dist/labels.svelte.d.ts +13 -0
- package/dist/labels.svelte.js +24 -0
- package/dist/modal-popover.svelte.js +5 -1
- package/dist/presence.svelte.js +5 -2
- package/dist/preview/Component.svelte +8 -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 -1
- package/dist/preview/index.d.ts +1 -0
- package/dist/root.d.ts +4 -2
- 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,24 @@
|
|
|
1
|
+
// The labels that a Labels provider gives the components inside it, in the app's language. They
|
|
2
|
+
// reach a component through context, so that a provider far up the tree applies without each
|
|
3
|
+
// screen passing them along, and each provider merges its own over the ones around it.
|
|
4
|
+
import { DEFAULT_LABELS, mergeLabels } from "@xds/core";
|
|
5
|
+
import { createContext } from "svelte";
|
|
6
|
+
// Not exported from the package: apps give labels with the Labels component.
|
|
7
|
+
const [getLabels, setLabels, hasLabels] = createContext();
|
|
8
|
+
/**
|
|
9
|
+
* For Labels: gives the components inside it the labels around it, with those of `own`
|
|
10
|
+
* replaced. Call it while the component is set up.
|
|
11
|
+
*/
|
|
12
|
+
export function provideLabels(own) {
|
|
13
|
+
const outer = hasLabels() ? getLabels() : undefined;
|
|
14
|
+
const merged = $derived(mergeLabels(outer?.(), own()));
|
|
15
|
+
setLabels(() => merged);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* For a component with labels of its own: the labels of the closest Labels, or the English ones.
|
|
19
|
+
* Call it while the component is set up; the result follows the providers' values.
|
|
20
|
+
*/
|
|
21
|
+
export function useLabels() {
|
|
22
|
+
const labels = hasLabels() ? getLabels() : undefined;
|
|
23
|
+
return () => labels?.() ?? DEFAULT_LABELS;
|
|
24
|
+
}
|
|
@@ -8,8 +8,12 @@ import { preventBodyScroll } from "@zag-js/remove-scroll";
|
|
|
8
8
|
* while the component is set up.
|
|
9
9
|
*/
|
|
10
10
|
export function modalPopover(open, popup) {
|
|
11
|
+
// Derived, so that the effect runs as the popup opens or closes: `open` usually reads the
|
|
12
|
+
// machine's api, which changes with every step of the highlight, and the effect would let the
|
|
13
|
+
// page scroll and hide it from assistive technology again each time.
|
|
14
|
+
const isOpen = $derived(open());
|
|
11
15
|
$effect(() => {
|
|
12
|
-
if (!
|
|
16
|
+
if (!isOpen)
|
|
13
17
|
return;
|
|
14
18
|
const unlock = preventBodyScroll(document);
|
|
15
19
|
// A frame later, once the popup is shown.
|
package/dist/presence.svelte.js
CHANGED
|
@@ -6,14 +6,17 @@ import { afterAnimations } from "@xds/core";
|
|
|
6
6
|
*/
|
|
7
7
|
export function createPresence(open, parts) {
|
|
8
8
|
let exited = $state(true);
|
|
9
|
+
// Derived, so that the effect runs as the overlay opens or closes, not on every change to the
|
|
10
|
+
// machine that `open` usually reads.
|
|
11
|
+
const isOpen = $derived(open());
|
|
9
12
|
$effect(() => {
|
|
10
|
-
if (
|
|
13
|
+
if (isOpen) {
|
|
11
14
|
exited = false;
|
|
12
15
|
return;
|
|
13
16
|
}
|
|
14
17
|
// Opening again before the animation ends stops the wait.
|
|
15
18
|
return afterAnimations(parts(), () => (exited = true));
|
|
16
19
|
});
|
|
17
|
-
const present = $derived(
|
|
20
|
+
const present = $derived(isOpen || !exited);
|
|
18
21
|
return () => present;
|
|
19
22
|
}
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
type Slot,
|
|
17
17
|
type State,
|
|
18
18
|
} from "@xds/core/preview";
|
|
19
|
-
import { type Component, type Snippet, untrack } from "svelte";
|
|
20
|
-
import { COMPONENTS } from "./components.js";
|
|
19
|
+
import { type Component, getContext, type Snippet, untrack } from "svelte";
|
|
20
|
+
import { COMPONENTS, COMPONENTS_KEY, type PreviewComponents } from "./components.js";
|
|
21
21
|
import Snippets from "./Snippets.svelte";
|
|
22
22
|
|
|
23
23
|
let { node, host }: { node: ComponentNode; host: Host<Snippet> } = $props();
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
const values: Record<string, unknown> = {};
|
|
30
30
|
const slots: (readonly [string, Slot<State>])[] = [];
|
|
31
31
|
const takesNode = nodeProps[name] ?? [];
|
|
32
|
+
// Only the keys the data has: a control tells whether it is controlled by whether `value`
|
|
33
|
+
// or `checked` is passed at all, so one the data leaves out is not passed as `undefined`.
|
|
32
34
|
for (const [key, value] of Object.entries(given)) {
|
|
33
35
|
// A snippet only for what the data gives: a prop left undefined stays unset.
|
|
34
36
|
if (takesNode.includes(key) && value !== undefined) slots.push([key, value as Slot<State>]);
|
|
@@ -46,10 +48,13 @@
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
const { values, slots } = untrack(() => split(node, host));
|
|
51
|
+
const components = getContext<PreviewComponents | undefined>(COMPONENTS_KEY);
|
|
49
52
|
</script>
|
|
50
53
|
|
|
51
54
|
<Snippets
|
|
52
|
-
component={COMPONENTS[node.name] as Component<
|
|
55
|
+
component={(components?.[node.name] ?? COMPONENTS[node.name]) as Component<
|
|
56
|
+
Record<string, unknown>
|
|
57
|
+
>}
|
|
53
58
|
props={values}
|
|
54
59
|
{slots}
|
|
55
60
|
{host}
|
|
@@ -7,10 +7,16 @@
|
|
|
7
7
|
-->
|
|
8
8
|
<script lang="ts">
|
|
9
9
|
import type { Host, Screen } from "@xds/core/preview";
|
|
10
|
-
import { onMount, type Snippet, untrack } from "svelte";
|
|
10
|
+
import { onMount, setContext, type Snippet, untrack } from "svelte";
|
|
11
|
+
import { COMPONENTS_KEY, type PreviewComponents } from "./components.js";
|
|
11
12
|
import Draw from "./Draw.svelte";
|
|
12
13
|
|
|
13
|
-
let { screen }: { screen: Screen } = $props();
|
|
14
|
+
let { screen, components }: { screen: Screen; components?: PreviewComponents } = $props();
|
|
15
|
+
|
|
16
|
+
setContext(
|
|
17
|
+
COMPONENTS_KEY,
|
|
18
|
+
untrack(() => components),
|
|
19
|
+
);
|
|
14
20
|
|
|
15
21
|
const { state: first, root, mount } = untrack(() => screen);
|
|
16
22
|
const values: Record<string, unknown> = {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Screen } from "@xds/core/preview";
|
|
2
|
+
import { type PreviewComponents } from "./components.js";
|
|
2
3
|
type $$ComponentProps = {
|
|
3
4
|
screen: Screen;
|
|
5
|
+
components?: PreviewComponents;
|
|
4
6
|
};
|
|
5
7
|
/**
|
|
6
8
|
* Draws a screen of @xds/core/preview (the design preview, a behavior test's scenario) with
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComponentName, Components } from "@xds/core/preview";
|
|
2
2
|
import type { Component, Snippet } from "svelte";
|
|
3
|
-
type
|
|
3
|
+
type ComponentTable = {
|
|
4
4
|
readonly [N in ComponentName]: Component<Components<Snippet>[N]>;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
@@ -8,5 +8,12 @@ type Table = {
|
|
|
8
8
|
* each component, which a declaration file cannot name, and the published package would ship
|
|
9
9
|
* this module without one.
|
|
10
10
|
*/
|
|
11
|
-
export declare const COMPONENTS:
|
|
11
|
+
export declare const COMPONENTS: ComponentTable;
|
|
12
|
+
/**
|
|
13
|
+
* Components to draw in place of the library's, by name: an app's ejected copies (`xds eject`),
|
|
14
|
+
* which the design preview then shows as it shows the library's.
|
|
15
|
+
*/
|
|
16
|
+
export type PreviewComponents = Partial<ComponentTable>;
|
|
17
|
+
/** The context that Preview hands PreviewComponents to each component of the screen in. */
|
|
18
|
+
export declare const COMPONENTS_KEY: unique symbol;
|
|
12
19
|
export {};
|
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
// keep-sorted start
|
|
3
|
+
Accordion, Avatar, AvatarStack, Badge, Banner, Breadcrumb, Button, Card, Checkbox, Chip, ChipBar, Combobox, CountBadge, DatePicker, DateRangePicker, Defaults, Dialog, Divider, EmptyState, Icon, IconButton, Labels, Link, ListRow, MediaCard, Menu, Pagination, Popover, ProgressBar, RadioGroup, SearchField, SectionHeader, SegmentedControl, Select, Sidebar, Skeleton, Slider, Spinner, Switch, Table, Tabs, Text, TextField, Thumbnail, TimePicker, Toast, ToastQueue, Tooltip,
|
|
4
|
+
// keep-sorted end
|
|
5
|
+
} from "../index.js";
|
|
2
6
|
/**
|
|
3
7
|
* Every component the data can name, each taking the props the data gives it, with a snippet
|
|
4
8
|
* for each node. They are imported by name: a namespace import of the entry would put every
|
|
5
9
|
* component in the chunk that the app's own screens load too.
|
|
6
10
|
*/
|
|
7
11
|
const components = {
|
|
12
|
+
// keep-sorted start
|
|
8
13
|
Accordion,
|
|
9
14
|
Avatar,
|
|
10
15
|
AvatarStack,
|
|
11
16
|
Badge,
|
|
12
17
|
Banner,
|
|
18
|
+
Breadcrumb,
|
|
13
19
|
Button,
|
|
14
20
|
Card,
|
|
15
21
|
Checkbox,
|
|
16
22
|
Chip,
|
|
17
23
|
ChipBar,
|
|
24
|
+
Combobox,
|
|
18
25
|
CountBadge,
|
|
19
26
|
DatePicker,
|
|
20
27
|
DateRangePicker,
|
|
@@ -24,9 +31,13 @@ const components = {
|
|
|
24
31
|
EmptyState,
|
|
25
32
|
Icon,
|
|
26
33
|
IconButton,
|
|
34
|
+
Labels,
|
|
35
|
+
Link,
|
|
27
36
|
ListRow,
|
|
28
37
|
MediaCard,
|
|
29
38
|
Menu,
|
|
39
|
+
Pagination,
|
|
40
|
+
Popover,
|
|
30
41
|
ProgressBar,
|
|
31
42
|
RadioGroup,
|
|
32
43
|
SearchField,
|
|
@@ -38,12 +49,16 @@ const components = {
|
|
|
38
49
|
Slider,
|
|
39
50
|
Spinner,
|
|
40
51
|
Switch,
|
|
52
|
+
Table,
|
|
41
53
|
Tabs,
|
|
42
54
|
Text,
|
|
43
55
|
TextField,
|
|
44
56
|
Thumbnail,
|
|
57
|
+
TimePicker,
|
|
45
58
|
Toast,
|
|
59
|
+
ToastQueue,
|
|
46
60
|
Tooltip,
|
|
61
|
+
// keep-sorted end
|
|
47
62
|
};
|
|
48
63
|
/**
|
|
49
64
|
* The table under a type of its own: inferred, its type would name the class that Svelte gives
|
|
@@ -51,4 +66,6 @@ const components = {
|
|
|
51
66
|
* this module without one.
|
|
52
67
|
*/
|
|
53
68
|
export const COMPONENTS = components;
|
|
69
|
+
/** The context that Preview hands PreviewComponents to each component of the screen in. */
|
|
70
|
+
export const COMPONENTS_KEY = Symbol("preview components");
|
|
54
71
|
({});
|
package/dist/preview/index.d.ts
CHANGED
package/dist/root.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { RootAttributes } from "@xds/core";
|
|
1
2
|
/**
|
|
2
3
|
* Layer 7 of the library's customization: what an app adds to a component's root element, the
|
|
3
4
|
* one with its root part (`xds-<name>`). For an overlay that is its surface: the menu, the
|
|
4
|
-
* tooltip, the dialog or the toast, while it is open.
|
|
5
|
+
* tooltip, the dialog or the toast, while it is open. An `id` and `data-*` attributes, such as a
|
|
6
|
+
* test's `data-testid`, go on it too.
|
|
5
7
|
*/
|
|
6
|
-
export type RootProps = {
|
|
8
|
+
export type RootProps = RootAttributes & {
|
|
7
9
|
/** Classes added to the root element's own. */
|
|
8
10
|
class?: string;
|
|
9
11
|
/** Inline style for the root element. */
|
|
@@ -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>
|