@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
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Xds's web components for Svelte. Apps import from here and from nowhere else, so the parts
|
|
2
|
+
// underneath (Zag.js for behavior, @xds/ui-core for the classes and the stylesheet) can change
|
|
3
|
+
// without touching a screen.
|
|
4
|
+
//
|
|
5
|
+
// The React components are in @xds/ui, the Solid ones in @xds/ui-solid, the Vue ones in
|
|
6
|
+
// @xds/ui-vue, the React Native ones in @xds/ui-native, the GPUI ones in the xds-ui crate and
|
|
7
|
+
// the Compose ones under kotlin/ui. All of them take the same variants, sizes and tones, and draw
|
|
8
|
+
// them from the same design tokens.
|
|
9
|
+
export { default as Accordion } from "./Accordion.svelte";
|
|
10
|
+
export { default as Avatar } from "./Avatar.svelte";
|
|
11
|
+
export { default as AvatarStack } from "./AvatarStack.svelte";
|
|
12
|
+
export { default as Badge } from "./Badge.svelte";
|
|
13
|
+
export { default as Banner } from "./Banner.svelte";
|
|
14
|
+
export { default as Button, } from "./Button.svelte";
|
|
15
|
+
export { default as Card } from "./Card.svelte";
|
|
16
|
+
export { default as Checkbox } from "./Checkbox.svelte";
|
|
17
|
+
export { default as Chip } from "./Chip.svelte";
|
|
18
|
+
export { default as ChipBar } from "./ChipBar.svelte";
|
|
19
|
+
export { default as CountBadge } from "./CountBadge.svelte";
|
|
20
|
+
export { default as DatePicker } from "./DatePicker.svelte";
|
|
21
|
+
export { default as DateRangePicker, } from "./DateRangePicker.svelte";
|
|
22
|
+
export { default as Defaults } from "./Defaults.svelte";
|
|
23
|
+
export { default as Dialog } from "./Dialog.svelte";
|
|
24
|
+
export { default as Divider } from "./Divider.svelte";
|
|
25
|
+
export { default as EmptyState } from "./EmptyState.svelte";
|
|
26
|
+
export { default as Icon } from "./Icon.svelte";
|
|
27
|
+
export { default as IconButton } from "./IconButton.svelte";
|
|
28
|
+
export { default as ListRow } from "./ListRow.svelte";
|
|
29
|
+
export { default as MediaCard } from "./MediaCard.svelte";
|
|
30
|
+
export { default as Menu } from "./Menu.svelte";
|
|
31
|
+
export { default as ProgressBar } from "./ProgressBar.svelte";
|
|
32
|
+
export { default as RadioGroup } from "./RadioGroup.svelte";
|
|
33
|
+
export { default as SearchField } from "./SearchField.svelte";
|
|
34
|
+
export { default as SectionHeader } from "./SectionHeader.svelte";
|
|
35
|
+
export { default as SegmentedControl } from "./SegmentedControl.svelte";
|
|
36
|
+
export { default as Select } from "./Select.svelte";
|
|
37
|
+
export { default as Sidebar, } from "./Sidebar.svelte";
|
|
38
|
+
export { default as Skeleton } from "./Skeleton.svelte";
|
|
39
|
+
export { default as Slider } from "./Slider.svelte";
|
|
40
|
+
export { default as Spinner } from "./Spinner.svelte";
|
|
41
|
+
export { default as Switch } from "./Switch.svelte";
|
|
42
|
+
export { default as Tabs } from "./Tabs.svelte";
|
|
43
|
+
export { default as Text } from "./Text.svelte";
|
|
44
|
+
export { default as TextField } from "./TextField.svelte";
|
|
45
|
+
export { default as Thumbnail } from "./Thumbnail.svelte";
|
|
46
|
+
export { default as Toast } from "./Toast.svelte";
|
|
47
|
+
export { default as Tooltip } from "./Tooltip.svelte";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes an open Menu or Select list modal while `open()` is true: the rest of the page is
|
|
3
|
+
* hidden from assistive technology, so a screen reader's cursor stays in the popup, where the
|
|
4
|
+
* focus is held too, and the page does not scroll. The popup's underlay keeps the pointer off
|
|
5
|
+
* the page. Zag does all of this around a dialog, but not around a menu or a select. Call it
|
|
6
|
+
* while the component is set up.
|
|
7
|
+
*/
|
|
8
|
+
export declare function modalPopover(open: () => boolean, popup: () => HTMLElement | undefined): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ariaHidden } from "@zag-js/aria-hidden";
|
|
2
|
+
import { preventBodyScroll } from "@zag-js/remove-scroll";
|
|
3
|
+
/**
|
|
4
|
+
* Makes an open Menu or Select list modal while `open()` is true: the rest of the page is
|
|
5
|
+
* hidden from assistive technology, so a screen reader's cursor stays in the popup, where the
|
|
6
|
+
* focus is held too, and the page does not scroll. The popup's underlay keeps the pointer off
|
|
7
|
+
* the page. Zag does all of this around a dialog, but not around a menu or a select. Call it
|
|
8
|
+
* while the component is set up.
|
|
9
|
+
*/
|
|
10
|
+
export function modalPopover(open, popup) {
|
|
11
|
+
$effect(() => {
|
|
12
|
+
if (!open())
|
|
13
|
+
return;
|
|
14
|
+
const unlock = preventBodyScroll(document);
|
|
15
|
+
// A frame later, once the popup is shown.
|
|
16
|
+
const reveal = ariaHidden(() => [popup() ?? null], { defer: true });
|
|
17
|
+
return () => {
|
|
18
|
+
reveal();
|
|
19
|
+
unlock();
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Follows the loading of the picture at `src()`. `loaded()` is undefined while it loads, then
|
|
3
|
+
* true or false. The result is remembered with the address it belongs to, so a new `src` starts
|
|
4
|
+
* over without an effect.
|
|
5
|
+
*
|
|
6
|
+
* A picture that is in the cache still reports its load in a later task, after the handlers
|
|
7
|
+
* are attached, so no check of `complete` is needed on a page rendered in the browser.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createPicture(src: () => string | undefined): {
|
|
10
|
+
loaded: () => boolean | undefined;
|
|
11
|
+
onLoad: (address: string) => {
|
|
12
|
+
src: string;
|
|
13
|
+
loaded: true;
|
|
14
|
+
};
|
|
15
|
+
onError: (address: string) => {
|
|
16
|
+
src: string;
|
|
17
|
+
loaded: false;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Avatar and Thumbnail draw a picture over a placeholder, and show it only once it has loaded.
|
|
2
|
+
/**
|
|
3
|
+
* Follows the loading of the picture at `src()`. `loaded()` is undefined while it loads, then
|
|
4
|
+
* true or false. The result is remembered with the address it belongs to, so a new `src` starts
|
|
5
|
+
* over without an effect.
|
|
6
|
+
*
|
|
7
|
+
* A picture that is in the cache still reports its load in a later task, after the handlers
|
|
8
|
+
* are attached, so no check of `complete` is needed on a page rendered in the browser.
|
|
9
|
+
*/
|
|
10
|
+
export function createPicture(src) {
|
|
11
|
+
let picture = $state.raw();
|
|
12
|
+
const loaded = $derived(picture !== undefined && picture.src === src() ? picture.loaded : undefined);
|
|
13
|
+
return {
|
|
14
|
+
loaded: () => loaded,
|
|
15
|
+
onLoad: (address) => (picture = { src: address, loaded: true }),
|
|
16
|
+
onError: (address) => (picture = { src: address, loaded: false }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether an overlay is on the page: from when it opens until the exit animation that its
|
|
3
|
+
* stylesheet starts on `[data-state="closed"]` has finished. Zag hides a closed part at once.
|
|
4
|
+
* `parts` are the elements that animate. Call it while the component is set up.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createPresence(open: () => boolean, parts: () => readonly (Element | undefined)[]): () => boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { afterAnimations } from "@xds/core";
|
|
2
|
+
/**
|
|
3
|
+
* Whether an overlay is on the page: from when it opens until the exit animation that its
|
|
4
|
+
* stylesheet starts on `[data-state="closed"]` has finished. Zag hides a closed part at once.
|
|
5
|
+
* `parts` are the elements that animate. Call it while the component is set up.
|
|
6
|
+
*/
|
|
7
|
+
export function createPresence(open, parts) {
|
|
8
|
+
let exited = $state(true);
|
|
9
|
+
$effect(() => {
|
|
10
|
+
if (open()) {
|
|
11
|
+
exited = false;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
// Opening again before the animation ends stops the wait.
|
|
15
|
+
return afterAnimations(parts(), () => (exited = true));
|
|
16
|
+
});
|
|
17
|
+
const present = $derived(open() || !exited);
|
|
18
|
+
return () => present;
|
|
19
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A component node, drawn with the library's component of its name. A prop that takes a node
|
|
4
|
+
(NODE_PROPS), and the children, reach the component as snippets of the same names, whether they
|
|
5
|
+
hold a node or text; every other prop is resolved from the state where the component reads it,
|
|
6
|
+
and once if it reads nothing from the state.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import {
|
|
10
|
+
type ComponentName,
|
|
11
|
+
type ComponentNode,
|
|
12
|
+
type Host,
|
|
13
|
+
isStatic,
|
|
14
|
+
NODE_PROPS,
|
|
15
|
+
resolve,
|
|
16
|
+
type Slot,
|
|
17
|
+
type State,
|
|
18
|
+
} from "@xds/core/preview";
|
|
19
|
+
import { type Component, type Snippet, untrack } from "svelte";
|
|
20
|
+
import { COMPONENTS } from "./components.js";
|
|
21
|
+
import Snippets from "./Snippets.svelte";
|
|
22
|
+
|
|
23
|
+
let { node, host }: { node: ComponentNode; host: Host<Snippet> } = $props();
|
|
24
|
+
|
|
25
|
+
const nodeProps: Partial<Record<ComponentName, readonly string[]>> = NODE_PROPS;
|
|
26
|
+
|
|
27
|
+
// The props by kind. A node is drawn once: a new node is a new component.
|
|
28
|
+
function split({ name, props: given, children }: ComponentNode, host: Host<Snippet>) {
|
|
29
|
+
const values: Record<string, unknown> = {};
|
|
30
|
+
const slots: (readonly [string, Slot<State>])[] = [];
|
|
31
|
+
const takesNode = nodeProps[name] ?? [];
|
|
32
|
+
for (const [key, value] of Object.entries(given)) {
|
|
33
|
+
// A snippet only for what the data gives: a prop left undefined stays unset.
|
|
34
|
+
if (takesNode.includes(key) && value !== undefined) slots.push([key, value as Slot<State>]);
|
|
35
|
+
else if (isStatic(value, key)) values[key] = resolve(value, key, host);
|
|
36
|
+
// Read again each time the component reads it, as Svelte reads a prop written inline.
|
|
37
|
+
else
|
|
38
|
+
Object.defineProperty(values, key, {
|
|
39
|
+
get: () => resolve(value, key, host),
|
|
40
|
+
enumerable: true,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const [only, ...more] = children;
|
|
44
|
+
if (only !== undefined) slots.push(["children", more.length === 0 ? only : children]);
|
|
45
|
+
return { values, slots };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { values, slots } = untrack(() => split(node, host));
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<Snippets
|
|
52
|
+
component={COMPONENTS[node.name] as Component<Record<string, unknown>>}
|
|
53
|
+
props={values}
|
|
54
|
+
{slots}
|
|
55
|
+
{host}
|
|
56
|
+
/>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ComponentNode, type Host } from "@xds/core/preview";
|
|
2
|
+
import { type Component, type Snippet } from "svelte";
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
node: ComponentNode;
|
|
5
|
+
host: Host<Snippet>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A component node, drawn with the library's component of its name. A prop that takes a node
|
|
9
|
+
* (NODE_PROPS), and the children, reach the component as snippets of the same names, whether they
|
|
10
|
+
* hold a node or text; every other prop is resolved from the state where the component reads it,
|
|
11
|
+
* and once if it reads nothing from the state.
|
|
12
|
+
*/
|
|
13
|
+
declare const Component: Component<$$ComponentProps, {}, "">;
|
|
14
|
+
type Component = ReturnType<typeof Component>;
|
|
15
|
+
export default Component;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Draws a slot of a screen: an array is its children side by side; a string or a number is text;
|
|
4
|
+
a function is text that follows the state; a `show` node is its children while its condition
|
|
5
|
+
holds and its fallback otherwise; an `element` node is its tag, and a `component` node the
|
|
6
|
+
library's component of that name.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import {
|
|
10
|
+
type Child,
|
|
11
|
+
type Host,
|
|
12
|
+
isNode,
|
|
13
|
+
resolve,
|
|
14
|
+
type Slot,
|
|
15
|
+
type State,
|
|
16
|
+
} from "@xds/core/preview";
|
|
17
|
+
import type { Snippet } from "svelte";
|
|
18
|
+
import Component from "./Component.svelte";
|
|
19
|
+
import Self from "./Draw.svelte";
|
|
20
|
+
|
|
21
|
+
let { content, host }: { content: Slot<State> | undefined; host: Host<Snippet> } = $props();
|
|
22
|
+
|
|
23
|
+
const many = (slot: Slot<State> | undefined): slot is readonly Child<State>[] =>
|
|
24
|
+
Array.isArray(slot);
|
|
25
|
+
|
|
26
|
+
// An element's attributes, read again where they follow the state. The data names style
|
|
27
|
+
// properties as CSS does, which is what the style attribute takes.
|
|
28
|
+
const attributes = (props: Readonly<Record<string, unknown>>) =>
|
|
29
|
+
Object.fromEntries(
|
|
30
|
+
Object.entries(props).map(([key, value]) => [
|
|
31
|
+
key,
|
|
32
|
+
key === "style"
|
|
33
|
+
? Object.entries(value as Record<string, string>)
|
|
34
|
+
.map(([name, css]) => `${name}: ${css}`)
|
|
35
|
+
.join("; ")
|
|
36
|
+
: resolve(value, key, host),
|
|
37
|
+
]),
|
|
38
|
+
);
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
{#if many(content)}
|
|
42
|
+
{#each content as child, index (index)}<Self content={child} {host} />{/each}
|
|
43
|
+
{:else if typeof content === "function"}
|
|
44
|
+
{content(host.state)}
|
|
45
|
+
{:else if !isNode(content)}
|
|
46
|
+
{content}
|
|
47
|
+
{:else if content.kind === "show"}
|
|
48
|
+
{#if content.when(host.state)}
|
|
49
|
+
<Self content={content.children} {host} />
|
|
50
|
+
{:else}
|
|
51
|
+
<Self content={content.fallback} {host} />
|
|
52
|
+
{/if}
|
|
53
|
+
{:else if content.kind === "element" && content.children.length === 0}
|
|
54
|
+
<!-- Apart, since a void element such as img can take no children block. -->
|
|
55
|
+
<svelte:element this={content.tag} {...attributes(content.props)} />
|
|
56
|
+
{:else if content.kind === "element"}
|
|
57
|
+
<svelte:element this={content.tag} {...attributes(content.props)}
|
|
58
|
+
>{#each content.children as child, index (index)}<Self
|
|
59
|
+
content={child}
|
|
60
|
+
{host}
|
|
61
|
+
/>{/each}</svelte:element
|
|
62
|
+
>
|
|
63
|
+
{:else}
|
|
64
|
+
<Component node={content} {host} />
|
|
65
|
+
{/if}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Host, type Slot, type State } from "@xds/core/preview";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
content: Slot<State> | undefined;
|
|
5
|
+
host: Host<Snippet>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Draws a slot of a screen: an array is its children side by side; a string or a number is text;
|
|
9
|
+
* a function is text that follows the state; a `show` node is its children while its condition
|
|
10
|
+
* holds and its fallback otherwise; an `element` node is its tag, and a `component` node the
|
|
11
|
+
* library's component of that name.
|
|
12
|
+
*/
|
|
13
|
+
declare const Draw: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
14
|
+
type Draw = ReturnType<typeof Draw>;
|
|
15
|
+
export default Draw;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Draws a screen of @xds/core/preview (the design preview, a behavior test's scenario) with
|
|
4
|
+
this library's components. Each state slot is a state of its own, and a prop is read where the
|
|
5
|
+
component reads it, so a change updates only what reads the slot. The screen it is first given
|
|
6
|
+
is the one it draws.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import type { Host, Screen } from "@xds/core/preview";
|
|
10
|
+
import { onMount, type Snippet, untrack } from "svelte";
|
|
11
|
+
import Draw from "./Draw.svelte";
|
|
12
|
+
|
|
13
|
+
let { screen }: { screen: Screen } = $props();
|
|
14
|
+
|
|
15
|
+
const { state: first, root, mount } = untrack(() => screen);
|
|
16
|
+
const values: Record<string, unknown> = {};
|
|
17
|
+
const writes = new Map<string, (value: unknown) => void>();
|
|
18
|
+
for (const [key, value] of Object.entries(first)) {
|
|
19
|
+
// Raw: a list in a slot is replaced, never changed in place.
|
|
20
|
+
let slot = $state.raw(value);
|
|
21
|
+
Object.defineProperty(values, key, { get: () => slot, enumerable: true });
|
|
22
|
+
writes.set(key, (next) => (slot = next));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const host: Host<Snippet> = {
|
|
26
|
+
state: values,
|
|
27
|
+
set: (patch) => {
|
|
28
|
+
for (const [key, value] of Object.entries(patch)) writes.get(key)?.(value);
|
|
29
|
+
},
|
|
30
|
+
// Draw.svelte draws the slots, and a node prop reaches a component as a snippet that
|
|
31
|
+
// Snippets.svelte writes. The data puts no node anywhere else (see model.ts), so nothing
|
|
32
|
+
// asks this to draw one.
|
|
33
|
+
draw: () => {
|
|
34
|
+
throw new Error("A node goes only in a component's own prop or in its children.");
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
onMount(() => mount?.());
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<Draw content={root} {host} />
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Screen } from "@xds/core/preview";
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
screen: Screen;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Draws a screen of @xds/core/preview (the design preview, a behavior test's scenario) with
|
|
7
|
+
* this library's components. Each state slot is a state of its own, and a prop is read where the
|
|
8
|
+
* component reads it, so a change updates only what reads the slot. The screen it is first given
|
|
9
|
+
* is the one it draws.
|
|
10
|
+
*/
|
|
11
|
+
declare const Preview: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
12
|
+
type Preview = ReturnType<typeof Preview>;
|
|
13
|
+
export default Preview;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Draws a component with each of its node props as a snippet. Svelte has no public way to make a
|
|
4
|
+
snippet that draws components from a script, so this wraps one node prop at a time in a
|
|
5
|
+
template snippet, which adds nothing to the page, and calls itself for the next.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import type { Host, Slot, State } from "@xds/core/preview";
|
|
9
|
+
import type { Component, Snippet } from "svelte";
|
|
10
|
+
import Draw from "./Draw.svelte";
|
|
11
|
+
import Self from "./Snippets.svelte";
|
|
12
|
+
|
|
13
|
+
let {
|
|
14
|
+
component: Drawn,
|
|
15
|
+
props,
|
|
16
|
+
slots,
|
|
17
|
+
host,
|
|
18
|
+
made = {},
|
|
19
|
+
}: {
|
|
20
|
+
component: Component<Record<string, unknown>>;
|
|
21
|
+
props: Record<string, unknown>;
|
|
22
|
+
/** The node props still to wrap, by name. */
|
|
23
|
+
slots: readonly (readonly [string, Slot<State>])[];
|
|
24
|
+
host: Host<Snippet>;
|
|
25
|
+
/** The snippets made so far, by name. */
|
|
26
|
+
made?: Record<string, Snippet>;
|
|
27
|
+
} = $props();
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
{#if slots.length === 0}
|
|
31
|
+
<Drawn {...props} {...made} />
|
|
32
|
+
{:else}
|
|
33
|
+
{@const [name, content] = slots[0] ?? ["", undefined]}
|
|
34
|
+
{#snippet drawn()}<Draw {content} {host} />{/snippet}
|
|
35
|
+
<Self component={Drawn} {props} slots={slots.slice(1)} {host} made={{ ...made, [name]: drawn }} />
|
|
36
|
+
{/if}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Host, Slot, State } from "@xds/core/preview";
|
|
2
|
+
import type { Component, Snippet } from "svelte";
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
component: Component<Record<string, unknown>>;
|
|
5
|
+
props: Record<string, unknown>;
|
|
6
|
+
/** The node props still to wrap, by name. */
|
|
7
|
+
slots: readonly (readonly [string, Slot<State>])[];
|
|
8
|
+
host: Host<Snippet>;
|
|
9
|
+
/** The snippets made so far, by name. */
|
|
10
|
+
made?: Record<string, Snippet>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Draws a component with each of its node props as a snippet. Svelte has no public way to make a
|
|
14
|
+
* snippet that draws components from a script, so this wraps one node prop at a time in a
|
|
15
|
+
* template snippet, which adds nothing to the page, and calls itself for the next.
|
|
16
|
+
*/
|
|
17
|
+
declare const Snippets: Component<$$ComponentProps, {}, "">;
|
|
18
|
+
type Snippets = ReturnType<typeof Snippets>;
|
|
19
|
+
export default Snippets;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Accordion, Avatar, AvatarStack, Badge, Banner, Button, Card, Checkbox, Chip, ChipBar, CountBadge, DatePicker, DateRangePicker, Defaults, Dialog, Divider, EmptyState, Icon, IconButton, ListRow, MediaCard, Menu, ProgressBar, RadioGroup, SearchField, SectionHeader, SegmentedControl, Select, Sidebar, Skeleton, Slider, Spinner, Switch, Tabs, Text, TextField, Thumbnail, Toast, Tooltip, } from "../index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Every component the data can name, each taking the props the data gives it, with a snippet
|
|
4
|
+
* for each node. They are imported by name: a namespace import of the entry would put every
|
|
5
|
+
* component in the chunk that the app's own screens load too.
|
|
6
|
+
*/
|
|
7
|
+
export const COMPONENTS = {
|
|
8
|
+
Accordion,
|
|
9
|
+
Avatar,
|
|
10
|
+
AvatarStack,
|
|
11
|
+
Badge,
|
|
12
|
+
Banner,
|
|
13
|
+
Button,
|
|
14
|
+
Card,
|
|
15
|
+
Checkbox,
|
|
16
|
+
Chip,
|
|
17
|
+
ChipBar,
|
|
18
|
+
CountBadge,
|
|
19
|
+
DatePicker,
|
|
20
|
+
DateRangePicker,
|
|
21
|
+
Defaults,
|
|
22
|
+
Dialog,
|
|
23
|
+
Divider,
|
|
24
|
+
EmptyState,
|
|
25
|
+
Icon,
|
|
26
|
+
IconButton,
|
|
27
|
+
ListRow,
|
|
28
|
+
MediaCard,
|
|
29
|
+
Menu,
|
|
30
|
+
ProgressBar,
|
|
31
|
+
RadioGroup,
|
|
32
|
+
SearchField,
|
|
33
|
+
SectionHeader,
|
|
34
|
+
SegmentedControl,
|
|
35
|
+
Select,
|
|
36
|
+
Sidebar,
|
|
37
|
+
Skeleton,
|
|
38
|
+
Slider,
|
|
39
|
+
Spinner,
|
|
40
|
+
Switch,
|
|
41
|
+
Tabs,
|
|
42
|
+
Text,
|
|
43
|
+
TextField,
|
|
44
|
+
Thumbnail,
|
|
45
|
+
Toast,
|
|
46
|
+
Tooltip,
|
|
47
|
+
};
|
|
48
|
+
({});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Draws a screen of @xds/core/preview (the design preview, a behavior test's scenario) with
|
|
2
|
+
// this library's components. Each web app's design preview hands designPreview() to Preview.
|
|
3
|
+
export { designPreview } from "@xds/core/preview";
|
|
4
|
+
export { default as Preview } from "./Preview.svelte";
|
package/dist/root.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layer 7 of the library's customization: what an app adds to a component's root element, the
|
|
3
|
+
* one with its root part (`xds-<name>`). For an overlay that is its surface: the menu, the
|
|
4
|
+
* tooltip, the dialog or the toast, while it is open.
|
|
5
|
+
*/
|
|
6
|
+
export type RootProps = {
|
|
7
|
+
/** Classes added to the root element's own. */
|
|
8
|
+
class?: string;
|
|
9
|
+
/** Inline style for the root element. */
|
|
10
|
+
style?: string;
|
|
11
|
+
};
|
package/dist/root.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The props an overlay's machine has for the control that opens it. */
|
|
2
|
+
export type TriggerProps = Record<string, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* For an overlay: gives the control it draws its trigger props, joined with those of any
|
|
5
|
+
* overlay around this one. A Tooltip around a Menu's button gives the button both sets; the
|
|
6
|
+
* handlers of both run. Call it while the component is set up.
|
|
7
|
+
*/
|
|
8
|
+
export declare function provideTrigger(own: () => TriggerProps): void;
|
|
9
|
+
/**
|
|
10
|
+
* For an overlay's own content, such as a Dialog's buttons: nothing inside it opens an overlay
|
|
11
|
+
* from a control outside it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resetTrigger(): void;
|
|
14
|
+
/**
|
|
15
|
+
* For a control that can open an overlay: its own props, after those of the overlays it opens.
|
|
16
|
+
* Its own attributes win, its own handlers run first, and its class is added to theirs. While
|
|
17
|
+
* `inert` is true, as for a loading button, the overlays get none of its events and so do not
|
|
18
|
+
* open. Call it while the component is set up, and spread what the result returns on the
|
|
19
|
+
* element.
|
|
20
|
+
*/
|
|
21
|
+
export declare function withTrigger<T extends object>(own: () => T, inert?: () => boolean): () => T;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Menu and Tooltip take the control that opens them as a snippet, as in every web library:
|
|
2
|
+
// `<Menu>{#snippet trigger()}<Button>Actions</Button>{/snippet}</Menu>`, `<Tooltip label="Search">
|
|
3
|
+
// <IconButton … /></Tooltip>`. The overlay's machine has props for that control (its id, aria
|
|
4
|
+
// and event handlers), and they reach the Button or IconButton through this context, so an app
|
|
5
|
+
// never wires them up itself.
|
|
6
|
+
import { mergeProps } from "@zag-js/svelte";
|
|
7
|
+
import { createContext } from "svelte";
|
|
8
|
+
// Not exported from the package: only this package's controls and overlays use it.
|
|
9
|
+
const [getTrigger, setTrigger, hasTrigger] = createContext();
|
|
10
|
+
/** The trigger props of the overlays around the component being set up, if any. */
|
|
11
|
+
function outerTrigger() {
|
|
12
|
+
return hasTrigger() ? getTrigger() : null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* For an overlay: gives the control it draws its trigger props, joined with those of any
|
|
16
|
+
* overlay around this one. A Tooltip around a Menu's button gives the button both sets; the
|
|
17
|
+
* handlers of both run. Call it while the component is set up.
|
|
18
|
+
*/
|
|
19
|
+
export function provideTrigger(own) {
|
|
20
|
+
const outer = outerTrigger();
|
|
21
|
+
const merged = $derived(mergeProps(outer?.() ?? {}, own()));
|
|
22
|
+
setTrigger(() => merged);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* For an overlay's own content, such as a Dialog's buttons: nothing inside it opens an overlay
|
|
26
|
+
* from a control outside it.
|
|
27
|
+
*/
|
|
28
|
+
export function resetTrigger() {
|
|
29
|
+
setTrigger(null);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* For a control that can open an overlay: its own props, after those of the overlays it opens.
|
|
33
|
+
* Its own attributes win, its own handlers run first, and its class is added to theirs. While
|
|
34
|
+
* `inert` is true, as for a loading button, the overlays get none of its events and so do not
|
|
35
|
+
* open. Call it while the component is set up, and spread what the result returns on the
|
|
36
|
+
* element.
|
|
37
|
+
*/
|
|
38
|
+
export function withTrigger(own, inert) {
|
|
39
|
+
const trigger = outerTrigger();
|
|
40
|
+
const merged = $derived.by(() => {
|
|
41
|
+
let overlays = trigger?.() ?? {};
|
|
42
|
+
if (inert?.()) {
|
|
43
|
+
overlays = Object.fromEntries(Object.entries(overlays).filter(([key]) => !key.startsWith("on")));
|
|
44
|
+
}
|
|
45
|
+
return mergeProps(overlays, own());
|
|
46
|
+
});
|
|
47
|
+
return () => merged;
|
|
48
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xds/svelte",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The xds design system's components for Svelte.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"design-system",
|
|
7
|
+
"design-tokens",
|
|
8
|
+
"components",
|
|
9
|
+
"svelte"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://github.com/kjmin-dev/xds/blob/main/docs/library.md",
|
|
13
|
+
"bugs": "https://github.com/kjmin-dev/xds/issues",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/kjmin-dev/xds.git",
|
|
17
|
+
"directory": "packages/ui-svelte"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"sideEffects": [
|
|
21
|
+
"*.css"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"svelte": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./preview": {
|
|
30
|
+
"types": "./dist/preview/index.d.ts",
|
|
31
|
+
"svelte": "./dist/preview/index.js",
|
|
32
|
+
"default": "./dist/preview/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./styles.css": "./styles.css",
|
|
35
|
+
"./tailwind.css": "./tailwind.css",
|
|
36
|
+
"./page.css": "./page.css",
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"styles.css",
|
|
42
|
+
"tailwind.css",
|
|
43
|
+
"page.css"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@xds/tokens": "0.2.0",
|
|
47
|
+
"@xds/core": "0.2.0",
|
|
48
|
+
"@internationalized/date": "3.12.4",
|
|
49
|
+
"@zag-js/accordion": "2.0.0-next.4",
|
|
50
|
+
"@zag-js/aria-hidden": "2.0.0-next.4",
|
|
51
|
+
"@zag-js/date-picker": "2.0.0-next.4",
|
|
52
|
+
"@zag-js/dialog": "2.0.0-next.4",
|
|
53
|
+
"@zag-js/menu": "2.0.0-next.4",
|
|
54
|
+
"@zag-js/remove-scroll": "2.0.0-next.4",
|
|
55
|
+
"@zag-js/select": "2.0.0-next.4",
|
|
56
|
+
"@zag-js/slider": "2.0.0-next.4",
|
|
57
|
+
"@zag-js/svelte": "2.0.0-next.4",
|
|
58
|
+
"@zag-js/tabs": "2.0.0-next.4",
|
|
59
|
+
"@zag-js/tooltip": "2.0.0-next.4"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"svelte": "^5.57.3"
|
|
63
|
+
}
|
|
64
|
+
}
|