@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,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
|
+
What a screen or a list says when it has nothing to show. It centers itself in its container,
|
|
8
|
+
also vertically when the container is a flex box with room to spare.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
12
|
+
import type { Snippet } from "svelte";
|
|
13
|
+
import type { EmptyStateBaseProps } from "./empty-state.ts";
|
|
14
|
+
|
|
15
|
+
export type EmptyStateProps = EmptyStateBaseProps &
|
|
16
|
+
RootProps & {
|
|
17
|
+
/** The one thing to do about it, usually a Button. */
|
|
18
|
+
action?: Snippet;
|
|
19
|
+
};
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
24
|
+
import { EMPTY_STATE_PARTS } from "./empty-state.ts";
|
|
25
|
+
import Icon from "./Icon.svelte";
|
|
26
|
+
import { classes, rootPart } from "./parts.ts";
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
icon,
|
|
30
|
+
title,
|
|
31
|
+
description,
|
|
32
|
+
action,
|
|
33
|
+
class: className,
|
|
34
|
+
style,
|
|
35
|
+
...rest
|
|
36
|
+
}: EmptyStateProps = $props();
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<div
|
|
40
|
+
{...rootAttributes(rest)}
|
|
41
|
+
class={classes(rootPart("EmptyState"), EMPTY_STATE_PARTS.root, className)}
|
|
42
|
+
{style}
|
|
43
|
+
>
|
|
44
|
+
<Icon name={icon} size="xl" class={EMPTY_STATE_PARTS.icon} />
|
|
45
|
+
<p class={EMPTY_STATE_PARTS.title}>{title}</p>
|
|
46
|
+
{#if description}
|
|
47
|
+
<p class={EMPTY_STATE_PARTS.description}>{description}</p>
|
|
48
|
+
{/if}
|
|
49
|
+
{#if action}
|
|
50
|
+
<div class={EMPTY_STATE_PARTS.action}>{@render action()}</div>
|
|
51
|
+
{/if}
|
|
52
|
+
</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
|
+
An icon from design/icons. It takes the color of the text around it. An arrow or a chevron
|
|
8
|
+
mirrors itself in a right-to-left layout when given `rtl:-scale-x-100` in `class`.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
12
|
+
import type { IconBaseProps } from "./icon.ts";
|
|
13
|
+
|
|
14
|
+
export type IconProps = IconBaseProps & RootProps;
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import { icons, rootAttributes, useDefaults } from "@xds/svelte/base";
|
|
19
|
+
import { iconClass } from "./icon.ts";
|
|
20
|
+
import { classes, rootPart } from "./parts.ts";
|
|
21
|
+
|
|
22
|
+
let {
|
|
23
|
+
name,
|
|
24
|
+
size: ownSize,
|
|
25
|
+
filled,
|
|
26
|
+
label,
|
|
27
|
+
class: className,
|
|
28
|
+
style,
|
|
29
|
+
...rest
|
|
30
|
+
}: IconProps = $props();
|
|
31
|
+
|
|
32
|
+
const defaults = useDefaults("Icon");
|
|
33
|
+
const size = $derived(ownSize ?? defaults().size);
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<svg
|
|
37
|
+
{...rootAttributes(rest)}
|
|
38
|
+
viewBox="0 0 24 24"
|
|
39
|
+
fill={filled ? "currentColor" : "none"}
|
|
40
|
+
stroke="currentColor"
|
|
41
|
+
stroke-width="2"
|
|
42
|
+
stroke-linecap="round"
|
|
43
|
+
stroke-linejoin="round"
|
|
44
|
+
class={classes(rootPart("Icon"), iconClass(size), className)}
|
|
45
|
+
{style}
|
|
46
|
+
role={label ? "img" : undefined}
|
|
47
|
+
aria-label={label || undefined}
|
|
48
|
+
aria-hidden={label ? undefined : "true"}
|
|
49
|
+
>
|
|
50
|
+
{#each icons[name] as path, index (index)}<path d={path} />{/each}
|
|
51
|
+
</svg>
|
|
@@ -0,0 +1,99 @@
|
|
|
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 button that holds only an icon, in Button's variants, sizes and states. It is a square as
|
|
8
|
+
tall as a Button of its size, and its pressable area is never smaller than the minimum target,
|
|
9
|
+
even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger of.
|
|
10
|
+
|
|
11
|
+
`focus()`, `blur()` and `element()` on the instance reach the native button.
|
|
12
|
+
-->
|
|
13
|
+
<script module lang="ts">
|
|
14
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
15
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
16
|
+
import type { IconButtonBaseProps } from "./button.ts";
|
|
17
|
+
|
|
18
|
+
export type IconButtonProps = IconButtonBaseProps &
|
|
19
|
+
RootProps & {
|
|
20
|
+
onPress?: () => void;
|
|
21
|
+
onFocus?: FocusEventHandler<HTMLButtonElement>;
|
|
22
|
+
onBlur?: FocusEventHandler<HTMLButtonElement>;
|
|
23
|
+
};
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import { rootAttributes, useDefaults, withTrigger } from "@xds/svelte/base";
|
|
28
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
29
|
+
import { buttonClass, ICON_BUTTON_BOX, isHeld } from "./button.ts";
|
|
30
|
+
import Icon from "./Icon.svelte";
|
|
31
|
+
import { classes } from "./parts.ts";
|
|
32
|
+
import Spinner from "./Spinner.svelte";
|
|
33
|
+
|
|
34
|
+
let {
|
|
35
|
+
icon,
|
|
36
|
+
label,
|
|
37
|
+
variant: ownVariant,
|
|
38
|
+
size: ownSize,
|
|
39
|
+
selected,
|
|
40
|
+
disabled,
|
|
41
|
+
loading,
|
|
42
|
+
onPress,
|
|
43
|
+
onFocus,
|
|
44
|
+
onBlur,
|
|
45
|
+
class: className,
|
|
46
|
+
style,
|
|
47
|
+
...rest
|
|
48
|
+
}: IconButtonProps = $props();
|
|
49
|
+
|
|
50
|
+
const defaults = useDefaults("IconButton");
|
|
51
|
+
const variant = $derived(ownVariant ?? defaults().variant ?? "ghost");
|
|
52
|
+
const size = $derived(ownSize ?? defaults().size ?? "md");
|
|
53
|
+
|
|
54
|
+
const attributes = withTrigger(
|
|
55
|
+
(): HTMLButtonAttributes => ({
|
|
56
|
+
type: "button",
|
|
57
|
+
// The recipe gives the root part, `{{prefix}}-icon-button`.
|
|
58
|
+
class: classes(buttonClass({ variant, size, iconButton: true }), className),
|
|
59
|
+
style,
|
|
60
|
+
disabled,
|
|
61
|
+
"aria-disabled": loading ? "true" : undefined,
|
|
62
|
+
"data-pending": loading ? "" : undefined,
|
|
63
|
+
"aria-pressed": selected === undefined ? undefined : selected ? "true" : "false",
|
|
64
|
+
"aria-label": label,
|
|
65
|
+
onclick: () => {
|
|
66
|
+
if (!loading) onPress?.();
|
|
67
|
+
},
|
|
68
|
+
onfocus: onFocus,
|
|
69
|
+
onblur: onBlur,
|
|
70
|
+
}),
|
|
71
|
+
() => loading === true,
|
|
72
|
+
);
|
|
73
|
+
let button = $state<HTMLButtonElement>();
|
|
74
|
+
|
|
75
|
+
/** Moves the focus to the native button. */
|
|
76
|
+
export function focus(options?: FocusOptions) {
|
|
77
|
+
button?.focus(options);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Takes the focus from the native button. */
|
|
81
|
+
export function blur() {
|
|
82
|
+
button?.blur();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The native button, once it is on the page. */
|
|
86
|
+
export function element(): HTMLButtonElement | undefined {
|
|
87
|
+
return button;
|
|
88
|
+
}
|
|
89
|
+
</script>
|
|
90
|
+
|
|
91
|
+
<!-- The app's id gives way to the one an overlay gives its trigger, which the overlay's own
|
|
92
|
+
parts point at. -->
|
|
93
|
+
<button {...rootAttributes(rest)} {...attributes()} bind:this={button}>
|
|
94
|
+
{#if loading}
|
|
95
|
+
<span class={ICON_BUTTON_BOX[size]}><Spinner size="sm" /></span>
|
|
96
|
+
{:else}
|
|
97
|
+
<Icon name={icon} {size} filled={isHeld({ variant, selected, disabled })} />
|
|
98
|
+
{/if}
|
|
99
|
+
</button>
|
|
@@ -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>
|