@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,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
|
+
Text that takes the person somewhere, in the type of the text around it. It is underlined, so
|
|
8
|
+
it does not depend on color. With `href` it is a native link; without one, a button that
|
|
9
|
+
assistive technology hears as a link.
|
|
10
|
+
|
|
11
|
+
`focus()`, `blur()` and `element()` on the instance reach the native element.
|
|
12
|
+
-->
|
|
13
|
+
<script module lang="ts">
|
|
14
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
15
|
+
import type { Snippet } from "svelte";
|
|
16
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
17
|
+
import type { LinkBaseProps } from "./link.ts";
|
|
18
|
+
|
|
19
|
+
export type LinkProps = LinkBaseProps &
|
|
20
|
+
RootProps & {
|
|
21
|
+
/** Called on a press, before the browser follows `href`. A disabled link never calls it. */
|
|
22
|
+
onPress?: () => void;
|
|
23
|
+
onFocus?: FocusEventHandler<HTMLElement>;
|
|
24
|
+
onBlur?: FocusEventHandler<HTMLElement>;
|
|
25
|
+
/** The text, which names the link. */
|
|
26
|
+
children: Snippet;
|
|
27
|
+
};
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<script lang="ts">
|
|
31
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
32
|
+
import Icon from "./Icon.svelte";
|
|
33
|
+
import { LINK_ICON, LINK_PARTS, linkElement } from "./link.ts";
|
|
34
|
+
import { classes, rootPart } from "./parts.ts";
|
|
35
|
+
|
|
36
|
+
let {
|
|
37
|
+
href,
|
|
38
|
+
external = false,
|
|
39
|
+
disabled = false,
|
|
40
|
+
onPress,
|
|
41
|
+
onFocus,
|
|
42
|
+
onBlur,
|
|
43
|
+
class: className,
|
|
44
|
+
style,
|
|
45
|
+
children,
|
|
46
|
+
...rest
|
|
47
|
+
}: LinkProps = $props();
|
|
48
|
+
|
|
49
|
+
const shape = $derived(linkElement({ href, external, disabled }));
|
|
50
|
+
let root = $state<HTMLElement>();
|
|
51
|
+
|
|
52
|
+
/** Moves the focus to the native element. */
|
|
53
|
+
export function focus(options?: FocusOptions) {
|
|
54
|
+
root?.focus(options);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Takes the focus from the native element. */
|
|
58
|
+
export function blur() {
|
|
59
|
+
root?.blur();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The native element, an `<a>` or a `<button>`, once it is on the page. */
|
|
63
|
+
export function element(): HTMLElement | undefined {
|
|
64
|
+
return root;
|
|
65
|
+
}
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<svelte:element
|
|
69
|
+
this={shape.tag}
|
|
70
|
+
bind:this={root}
|
|
71
|
+
{...rootAttributes(rest)}
|
|
72
|
+
{...shape.attributes}
|
|
73
|
+
class={classes(rootPart("Link"), className)}
|
|
74
|
+
{style}
|
|
75
|
+
onclick={() => {
|
|
76
|
+
if (!disabled) onPress?.();
|
|
77
|
+
}}
|
|
78
|
+
onfocus={onFocus}
|
|
79
|
+
onblur={onBlur}
|
|
80
|
+
>{@render children()}{#if external}<Icon
|
|
81
|
+
name={LINK_ICON.name}
|
|
82
|
+
size={LINK_ICON.size}
|
|
83
|
+
class={LINK_PARTS.icon}
|
|
84
|
+
/>{/if}</svelte:element
|
|
85
|
+
>
|
|
@@ -0,0 +1,33 @@
|
|
|
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 line of a list or a settings screen. Separate rows with a Divider.
|
|
8
|
+
-->
|
|
9
|
+
<script module lang="ts">
|
|
10
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
11
|
+
import type { Snippet } from "svelte";
|
|
12
|
+
import type { ListRowBaseProps } from "./list-row.ts";
|
|
13
|
+
|
|
14
|
+
export type ListRowProps = ListRowBaseProps &
|
|
15
|
+
RootProps & {
|
|
16
|
+
/** In front of the title: an avatar or an icon. */
|
|
17
|
+
leading?: Snippet;
|
|
18
|
+
/** At the far end: a value, a badge or a switch. */
|
|
19
|
+
trailing?: Snippet;
|
|
20
|
+
/** Makes the whole row a button. Do not put another control in `trailing` then. */
|
|
21
|
+
onPress?: () => void;
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<script lang="ts">
|
|
26
|
+
import { classes, rootPart } from "./parts.ts";
|
|
27
|
+
import PlaceRow from "./PlaceRow.svelte";
|
|
28
|
+
|
|
29
|
+
let { class: className, ...props }: ListRowProps = $props();
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<!-- The root part is the ListRow's: a Sidebar's rows are PlaceRows, but not ListRows of the app. -->
|
|
33
|
+
<PlaceRow {...props} class={classes(rootPart("ListRow"), className)} current="true" />
|
|
@@ -0,0 +1,117 @@
|
|
|
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 thumbnail with its title and details: a video in a feed, an article in a list.
|
|
8
|
+
|
|
9
|
+
With `onPress` the whole card is one button with no surface at rest: under a pointer and while
|
|
10
|
+
pressed it takes the card's fills, and it has a focus ring. The button is named by the title
|
|
11
|
+
followed by the details. `action` is a separate control beside it, so pressing it does not
|
|
12
|
+
press the card.
|
|
13
|
+
-->
|
|
14
|
+
<script module lang="ts">
|
|
15
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
16
|
+
import type { Snippet } from "svelte";
|
|
17
|
+
import type { MediaCardBaseProps } from "./media-card.ts";
|
|
18
|
+
|
|
19
|
+
export type MediaCardProps = MediaCardBaseProps &
|
|
20
|
+
RootProps & {
|
|
21
|
+
/** Before the text in the vertical layout, such as an Avatar. */
|
|
22
|
+
leading?: Snippet;
|
|
23
|
+
/** At the end of the text: an IconButton or a Menu. It stays a control of its own. */
|
|
24
|
+
action?: Snippet;
|
|
25
|
+
/** Makes the whole card one button. */
|
|
26
|
+
onPress?: () => void;
|
|
27
|
+
};
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<script lang="ts">
|
|
31
|
+
import { rootAttributes, useDefaults } from "@xds/svelte/base";
|
|
32
|
+
import {
|
|
33
|
+
MEDIA_CARD_PARTS,
|
|
34
|
+
mediaCardContentClass,
|
|
35
|
+
mediaCardIds,
|
|
36
|
+
mediaCardThumbnailClass,
|
|
37
|
+
} from "./media-card.ts";
|
|
38
|
+
import { classes, rootPart } from "./parts.ts";
|
|
39
|
+
import Thumbnail from "./Thumbnail.svelte";
|
|
40
|
+
|
|
41
|
+
let {
|
|
42
|
+
layout: ownLayout,
|
|
43
|
+
src,
|
|
44
|
+
alt,
|
|
45
|
+
// The card's own ratio, not one the app gives its other thumbnails.
|
|
46
|
+
ratio = "16:9",
|
|
47
|
+
badge,
|
|
48
|
+
progress,
|
|
49
|
+
title,
|
|
50
|
+
meta,
|
|
51
|
+
leading,
|
|
52
|
+
action,
|
|
53
|
+
onPress,
|
|
54
|
+
class: className,
|
|
55
|
+
style,
|
|
56
|
+
...rest
|
|
57
|
+
}: MediaCardProps = $props();
|
|
58
|
+
|
|
59
|
+
const defaults = useDefaults("MediaCard");
|
|
60
|
+
const layout = $derived(ownLayout ?? defaults().layout);
|
|
61
|
+
const root = $derived(classes(rootPart("MediaCard"), className));
|
|
62
|
+
|
|
63
|
+
const id = $props.id();
|
|
64
|
+
const ids = $derived(mediaCardIds(id, meta));
|
|
65
|
+
const horizontal = $derived(layout === "horizontal");
|
|
66
|
+
const pressable = $derived(onPress !== undefined);
|
|
67
|
+
// On a pressable card the button says all of this, so the parts are hidden from assistive
|
|
68
|
+
// technology and only the action is left beside it.
|
|
69
|
+
const hidden = $derived(pressable ? "true" : undefined);
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
{#snippet content()}
|
|
73
|
+
<div class={mediaCardContentClass({ horizontal, pressable })}>
|
|
74
|
+
<span aria-hidden={hidden} class={mediaCardThumbnailClass(horizontal)}>
|
|
75
|
+
<Thumbnail {src} alt={alt ?? ""} {ratio} {badge} {progress} />
|
|
76
|
+
</span>
|
|
77
|
+
<div class={MEDIA_CARD_PARTS.body}>
|
|
78
|
+
{#if !horizontal && leading}
|
|
79
|
+
<span aria-hidden={hidden} class={MEDIA_CARD_PARTS.leading}>{@render leading()}</span>
|
|
80
|
+
{/if}
|
|
81
|
+
<span aria-hidden={hidden} class={MEDIA_CARD_PARTS.text}>
|
|
82
|
+
<span id={ids.title} class={MEDIA_CARD_PARTS.title}>{title}</span>
|
|
83
|
+
<!-- Two details may read the same, so they are told apart by their position. -->
|
|
84
|
+
{#each meta ?? [] as line, index (index)}
|
|
85
|
+
<span id={ids.details[index]} class={MEDIA_CARD_PARTS.meta}>{line}</span>
|
|
86
|
+
{/each}
|
|
87
|
+
</span>
|
|
88
|
+
{#if action}
|
|
89
|
+
<div class={MEDIA_CARD_PARTS.action}>{@render action()}</div>
|
|
90
|
+
{/if}
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
{/snippet}
|
|
94
|
+
|
|
95
|
+
{#if pressable}
|
|
96
|
+
<div {...rootAttributes(rest)} class={classes(MEDIA_CARD_PARTS.pressable, root)} {style}>
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
onclick={() => onPress?.()}
|
|
100
|
+
aria-labelledby={ids.names}
|
|
101
|
+
class={MEDIA_CARD_PARTS.button}
|
|
102
|
+
></button>
|
|
103
|
+
{@render content()}
|
|
104
|
+
</div>
|
|
105
|
+
{:else}
|
|
106
|
+
<!-- A group, not a fieldset: a fieldset groups form controls, and sizes itself to its
|
|
107
|
+
content, which would undo the ellipses. -->
|
|
108
|
+
<div
|
|
109
|
+
{...rootAttributes(rest)}
|
|
110
|
+
role="group"
|
|
111
|
+
aria-labelledby={ids.names}
|
|
112
|
+
class={classes(MEDIA_CARD_PARTS.group, root)}
|
|
113
|
+
{style}
|
|
114
|
+
>
|
|
115
|
+
{@render content()}
|
|
116
|
+
</div>
|
|
117
|
+
{/if}
|
|
@@ -0,0 +1,183 @@
|
|
|
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 list of actions that opens from a control. Choosing an item calls its `onSelect` and closes
|
|
8
|
+
the menu; a press outside or Escape closes it too, and focus goes back to the trigger.
|
|
9
|
+
|
|
10
|
+
The trigger reports that it opens a menu and whether the menu is open. The arrow keys move the
|
|
11
|
+
highlight and Enter chooses.
|
|
12
|
+
-->
|
|
13
|
+
<script module lang="ts">
|
|
14
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
15
|
+
import type { Snippet } from "svelte";
|
|
16
|
+
import type { MenuBaseProps } from "./menu.ts";
|
|
17
|
+
|
|
18
|
+
export type { MenuItem } from "./menu.ts";
|
|
19
|
+
|
|
20
|
+
/** Its root is the menu, while it is open, not its trigger. */
|
|
21
|
+
export type MenuProps = MenuBaseProps &
|
|
22
|
+
RootProps & {
|
|
23
|
+
/** The control that opens the menu: a Button or an IconButton. */
|
|
24
|
+
trigger: Snippet;
|
|
25
|
+
};
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<script lang="ts">
|
|
29
|
+
import {
|
|
30
|
+
createItemPropsCache,
|
|
31
|
+
createPresence,
|
|
32
|
+
keepListKeys,
|
|
33
|
+
leaveEscapeToFields,
|
|
34
|
+
modalPopover,
|
|
35
|
+
Portal,
|
|
36
|
+
provideTrigger,
|
|
37
|
+
readCssPx,
|
|
38
|
+
rootAttributes,
|
|
39
|
+
space,
|
|
40
|
+
type TriggerProps,
|
|
41
|
+
underlayLayerStyle,
|
|
42
|
+
} from "@xds/svelte/base";
|
|
43
|
+
import * as menu from "@zag-js/menu";
|
|
44
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
45
|
+
import Icon from "./Icon.svelte";
|
|
46
|
+
import { firstMenuValue, layoutRect, menuItemClass, opensOnPress } from "./menu.ts";
|
|
47
|
+
import { classes } from "./parts.ts";
|
|
48
|
+
|
|
49
|
+
let {
|
|
50
|
+
label,
|
|
51
|
+
items,
|
|
52
|
+
align = "start",
|
|
53
|
+
trigger,
|
|
54
|
+
class: className,
|
|
55
|
+
style,
|
|
56
|
+
...rest
|
|
57
|
+
}: MenuProps = $props();
|
|
58
|
+
|
|
59
|
+
const id = $props.id();
|
|
60
|
+
const service = useMachine(menu.machine, () => ({
|
|
61
|
+
id,
|
|
62
|
+
// The app's id names the menu, and the trigger's aria-controls points there.
|
|
63
|
+
ids: rest.id === undefined ? undefined : { content: rest.id },
|
|
64
|
+
"aria-label": label,
|
|
65
|
+
positioning: {
|
|
66
|
+
placement: `bottom-${align}` as const,
|
|
67
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
68
|
+
getAnchorRect: (anchor) => (anchor instanceof HTMLElement ? layoutRect(anchor) : null),
|
|
69
|
+
},
|
|
70
|
+
onSelect: (details: menu.SelectionDetails) => {
|
|
71
|
+
// The values are positions, because two items may have the same label.
|
|
72
|
+
const item = items[Number(details.value)];
|
|
73
|
+
if (item && item !== "separator") item.onSelect();
|
|
74
|
+
},
|
|
75
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
76
|
+
// The arrow keys go round from the last item to the first, as in a native menu.
|
|
77
|
+
loopFocus: true,
|
|
78
|
+
}));
|
|
79
|
+
const api = $derived(menu.connect(service, normalizeProps));
|
|
80
|
+
// The items' props as they last were while they draw the same, so that a step of the highlight
|
|
81
|
+
// sets the attributes and the handlers of the two items it moves between, not of every item.
|
|
82
|
+
const keep = createItemPropsCache();
|
|
83
|
+
// Whether the last press on the trigger opened the menu, which its click must then not do.
|
|
84
|
+
let pressOpened = false;
|
|
85
|
+
provideTrigger(() => {
|
|
86
|
+
// Zag's handler for a press is left out: it keeps the press from focusing the trigger, so
|
|
87
|
+
// the focus would reach the menu, and come back to the trigger as the menu closes, only
|
|
88
|
+
// from a script, which the browser marks with the keyboard ring.
|
|
89
|
+
const { onpointerdown: _onPointerDown, ...rest } = api.getTriggerProps() as TriggerProps;
|
|
90
|
+
return mergeProps(rest, {
|
|
91
|
+
// Added to the control's own class; the trigger looks pressed while its menu is open.
|
|
92
|
+
class: "{{prefix}}-menu__trigger",
|
|
93
|
+
// A mouse opens the menu as its button goes down; touch and pen open it on the click, as
|
|
94
|
+
// Zag does.
|
|
95
|
+
onpointerdown: (event: PointerEvent & { currentTarget: HTMLElement }) => {
|
|
96
|
+
pressOpened = opensOnPress(event) && !api.open;
|
|
97
|
+
if (pressOpened) api.setOpen(true);
|
|
98
|
+
},
|
|
99
|
+
onclick: (event: MouseEvent) => {
|
|
100
|
+
// A click with no pointer behind it comes from a screen reader or a script.
|
|
101
|
+
const pointer = event.detail !== 0;
|
|
102
|
+
// The press opened the menu already. This handler runs before Zag's, which skips a
|
|
103
|
+
// handled click. Not told by the click's pointer type: a browser may send the click as
|
|
104
|
+
// a plain mouse event.
|
|
105
|
+
if (pressOpened && pointer) {
|
|
106
|
+
pressOpened = false;
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (pointer) return;
|
|
111
|
+
// After the machine has opened the menu.
|
|
112
|
+
requestAnimationFrame(() => {
|
|
113
|
+
if (!api.open) return;
|
|
114
|
+
const first = firstMenuValue(items);
|
|
115
|
+
if (first !== undefined) api.setHighlightedValue(first);
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
let positioner = $state<HTMLDivElement>();
|
|
121
|
+
let surface = $state<HTMLDivElement>();
|
|
122
|
+
modalPopover(
|
|
123
|
+
() => api.open,
|
|
124
|
+
() => positioner,
|
|
125
|
+
);
|
|
126
|
+
const present = createPresence(
|
|
127
|
+
() => api.open,
|
|
128
|
+
() => [surface],
|
|
129
|
+
);
|
|
130
|
+
const content = $derived(
|
|
131
|
+
mergeProps(api.getContentProps(), {
|
|
132
|
+
...rootAttributes(rest),
|
|
133
|
+
class: classes("{{prefix}}-menu", className),
|
|
134
|
+
style,
|
|
135
|
+
// This handler runs before Zag's.
|
|
136
|
+
onkeydown: (event: KeyboardEvent) =>
|
|
137
|
+
keepListKeys(event, surface, ".{{prefix}}-menu__item:not([data-disabled])", (value) =>
|
|
138
|
+
api.setHighlightedValue(value),
|
|
139
|
+
),
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
</script>
|
|
143
|
+
|
|
144
|
+
{@render trigger()}
|
|
145
|
+
<Portal>
|
|
146
|
+
{#if api.open}
|
|
147
|
+
<!-- Takes a press outside, which then only closes the menu. The focus stays in the menu until
|
|
148
|
+
the menu hands it back to the trigger. -->
|
|
149
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
150
|
+
<div
|
|
151
|
+
class="{{prefix}}-menu__underlay"
|
|
152
|
+
style:--layer-index={underlayLayerStyle(api.getPositionerProps().style)?.["--layer-index"]}
|
|
153
|
+
onmousedown={(event) => event.preventDefault()}
|
|
154
|
+
></div>
|
|
155
|
+
{/if}
|
|
156
|
+
<div {...api.getPositionerProps()} bind:this={positioner} class="{{prefix}}-menu__positioner">
|
|
157
|
+
<!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
|
|
158
|
+
<div {...content} bind:this={surface} hidden={!present()}>
|
|
159
|
+
{#each items as item, index (index)}
|
|
160
|
+
{#if item === "separator"}
|
|
161
|
+
<div {...api.getSeparatorProps()} class="{{prefix}}-menu__separator"></div>
|
|
162
|
+
{:else}
|
|
163
|
+
<div
|
|
164
|
+
{...keep(
|
|
165
|
+
`item:${index}`,
|
|
166
|
+
api.getItemProps({ value: String(index), disabled: item.disabled }),
|
|
167
|
+
)}
|
|
168
|
+
class={menuItemClass(item.danger)}
|
|
169
|
+
>
|
|
170
|
+
{#if item.icon}
|
|
171
|
+
<Icon name={item.icon} size="sm" class="{{prefix}}-menu__item-icon" />
|
|
172
|
+
{/if}
|
|
173
|
+
<span class="flex-1">{item.label}</span>
|
|
174
|
+
<!-- Named, so a screen reader hears the state that the check shows. -->
|
|
175
|
+
{#if item.selected}
|
|
176
|
+
<Icon name="check" size="sm" label="Selected" />
|
|
177
|
+
{/if}
|
|
178
|
+
</div>
|
|
179
|
+
{/if}
|
|
180
|
+
{/each}
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
</Portal>
|
|
@@ -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}
|