@xds/svelte 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +19 -2
- package/dist/Accordion.svelte +89 -0
- package/dist/Accordion.svelte.d.ts +43 -0
- package/dist/AccordionPanel.svelte +40 -0
- package/dist/AccordionPanel.svelte.d.ts +15 -0
- package/dist/Avatar.svelte +45 -0
- package/dist/Avatar.svelte.d.ts +11 -0
- package/dist/AvatarStack.svelte +49 -0
- package/dist/AvatarStack.svelte.d.ts +10 -0
- package/dist/Badge.svelte +36 -0
- package/dist/Badge.svelte.d.ts +15 -0
- package/dist/Banner.svelte +88 -0
- package/dist/Banner.svelte.d.ts +25 -0
- package/dist/Button.svelte +90 -0
- package/dist/Button.svelte.d.ts +16 -0
- package/dist/Card.svelte +99 -0
- package/dist/Card.svelte.d.ts +20 -0
- package/dist/Checkbox.svelte +68 -0
- package/dist/Checkbox.svelte.d.ts +12 -0
- package/dist/Chip.svelte +43 -0
- package/dist/Chip.svelte.d.ts +14 -0
- package/dist/ChipBar.svelte +32 -0
- package/dist/ChipBar.svelte.d.ts +14 -0
- package/dist/CountBadge.svelte +50 -0
- package/dist/CountBadge.svelte.d.ts +14 -0
- package/dist/DatePicker.svelte +178 -0
- package/dist/DatePicker.svelte.d.ts +22 -0
- package/dist/DateRangePicker.svelte +264 -0
- package/dist/DateRangePicker.svelte.d.ts +25 -0
- package/dist/Defaults.svelte +29 -0
- package/dist/Defaults.svelte.d.ts +17 -0
- package/dist/Dialog.svelte +104 -0
- package/dist/Dialog.svelte.d.ts +22 -0
- package/dist/Divider.svelte +17 -0
- package/dist/Divider.svelte.d.ts +6 -0
- package/dist/EmptyState.svelte +34 -0
- package/dist/EmptyState.svelte.d.ts +14 -0
- package/dist/Icon.svelte +38 -0
- package/dist/Icon.svelte.d.ts +10 -0
- package/dist/IconButton.svelte +67 -0
- package/dist/IconButton.svelte.d.ts +13 -0
- package/dist/ListRow.svelte +29 -0
- package/dist/ListRow.svelte.d.ts +15 -0
- package/dist/MediaCard.svelte +112 -0
- package/dist/MediaCard.svelte.d.ts +22 -0
- package/dist/Menu.svelte +156 -0
- package/dist/Menu.svelte.d.ts +19 -0
- package/dist/PlaceRow.svelte +66 -0
- package/dist/PlaceRow.svelte.d.ts +12 -0
- package/dist/Portal.svelte +27 -0
- package/dist/Portal.svelte.d.ts +15 -0
- package/dist/ProgressBar.svelte +37 -0
- package/dist/ProgressBar.svelte.d.ts +10 -0
- package/dist/RadioGroup.svelte +114 -0
- package/dist/RadioGroup.svelte.d.ts +38 -0
- package/dist/SearchField.svelte +93 -0
- package/dist/SearchField.svelte.d.ts +17 -0
- package/dist/SectionHeader.svelte +56 -0
- package/dist/SectionHeader.svelte.d.ts +16 -0
- package/dist/SegmentedControl.svelte +70 -0
- package/dist/SegmentedControl.svelte.d.ts +35 -0
- package/dist/Select.svelte +214 -0
- package/dist/Select.svelte.d.ts +40 -0
- package/dist/Sidebar.svelte +125 -0
- package/dist/Sidebar.svelte.d.ts +43 -0
- package/dist/SidebarRailButton.svelte +29 -0
- package/dist/SidebarRailButton.svelte.d.ts +14 -0
- package/dist/Skeleton.svelte +34 -0
- package/dist/Skeleton.svelte.d.ts +13 -0
- package/dist/Slider.svelte +111 -0
- package/dist/Slider.svelte.d.ts +15 -0
- package/dist/Spinner.svelte +35 -0
- package/dist/Spinner.svelte.d.ts +11 -0
- package/dist/Switch.svelte +60 -0
- package/dist/Switch.svelte.d.ts +15 -0
- package/dist/Tabs.svelte +65 -0
- package/dist/Tabs.svelte.d.ts +36 -0
- package/dist/Text.svelte +36 -0
- package/dist/Text.svelte.d.ts +11 -0
- package/dist/TextField.svelte +163 -0
- package/dist/TextField.svelte.d.ts +23 -0
- package/dist/Thumbnail.svelte +81 -0
- package/dist/Thumbnail.svelte.d.ts +11 -0
- package/dist/Toast.svelte +83 -0
- package/dist/Toast.svelte.d.ts +17 -0
- package/dist/Tooltip.svelte +40 -0
- package/dist/Tooltip.svelte.d.ts +19 -0
- package/dist/TooltipOverlay.svelte +66 -0
- package/dist/TooltipOverlay.svelte.d.ts +17 -0
- package/dist/controlled.d.ts +4 -0
- package/dist/controlled.js +23 -0
- package/dist/defaults.svelte.d.ts +12 -0
- package/dist/defaults.svelte.js +25 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +47 -0
- package/dist/modal-popover.svelte.d.ts +8 -0
- package/dist/modal-popover.svelte.js +22 -0
- package/dist/picture.svelte.d.ts +19 -0
- package/dist/picture.svelte.js +18 -0
- package/dist/presence.svelte.d.ts +6 -0
- package/dist/presence.svelte.js +19 -0
- package/dist/preview/Component.svelte +56 -0
- package/dist/preview/Component.svelte.d.ts +15 -0
- package/dist/preview/Draw.svelte +65 -0
- package/dist/preview/Draw.svelte.d.ts +15 -0
- package/dist/preview/Preview.svelte +41 -0
- package/dist/preview/Preview.svelte.d.ts +13 -0
- package/dist/preview/Snippets.svelte +36 -0
- package/dist/preview/Snippets.svelte.d.ts +19 -0
- package/dist/preview/components.js +48 -0
- package/dist/preview/index.d.ts +2 -0
- package/dist/preview/index.js +4 -0
- package/dist/root.d.ts +11 -0
- package/dist/root.js +1 -0
- package/dist/styles/index.css +5 -0
- package/dist/trigger.svelte.d.ts +21 -0
- package/dist/trigger.svelte.js +48 -0
- package/package.json +62 -4
- package/page.css +20 -0
- package/styles.css +3354 -0
- package/tailwind.css +2665 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
The top-level places of an app used with a pointer: the counterpart of TabBar on touch. Each row
|
|
4
|
+
is a compact list row; the current one is selected, its title heavier and its icon filled, so
|
|
5
|
+
the place does not depend on the tint alone.
|
|
6
|
+
|
|
7
|
+
It is navigation named by `label`, and the current row says it is the current page. Collapsed,
|
|
8
|
+
the rows keep their names, and show them in a Tooltip under a pointer and on keyboard focus.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { SidebarBaseProps } from "@xds/core";
|
|
12
|
+
import type { Snippet } from "svelte";
|
|
13
|
+
import type { RootProps } from "./root.js";
|
|
14
|
+
|
|
15
|
+
export type { SidebarItem, SidebarSection } from "@xds/core";
|
|
16
|
+
|
|
17
|
+
export type SidebarProps<Value extends string = string> = SidebarBaseProps<Value> &
|
|
18
|
+
RootProps & {
|
|
19
|
+
onChange: (value: Value) => void;
|
|
20
|
+
/** At the top, such as the app's name. It has to fit the rail itself while collapsed. */
|
|
21
|
+
header?: Snippet;
|
|
22
|
+
/** At the bottom, such as an account row. It has to fit the rail itself while collapsed. */
|
|
23
|
+
footer?: Snippet;
|
|
24
|
+
};
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script lang="ts" generics="Value extends string = string">
|
|
28
|
+
import {
|
|
29
|
+
classes,
|
|
30
|
+
rootPart,
|
|
31
|
+
SIDEBAR_PARTS,
|
|
32
|
+
sidebarClass,
|
|
33
|
+
sidebarCount,
|
|
34
|
+
sidebarIconClass,
|
|
35
|
+
sidebarSectionClass,
|
|
36
|
+
sidebarTitleClass,
|
|
37
|
+
tooltipEndSide,
|
|
38
|
+
} from "@xds/core";
|
|
39
|
+
import Icon from "./Icon.svelte";
|
|
40
|
+
import PlaceRow from "./PlaceRow.svelte";
|
|
41
|
+
import SidebarRailButton from "./SidebarRailButton.svelte";
|
|
42
|
+
import TooltipOverlay from "./TooltipOverlay.svelte";
|
|
43
|
+
|
|
44
|
+
let {
|
|
45
|
+
sections,
|
|
46
|
+
value,
|
|
47
|
+
label,
|
|
48
|
+
collapsed = false,
|
|
49
|
+
onChange,
|
|
50
|
+
header,
|
|
51
|
+
footer,
|
|
52
|
+
class: className,
|
|
53
|
+
style,
|
|
54
|
+
}: SidebarProps<Value> = $props();
|
|
55
|
+
|
|
56
|
+
const id = $props.id();
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<nav
|
|
60
|
+
aria-label={label}
|
|
61
|
+
class={classes(rootPart("Sidebar"), sidebarClass(collapsed), className)}
|
|
62
|
+
{style}
|
|
63
|
+
>
|
|
64
|
+
{#if header}
|
|
65
|
+
<div class={SIDEBAR_PARTS.edge}>{@render header()}</div>
|
|
66
|
+
{/if}
|
|
67
|
+
<!-- The places scroll when there are more than fit; the header and footer stay. -->
|
|
68
|
+
<div class={SIDEBAR_PARTS.places}>
|
|
69
|
+
{#each sections as section, index (index)}
|
|
70
|
+
<!-- A section has nothing but its position to tell it apart: titles are optional. -->
|
|
71
|
+
{@const title = `${id}-${index}`}
|
|
72
|
+
<div class={sidebarSectionClass(index, collapsed)}>
|
|
73
|
+
{#if section.title}
|
|
74
|
+
<p id={title} class={sidebarTitleClass(collapsed)}>{section.title}</p>
|
|
75
|
+
{/if}
|
|
76
|
+
{#if collapsed && index > 0}
|
|
77
|
+
<div aria-hidden="true" class={SIDEBAR_PARTS.rule}></div>
|
|
78
|
+
{/if}
|
|
79
|
+
<ul aria-labelledby={section.title ? title : undefined} class={SIDEBAR_PARTS.list}>
|
|
80
|
+
{#each section.items as item (item.value)}
|
|
81
|
+
{@const selected = item.value === value}
|
|
82
|
+
<li class={SIDEBAR_PARTS.item}>
|
|
83
|
+
{#if collapsed}
|
|
84
|
+
<TooltipOverlay label={item.label} placement={tooltipEndSide}>
|
|
85
|
+
<SidebarRailButton
|
|
86
|
+
label={item.label}
|
|
87
|
+
icon={item.icon}
|
|
88
|
+
{selected}
|
|
89
|
+
onPress={() => onChange(item.value)}
|
|
90
|
+
/>
|
|
91
|
+
</TooltipOverlay>
|
|
92
|
+
{:else}
|
|
93
|
+
{@const count = sidebarCount(item.count)}
|
|
94
|
+
<PlaceRow
|
|
95
|
+
compact
|
|
96
|
+
current="page"
|
|
97
|
+
{selected}
|
|
98
|
+
onPress={() => onChange(item.value)}
|
|
99
|
+
title={item.label}
|
|
100
|
+
>
|
|
101
|
+
{#snippet leading()}
|
|
102
|
+
<Icon
|
|
103
|
+
name={item.icon}
|
|
104
|
+
size="md"
|
|
105
|
+
filled={selected}
|
|
106
|
+
class={sidebarIconClass(selected)}
|
|
107
|
+
/>
|
|
108
|
+
{/snippet}
|
|
109
|
+
{#snippet trailing()}
|
|
110
|
+
{#if count}
|
|
111
|
+
<span class={SIDEBAR_PARTS.count}>{count}</span>
|
|
112
|
+
{/if}
|
|
113
|
+
{/snippet}
|
|
114
|
+
</PlaceRow>
|
|
115
|
+
{/if}
|
|
116
|
+
</li>
|
|
117
|
+
{/each}
|
|
118
|
+
</ul>
|
|
119
|
+
</div>
|
|
120
|
+
{/each}
|
|
121
|
+
</div>
|
|
122
|
+
{#if footer}
|
|
123
|
+
<div class={SIDEBAR_PARTS.edge}>{@render footer()}</div>
|
|
124
|
+
{/if}
|
|
125
|
+
</nav>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { SidebarBaseProps } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { RootProps } from "./root.js";
|
|
4
|
+
export type { SidebarItem, SidebarSection } from "@xds/core";
|
|
5
|
+
export type SidebarProps<Value extends string = string> = SidebarBaseProps<Value> & RootProps & {
|
|
6
|
+
onChange: (value: Value) => void;
|
|
7
|
+
/** At the top, such as the app's name. It has to fit the rail itself while collapsed. */
|
|
8
|
+
header?: Snippet;
|
|
9
|
+
/** At the bottom, such as an account row. It has to fit the rail itself while collapsed. */
|
|
10
|
+
footer?: Snippet;
|
|
11
|
+
};
|
|
12
|
+
declare function $$render<Value extends string = string>(): {
|
|
13
|
+
props: SidebarProps<Value>;
|
|
14
|
+
exports: {};
|
|
15
|
+
bindings: "";
|
|
16
|
+
slots: {};
|
|
17
|
+
events: {};
|
|
18
|
+
};
|
|
19
|
+
declare class __sveltets_Render<Value extends string = string> {
|
|
20
|
+
props(): ReturnType<typeof $$render<Value>>['props'];
|
|
21
|
+
events(): ReturnType<typeof $$render<Value>>['events'];
|
|
22
|
+
slots(): ReturnType<typeof $$render<Value>>['slots'];
|
|
23
|
+
bindings(): "";
|
|
24
|
+
exports(): {};
|
|
25
|
+
}
|
|
26
|
+
interface $$IsomorphicComponent {
|
|
27
|
+
new <Value extends string = string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Value>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Value>['props']>, ReturnType<__sveltets_Render<Value>['events']>, ReturnType<__sveltets_Render<Value>['slots']>> & {
|
|
28
|
+
$$bindings?: ReturnType<__sveltets_Render<Value>['bindings']>;
|
|
29
|
+
} & ReturnType<__sveltets_Render<Value>['exports']>;
|
|
30
|
+
<Value extends string = string>(internal: unknown, props: ReturnType<__sveltets_Render<Value>['props']> & {}): ReturnType<__sveltets_Render<Value>['exports']>;
|
|
31
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The top-level places of an app used with a pointer: the counterpart of TabBar on touch. Each row
|
|
35
|
+
* is a compact list row; the current one is selected, its title heavier and its icon filled, so
|
|
36
|
+
* the place does not depend on the tint alone.
|
|
37
|
+
*
|
|
38
|
+
* It is navigation named by `label`, and the current row says it is the current page. Collapsed,
|
|
39
|
+
* the rows keep their names, and show them in a Tooltip under a pointer and on keyboard focus.
|
|
40
|
+
*/
|
|
41
|
+
declare const Sidebar: $$IsomorphicComponent;
|
|
42
|
+
type Sidebar<Value extends string = string> = InstanceType<typeof Sidebar<Value>>;
|
|
43
|
+
export default Sidebar;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A row of a collapsed Sidebar. It is the trigger of the Tooltip that names it. Only for Sidebar:
|
|
4
|
+
the index does not export it.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { IconName } from "@xds/tokens";
|
|
8
|
+
import { sidebarRailButtonClass } from "@xds/core";
|
|
9
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
10
|
+
import Icon from "./Icon.svelte";
|
|
11
|
+
import { withTrigger } from "./trigger.svelte.js";
|
|
12
|
+
|
|
13
|
+
let {
|
|
14
|
+
label,
|
|
15
|
+
icon,
|
|
16
|
+
selected,
|
|
17
|
+
onPress,
|
|
18
|
+
}: { label: string; icon: IconName; selected: boolean; onPress: () => void } = $props();
|
|
19
|
+
|
|
20
|
+
const attributes = withTrigger((): HTMLButtonAttributes => ({
|
|
21
|
+
type: "button",
|
|
22
|
+
class: sidebarRailButtonClass(selected),
|
|
23
|
+
"aria-label": label,
|
|
24
|
+
"aria-current": selected ? "page" : undefined,
|
|
25
|
+
onclick: () => onPress(),
|
|
26
|
+
}));
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<button {...attributes()}><Icon name={icon} size="md" filled={selected} /></button>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IconName } from "@xds/tokens";
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
label: string;
|
|
4
|
+
icon: IconName;
|
|
5
|
+
selected: boolean;
|
|
6
|
+
onPress: () => void;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A row of a collapsed Sidebar. It is the trigger of the Tooltip that names it. Only for Sidebar:
|
|
10
|
+
* the index does not export it.
|
|
11
|
+
*/
|
|
12
|
+
declare const SidebarRailButton: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
13
|
+
type SidebarRailButton = ReturnType<typeof SidebarRailButton>;
|
|
14
|
+
export default SidebarRailButton;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Holds the place of content that is loading, in the shape the content will have. It pulses, and
|
|
4
|
+
stands still for people who ask for less motion.
|
|
5
|
+
|
|
6
|
+
It is hidden from assistive technology: the screen that shows skeletons says that it is
|
|
7
|
+
loading, once, instead of every placeholder saying so.
|
|
8
|
+
-->
|
|
9
|
+
<script module lang="ts">
|
|
10
|
+
import type { SkeletonBaseProps } from "@xds/core";
|
|
11
|
+
import type { RootProps } from "./root.js";
|
|
12
|
+
|
|
13
|
+
export type SkeletonProps = SkeletonBaseProps & RootProps;
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script lang="ts">
|
|
17
|
+
import { classes, rootPart, skeletonClass, skeletonSize } from "@xds/core";
|
|
18
|
+
import { useDefaults } from "./defaults.svelte.js";
|
|
19
|
+
|
|
20
|
+
let { shape: ownShape, width, height, class: className, style }: SkeletonProps = $props();
|
|
21
|
+
|
|
22
|
+
const defaults = useDefaults("Skeleton");
|
|
23
|
+
const shape = $derived(ownShape ?? defaults().shape);
|
|
24
|
+
|
|
25
|
+
const box = $derived(skeletonSize({ shape, width, height }));
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<span
|
|
29
|
+
aria-hidden="true"
|
|
30
|
+
class={classes(rootPart("Skeleton"), skeletonClass(shape), className)}
|
|
31
|
+
{style}
|
|
32
|
+
style:width={box.width}
|
|
33
|
+
style:height={box.height}
|
|
34
|
+
></span>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SkeletonBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
3
|
+
export type SkeletonProps = SkeletonBaseProps & RootProps;
|
|
4
|
+
/**
|
|
5
|
+
* Holds the place of content that is loading, in the shape the content will have. It pulses, and
|
|
6
|
+
* stands still for people who ask for less motion.
|
|
7
|
+
*
|
|
8
|
+
* It is hidden from assistive technology: the screen that shows skeletons says that it is
|
|
9
|
+
* loading, once, instead of every placeholder saying so.
|
|
10
|
+
*/
|
|
11
|
+
declare const Skeleton: import("svelte").Component<SkeletonProps, {}, "">;
|
|
12
|
+
type Skeleton = ReturnType<typeof Skeleton>;
|
|
13
|
+
export default Skeleton;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Picks a number in a range by dragging the thumb, or by pressing the track where it should go.
|
|
4
|
+
The values snap to `step`.
|
|
5
|
+
|
|
6
|
+
It is a slider named by its label with its value, minimum and maximum, and each arrow key moves
|
|
7
|
+
it one step.
|
|
8
|
+
-->
|
|
9
|
+
<script module lang="ts">
|
|
10
|
+
import type { SliderBaseProps } from "@xds/core";
|
|
11
|
+
import type { RootProps } from "./root.js";
|
|
12
|
+
|
|
13
|
+
export type SliderProps = SliderBaseProps &
|
|
14
|
+
RootProps & {
|
|
15
|
+
onChange: (value: number) => void;
|
|
16
|
+
};
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
import {
|
|
21
|
+
classes,
|
|
22
|
+
focusThumbOnPress,
|
|
23
|
+
sliderArrowValue,
|
|
24
|
+
sliderPageSize,
|
|
25
|
+
sliderValueText,
|
|
26
|
+
} from "@xds/core";
|
|
27
|
+
import * as slider from "@zag-js/slider";
|
|
28
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
label,
|
|
32
|
+
value,
|
|
33
|
+
min = 0,
|
|
34
|
+
max = 100,
|
|
35
|
+
step = 1,
|
|
36
|
+
disabled,
|
|
37
|
+
showValue,
|
|
38
|
+
onChange,
|
|
39
|
+
class: className,
|
|
40
|
+
style,
|
|
41
|
+
}: SliderProps = $props();
|
|
42
|
+
|
|
43
|
+
const id = $props.id();
|
|
44
|
+
const pageSize = $derived(sliderPageSize({ min, max, step }));
|
|
45
|
+
const service = useMachine(slider.machine, () => ({
|
|
46
|
+
id,
|
|
47
|
+
value: [value],
|
|
48
|
+
// One thumb, so one number.
|
|
49
|
+
onValueChange: (details: slider.ValueChangeDetails) => onChange(details.value[0] ?? min),
|
|
50
|
+
min,
|
|
51
|
+
max,
|
|
52
|
+
step,
|
|
53
|
+
largeStep: pageSize,
|
|
54
|
+
disabled,
|
|
55
|
+
// The thumb's center is on the value, at the ends too; the band is inset to make room.
|
|
56
|
+
thumbAlignment: "center" as const,
|
|
57
|
+
getAriaValueText: (details: { value: number }) => sliderValueText(details.value),
|
|
58
|
+
}));
|
|
59
|
+
const api = $derived(slider.connect(service, normalizeProps));
|
|
60
|
+
let thumbElement = $state<HTMLDivElement>();
|
|
61
|
+
const thumb = $derived(
|
|
62
|
+
mergeProps(api.getThumbProps({ index: 0 }), {
|
|
63
|
+
// Up and Down move a horizontal slider too, as they move a native range input.
|
|
64
|
+
onkeydown: (event: KeyboardEvent) => {
|
|
65
|
+
if (disabled) return;
|
|
66
|
+
const next = sliderArrowValue(event, {
|
|
67
|
+
value: api.value[0] ?? min,
|
|
68
|
+
min,
|
|
69
|
+
max,
|
|
70
|
+
step,
|
|
71
|
+
pageSize,
|
|
72
|
+
});
|
|
73
|
+
if (next !== undefined) api.setThumbValue(0, next);
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
const control = $derived(
|
|
78
|
+
mergeProps(api.getControlProps(), {
|
|
79
|
+
// No focus ring after a press. This handler runs before Zag's.
|
|
80
|
+
onpointerdown: (event: PointerEvent) => {
|
|
81
|
+
if (!disabled) focusThumbOnPress(event, thumbElement);
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<!-- A group named by the label, around the label, the value and the slider. Not a fieldset:
|
|
88
|
+
that is for a set of fields, and this is one slider and its label. The app's style is merged
|
|
89
|
+
with the one the machine writes on the root. -->
|
|
90
|
+
<div
|
|
91
|
+
{...mergeProps(api.getRootProps(), { class: classes("xds-slider", className), style })}
|
|
92
|
+
role="group"
|
|
93
|
+
aria-labelledby={api.getLabelProps().id}
|
|
94
|
+
>
|
|
95
|
+
<!-- Zag's props give it `for`, the hidden input's id. -->
|
|
96
|
+
<label {...api.getLabelProps()} class="xds-slider__label">{label}</label>
|
|
97
|
+
{#if showValue}
|
|
98
|
+
<!-- Read when asked for, not at every step: the slider itself announces its value. -->
|
|
99
|
+
<output {...api.getValueTextProps()} aria-live="off" class="xds-slider__output"
|
|
100
|
+
>{sliderValueText(api.value[0] ?? value)}</output
|
|
101
|
+
>
|
|
102
|
+
{/if}
|
|
103
|
+
<div {...control} class="xds-slider__control">
|
|
104
|
+
<div {...api.getTrackProps()} class="xds-slider__track">
|
|
105
|
+
<div {...api.getRangeProps()} class="xds-slider__range"></div>
|
|
106
|
+
</div>
|
|
107
|
+
<div {...thumb} bind:this={thumbElement} class="xds-slider__thumb">
|
|
108
|
+
<input {...api.getHiddenInputProps({ index: 0 })} />
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SliderBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
3
|
+
export type SliderProps = SliderBaseProps & RootProps & {
|
|
4
|
+
onChange: (value: number) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
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.
|
|
12
|
+
*/
|
|
13
|
+
declare const Slider: import("svelte").Component<SliderProps, {}, "">;
|
|
14
|
+
type Slider = ReturnType<typeof Slider>;
|
|
15
|
+
export default Slider;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Says that something is in progress and how long is unknown. Takes the color of the text around
|
|
4
|
+
it. With `label` it is announced; without one it is decoration next to text that already says
|
|
5
|
+
what is happening.
|
|
6
|
+
-->
|
|
7
|
+
<script module lang="ts">
|
|
8
|
+
import type { SpinnerBaseProps } from "@xds/core";
|
|
9
|
+
import type { RootProps } from "./root.js";
|
|
10
|
+
|
|
11
|
+
export type SpinnerProps = SpinnerBaseProps & RootProps;
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import { classes, rootPart, spinnerClass } from "@xds/core";
|
|
16
|
+
import { useDefaults } from "./defaults.svelte.js";
|
|
17
|
+
|
|
18
|
+
let { size: ownSize, label, class: className, style }: SpinnerProps = $props();
|
|
19
|
+
|
|
20
|
+
const defaults = useDefaults("Spinner");
|
|
21
|
+
const size = $derived(ownSize ?? defaults().size);
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<span
|
|
25
|
+
class={classes(rootPart("Spinner"), "inline-flex shrink-0", className)}
|
|
26
|
+
{style}
|
|
27
|
+
role={label ? "status" : undefined}
|
|
28
|
+
aria-label={label || undefined}
|
|
29
|
+
aria-hidden={label ? undefined : "true"}
|
|
30
|
+
>
|
|
31
|
+
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" class={spinnerClass(size)}>
|
|
32
|
+
<circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="3" opacity="0.25" />
|
|
33
|
+
<path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" stroke-width="3" stroke-linecap="round" />
|
|
34
|
+
</svg>
|
|
35
|
+
</span>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SpinnerBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
3
|
+
export type SpinnerProps = SpinnerBaseProps & RootProps;
|
|
4
|
+
/**
|
|
5
|
+
* Says that something is in progress and how long is unknown. Takes the color of the text around
|
|
6
|
+
* it. With `label` it is announced; without one it is decoration next to text that already says
|
|
7
|
+
* what is happening.
|
|
8
|
+
*/
|
|
9
|
+
declare const Spinner: import("svelte").Component<SpinnerProps, {}, "">;
|
|
10
|
+
type Spinner = ReturnType<typeof Spinner>;
|
|
11
|
+
export default Spinner;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Turns a setting on or off, and takes effect at once. For a choice that is applied later, with a
|
|
4
|
+
form, use a Checkbox.
|
|
5
|
+
|
|
6
|
+
It is a native checkbox with the switch role, so the keyboard, forms and screen readers treat
|
|
7
|
+
it as one. The input is hidden and the track is drawn beside it.
|
|
8
|
+
-->
|
|
9
|
+
<script module lang="ts">
|
|
10
|
+
import {
|
|
11
|
+
classes,
|
|
12
|
+
rootPart,
|
|
13
|
+
type SwitchBaseProps,
|
|
14
|
+
switchClass,
|
|
15
|
+
switchLabelClass,
|
|
16
|
+
switchThumbClass,
|
|
17
|
+
switchTrackClass,
|
|
18
|
+
} from "@xds/core";
|
|
19
|
+
import type { RootProps } from "./root.js";
|
|
20
|
+
|
|
21
|
+
export type SwitchProps = SwitchBaseProps &
|
|
22
|
+
RootProps & {
|
|
23
|
+
onChange: (checked: boolean) => void;
|
|
24
|
+
};
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script lang="ts">
|
|
28
|
+
import { keepChecked } from "./controlled.js";
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
checked,
|
|
32
|
+
label,
|
|
33
|
+
"aria-label": ariaLabel,
|
|
34
|
+
disabled,
|
|
35
|
+
onChange,
|
|
36
|
+
class: className,
|
|
37
|
+
style,
|
|
38
|
+
}: SwitchProps = $props();
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<label class={classes(rootPart("Switch"), switchClass, className)} {style}>
|
|
42
|
+
<input
|
|
43
|
+
type="checkbox"
|
|
44
|
+
role="switch"
|
|
45
|
+
aria-checked={checked ? "true" : "false"}
|
|
46
|
+
aria-label={ariaLabel}
|
|
47
|
+
class="peer sr-only"
|
|
48
|
+
{checked}
|
|
49
|
+
defaultChecked={checked}
|
|
50
|
+
{disabled}
|
|
51
|
+
onchange={(event) => {
|
|
52
|
+
onChange(event.currentTarget.checked);
|
|
53
|
+
keepChecked(event.currentTarget, () => checked);
|
|
54
|
+
}}
|
|
55
|
+
/>
|
|
56
|
+
<span class={switchTrackClass}><span class={switchThumbClass}></span></span>
|
|
57
|
+
{#if label}
|
|
58
|
+
<span class={switchLabelClass}>{label}</span>
|
|
59
|
+
{/if}
|
|
60
|
+
</label>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type SwitchBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
3
|
+
export type SwitchProps = SwitchBaseProps & RootProps & {
|
|
4
|
+
onChange: (checked: boolean) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
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.
|
|
12
|
+
*/
|
|
13
|
+
declare const Switch: import("svelte").Component<SwitchProps, {}, "">;
|
|
14
|
+
type Switch = ReturnType<typeof Switch>;
|
|
15
|
+
export default Switch;
|
package/dist/Tabs.svelte
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Switches between views inside one screen. For two to four short modes a SegmentedControl is
|
|
4
|
+
lighter; tabs are for more items, longer labels, or a row that may have to scroll.
|
|
5
|
+
|
|
6
|
+
The selected tab is underlined as well as darker, so the choice does not depend on color. This
|
|
7
|
+
is only the row: the app shows the view that matches `value`. The arrow keys move between tabs.
|
|
8
|
+
-->
|
|
9
|
+
<script module lang="ts">
|
|
10
|
+
import type { TabsBaseProps } from "@xds/core";
|
|
11
|
+
import type { RootProps } from "./root.js";
|
|
12
|
+
|
|
13
|
+
export type TabsProps<Value extends string> = TabsBaseProps<Value> &
|
|
14
|
+
RootProps & {
|
|
15
|
+
onChange: (value: Value) => void;
|
|
16
|
+
};
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts" generics="Value extends string">
|
|
20
|
+
import { classes, tabStopIndex, tabsClass } from "@xds/core";
|
|
21
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
22
|
+
import * as tabs from "@zag-js/tabs";
|
|
23
|
+
import Icon from "./Icon.svelte";
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
items,
|
|
27
|
+
value,
|
|
28
|
+
label,
|
|
29
|
+
fullWidth,
|
|
30
|
+
onChange,
|
|
31
|
+
class: className,
|
|
32
|
+
style,
|
|
33
|
+
}: TabsProps<Value> = $props();
|
|
34
|
+
|
|
35
|
+
const id = $props.id();
|
|
36
|
+
const service = useMachine(tabs.machine, () => ({
|
|
37
|
+
id,
|
|
38
|
+
value,
|
|
39
|
+
onValueChange: (details: tabs.ValueChangeDetails) => onChange(details.value as Value),
|
|
40
|
+
}));
|
|
41
|
+
const api = $derived(tabs.connect(service, normalizeProps));
|
|
42
|
+
// Merged, so that the app's style joins any the machine writes on the root. The recipe gives
|
|
43
|
+
// the root part, `xds-tabs`.
|
|
44
|
+
const root = $derived(
|
|
45
|
+
mergeProps(api.getRootProps(), { class: classes(tabsClass(fullWidth), className), style }),
|
|
46
|
+
);
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<div {...root}>
|
|
50
|
+
<div {...api.getListProps()} aria-label={label} class="xds-tabs__list">
|
|
51
|
+
{#each items as item (item.value)}
|
|
52
|
+
{@const trigger = api.getTriggerProps({ value: item.value })}
|
|
53
|
+
<!-- Zag points the selected tab at its panel, which this row never renders: the app shows
|
|
54
|
+
the view. A reference to an element that does not exist is invalid. -->
|
|
55
|
+
<button
|
|
56
|
+
{...trigger}
|
|
57
|
+
tabindex={tabStopIndex(api.focusedValue, item.value, trigger.tabindex)}
|
|
58
|
+
aria-controls={undefined}
|
|
59
|
+
class="xds-tabs__tab"
|
|
60
|
+
>{#if item.icon}<Icon name={item.icon} size="sm" />{/if}{item.label}</button
|
|
61
|
+
>
|
|
62
|
+
{/each}
|
|
63
|
+
<div {...api.getIndicatorProps()} class="xds-tabs__indicator"></div>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { TabsBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
3
|
+
export type TabsProps<Value extends string> = TabsBaseProps<Value> & RootProps & {
|
|
4
|
+
onChange: (value: Value) => void;
|
|
5
|
+
};
|
|
6
|
+
declare function $$render<Value extends string>(): {
|
|
7
|
+
props: TabsProps<Value>;
|
|
8
|
+
exports: {};
|
|
9
|
+
bindings: "";
|
|
10
|
+
slots: {};
|
|
11
|
+
events: {};
|
|
12
|
+
};
|
|
13
|
+
declare class __sveltets_Render<Value extends string> {
|
|
14
|
+
props(): ReturnType<typeof $$render<Value>>['props'];
|
|
15
|
+
events(): ReturnType<typeof $$render<Value>>['events'];
|
|
16
|
+
slots(): ReturnType<typeof $$render<Value>>['slots'];
|
|
17
|
+
bindings(): "";
|
|
18
|
+
exports(): {};
|
|
19
|
+
}
|
|
20
|
+
interface $$IsomorphicComponent {
|
|
21
|
+
new <Value extends string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Value>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Value>['props']>, ReturnType<__sveltets_Render<Value>['events']>, ReturnType<__sveltets_Render<Value>['slots']>> & {
|
|
22
|
+
$$bindings?: ReturnType<__sveltets_Render<Value>['bindings']>;
|
|
23
|
+
} & ReturnType<__sveltets_Render<Value>['exports']>;
|
|
24
|
+
<Value extends string>(internal: unknown, props: ReturnType<__sveltets_Render<Value>['props']> & {}): ReturnType<__sveltets_Render<Value>['exports']>;
|
|
25
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Switches between views inside one screen. For two to four short modes a SegmentedControl is
|
|
29
|
+
* lighter; tabs are for more items, longer labels, or a row that may have to scroll.
|
|
30
|
+
*
|
|
31
|
+
* The selected tab is underlined as well as darker, so the choice does not depend on color. This
|
|
32
|
+
* is only the row: the app shows the view that matches `value`. The arrow keys move between tabs.
|
|
33
|
+
*/
|
|
34
|
+
declare const Tabs: $$IsomorphicComponent;
|
|
35
|
+
type Tabs<Value extends string> = InstanceType<typeof Tabs<Value>>;
|
|
36
|
+
export default Tabs;
|
package/dist/Text.svelte
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { TextBaseProps } from "@xds/core";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
4
|
+
import type { RootProps } from "./root.js";
|
|
5
|
+
|
|
6
|
+
export type TextProps = TextBaseProps &
|
|
7
|
+
RootProps & {
|
|
8
|
+
/** The element to render. Pick it for the document outline (`h1`, `h2`, `p`), not for looks. */
|
|
9
|
+
as?: keyof HTMLElementTagNameMap;
|
|
10
|
+
children: Snippet;
|
|
11
|
+
};
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import { classes, rootPart, textClass } from "@xds/core";
|
|
16
|
+
import { useDefaults } from "./defaults.svelte.js";
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
variant: ownVariant,
|
|
20
|
+
tone: ownTone,
|
|
21
|
+
as = "p",
|
|
22
|
+
class: className,
|
|
23
|
+
style,
|
|
24
|
+
children,
|
|
25
|
+
}: TextProps = $props();
|
|
26
|
+
|
|
27
|
+
const defaults = useDefaults("Text");
|
|
28
|
+
const variant = $derived(ownVariant ?? defaults().variant);
|
|
29
|
+
const tone = $derived(ownTone ?? defaults().tone);
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<svelte:element
|
|
33
|
+
this={as}
|
|
34
|
+
class={classes(rootPart("Text"), textClass({ variant, tone }), className)}
|
|
35
|
+
{style}>{@render children()}</svelte:element
|
|
36
|
+
>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TextBaseProps } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { RootProps } from "./root.js";
|
|
4
|
+
export type TextProps = TextBaseProps & RootProps & {
|
|
5
|
+
/** The element to render. Pick it for the document outline (`h1`, `h2`, `p`), not for looks. */
|
|
6
|
+
as?: keyof HTMLElementTagNameMap;
|
|
7
|
+
children: Snippet;
|
|
8
|
+
};
|
|
9
|
+
declare const Text: import("svelte").Component<TextProps, {}, "">;
|
|
10
|
+
type Text = ReturnType<typeof Text>;
|
|
11
|
+
export default Text;
|