@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,136 @@
|
|
|
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
|
+
Picks a number in a range by dragging the thumb, or by pressing the track where it should go.
|
|
8
|
+
The values snap to `step`.
|
|
9
|
+
|
|
10
|
+
It is a slider named by its label with its value, minimum and maximum, and each arrow key moves
|
|
11
|
+
it one step. Without `value` it keeps its own, from `defaultValue` or else `min`.
|
|
12
|
+
-->
|
|
13
|
+
<script module lang="ts">
|
|
14
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
15
|
+
import type { SliderBaseProps } from "./slider.ts";
|
|
16
|
+
|
|
17
|
+
export type SliderProps = SliderBaseProps &
|
|
18
|
+
RootProps & {
|
|
19
|
+
onChange?: (value: number) => void;
|
|
20
|
+
};
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<script lang="ts">
|
|
24
|
+
import { controllable, rootAttributes } from "@xds/svelte/base";
|
|
25
|
+
import * as slider from "@zag-js/slider";
|
|
26
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
27
|
+
import { classes } from "./parts.ts";
|
|
28
|
+
import {
|
|
29
|
+
focusThumbOnPress,
|
|
30
|
+
sliderArrowValue,
|
|
31
|
+
sliderPageSize,
|
|
32
|
+
sliderValueText,
|
|
33
|
+
} from "./slider.ts";
|
|
34
|
+
|
|
35
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
36
|
+
let {
|
|
37
|
+
label,
|
|
38
|
+
defaultValue,
|
|
39
|
+
min = 0,
|
|
40
|
+
max = 100,
|
|
41
|
+
step = 1,
|
|
42
|
+
disabled,
|
|
43
|
+
showValue,
|
|
44
|
+
name,
|
|
45
|
+
locale,
|
|
46
|
+
onChange,
|
|
47
|
+
class: className,
|
|
48
|
+
style,
|
|
49
|
+
...rest
|
|
50
|
+
}: SliderProps = $props();
|
|
51
|
+
|
|
52
|
+
const position = controllable(
|
|
53
|
+
() => rest,
|
|
54
|
+
"value",
|
|
55
|
+
() => rest.value ?? min,
|
|
56
|
+
() => defaultValue ?? min,
|
|
57
|
+
() => onChange,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const id = $props.id();
|
|
61
|
+
const pageSize = $derived(sliderPageSize({ min, max, step }));
|
|
62
|
+
const service = useMachine(slider.machine, () => ({
|
|
63
|
+
id,
|
|
64
|
+
name,
|
|
65
|
+
value: [position.current],
|
|
66
|
+
// One thumb, so one number.
|
|
67
|
+
onValueChange: (details: slider.ValueChangeDetails) => position.set(details.value[0] ?? min),
|
|
68
|
+
min,
|
|
69
|
+
max,
|
|
70
|
+
step,
|
|
71
|
+
largeStep: pageSize,
|
|
72
|
+
disabled,
|
|
73
|
+
// The thumb's center is on the value, at the ends too; the band is inset to make room.
|
|
74
|
+
thumbAlignment: "center" as const,
|
|
75
|
+
getAriaValueText: (details: { value: number }) => sliderValueText(details.value, locale),
|
|
76
|
+
}));
|
|
77
|
+
const api = $derived(slider.connect(service, normalizeProps));
|
|
78
|
+
let thumbElement = $state<HTMLDivElement>();
|
|
79
|
+
const thumb = $derived(
|
|
80
|
+
mergeProps(api.getThumbProps({ index: 0 }), {
|
|
81
|
+
// Up and Down move a horizontal slider too, as they move a native range input.
|
|
82
|
+
onkeydown: (event: KeyboardEvent) => {
|
|
83
|
+
if (disabled) return;
|
|
84
|
+
const next = sliderArrowValue(event, {
|
|
85
|
+
value: api.value[0] ?? min,
|
|
86
|
+
min,
|
|
87
|
+
max,
|
|
88
|
+
step,
|
|
89
|
+
pageSize,
|
|
90
|
+
});
|
|
91
|
+
if (next !== undefined) {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
api.setThumbValue(0, next);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
const control = $derived(
|
|
99
|
+
mergeProps(api.getControlProps(), {
|
|
100
|
+
// No focus ring after a press. This handler runs before Zag's.
|
|
101
|
+
onpointerdown: (event: PointerEvent) => {
|
|
102
|
+
if (!disabled) focusThumbOnPress(event, thumbElement);
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
</script>
|
|
107
|
+
|
|
108
|
+
<!-- A group named by the label, around the label, the value and the slider. Not a fieldset:
|
|
109
|
+
that is for a set of fields, and this is one slider and its label. The app's style is merged
|
|
110
|
+
with the one the machine writes on the root. -->
|
|
111
|
+
<div
|
|
112
|
+
{...mergeProps(api.getRootProps(), {
|
|
113
|
+
...rootAttributes(rest),
|
|
114
|
+
class: classes("{{prefix}}-slider", className),
|
|
115
|
+
style,
|
|
116
|
+
})}
|
|
117
|
+
role="group"
|
|
118
|
+
aria-labelledby={api.getLabelProps().id}
|
|
119
|
+
>
|
|
120
|
+
<!-- Zag's props give it `for`, the hidden input's id. -->
|
|
121
|
+
<label {...api.getLabelProps()} class="{{prefix}}-slider__label">{label}</label>
|
|
122
|
+
{#if showValue}
|
|
123
|
+
<!-- Read when asked for, not at every step: the slider itself announces its value. -->
|
|
124
|
+
<output {...api.getValueTextProps()} aria-live="off" class="{{prefix}}-slider__output"
|
|
125
|
+
>{sliderValueText(api.value[0] ?? position.current, locale)}</output
|
|
126
|
+
>
|
|
127
|
+
{/if}
|
|
128
|
+
<div {...control} class="{{prefix}}-slider__control">
|
|
129
|
+
<div {...api.getTrackProps()} class="{{prefix}}-slider__track">
|
|
130
|
+
<div {...api.getRangeProps()} class="{{prefix}}-slider__range"></div>
|
|
131
|
+
</div>
|
|
132
|
+
<div {...thumb} bind:this={thumbElement} class="{{prefix}}-slider__thumb">
|
|
133
|
+
<input {...api.getHiddenInputProps({ index: 0 })} />
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
Says that something is in progress and how long is unknown. Takes the color of the text around
|
|
8
|
+
it. With `label` it is announced; without one it is decoration next to text that already says
|
|
9
|
+
what is happening.
|
|
10
|
+
-->
|
|
11
|
+
<script module lang="ts">
|
|
12
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
13
|
+
import type { SpinnerBaseProps } from "./spinner.ts";
|
|
14
|
+
|
|
15
|
+
export type SpinnerProps = SpinnerBaseProps & RootProps;
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { rootAttributes, useDefaults } from "@xds/svelte/base";
|
|
20
|
+
import { classes, rootPart } from "./parts.ts";
|
|
21
|
+
import { spinnerClass } from "./spinner.ts";
|
|
22
|
+
|
|
23
|
+
let { size: ownSize, label, class: className, style, ...rest }: SpinnerProps = $props();
|
|
24
|
+
|
|
25
|
+
const defaults = useDefaults("Spinner");
|
|
26
|
+
const size = $derived(ownSize ?? defaults().size);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<span
|
|
30
|
+
{...rootAttributes(rest)}
|
|
31
|
+
class={classes(rootPart("Spinner"), "inline-flex shrink-0", className)}
|
|
32
|
+
{style}
|
|
33
|
+
role={label ? "status" : undefined}
|
|
34
|
+
aria-label={label || undefined}
|
|
35
|
+
aria-hidden={label ? undefined : "true"}
|
|
36
|
+
>
|
|
37
|
+
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" class={spinnerClass(size)}>
|
|
38
|
+
<circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="3" opacity="0.25" />
|
|
39
|
+
<path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" stroke-width="3" stroke-linecap="round" />
|
|
40
|
+
</svg>
|
|
41
|
+
</span>
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
Turns a setting on or off, and takes effect at once. For a choice that is applied later, with a
|
|
8
|
+
form, use a Checkbox.
|
|
9
|
+
|
|
10
|
+
It is a native checkbox with the switch role, so the keyboard, forms and screen readers treat
|
|
11
|
+
it as one. The input is hidden and the track is drawn beside it. Without `checked` it keeps its
|
|
12
|
+
own state, from `defaultChecked`, and a reset of its form puts that back.
|
|
13
|
+
|
|
14
|
+
`focus()`, `blur()` and `element()` on the instance reach the native checkbox.
|
|
15
|
+
-->
|
|
16
|
+
<script module lang="ts">
|
|
17
|
+
import { type RootProps, rootAttributes } from "@xds/svelte/base";
|
|
18
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
19
|
+
import { classes, rootPart } from "./parts.ts";
|
|
20
|
+
import {
|
|
21
|
+
type SwitchBaseProps,
|
|
22
|
+
switchClass,
|
|
23
|
+
switchLabelClass,
|
|
24
|
+
switchThumbClass,
|
|
25
|
+
switchTrackClass,
|
|
26
|
+
} from "./switch.ts";
|
|
27
|
+
|
|
28
|
+
export type SwitchProps = SwitchBaseProps &
|
|
29
|
+
RootProps & {
|
|
30
|
+
onChange?: (checked: boolean) => void;
|
|
31
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
32
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
33
|
+
};
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<script lang="ts">
|
|
37
|
+
import { controllable, followFormReset, keepChecked } from "@xds/svelte/base";
|
|
38
|
+
|
|
39
|
+
// `checked` stays in the rest, where whether it is given at all can be asked.
|
|
40
|
+
let {
|
|
41
|
+
defaultChecked = false,
|
|
42
|
+
label,
|
|
43
|
+
"aria-label": ariaLabel,
|
|
44
|
+
disabled,
|
|
45
|
+
onChange,
|
|
46
|
+
onFocus,
|
|
47
|
+
onBlur,
|
|
48
|
+
class: className,
|
|
49
|
+
style,
|
|
50
|
+
...rest
|
|
51
|
+
}: SwitchProps = $props();
|
|
52
|
+
|
|
53
|
+
const control = controllable(
|
|
54
|
+
() => rest,
|
|
55
|
+
"checked",
|
|
56
|
+
() => rest.checked ?? false,
|
|
57
|
+
() => defaultChecked,
|
|
58
|
+
() => onChange,
|
|
59
|
+
);
|
|
60
|
+
let input = $state<HTMLInputElement>();
|
|
61
|
+
followFormReset(() => input, control);
|
|
62
|
+
|
|
63
|
+
/** Moves the focus to the native checkbox. */
|
|
64
|
+
export function focus(options?: FocusOptions) {
|
|
65
|
+
input?.focus(options);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Takes the focus from the native checkbox. */
|
|
69
|
+
export function blur() {
|
|
70
|
+
input?.blur();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The native checkbox, once it is on the page. */
|
|
74
|
+
export function element(): HTMLInputElement | undefined {
|
|
75
|
+
return input;
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<label
|
|
80
|
+
{...rootAttributes(rest)}
|
|
81
|
+
class={classes(rootPart("Switch"), switchClass, className)}
|
|
82
|
+
{style}
|
|
83
|
+
>
|
|
84
|
+
<input
|
|
85
|
+
bind:this={input}
|
|
86
|
+
type="checkbox"
|
|
87
|
+
role="switch"
|
|
88
|
+
aria-checked={control.current ? "true" : "false"}
|
|
89
|
+
aria-label={ariaLabel}
|
|
90
|
+
class="peer sr-only"
|
|
91
|
+
checked={control.current}
|
|
92
|
+
defaultChecked={control.controlled ? control.current : defaultChecked}
|
|
93
|
+
{disabled}
|
|
94
|
+
onchange={(event) => {
|
|
95
|
+
control.set(event.currentTarget.checked);
|
|
96
|
+
keepChecked(event.currentTarget, () => control.current);
|
|
97
|
+
}}
|
|
98
|
+
onfocus={onFocus}
|
|
99
|
+
onblur={onBlur}
|
|
100
|
+
/>
|
|
101
|
+
<span class={switchTrackClass}><span class={switchThumbClass}></span></span>
|
|
102
|
+
{#if label}
|
|
103
|
+
<span class={switchLabelClass}>{label}</span>
|
|
104
|
+
{/if}
|
|
105
|
+
</label>
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
Rows of data under a row of column headers, to read and compare across. The header of a
|
|
8
|
+
sortable column is a button that asks for the rows sorted by it (`onSortChange`), ascending
|
|
9
|
+
first and then the other way, and the header they are sorted by says so with `aria-sort` and an
|
|
10
|
+
arrow. The rows are shown in the order given. Where the columns do not fit, the table scrolls
|
|
11
|
+
sideways.
|
|
12
|
+
-->
|
|
13
|
+
<script module lang="ts">
|
|
14
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
15
|
+
import type { TableBaseProps, TableSort } from "./table.ts";
|
|
16
|
+
|
|
17
|
+
export type { SortDirection, TableColumn, TableRow, TableSort } from "./table.ts";
|
|
18
|
+
|
|
19
|
+
export type TableProps = TableBaseProps &
|
|
20
|
+
RootProps & {
|
|
21
|
+
/** The sort a press on a sortable column's header asks for; the app sorts the rows. */
|
|
22
|
+
onSortChange?: (sort: TableSort) => void;
|
|
23
|
+
};
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import { rootAttributes } from "@xds/svelte/base";
|
|
28
|
+
import Icon from "./Icon.svelte";
|
|
29
|
+
import { classes, rootPart } from "./parts.ts";
|
|
30
|
+
import { columnSort, nextSort, sortIcon, TABLE_PARTS } from "./table.ts";
|
|
31
|
+
|
|
32
|
+
let {
|
|
33
|
+
label,
|
|
34
|
+
columns,
|
|
35
|
+
rows,
|
|
36
|
+
sort,
|
|
37
|
+
empty,
|
|
38
|
+
onSortChange,
|
|
39
|
+
class: className,
|
|
40
|
+
style,
|
|
41
|
+
...rest
|
|
42
|
+
}: TableProps = $props();
|
|
43
|
+
|
|
44
|
+
const end = (align: string | undefined) => align === "end" && TABLE_PARTS.end;
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<div {...rootAttributes(rest)} class={classes(rootPart("Table"), className)} {style}>
|
|
48
|
+
<table class={TABLE_PARTS.table} aria-label={label}>
|
|
49
|
+
<thead>
|
|
50
|
+
<tr class={TABLE_PARTS.row}>
|
|
51
|
+
{#each columns as column (column.key)}
|
|
52
|
+
{@const direction = columnSort(sort, column.key)}
|
|
53
|
+
<th
|
|
54
|
+
scope="col"
|
|
55
|
+
aria-sort={direction}
|
|
56
|
+
class={classes(TABLE_PARTS.header, end(column.align))}
|
|
57
|
+
>
|
|
58
|
+
{#if column.sortable}
|
|
59
|
+
<button
|
|
60
|
+
type="button"
|
|
61
|
+
class={TABLE_PARTS.sort}
|
|
62
|
+
onclick={() => onSortChange?.(nextSort(sort, column.key))}
|
|
63
|
+
>
|
|
64
|
+
{column.label}
|
|
65
|
+
<Icon name={sortIcon(direction)} size="xs" />
|
|
66
|
+
</button>
|
|
67
|
+
{:else}
|
|
68
|
+
{column.label}
|
|
69
|
+
{/if}
|
|
70
|
+
</th>
|
|
71
|
+
{/each}
|
|
72
|
+
</tr>
|
|
73
|
+
</thead>
|
|
74
|
+
<tbody>
|
|
75
|
+
{#if rows.length === 0 && empty !== undefined}
|
|
76
|
+
<tr class={TABLE_PARTS.row}>
|
|
77
|
+
<td class={TABLE_PARTS.empty} colspan={columns.length}>{empty}</td>
|
|
78
|
+
</tr>
|
|
79
|
+
{:else}
|
|
80
|
+
{#each rows as row (row.id)}
|
|
81
|
+
<tr class={TABLE_PARTS.row}>
|
|
82
|
+
{#each columns as column, index (column.key)}
|
|
83
|
+
<td class={classes(TABLE_PARTS.cell, end(column.align))}>{row.cells[index]}</td>
|
|
84
|
+
{/each}
|
|
85
|
+
</tr>
|
|
86
|
+
{/each}
|
|
87
|
+
{/if}
|
|
88
|
+
</tbody>
|
|
89
|
+
</table>
|
|
90
|
+
</div>
|
|
@@ -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
|
+
Switches between views inside one screen. For two to four short modes a SegmentedControl is
|
|
8
|
+
lighter; tabs are for more items, longer labels, or a row that may have to scroll.
|
|
9
|
+
|
|
10
|
+
The selected tab is underlined as well as darker, so the choice does not depend on color. This
|
|
11
|
+
is only the row: the app shows the view that matches `value`. The arrow keys move between tabs.
|
|
12
|
+
Without `value` the tabs keep their own, from `defaultValue` or else the first.
|
|
13
|
+
-->
|
|
14
|
+
<script module lang="ts">
|
|
15
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
16
|
+
import type { TabsBaseProps } from "./tabs.ts";
|
|
17
|
+
|
|
18
|
+
export type TabsProps<Value extends string> = TabsBaseProps<Value> &
|
|
19
|
+
RootProps & {
|
|
20
|
+
onChange?: (value: Value) => void;
|
|
21
|
+
};
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<script lang="ts" generics="Value extends string">
|
|
25
|
+
import { controllable, rootAttributes } from "@xds/svelte/base";
|
|
26
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
27
|
+
import * as tabs from "@zag-js/tabs";
|
|
28
|
+
import Icon from "./Icon.svelte";
|
|
29
|
+
import { classes } from "./parts.ts";
|
|
30
|
+
import { tabStopIndex, tabsClass } from "./tabs.ts";
|
|
31
|
+
|
|
32
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
33
|
+
let {
|
|
34
|
+
items,
|
|
35
|
+
defaultValue,
|
|
36
|
+
label,
|
|
37
|
+
fullWidth,
|
|
38
|
+
onChange,
|
|
39
|
+
class: className,
|
|
40
|
+
style,
|
|
41
|
+
...rest
|
|
42
|
+
}: TabsProps<Value> = $props();
|
|
43
|
+
|
|
44
|
+
const control = controllable<Value | undefined, Value>(
|
|
45
|
+
() => rest,
|
|
46
|
+
"value",
|
|
47
|
+
() => rest.value,
|
|
48
|
+
() => defaultValue ?? items[0]?.value,
|
|
49
|
+
() => onChange,
|
|
50
|
+
);
|
|
51
|
+
const id = $props.id();
|
|
52
|
+
const service = useMachine(tabs.machine, () => ({
|
|
53
|
+
id,
|
|
54
|
+
value: control.current ?? null,
|
|
55
|
+
onValueChange: (details: tabs.ValueChangeDetails) => control.set(details.value as Value),
|
|
56
|
+
}));
|
|
57
|
+
const api = $derived(tabs.connect(service, normalizeProps));
|
|
58
|
+
// Merged, so that the app's style joins any the machine writes on the root. The recipe gives
|
|
59
|
+
// the root part, `{{prefix}}-tabs`.
|
|
60
|
+
const root = $derived(
|
|
61
|
+
mergeProps(api.getRootProps(), {
|
|
62
|
+
...rootAttributes(rest),
|
|
63
|
+
class: classes(tabsClass(fullWidth), className),
|
|
64
|
+
style,
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<div {...root}>
|
|
70
|
+
<div {...api.getListProps()} aria-label={label} class="{{prefix}}-tabs__list">
|
|
71
|
+
{#each items as item (item.value)}
|
|
72
|
+
{@const trigger = api.getTriggerProps({ value: item.value })}
|
|
73
|
+
<!-- Zag points the selected tab at its panel, which this row never renders: the app shows
|
|
74
|
+
the view. A reference to an element that does not exist is invalid. -->
|
|
75
|
+
<button
|
|
76
|
+
{...trigger}
|
|
77
|
+
tabindex={tabStopIndex(api.focusedValue, item.value, trigger.tabindex)}
|
|
78
|
+
aria-controls={undefined}
|
|
79
|
+
class="{{prefix}}-tabs__tab"
|
|
80
|
+
>{#if item.icon}<Icon name={item.icon} size="sm" />{/if}{item.label}</button
|
|
81
|
+
>
|
|
82
|
+
{/each}
|
|
83
|
+
<div {...api.getIndicatorProps()} class="{{prefix}}-tabs__indicator"></div>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
<script module lang="ts">
|
|
6
|
+
import type { RootProps } from "@xds/svelte/base";
|
|
7
|
+
import type { Snippet } from "svelte";
|
|
8
|
+
import type { TextBaseProps } from "./text.ts";
|
|
9
|
+
|
|
10
|
+
export type TextProps = TextBaseProps &
|
|
11
|
+
RootProps & {
|
|
12
|
+
/** The element to render. Pick it for the document outline (`h1`, `h2`, `p`), not for looks. */
|
|
13
|
+
as?: keyof HTMLElementTagNameMap;
|
|
14
|
+
children: Snippet;
|
|
15
|
+
};
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { rootAttributes, useDefaults } from "@xds/svelte/base";
|
|
20
|
+
import { classes, rootPart } from "./parts.ts";
|
|
21
|
+
import { textClass } from "./text.ts";
|
|
22
|
+
|
|
23
|
+
let {
|
|
24
|
+
variant: ownVariant,
|
|
25
|
+
tone: ownTone,
|
|
26
|
+
as = "p",
|
|
27
|
+
class: className,
|
|
28
|
+
style,
|
|
29
|
+
children,
|
|
30
|
+
...rest
|
|
31
|
+
}: TextProps = $props();
|
|
32
|
+
|
|
33
|
+
const defaults = useDefaults("Text");
|
|
34
|
+
const variant = $derived(ownVariant ?? defaults().variant);
|
|
35
|
+
const tone = $derived(ownTone ?? defaults().tone);
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<svelte:element
|
|
39
|
+
this={as}
|
|
40
|
+
{...rootAttributes(rest)}
|
|
41
|
+
class={classes(rootPart("Text"), textClass({ variant, tone }), className)}
|
|
42
|
+
{style}>{@render children()}</svelte:element
|
|
43
|
+
>
|