@xds/svelte 0.0.0-stage → 0.1.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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kjmin-dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @xds/svelte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The components of the xds design system for Svelte, with the look of an app made with `xds create`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @xds/svelte
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Import the stylesheet once, then use the components:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import "@xds/svelte/styles.css";
|
|
13
|
+
import { Button } from "@xds/svelte";
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`<Button>` and every other component take the app's class and style on their root element, which also carries a stable class such as `xds-button`. The `Defaults` component sets what the components inside it take when the app passes no variant, size or tone.
|
|
17
|
+
|
|
18
|
+
The stylesheet keeps to the `xds` cascade layer and to the library's own elements, so the app's styles win. `@xds/svelte/page.css` gives the page the library's background, text color and font. An app with Tailwind CSS 4.1 or later can import `@xds/svelte/tailwind.css` before Tailwind instead of `styles.css`.
|
|
19
|
+
|
|
20
|
+
This channel is a preview while its behavior library, Zag.js 2, is a prerelease. See [xds as a library](https://github.com/kjmin-dev/xds/blob/main/docs/library.md) for modes, themes and the rest of the customization.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Items whose bodies open and close under their titles, separated by hairlines. The chevron turns
|
|
4
|
+
over when an item is open, so the state does not depend on color. Opening and closing animate
|
|
5
|
+
the height, and do not for people who ask for less motion.
|
|
6
|
+
|
|
7
|
+
Each title is a heading holding a button that says whether its body is expanded and which body
|
|
8
|
+
it controls. A closed body is hidden, but the browser's find in page still opens it.
|
|
9
|
+
-->
|
|
10
|
+
<script module lang="ts">
|
|
11
|
+
import type { AccordionBaseProps, AccordionItemBase } from "@xds/core";
|
|
12
|
+
import type { Snippet } from "svelte";
|
|
13
|
+
import type { RootProps } from "./root.js";
|
|
14
|
+
|
|
15
|
+
export type AccordionItem<Value extends string = string> = AccordionItemBase<Value> & {
|
|
16
|
+
/** The body, shown under the title while the item is open: text, or a snippet. */
|
|
17
|
+
content: string | Snippet;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type AccordionProps<Value extends string = string> = AccordionBaseProps<Value> &
|
|
21
|
+
RootProps & {
|
|
22
|
+
items: readonly AccordionItem<Value>[];
|
|
23
|
+
onChange: (expanded: Value[]) => void;
|
|
24
|
+
};
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script lang="ts" generics="Value extends string = string">
|
|
28
|
+
import { ACCORDION_PARTS, classes, focusTitleOnClick } from "@xds/core";
|
|
29
|
+
import * as accordion from "@zag-js/accordion";
|
|
30
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
31
|
+
import AccordionPanel from "./AccordionPanel.svelte";
|
|
32
|
+
import Icon from "./Icon.svelte";
|
|
33
|
+
|
|
34
|
+
let {
|
|
35
|
+
items,
|
|
36
|
+
expanded,
|
|
37
|
+
multiple = false,
|
|
38
|
+
onChange,
|
|
39
|
+
class: className,
|
|
40
|
+
style,
|
|
41
|
+
}: AccordionProps<Value> = $props();
|
|
42
|
+
|
|
43
|
+
const id = $props.id();
|
|
44
|
+
const service = useMachine(accordion.machine, () => ({
|
|
45
|
+
id,
|
|
46
|
+
value: [...expanded],
|
|
47
|
+
onValueChange: (details: accordion.ValueChangeDetails) => onChange(details.value as Value[]),
|
|
48
|
+
multiple,
|
|
49
|
+
collapsible: true,
|
|
50
|
+
hiddenUntilFound: true,
|
|
51
|
+
}));
|
|
52
|
+
const api = $derived(accordion.connect(service, normalizeProps));
|
|
53
|
+
// Merged, so that the app's style joins any the machine writes on the root.
|
|
54
|
+
const root = $derived(
|
|
55
|
+
mergeProps(api.getRootProps(), { class: classes("xds-accordion", className), style }),
|
|
56
|
+
);
|
|
57
|
+
const body = (value: Value) => {
|
|
58
|
+
// The panel hides itself once it has finished closing; see AccordionPanel.
|
|
59
|
+
const { hidden: _hidden, ...attributes } = api.getItemContentProps({ value });
|
|
60
|
+
return attributes;
|
|
61
|
+
};
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<div {...root}>
|
|
65
|
+
{#each items as item (item.value)}
|
|
66
|
+
<div {...api.getItemProps({ value: item.value })} class="xds-accordion__item">
|
|
67
|
+
<h3 {...api.getItemHeaderProps({ value: item.value })} class="xds-accordion__heading">
|
|
68
|
+
<button
|
|
69
|
+
{...mergeProps(api.getItemTriggerProps({ value: item.value }), {
|
|
70
|
+
// Runs before Zag's handler.
|
|
71
|
+
onclick: focusTitleOnClick,
|
|
72
|
+
})}
|
|
73
|
+
class="xds-accordion__trigger group"
|
|
74
|
+
>
|
|
75
|
+
<span class={ACCORDION_PARTS.text}>
|
|
76
|
+
<span class={ACCORDION_PARTS.title}>{item.title}</span>
|
|
77
|
+
{#if item.description}
|
|
78
|
+
<span class={ACCORDION_PARTS.description}>{item.description}</span>
|
|
79
|
+
{/if}
|
|
80
|
+
</span>
|
|
81
|
+
<Icon name="chevron-down" size="sm" class={ACCORDION_PARTS.chevron} />
|
|
82
|
+
</button>
|
|
83
|
+
</h3>
|
|
84
|
+
<AccordionPanel open={api.value.includes(item.value)} attributes={body(item.value)}>
|
|
85
|
+
{#if typeof item.content === "string"}{item.content}{:else}{@render item.content()}{/if}
|
|
86
|
+
</AccordionPanel>
|
|
87
|
+
</div>
|
|
88
|
+
{/each}
|
|
89
|
+
</div>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AccordionBaseProps, AccordionItemBase } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { RootProps } from "./root.js";
|
|
4
|
+
export type AccordionItem<Value extends string = string> = AccordionItemBase<Value> & {
|
|
5
|
+
/** The body, shown under the title while the item is open: text, or a snippet. */
|
|
6
|
+
content: string | Snippet;
|
|
7
|
+
};
|
|
8
|
+
export type AccordionProps<Value extends string = string> = AccordionBaseProps<Value> & RootProps & {
|
|
9
|
+
items: readonly AccordionItem<Value>[];
|
|
10
|
+
onChange: (expanded: Value[]) => void;
|
|
11
|
+
};
|
|
12
|
+
declare function $$render<Value extends string = string>(): {
|
|
13
|
+
props: AccordionProps<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
|
+
* Items whose bodies open and close under their titles, separated by hairlines. The chevron turns
|
|
35
|
+
* over when an item is open, so the state does not depend on color. Opening and closing animate
|
|
36
|
+
* the height, and do not for people who ask for less motion.
|
|
37
|
+
*
|
|
38
|
+
* Each title is a heading holding a button that says whether its body is expanded and which body
|
|
39
|
+
* it controls. A closed body is hidden, but the browser's find in page still opens it.
|
|
40
|
+
*/
|
|
41
|
+
declare const Accordion: $$IsomorphicComponent;
|
|
42
|
+
type Accordion<Value extends string = string> = InstanceType<typeof Accordion<Value>>;
|
|
43
|
+
export default Accordion;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
An Accordion item's body. Its height moves between zero and the height of what it holds, and
|
|
4
|
+
it is hidden only once it has finished closing. Only for Accordion: the index does not export
|
|
5
|
+
it.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { setPanelOpen } from "@xds/core";
|
|
9
|
+
import type { Snippet } from "svelte";
|
|
10
|
+
import type { Attachment } from "svelte/attachments";
|
|
11
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
12
|
+
|
|
13
|
+
let {
|
|
14
|
+
open,
|
|
15
|
+
attributes,
|
|
16
|
+
children,
|
|
17
|
+
}: { open: boolean; attributes: HTMLAttributes<HTMLDivElement>; children: Snippet } = $props();
|
|
18
|
+
|
|
19
|
+
let rendered = false;
|
|
20
|
+
// Again on each toggle; the next one takes over from this one.
|
|
21
|
+
const toggle: Attachment<HTMLDivElement> = (panel) => {
|
|
22
|
+
const stop = setPanelOpen(panel, open, rendered);
|
|
23
|
+
rendered = true;
|
|
24
|
+
return stop;
|
|
25
|
+
};
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<!-- A group: a region is a landmark, and a page of accordions would fill the list of landmarks.
|
|
29
|
+
A closed one is left out of the accessibility tree as soon as it starts closing;
|
|
30
|
+
`hidden="until-found"` alone leaves the empty group in it. A group, not a fieldset: it is the
|
|
31
|
+
body of a disclosure, not a set of form fields. -->
|
|
32
|
+
<div
|
|
33
|
+
{...attributes}
|
|
34
|
+
{@attach toggle}
|
|
35
|
+
role="group"
|
|
36
|
+
aria-hidden={open ? undefined : "true"}
|
|
37
|
+
class="xds-accordion__panel"
|
|
38
|
+
>
|
|
39
|
+
<div class="xds-accordion__body">{@render children()}</div>
|
|
40
|
+
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
open: boolean;
|
|
5
|
+
attributes: HTMLAttributes<HTMLDivElement>;
|
|
6
|
+
children: Snippet;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* An Accordion item's body. Its height moves between zero and the height of what it holds, and
|
|
10
|
+
* it is hidden only once it has finished closing. Only for Accordion: the index does not export
|
|
11
|
+
* it.
|
|
12
|
+
*/
|
|
13
|
+
declare const AccordionPanel: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
14
|
+
type AccordionPanel = ReturnType<typeof AccordionPanel>;
|
|
15
|
+
export default AccordionPanel;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Stands for a person or a team by a picture, or by their initials when there is none. Assistive
|
|
4
|
+
technology gets the full name either way. The small size has room for one letter.
|
|
5
|
+
-->
|
|
6
|
+
<script module lang="ts">
|
|
7
|
+
import type { AvatarBaseProps } from "@xds/core";
|
|
8
|
+
import type { RootProps } from "./root.js";
|
|
9
|
+
|
|
10
|
+
export type { AvatarSize } from "@xds/core";
|
|
11
|
+
|
|
12
|
+
export type AvatarProps = AvatarBaseProps & RootProps;
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script lang="ts">
|
|
16
|
+
import { avatarClass, avatarInitials, classes, pictureClass, rootPart } from "@xds/core";
|
|
17
|
+
import { useDefaults } from "./defaults.svelte.js";
|
|
18
|
+
import { createPicture } from "./picture.svelte.js";
|
|
19
|
+
|
|
20
|
+
let { name, src, size: ownSize, class: className, style }: AvatarProps = $props();
|
|
21
|
+
|
|
22
|
+
const defaults = useDefaults("Avatar");
|
|
23
|
+
const size = $derived(ownSize ?? defaults().size);
|
|
24
|
+
|
|
25
|
+
const picture = createPicture(() => src);
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<span
|
|
29
|
+
role="img"
|
|
30
|
+
aria-label={name}
|
|
31
|
+
class={classes(rootPart("Avatar"), avatarClass(size), className)}
|
|
32
|
+
{style}
|
|
33
|
+
>{avatarInitials(name, size)}{#if picture.loaded() !== false && src}
|
|
34
|
+
{@const address = src}
|
|
35
|
+
<!-- The name is on the avatar itself; a second one on the picture would be read twice. -->
|
|
36
|
+
<img
|
|
37
|
+
src={address}
|
|
38
|
+
alt=""
|
|
39
|
+
aria-hidden="true"
|
|
40
|
+
class={pictureClass(picture.loaded() === true)}
|
|
41
|
+
onload={() => picture.onLoad(address)}
|
|
42
|
+
onerror={() => picture.onError(address)}
|
|
43
|
+
/>
|
|
44
|
+
{/if}</span
|
|
45
|
+
>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AvatarBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
3
|
+
export type { AvatarSize } from "@xds/core";
|
|
4
|
+
export type AvatarProps = AvatarBaseProps & RootProps;
|
|
5
|
+
/**
|
|
6
|
+
* Stands for a person or a team by a picture, or by their initials when there is none. Assistive
|
|
7
|
+
* technology gets the full name either way. The small size has room for one letter.
|
|
8
|
+
*/
|
|
9
|
+
declare const Avatar: import("svelte").Component<AvatarProps, {}, "">;
|
|
10
|
+
type Avatar = ReturnType<typeof Avatar>;
|
|
11
|
+
export default Avatar;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Several people in the room of one. Assistive technology gets one image named after everyone in
|
|
4
|
+
it, including those who did not fit.
|
|
5
|
+
-->
|
|
6
|
+
<script module lang="ts">
|
|
7
|
+
import type { AvatarStackBaseProps } from "@xds/core";
|
|
8
|
+
import type { RootProps } from "./root.js";
|
|
9
|
+
|
|
10
|
+
export type AvatarStackProps = AvatarStackBaseProps & RootProps;
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
import {
|
|
15
|
+
avatarStack,
|
|
16
|
+
avatarStackClass,
|
|
17
|
+
avatarStackItemClass,
|
|
18
|
+
avatarStackRestClass,
|
|
19
|
+
classes,
|
|
20
|
+
rootPart,
|
|
21
|
+
} from "@xds/core";
|
|
22
|
+
import Avatar from "./Avatar.svelte";
|
|
23
|
+
import { useDefaults } from "./defaults.svelte.js";
|
|
24
|
+
|
|
25
|
+
let { people, max, size: ownSize, label, class: className, style }: AvatarStackProps = $props();
|
|
26
|
+
|
|
27
|
+
const defaults = useDefaults("AvatarStack");
|
|
28
|
+
// Resolved here, built-in default included, so that the avatars take the stack's size rather
|
|
29
|
+
// than an Avatar default of their own.
|
|
30
|
+
const size = $derived(ownSize ?? defaults().size ?? "md");
|
|
31
|
+
|
|
32
|
+
const stack = $derived(avatarStack(people, max, label));
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<span
|
|
36
|
+
role="img"
|
|
37
|
+
aria-label={stack.name}
|
|
38
|
+
class={classes(rootPart("AvatarStack"), avatarStackClass, className)}
|
|
39
|
+
{style}
|
|
40
|
+
>
|
|
41
|
+
{#each stack.shown as person, index (index)}
|
|
42
|
+
<span aria-hidden="true" class={avatarStackItemClass(size)}>
|
|
43
|
+
<Avatar name={person.name} src={person.src} {size} />
|
|
44
|
+
</span>
|
|
45
|
+
{/each}
|
|
46
|
+
{#if stack.rest > 0}
|
|
47
|
+
<span aria-hidden="true" class={avatarStackRestClass(size)}>+{stack.rest}</span>
|
|
48
|
+
{/if}
|
|
49
|
+
</span>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AvatarStackBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
3
|
+
export type AvatarStackProps = AvatarStackBaseProps & RootProps;
|
|
4
|
+
/**
|
|
5
|
+
* Several people in the room of one. Assistive technology gets one image named after everyone in
|
|
6
|
+
* it, including those who did not fit.
|
|
7
|
+
*/
|
|
8
|
+
declare const AvatarStack: import("svelte").Component<AvatarStackProps, {}, "">;
|
|
9
|
+
type AvatarStack = ReturnType<typeof AvatarStack>;
|
|
10
|
+
export default AvatarStack;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A short status or category. The words carry the meaning; the color only reinforces it, so a
|
|
4
|
+
badge still reads for someone who cannot tell the tones apart. `dot` adds a small mark for live
|
|
5
|
+
states such as "connected", and `icon` a drawing in front of the words.
|
|
6
|
+
-->
|
|
7
|
+
<script module lang="ts">
|
|
8
|
+
import type { BadgeBaseProps } from "@xds/core";
|
|
9
|
+
import type { Snippet } from "svelte";
|
|
10
|
+
import type { RootProps } from "./root.js";
|
|
11
|
+
|
|
12
|
+
export type { BadgeTone } from "@xds/core";
|
|
13
|
+
|
|
14
|
+
export type BadgeProps = BadgeBaseProps &
|
|
15
|
+
RootProps & {
|
|
16
|
+
children: Snippet;
|
|
17
|
+
};
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import { badgeClass, badgeDotClass, classes, rootPart } from "@xds/core";
|
|
22
|
+
import { useDefaults } from "./defaults.svelte.js";
|
|
23
|
+
import Icon from "./Icon.svelte";
|
|
24
|
+
|
|
25
|
+
let { tone: ownTone, dot, icon, class: className, style, children }: BadgeProps = $props();
|
|
26
|
+
|
|
27
|
+
const defaults = useDefaults("Badge");
|
|
28
|
+
const tone = $derived(ownTone ?? defaults().tone);
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<span class={classes(rootPart("Badge"), badgeClass(tone), className)} {style}
|
|
32
|
+
>{#if dot}<span aria-hidden="true" class={badgeDotClass}></span>{/if}{#if icon}<Icon
|
|
33
|
+
name={icon}
|
|
34
|
+
size="xs"
|
|
35
|
+
/>{/if}{@render children()}</span
|
|
36
|
+
>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BadgeBaseProps } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { RootProps } from "./root.js";
|
|
4
|
+
export type { BadgeTone } from "@xds/core";
|
|
5
|
+
export type BadgeProps = BadgeBaseProps & RootProps & {
|
|
6
|
+
children: Snippet;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A short status or category. The words carry the meaning; the color only reinforces it, so a
|
|
10
|
+
* badge still reads for someone who cannot tell the tones apart. `dot` adds a small mark for live
|
|
11
|
+
* states such as "connected", and `icon` a drawing in front of the words.
|
|
12
|
+
*/
|
|
13
|
+
declare const Badge: import("svelte").Component<BadgeProps, {}, "">;
|
|
14
|
+
type Badge = ReturnType<typeof Badge>;
|
|
15
|
+
export default Badge;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A message about the whole view or a section of it. Each tone has its own icon shape, so the tone
|
|
4
|
+
does not depend on color. Problems (`warning`, `danger`) interrupt a screen reader; `info` and
|
|
5
|
+
`success` wait their turn.
|
|
6
|
+
-->
|
|
7
|
+
<script module lang="ts">
|
|
8
|
+
import type { BannerBaseProps } from "@xds/core";
|
|
9
|
+
import type { Snippet } from "svelte";
|
|
10
|
+
import type { RootProps } from "./root.js";
|
|
11
|
+
|
|
12
|
+
export type { BannerTone } from "@xds/core";
|
|
13
|
+
|
|
14
|
+
export type BannerProps = BannerBaseProps &
|
|
15
|
+
RootProps & {
|
|
16
|
+
/** What the person can do about the message. Drawn under it as a small secondary button. */
|
|
17
|
+
action?: { label: string; onPress: () => void };
|
|
18
|
+
/**
|
|
19
|
+
* Shows a close control. The banner does not hide itself: the handler decides what happens
|
|
20
|
+
* to it.
|
|
21
|
+
*/
|
|
22
|
+
onDismiss?: () => void;
|
|
23
|
+
children: Snippet;
|
|
24
|
+
};
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script lang="ts">
|
|
28
|
+
import {
|
|
29
|
+
BANNER_PARTS,
|
|
30
|
+
bannerClass,
|
|
31
|
+
bannerIconClass,
|
|
32
|
+
bannerIconPath,
|
|
33
|
+
bannerRole,
|
|
34
|
+
classes,
|
|
35
|
+
rootPart,
|
|
36
|
+
} from "@xds/core";
|
|
37
|
+
import Button from "./Button.svelte";
|
|
38
|
+
import { useDefaults } from "./defaults.svelte.js";
|
|
39
|
+
import IconButton from "./IconButton.svelte";
|
|
40
|
+
|
|
41
|
+
let {
|
|
42
|
+
tone: ownTone,
|
|
43
|
+
title,
|
|
44
|
+
dismissLabel,
|
|
45
|
+
action,
|
|
46
|
+
onDismiss,
|
|
47
|
+
class: className,
|
|
48
|
+
style,
|
|
49
|
+
children,
|
|
50
|
+
}: BannerProps = $props();
|
|
51
|
+
|
|
52
|
+
const defaults = useDefaults("Banner");
|
|
53
|
+
const tone = $derived(ownTone ?? defaults().tone);
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<div
|
|
57
|
+
role={bannerRole(tone)}
|
|
58
|
+
class={classes(rootPart("Banner"), bannerClass(tone), className)}
|
|
59
|
+
{style}
|
|
60
|
+
>
|
|
61
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" class={bannerIconClass(tone)}>
|
|
62
|
+
<path fill="currentColor" d={bannerIconPath(tone)} />
|
|
63
|
+
</svg>
|
|
64
|
+
<div class={BANNER_PARTS.body}>
|
|
65
|
+
{#if title}
|
|
66
|
+
<p class={BANNER_PARTS.title}>{title}</p>
|
|
67
|
+
{/if}
|
|
68
|
+
<div>{@render children()}</div>
|
|
69
|
+
{#if action}
|
|
70
|
+
<div class={BANNER_PARTS.action}>
|
|
71
|
+
<Button variant="secondary" size="sm" onPress={() => action.onPress()}
|
|
72
|
+
>{action.label}</Button
|
|
73
|
+
>
|
|
74
|
+
</div>
|
|
75
|
+
{/if}
|
|
76
|
+
</div>
|
|
77
|
+
{#if onDismiss}
|
|
78
|
+
<div class={BANNER_PARTS.dismiss}>
|
|
79
|
+
<IconButton
|
|
80
|
+
icon="x"
|
|
81
|
+
label={dismissLabel ?? "Dismiss"}
|
|
82
|
+
variant="ghost"
|
|
83
|
+
size="sm"
|
|
84
|
+
onPress={() => onDismiss()}
|
|
85
|
+
/>
|
|
86
|
+
</div>
|
|
87
|
+
{/if}
|
|
88
|
+
</div>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BannerBaseProps } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { RootProps } from "./root.js";
|
|
4
|
+
export type { BannerTone } from "@xds/core";
|
|
5
|
+
export type BannerProps = BannerBaseProps & RootProps & {
|
|
6
|
+
/** What the person can do about the message. Drawn under it as a small secondary button. */
|
|
7
|
+
action?: {
|
|
8
|
+
label: string;
|
|
9
|
+
onPress: () => void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Shows a close control. The banner does not hide itself: the handler decides what happens
|
|
13
|
+
* to it.
|
|
14
|
+
*/
|
|
15
|
+
onDismiss?: () => void;
|
|
16
|
+
children: Snippet;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A message about the whole view or a section of it. Each tone has its own icon shape, so the tone
|
|
20
|
+
* does not depend on color. Problems (`warning`, `danger`) interrupt a screen reader; `info` and
|
|
21
|
+
* `success` wait their turn.
|
|
22
|
+
*/
|
|
23
|
+
declare const Banner: import("svelte").Component<BannerProps, {}, "">;
|
|
24
|
+
type Banner = ReturnType<typeof Banner>;
|
|
25
|
+
export default Banner;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach it
|
|
4
|
+
through context.
|
|
5
|
+
-->
|
|
6
|
+
<script module lang="ts">
|
|
7
|
+
import type { ButtonBaseProps } from "@xds/core";
|
|
8
|
+
import type { Snippet } from "svelte";
|
|
9
|
+
import type { RootProps } from "./root.js";
|
|
10
|
+
|
|
11
|
+
export type { ButtonVariant, ControlSize } from "@xds/core";
|
|
12
|
+
|
|
13
|
+
export type ButtonProps = ButtonBaseProps &
|
|
14
|
+
RootProps & {
|
|
15
|
+
onPress?: () => void;
|
|
16
|
+
/** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
};
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import { BUTTON_ICON, buttonClass, classes, isHeld } from "@xds/core";
|
|
23
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
24
|
+
import { useDefaults } from "./defaults.svelte.js";
|
|
25
|
+
import Icon from "./Icon.svelte";
|
|
26
|
+
import Spinner from "./Spinner.svelte";
|
|
27
|
+
import { withTrigger } from "./trigger.svelte.js";
|
|
28
|
+
|
|
29
|
+
let {
|
|
30
|
+
variant: ownVariant,
|
|
31
|
+
size: ownSize,
|
|
32
|
+
iconStart,
|
|
33
|
+
iconEnd,
|
|
34
|
+
selected,
|
|
35
|
+
disabled,
|
|
36
|
+
loading,
|
|
37
|
+
fullWidth = false,
|
|
38
|
+
type = "button",
|
|
39
|
+
onPress,
|
|
40
|
+
"aria-label": ariaLabel,
|
|
41
|
+
class: className,
|
|
42
|
+
style,
|
|
43
|
+
children,
|
|
44
|
+
}: ButtonProps = $props();
|
|
45
|
+
|
|
46
|
+
const defaults = useDefaults("Button");
|
|
47
|
+
const variant = $derived(ownVariant ?? defaults().variant ?? "secondary");
|
|
48
|
+
const size = $derived(ownSize ?? defaults().size ?? "md");
|
|
49
|
+
|
|
50
|
+
const icon = $derived(BUTTON_ICON[size]);
|
|
51
|
+
const held = $derived(isHeld({ variant, selected, disabled }));
|
|
52
|
+
const attributes = withTrigger(
|
|
53
|
+
(): HTMLButtonAttributes => ({
|
|
54
|
+
type,
|
|
55
|
+
// The recipe gives the root part, `xds-button`.
|
|
56
|
+
class: classes(
|
|
57
|
+
buttonClass({
|
|
58
|
+
variant,
|
|
59
|
+
size,
|
|
60
|
+
iconOnly: children === undefined && (iconStart !== undefined || iconEnd !== undefined),
|
|
61
|
+
fullWidth,
|
|
62
|
+
}),
|
|
63
|
+
className,
|
|
64
|
+
),
|
|
65
|
+
style,
|
|
66
|
+
disabled,
|
|
67
|
+
// Loading keeps the button focusable, so focus is not lost while it waits.
|
|
68
|
+
"aria-disabled": loading ? "true" : undefined,
|
|
69
|
+
"data-pending": loading ? "" : undefined,
|
|
70
|
+
"aria-pressed": selected === undefined ? undefined : selected ? "true" : "false",
|
|
71
|
+
"aria-label": ariaLabel,
|
|
72
|
+
onclick: () => {
|
|
73
|
+
// The press was taken already.
|
|
74
|
+
if (!loading) onPress?.();
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
() => loading === true,
|
|
78
|
+
);
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<button {...attributes()}
|
|
82
|
+
>{#if loading}{#if iconStart}
|
|
83
|
+
<!-- Where the icon was, so the button keeps its width. -->
|
|
84
|
+
<span class={icon.box}><Spinner size="sm" /></span>
|
|
85
|
+
{:else}<Spinner size="sm" />{/if}{:else if iconStart}<Icon
|
|
86
|
+
name={iconStart}
|
|
87
|
+
size={icon.size}
|
|
88
|
+
filled={held}
|
|
89
|
+
/>{/if}{@render children?.()}{#if iconEnd}<Icon name={iconEnd} size={icon.size} />{/if}</button
|
|
90
|
+
>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ButtonBaseProps } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { RootProps } from "./root.js";
|
|
4
|
+
export type { ButtonVariant, ControlSize } from "@xds/core";
|
|
5
|
+
export type ButtonProps = ButtonBaseProps & RootProps & {
|
|
6
|
+
onPress?: () => void;
|
|
7
|
+
/** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
|
|
8
|
+
children?: Snippet;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach it
|
|
12
|
+
* through context.
|
|
13
|
+
*/
|
|
14
|
+
declare const Button: import("svelte").Component<ButtonProps, {}, "">;
|
|
15
|
+
type Button = ReturnType<typeof Button>;
|
|
16
|
+
export default Button;
|