@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,91 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A surface that opens beside the control that opens it, for details or a short task that do not
|
|
4
|
+
need the whole screen: a press outside, Escape or its close button closes it, and the focus goes
|
|
5
|
+
back to the trigger. It is a dialog named by its title, and not modal: the page stays as it is
|
|
6
|
+
behind it. Without `open` it keeps its own, from `defaultOpen`.
|
|
7
|
+
-->
|
|
8
|
+
<script module lang="ts">
|
|
9
|
+
import type { PopoverBaseProps } from "@xds/core";
|
|
10
|
+
import type { Snippet } from "svelte";
|
|
11
|
+
import type { RootProps } from "./root.js";
|
|
12
|
+
|
|
13
|
+
/** Its root is the surface, while it is open, not its trigger. */
|
|
14
|
+
export type PopoverProps = PopoverBaseProps &
|
|
15
|
+
RootProps & {
|
|
16
|
+
/** The control that opens it: a Button or an IconButton. */
|
|
17
|
+
trigger: Snippet;
|
|
18
|
+
/** Called with whether it is open, as it opens and closes. */
|
|
19
|
+
onOpenChange?: (open: boolean) => void;
|
|
20
|
+
/** What it holds: a few lines of text, a short form, actions. */
|
|
21
|
+
children?: Snippet;
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<script lang="ts">
|
|
26
|
+
import { space } from "@xds/tokens";
|
|
27
|
+
import { leaveEscapeToFields, POPOVER_PARTS, readCssPx } from "@xds/core";
|
|
28
|
+
import * as popover from "@zag-js/popover";
|
|
29
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
30
|
+
import { controllable } from "./controllable.svelte.js";
|
|
31
|
+
import PopoverSurface from "./PopoverSurface.svelte";
|
|
32
|
+
import { provideTrigger, type TriggerProps } from "./trigger.svelte.js";
|
|
33
|
+
|
|
34
|
+
// `open` stays in the rest, where whether it is given at all can be asked.
|
|
35
|
+
let {
|
|
36
|
+
title,
|
|
37
|
+
placement,
|
|
38
|
+
closeLabel,
|
|
39
|
+
defaultOpen,
|
|
40
|
+
onOpenChange,
|
|
41
|
+
trigger,
|
|
42
|
+
children,
|
|
43
|
+
class: className,
|
|
44
|
+
style,
|
|
45
|
+
...rest
|
|
46
|
+
}: PopoverProps = $props();
|
|
47
|
+
|
|
48
|
+
const control = controllable<boolean | undefined, boolean>(
|
|
49
|
+
() => rest,
|
|
50
|
+
"open",
|
|
51
|
+
() => rest.open,
|
|
52
|
+
() => defaultOpen ?? false,
|
|
53
|
+
() => onOpenChange,
|
|
54
|
+
);
|
|
55
|
+
const id = $props.id();
|
|
56
|
+
let content = $state<HTMLElement>();
|
|
57
|
+
const service = useMachine(popover.machine, () => ({
|
|
58
|
+
id,
|
|
59
|
+
// The app's id names the surface, and the trigger's aria-controls points there.
|
|
60
|
+
ids: rest.id === undefined ? undefined : { content: rest.id },
|
|
61
|
+
open: control.current ?? false,
|
|
62
|
+
onOpenChange: (details: popover.OpenChangeDetails) => control.set(details.open),
|
|
63
|
+
positioning: {
|
|
64
|
+
placement: placement ?? "bottom",
|
|
65
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
66
|
+
},
|
|
67
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
68
|
+
// The surface itself rather than its first control: a screen reader then reads the title
|
|
69
|
+
// first, and the close button is the next stop.
|
|
70
|
+
initialFocusEl: () => content ?? null,
|
|
71
|
+
}));
|
|
72
|
+
const api = $derived(popover.connect(service, normalizeProps));
|
|
73
|
+
// Added to the control's own class; the trigger looks pressed while it is open.
|
|
74
|
+
provideTrigger(
|
|
75
|
+
() => mergeProps(api.getTriggerProps(), { class: POPOVER_PARTS.trigger }) as TriggerProps,
|
|
76
|
+
);
|
|
77
|
+
// What the app gives the root, without `open`, which is the machine's.
|
|
78
|
+
const { open: _open, ...attributes } = $derived(rest);
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
{@render trigger()}
|
|
82
|
+
<PopoverSurface
|
|
83
|
+
api={() => api}
|
|
84
|
+
{title}
|
|
85
|
+
{closeLabel}
|
|
86
|
+
class={className}
|
|
87
|
+
{style}
|
|
88
|
+
{attributes}
|
|
89
|
+
{children}
|
|
90
|
+
bind:content
|
|
91
|
+
/>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PopoverBaseProps } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { RootProps } from "./root.js";
|
|
4
|
+
/** Its root is the surface, while it is open, not its trigger. */
|
|
5
|
+
export type PopoverProps = PopoverBaseProps & RootProps & {
|
|
6
|
+
/** The control that opens it: a Button or an IconButton. */
|
|
7
|
+
trigger: Snippet;
|
|
8
|
+
/** Called with whether it is open, as it opens and closes. */
|
|
9
|
+
onOpenChange?: (open: boolean) => void;
|
|
10
|
+
/** What it holds: a few lines of text, a short form, actions. */
|
|
11
|
+
children?: Snippet;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A surface that opens beside the control that opens it, for details or a short task that do not
|
|
15
|
+
* need the whole screen: a press outside, Escape or its close button closes it, and the focus goes
|
|
16
|
+
* back to the trigger. It is a dialog named by its title, and not modal: the page stays as it is
|
|
17
|
+
* behind it. Without `open` it keeps its own, from `defaultOpen`.
|
|
18
|
+
*/
|
|
19
|
+
declare const Popover: import("svelte").Component<PopoverProps, {}, "">;
|
|
20
|
+
type Popover = ReturnType<typeof Popover>;
|
|
21
|
+
export default Popover;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
What a Popover draws while it is open: the surface, with its title, its close button and its
|
|
4
|
+
content. A component of its own so that the controls in it get none of the trigger props the
|
|
5
|
+
Popover gives its trigger. Only for Popover: the index does not export it.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { classes, POPOVER_PARTS, rootAttributes } from "@xds/core";
|
|
9
|
+
import type * as popover from "@zag-js/popover";
|
|
10
|
+
import { mergeProps, type PropTypes } from "@zag-js/svelte";
|
|
11
|
+
import type { Snippet } from "svelte";
|
|
12
|
+
import IconButton from "./IconButton.svelte";
|
|
13
|
+
import { useLabels } from "./labels.svelte.js";
|
|
14
|
+
import Portal from "./Portal.svelte";
|
|
15
|
+
import { createPresence } from "./presence.svelte.js";
|
|
16
|
+
import { resetTrigger } from "./trigger.svelte.js";
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
api,
|
|
20
|
+
title,
|
|
21
|
+
closeLabel,
|
|
22
|
+
class: className,
|
|
23
|
+
style,
|
|
24
|
+
attributes,
|
|
25
|
+
children,
|
|
26
|
+
content = $bindable(),
|
|
27
|
+
}: {
|
|
28
|
+
api: () => popover.Api<PropTypes>;
|
|
29
|
+
title: string;
|
|
30
|
+
closeLabel: string | undefined;
|
|
31
|
+
class: string | undefined;
|
|
32
|
+
style: string | undefined;
|
|
33
|
+
attributes: Record<string, unknown>;
|
|
34
|
+
children: Snippet | undefined;
|
|
35
|
+
content: HTMLElement | undefined;
|
|
36
|
+
} = $props();
|
|
37
|
+
|
|
38
|
+
// Nothing inside opens an overlay from a control outside it.
|
|
39
|
+
resetTrigger();
|
|
40
|
+
const labels = useLabels();
|
|
41
|
+
const present = createPresence(
|
|
42
|
+
() => api().open,
|
|
43
|
+
() => [content],
|
|
44
|
+
);
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
{#if present()}
|
|
48
|
+
<Portal>
|
|
49
|
+
<div {...api().getPositionerProps()} class={POPOVER_PARTS.positioner}>
|
|
50
|
+
<!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
|
|
51
|
+
<section
|
|
52
|
+
{...mergeProps(api().getContentProps(), {
|
|
53
|
+
...rootAttributes(attributes),
|
|
54
|
+
class: classes("xds-popover", className),
|
|
55
|
+
style,
|
|
56
|
+
})}
|
|
57
|
+
bind:this={content}
|
|
58
|
+
hidden={false}
|
|
59
|
+
>
|
|
60
|
+
<div class={POPOVER_PARTS.header}>
|
|
61
|
+
<h2 {...api().getTitleProps()} class={POPOVER_PARTS.title}>{title}</h2>
|
|
62
|
+
<IconButton
|
|
63
|
+
icon="x"
|
|
64
|
+
label={closeLabel ?? labels().close}
|
|
65
|
+
variant="ghost"
|
|
66
|
+
size="sm"
|
|
67
|
+
class={POPOVER_PARTS.close}
|
|
68
|
+
onPress={() => api().setOpen(false)}
|
|
69
|
+
/>
|
|
70
|
+
</div>
|
|
71
|
+
{#if children}
|
|
72
|
+
<div class={POPOVER_PARTS.body}>{@render children()}</div>
|
|
73
|
+
{/if}
|
|
74
|
+
</section>
|
|
75
|
+
</div>
|
|
76
|
+
</Portal>
|
|
77
|
+
{/if}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type * as popover from "@zag-js/popover";
|
|
2
|
+
import { type PropTypes } from "@zag-js/svelte";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
type $$ComponentProps = {
|
|
5
|
+
api: () => popover.Api<PropTypes>;
|
|
6
|
+
title: string;
|
|
7
|
+
closeLabel: string | undefined;
|
|
8
|
+
class: string | undefined;
|
|
9
|
+
style: string | undefined;
|
|
10
|
+
attributes: Record<string, unknown>;
|
|
11
|
+
children: Snippet | undefined;
|
|
12
|
+
content: HTMLElement | undefined;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* What a Popover draws while it is open: the surface, with its title, its close button and its
|
|
16
|
+
* content. A component of its own so that the controls in it get none of the trigger props the
|
|
17
|
+
* Popover gives its trigger. Only for Popover: the index does not export it.
|
|
18
|
+
*/
|
|
19
|
+
declare const PopoverSurface: import("svelte").Component<$$ComponentProps, {}, "content">;
|
|
20
|
+
type PopoverSurface = ReturnType<typeof PopoverSurface>;
|
|
21
|
+
export default PopoverSurface;
|
package/dist/Select.svelte
CHANGED
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
|
|
10
10
|
selected for assistive technology and marked with a check. Without `value` it keeps its own
|
|
11
11
|
choice, from `defaultValue`.
|
|
12
|
+
|
|
13
|
+
With `multiple`, any number of options can be chosen: choosing one adds it or takes it away, the
|
|
14
|
+
list stays open, and `onValuesChange` gets them all. The list box says that several can be
|
|
15
|
+
chosen.
|
|
12
16
|
-->
|
|
13
17
|
<script module lang="ts">
|
|
14
18
|
import type { SelectBaseProps } from "@xds/core";
|
|
@@ -19,6 +23,8 @@
|
|
|
19
23
|
export type SelectProps<Value extends string = string> = SelectBaseProps<Value> &
|
|
20
24
|
RootProps & {
|
|
21
25
|
onChange?: (value: Value) => void;
|
|
26
|
+
/** Called with the chosen options of a select with `multiple`, in the options' order. */
|
|
27
|
+
onValuesChange?: (values: Value[]) => void;
|
|
22
28
|
};
|
|
23
29
|
</script>
|
|
24
30
|
|
|
@@ -26,10 +32,13 @@
|
|
|
26
32
|
import { space } from "@xds/tokens";
|
|
27
33
|
import {
|
|
28
34
|
classes,
|
|
35
|
+
createItemPropsCache,
|
|
29
36
|
keepListKeys,
|
|
37
|
+
orderedValues,
|
|
30
38
|
readCssPx,
|
|
31
39
|
rootAttributes,
|
|
32
40
|
type SelectOption,
|
|
41
|
+
selectedLabels,
|
|
33
42
|
selectOptionIds,
|
|
34
43
|
underlayLayerStyle,
|
|
35
44
|
} from "@xds/core";
|
|
@@ -44,7 +53,7 @@
|
|
|
44
53
|
|
|
45
54
|
type KeyHandler = (event: KeyboardEvent) => void;
|
|
46
55
|
|
|
47
|
-
// `value`
|
|
56
|
+
// `value` and `values` stay in the rest, where whether they are given at all can be asked.
|
|
48
57
|
let {
|
|
49
58
|
label,
|
|
50
59
|
options,
|
|
@@ -55,6 +64,9 @@
|
|
|
55
64
|
name,
|
|
56
65
|
disabled,
|
|
57
66
|
onChange,
|
|
67
|
+
multiple = false,
|
|
68
|
+
defaultValues,
|
|
69
|
+
onValuesChange,
|
|
58
70
|
class: className,
|
|
59
71
|
style,
|
|
60
72
|
...rest
|
|
@@ -68,6 +80,14 @@
|
|
|
68
80
|
() => onChange,
|
|
69
81
|
);
|
|
70
82
|
const value = $derived(control.current);
|
|
83
|
+
const valuesControl = controllable<readonly Value[], Value[]>(
|
|
84
|
+
() => rest,
|
|
85
|
+
"values",
|
|
86
|
+
() => rest.values ?? [],
|
|
87
|
+
() => defaultValues ?? [],
|
|
88
|
+
() => onValuesChange,
|
|
89
|
+
);
|
|
90
|
+
const values = $derived(valuesControl.current);
|
|
71
91
|
|
|
72
92
|
const id = $props.id();
|
|
73
93
|
const valueId = `${id}-value`;
|
|
@@ -84,11 +104,18 @@
|
|
|
84
104
|
const service = useMachine(select.machine, () => ({
|
|
85
105
|
id,
|
|
86
106
|
collection,
|
|
87
|
-
value: value === undefined ? [] : [value],
|
|
107
|
+
value: multiple ? [...values] : value === undefined ? [] : [value],
|
|
88
108
|
onValueChange: (details: select.ValueChangeDetails<SelectOption<Value>>) => {
|
|
109
|
+
if (multiple) {
|
|
110
|
+
valuesControl.set(orderedValues(options, details.value as Value[]));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
89
113
|
const next = details.value[0];
|
|
90
114
|
if (next !== undefined) control.set(next as Value);
|
|
91
115
|
},
|
|
116
|
+
multiple,
|
|
117
|
+
// Several are chosen one after another, so the list stays until the person closes it.
|
|
118
|
+
closeOnSelect: !multiple,
|
|
92
119
|
disabled,
|
|
93
120
|
invalid,
|
|
94
121
|
name,
|
|
@@ -101,6 +128,9 @@
|
|
|
101
128
|
},
|
|
102
129
|
}));
|
|
103
130
|
const api = $derived(select.connect(service, normalizeProps));
|
|
131
|
+
// The rows' props as they last were while they draw the same, so that a step of the highlight
|
|
132
|
+
// sets the attributes and the handlers of the two rows it moves between, not of every row.
|
|
133
|
+
const keep = createItemPropsCache();
|
|
104
134
|
// Zag's key handlers read whether a search by typing is under way when the field renders, and
|
|
105
135
|
// a search ends on a timer, which renders nothing: long after a search, Space would still
|
|
106
136
|
// search for a space instead of opening the list or choosing. A handler taken from the
|
|
@@ -174,7 +204,7 @@
|
|
|
174
204
|
<!-- The chosen option's label alone: the list's rows also hold a description and a check,
|
|
175
205
|
which do not belong in the field. -->
|
|
176
206
|
<span {...api.getValueTextProps()} id={valueId} class="xds-select__value"
|
|
177
|
-
>{api.valueAsString || placeholder}</span
|
|
207
|
+
>{(multiple ? selectedLabels(options, values) : api.valueAsString) || placeholder}</span
|
|
178
208
|
>
|
|
179
209
|
<Icon name="chevrons-up-down" size="sm" class="text-xds-field-placeholder" />
|
|
180
210
|
</button>
|
|
@@ -186,10 +216,12 @@
|
|
|
186
216
|
{/if}
|
|
187
217
|
<span id={errorId} class="xds-select__error" aria-live="polite">{error}</span>
|
|
188
218
|
</div>
|
|
189
|
-
<!-- What a form submits; the first option stands for no choice. Zag's props
|
|
190
|
-
from assistive technology, which uses the trigger. -->
|
|
219
|
+
<!-- What a form submits; in a select of one, the first option stands for no choice. Zag's props
|
|
220
|
+
hide the select from assistive technology, which uses the trigger. -->
|
|
191
221
|
<select {...api.getHiddenSelectProps()}>
|
|
192
|
-
|
|
222
|
+
{#if !multiple}
|
|
223
|
+
<option value=""></option>
|
|
224
|
+
{/if}
|
|
193
225
|
{#each options as option (option.value)}
|
|
194
226
|
<option value={option.value}>{option.label}</option>
|
|
195
227
|
{/each}
|
|
@@ -213,14 +245,14 @@
|
|
|
213
245
|
{@const ids = selectOptionIds(id, index)}
|
|
214
246
|
<!-- Named by its label alone, as the field shows it; the help line describes it. -->
|
|
215
247
|
<div
|
|
216
|
-
{...api.getItemProps({ item: option })}
|
|
248
|
+
{...keep(`item:${option.value}`, api.getItemProps({ item: option }))}
|
|
217
249
|
aria-labelledby={ids.label}
|
|
218
250
|
aria-describedby={option.description ? ids.description : undefined}
|
|
219
251
|
class="xds-select__item"
|
|
220
252
|
>
|
|
221
253
|
<span class="xds-select__item-words">
|
|
222
254
|
<span
|
|
223
|
-
{...api.getItemTextProps({ item: option })}
|
|
255
|
+
{...keep(`text:${option.value}`, api.getItemTextProps({ item: option }))}
|
|
224
256
|
id={ids.label}
|
|
225
257
|
class="xds-select__item-label">{option.label}</span
|
|
226
258
|
>
|
package/dist/Select.svelte.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { RootProps } from "./root.js";
|
|
|
3
3
|
export type { SelectOption } from "@xds/core";
|
|
4
4
|
export type SelectProps<Value extends string = string> = SelectBaseProps<Value> & RootProps & {
|
|
5
5
|
onChange?: (value: Value) => void;
|
|
6
|
+
/** Called with the chosen options of a select with `multiple`, in the options' order. */
|
|
7
|
+
onValuesChange?: (values: Value[]) => void;
|
|
6
8
|
};
|
|
7
9
|
declare function $$render<Value extends string = string>(): {
|
|
8
10
|
props: SelectProps<Value>;
|
|
@@ -35,6 +37,10 @@ interface $$IsomorphicComponent {
|
|
|
35
37
|
* the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
|
|
36
38
|
* selected for assistive technology and marked with a check. Without `value` it keeps its own
|
|
37
39
|
* choice, from `defaultValue`.
|
|
40
|
+
*
|
|
41
|
+
* With `multiple`, any number of options can be chosen: choosing one adds it or takes it away, the
|
|
42
|
+
* list stays open, and `onValuesChange` gets them all. The list box says that several can be
|
|
43
|
+
* chosen.
|
|
38
44
|
*/
|
|
39
45
|
declare const Select: $$IsomorphicComponent;
|
|
40
46
|
type Select<Value extends string = string> = InstanceType<typeof Select<Value>>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Rows of data under a row of column headers, to read and compare across. The header of a
|
|
4
|
+
sortable column is a button that asks for the rows sorted by it (`onSortChange`), ascending
|
|
5
|
+
first and then the other way, and the header they are sorted by says so with `aria-sort` and an
|
|
6
|
+
arrow. The rows are shown in the order given. Where the columns do not fit, the table scrolls
|
|
7
|
+
sideways.
|
|
8
|
+
-->
|
|
9
|
+
<script module lang="ts">
|
|
10
|
+
import type { TableBaseProps, TableSort } from "@xds/core";
|
|
11
|
+
import type { RootProps } from "./root.js";
|
|
12
|
+
|
|
13
|
+
export type { SortDirection, TableColumn, TableRow, TableSort } from "@xds/core";
|
|
14
|
+
|
|
15
|
+
export type TableProps = TableBaseProps &
|
|
16
|
+
RootProps & {
|
|
17
|
+
/** The sort a press on a sortable column's header asks for; the app sorts the rows. */
|
|
18
|
+
onSortChange?: (sort: TableSort) => void;
|
|
19
|
+
};
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import {
|
|
24
|
+
classes,
|
|
25
|
+
columnSort,
|
|
26
|
+
nextSort,
|
|
27
|
+
rootAttributes,
|
|
28
|
+
rootPart,
|
|
29
|
+
sortIcon,
|
|
30
|
+
TABLE_PARTS,
|
|
31
|
+
} from "@xds/core";
|
|
32
|
+
import Icon from "./Icon.svelte";
|
|
33
|
+
|
|
34
|
+
let {
|
|
35
|
+
label,
|
|
36
|
+
columns,
|
|
37
|
+
rows,
|
|
38
|
+
sort,
|
|
39
|
+
empty,
|
|
40
|
+
onSortChange,
|
|
41
|
+
class: className,
|
|
42
|
+
style,
|
|
43
|
+
...rest
|
|
44
|
+
}: TableProps = $props();
|
|
45
|
+
|
|
46
|
+
const end = (align: string | undefined) => align === "end" && TABLE_PARTS.end;
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<div {...rootAttributes(rest)} class={classes(rootPart("Table"), className)} {style}>
|
|
50
|
+
<table class={TABLE_PARTS.table} aria-label={label}>
|
|
51
|
+
<thead>
|
|
52
|
+
<tr class={TABLE_PARTS.row}>
|
|
53
|
+
{#each columns as column (column.key)}
|
|
54
|
+
{@const direction = columnSort(sort, column.key)}
|
|
55
|
+
<th
|
|
56
|
+
scope="col"
|
|
57
|
+
aria-sort={direction}
|
|
58
|
+
class={classes(TABLE_PARTS.header, end(column.align))}
|
|
59
|
+
>
|
|
60
|
+
{#if column.sortable}
|
|
61
|
+
<button
|
|
62
|
+
type="button"
|
|
63
|
+
class={TABLE_PARTS.sort}
|
|
64
|
+
onclick={() => onSortChange?.(nextSort(sort, column.key))}
|
|
65
|
+
>
|
|
66
|
+
{column.label}
|
|
67
|
+
<Icon name={sortIcon(direction)} size="xs" />
|
|
68
|
+
</button>
|
|
69
|
+
{:else}
|
|
70
|
+
{column.label}
|
|
71
|
+
{/if}
|
|
72
|
+
</th>
|
|
73
|
+
{/each}
|
|
74
|
+
</tr>
|
|
75
|
+
</thead>
|
|
76
|
+
<tbody>
|
|
77
|
+
{#if rows.length === 0 && empty !== undefined}
|
|
78
|
+
<tr class={TABLE_PARTS.row}>
|
|
79
|
+
<td class={TABLE_PARTS.empty} colspan={columns.length}>{empty}</td>
|
|
80
|
+
</tr>
|
|
81
|
+
{:else}
|
|
82
|
+
{#each rows as row (row.id)}
|
|
83
|
+
<tr class={TABLE_PARTS.row}>
|
|
84
|
+
{#each columns as column, index (column.key)}
|
|
85
|
+
<td class={classes(TABLE_PARTS.cell, end(column.align))}>{row.cells[index]}</td>
|
|
86
|
+
{/each}
|
|
87
|
+
</tr>
|
|
88
|
+
{/each}
|
|
89
|
+
{/if}
|
|
90
|
+
</tbody>
|
|
91
|
+
</table>
|
|
92
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TableBaseProps, TableSort } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
3
|
+
export type { SortDirection, TableColumn, TableRow, TableSort } from "@xds/core";
|
|
4
|
+
export type TableProps = TableBaseProps & RootProps & {
|
|
5
|
+
/** The sort a press on a sortable column's header asks for; the app sorts the rows. */
|
|
6
|
+
onSortChange?: (sort: TableSort) => void;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Rows of data under a row of column headers, to read and compare across. The header of a
|
|
10
|
+
* sortable column is a button that asks for the rows sorted by it (`onSortChange`), ascending
|
|
11
|
+
* first and then the other way, and the header they are sorted by says so with `aria-sort` and an
|
|
12
|
+
* arrow. The rows are shown in the order given. Where the columns do not fit, the table scrolls
|
|
13
|
+
* sideways.
|
|
14
|
+
*/
|
|
15
|
+
declare const Table: import("svelte").Component<TableProps, {}, "">;
|
|
16
|
+
type Table = ReturnType<typeof Table>;
|
|
17
|
+
export default Table;
|