@xds/solid 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/dom/Accordion.js +139 -0
- package/dist/dom/Avatar.js +59 -0
- package/dist/dom/AvatarStack.js +74 -0
- package/dist/dom/Badge.js +58 -0
- package/dist/dom/Banner.js +102 -0
- package/dist/dom/Button.js +107 -0
- package/dist/dom/Card.js +164 -0
- package/dist/dom/Checkbox.js +64 -0
- package/dist/dom/Chip.js +52 -0
- package/dist/dom/ChipBar.js +28 -0
- package/dist/dom/CountBadge.js +67 -0
- package/dist/dom/DatePicker.js +300 -0
- package/dist/dom/DateRangePicker.js +404 -0
- package/dist/dom/Defaults.js +29 -0
- package/dist/dom/Dialog.js +136 -0
- package/dist/dom/Divider.js +20 -0
- package/dist/dom/EmptyState.js +70 -0
- package/dist/dom/Icon.js +46 -0
- package/dist/dom/IconButton.js +72 -0
- package/dist/dom/ListRow.js +126 -0
- package/dist/dom/MediaCard.js +178 -0
- package/dist/dom/Menu.js +176 -0
- package/dist/dom/ProgressBar.js +33 -0
- package/dist/dom/RadioGroup.js +123 -0
- package/dist/dom/SearchField.js +94 -0
- package/dist/dom/SectionHeader.js +104 -0
- package/dist/dom/SegmentedControl.js +69 -0
- package/dist/dom/Select.js +271 -0
- package/dist/dom/Sidebar.js +233 -0
- package/dist/dom/Skeleton.js +34 -0
- package/dist/dom/Slider.js +115 -0
- package/dist/dom/Spinner.js +35 -0
- package/dist/dom/Switch.js +65 -0
- package/dist/dom/Tabs.js +80 -0
- package/dist/dom/Text.js +24 -0
- package/dist/dom/TextField.js +172 -0
- package/dist/dom/Thumbnail.js +119 -0
- package/dist/dom/Toast.js +99 -0
- package/dist/dom/Tooltip.js +128 -0
- package/dist/dom/controlled.js +13 -0
- package/dist/dom/index.js +40 -0
- package/dist/dom/modal-popover.js +22 -0
- package/dist/dom/picture.js +29 -0
- package/dist/dom/presence.js +20 -0
- package/dist/dom/preview.js +139 -0
- package/dist/dom/root.js +26 -0
- package/dist/dom/trigger.js +31 -0
- package/dist/source/Accordion.d.ts +21 -0
- package/dist/source/Accordion.jsx +57 -0
- package/dist/source/Avatar.d.ts +9 -0
- package/dist/source/Avatar.jsx +16 -0
- package/dist/source/AvatarStack.d.ts +8 -0
- package/dist/source/AvatarStack.jsx +22 -0
- package/dist/source/Badge.d.ts +13 -0
- package/dist/source/Badge.jsx +15 -0
- package/dist/source/Banner.d.ts +23 -0
- package/dist/source/Banner.jsx +32 -0
- package/dist/source/Button.d.ts +15 -0
- package/dist/source/Button.jsx +48 -0
- package/dist/source/Card.d.ts +18 -0
- package/dist/source/Card.jsx +46 -0
- package/dist/source/Checkbox.d.ts +10 -0
- package/dist/source/Checkbox.jsx +20 -0
- package/dist/source/Chip.d.ts +12 -0
- package/dist/source/Chip.jsx +12 -0
- package/dist/source/ChipBar.d.ts +12 -0
- package/dist/source/ChipBar.jsx +7 -0
- package/dist/source/CountBadge.d.ts +12 -0
- package/dist/source/CountBadge.jsx +17 -0
- package/dist/source/DatePicker.d.ts +20 -0
- package/dist/source/DatePicker.jsx +109 -0
- package/dist/source/DateRangePicker.d.ts +24 -0
- package/dist/source/DateRangePicker.jsx +150 -0
- package/dist/source/Defaults.d.ts +23 -0
- package/dist/source/Defaults.jsx +12 -0
- package/dist/source/Dialog.d.ts +21 -0
- package/dist/source/Dialog.jsx +58 -0
- package/dist/source/Divider.d.ts +4 -0
- package/dist/source/Divider.jsx +5 -0
- package/dist/source/EmptyState.d.ts +12 -0
- package/dist/source/EmptyState.jsx +16 -0
- package/dist/source/Icon.d.ts +8 -0
- package/dist/source/Icon.jsx +11 -0
- package/dist/source/IconButton.d.ts +13 -0
- package/dist/source/IconButton.jsx +36 -0
- package/dist/source/ListRow.d.ts +21 -0
- package/dist/source/ListRow.jsx +38 -0
- package/dist/source/MediaCard.d.ts +20 -0
- package/dist/source/MediaCard.jsx +47 -0
- package/dist/source/Menu.d.ts +19 -0
- package/dist/source/Menu.jsx +99 -0
- package/dist/source/ProgressBar.d.ts +8 -0
- package/dist/source/ProgressBar.jsx +8 -0
- package/dist/source/RadioGroup.d.ts +15 -0
- package/dist/source/RadioGroup.jsx +57 -0
- package/dist/source/SearchField.d.ts +15 -0
- package/dist/source/SearchField.jsx +39 -0
- package/dist/source/SectionHeader.d.ts +14 -0
- package/dist/source/SectionHeader.jsx +32 -0
- package/dist/source/SegmentedControl.d.ts +12 -0
- package/dist/source/SegmentedControl.jsx +21 -0
- package/dist/source/Select.d.ts +18 -0
- package/dist/source/Select.jsx +139 -0
- package/dist/source/Sidebar.d.ts +22 -0
- package/dist/source/Sidebar.jsx +65 -0
- package/dist/source/Skeleton.d.ts +11 -0
- package/dist/source/Skeleton.jsx +9 -0
- package/dist/source/Slider.d.ts +13 -0
- package/dist/source/Slider.jsx +69 -0
- package/dist/source/Spinner.d.ts +9 -0
- package/dist/source/Spinner.jsx +12 -0
- package/dist/source/Switch.d.ts +13 -0
- package/dist/source/Switch.jsx +18 -0
- package/dist/source/Tabs.d.ts +14 -0
- package/dist/source/Tabs.jsx +31 -0
- package/dist/source/Text.d.ts +10 -0
- package/dist/source/Text.jsx +14 -0
- package/dist/source/TextField.d.ts +22 -0
- package/dist/source/TextField.jsx +73 -0
- package/dist/source/Thumbnail.d.ts +9 -0
- package/dist/source/Thumbnail.jsx +34 -0
- package/dist/source/Toast.d.ts +16 -0
- package/dist/source/Toast.jsx +42 -0
- package/dist/source/Tooltip.d.ts +28 -0
- package/dist/source/Tooltip.jsx +52 -0
- package/dist/source/controlled.d.ts +4 -0
- package/dist/source/controlled.js +11 -0
- package/dist/source/index.d.ts +40 -0
- package/dist/source/index.js +39 -0
- package/dist/source/modal-popover.d.ts +7 -0
- package/dist/source/modal-popover.js +15 -0
- package/dist/source/picture.d.ts +20 -0
- package/dist/source/picture.js +13 -0
- package/dist/source/presence.d.ts +7 -0
- package/dist/source/presence.js +13 -0
- package/dist/source/preview.d.ts +6 -0
- package/dist/source/preview.jsx +110 -0
- package/dist/source/root.d.ts +25 -0
- package/dist/source/root.js +19 -0
- package/dist/source/trigger.d.ts +18 -0
- package/dist/source/trigger.js +18 -0
- package/package.json +63 -4
- package/page.css +20 -0
- package/styles.css +3353 -0
- package/tailwind.css +2665 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Defaults } from "./Defaults.js";
|
|
2
|
+
import { Icon } from "./Icon.js";
|
|
3
|
+
import { Accordion } from "./Accordion.js";
|
|
4
|
+
import { Avatar } from "./Avatar.js";
|
|
5
|
+
import { AvatarStack } from "./AvatarStack.js";
|
|
6
|
+
import { Badge } from "./Badge.js";
|
|
7
|
+
import { Spinner } from "./Spinner.js";
|
|
8
|
+
import { Button } from "./Button.js";
|
|
9
|
+
import { IconButton } from "./IconButton.js";
|
|
10
|
+
import { Banner } from "./Banner.js";
|
|
11
|
+
import { Card } from "./Card.js";
|
|
12
|
+
import { Checkbox } from "./Checkbox.js";
|
|
13
|
+
import { Chip } from "./Chip.js";
|
|
14
|
+
import { ChipBar } from "./ChipBar.js";
|
|
15
|
+
import { CountBadge } from "./CountBadge.js";
|
|
16
|
+
import { DatePicker } from "./DatePicker.js";
|
|
17
|
+
import { DateRangePicker } from "./DateRangePicker.js";
|
|
18
|
+
import { Dialog } from "./Dialog.js";
|
|
19
|
+
import { Divider } from "./Divider.js";
|
|
20
|
+
import { EmptyState } from "./EmptyState.js";
|
|
21
|
+
import { ListRow } from "./ListRow.js";
|
|
22
|
+
import { Thumbnail } from "./Thumbnail.js";
|
|
23
|
+
import { MediaCard } from "./MediaCard.js";
|
|
24
|
+
import { Menu } from "./Menu.js";
|
|
25
|
+
import { ProgressBar } from "./ProgressBar.js";
|
|
26
|
+
import { RadioGroup } from "./RadioGroup.js";
|
|
27
|
+
import { SearchField } from "./SearchField.js";
|
|
28
|
+
import { SectionHeader } from "./SectionHeader.js";
|
|
29
|
+
import { SegmentedControl } from "./SegmentedControl.js";
|
|
30
|
+
import { Select } from "./Select.js";
|
|
31
|
+
import { Tooltip } from "./Tooltip.js";
|
|
32
|
+
import { Sidebar } from "./Sidebar.js";
|
|
33
|
+
import { Skeleton } from "./Skeleton.js";
|
|
34
|
+
import { Slider } from "./Slider.js";
|
|
35
|
+
import { Switch } from "./Switch.js";
|
|
36
|
+
import { Tabs } from "./Tabs.js";
|
|
37
|
+
import { Text } from "./Text.js";
|
|
38
|
+
import { TextField } from "./TextField.js";
|
|
39
|
+
import { Toast } from "./Toast.js";
|
|
40
|
+
import "./index.js";
|
|
41
|
+
import { dynamic, memo } from "@solidjs/web";
|
|
42
|
+
import { Show, createComponent as createComponent$1, createSignal, onSettled, untrack } from "solid-js";
|
|
43
|
+
import { designPreview, isNode, isStatic, resolve } from "@xds/core/preview";
|
|
44
|
+
// packages/ui-solid/src/preview.tsx
|
|
45
|
+
var COMPONENTS = {
|
|
46
|
+
Accordion,
|
|
47
|
+
Avatar,
|
|
48
|
+
AvatarStack,
|
|
49
|
+
Badge,
|
|
50
|
+
Banner,
|
|
51
|
+
Button,
|
|
52
|
+
Card,
|
|
53
|
+
Checkbox,
|
|
54
|
+
Chip,
|
|
55
|
+
ChipBar,
|
|
56
|
+
CountBadge,
|
|
57
|
+
DatePicker,
|
|
58
|
+
DateRangePicker,
|
|
59
|
+
Defaults,
|
|
60
|
+
Dialog,
|
|
61
|
+
Divider,
|
|
62
|
+
EmptyState,
|
|
63
|
+
Icon,
|
|
64
|
+
IconButton,
|
|
65
|
+
ListRow,
|
|
66
|
+
MediaCard,
|
|
67
|
+
Menu,
|
|
68
|
+
ProgressBar,
|
|
69
|
+
RadioGroup,
|
|
70
|
+
SearchField,
|
|
71
|
+
SectionHeader,
|
|
72
|
+
SegmentedControl,
|
|
73
|
+
Select,
|
|
74
|
+
Sidebar,
|
|
75
|
+
Skeleton,
|
|
76
|
+
Slider,
|
|
77
|
+
Spinner,
|
|
78
|
+
Switch,
|
|
79
|
+
Tabs,
|
|
80
|
+
Text,
|
|
81
|
+
TextField,
|
|
82
|
+
Thumbnail,
|
|
83
|
+
Toast,
|
|
84
|
+
Tooltip
|
|
85
|
+
};
|
|
86
|
+
function Preview(props) {
|
|
87
|
+
const screen = untrack(() => props.screen);
|
|
88
|
+
const state = {};
|
|
89
|
+
const writes = /* @__PURE__ */ new Map();
|
|
90
|
+
for (const [key, first] of Object.entries(screen.state)) {
|
|
91
|
+
const [read, write] = createSignal(first, { name: key });
|
|
92
|
+
Object.defineProperty(state, key, {
|
|
93
|
+
get: read,
|
|
94
|
+
enumerable: true
|
|
95
|
+
});
|
|
96
|
+
writes.set(key, (value) => write(() => value));
|
|
97
|
+
}
|
|
98
|
+
const host = {
|
|
99
|
+
state,
|
|
100
|
+
set: (patch) => {
|
|
101
|
+
for (const [key, value] of Object.entries(patch)) writes.get(key)?.(value);
|
|
102
|
+
},
|
|
103
|
+
draw: (slot) => {
|
|
104
|
+
if (Array.isArray(slot)) return slot.map((child) => typeof child === "function" ? memo(() => child(state)) : host.draw(child));
|
|
105
|
+
if (typeof slot === "function") return slot(state);
|
|
106
|
+
if (!isNode(slot)) return slot;
|
|
107
|
+
if (slot.kind === "show") return createComponent$1(Show, {
|
|
108
|
+
get when() {
|
|
109
|
+
return slot.when(state);
|
|
110
|
+
},
|
|
111
|
+
get children() {
|
|
112
|
+
return host.draw(slot.children);
|
|
113
|
+
},
|
|
114
|
+
get fallback() {
|
|
115
|
+
return host.draw(slot.fallback);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const type = slot.kind === "element" ? dynamic(() => slot.tag, { static: true }) : COMPONENTS[slot.name];
|
|
119
|
+
return createComponent$1(type, propsOf(slot));
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const propsOf = ({ props: given, children }) => {
|
|
123
|
+
const props = {};
|
|
124
|
+
const read = (key, get) => Object.defineProperty(props, key, {
|
|
125
|
+
get,
|
|
126
|
+
enumerable: true
|
|
127
|
+
});
|
|
128
|
+
for (const [key, value] of Object.entries(given)) if (isStatic(value, key)) props[key] = resolve(value, key, host);
|
|
129
|
+
else read(key, () => resolve(value, key, host));
|
|
130
|
+
if (children.length === 0) return props;
|
|
131
|
+
const content = children.length === 1 ? children[0] : children;
|
|
132
|
+
if (children.every((child) => isStatic(child))) props.children = content;
|
|
133
|
+
else read("children", () => host.draw(content));
|
|
134
|
+
return props;
|
|
135
|
+
};
|
|
136
|
+
onSettled(() => screen.mount?.());
|
|
137
|
+
return host.draw(screen.root);
|
|
138
|
+
}
|
|
139
|
+
export { Preview, designPreview };
|
package/dist/dom/root.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mergeProps } from "@zag-js/solid";
|
|
2
|
+
// packages/ui-solid/src/root.ts
|
|
3
|
+
var css = (style) => typeof style === "string" ? style : Object.entries(style).filter(([, value]) => value !== void 0).map(([property, value]) => `${property}:${String(value)}`).join(";");
|
|
4
|
+
/**
|
|
5
|
+
* The style of a root element that sets one of its own: the app's comes after it, so that it
|
|
6
|
+
* wins property by property. A string cannot be merged into an object without parsing it, so a
|
|
7
|
+
* string on either side makes both into one declaration list.
|
|
8
|
+
*/
|
|
9
|
+
function layStyle(own, app) {
|
|
10
|
+
if (app === void 0) return own;
|
|
11
|
+
if (own === void 0) return app;
|
|
12
|
+
if (typeof own === "string" || typeof app === "string") return `${css(own)};${css(app)}`;
|
|
13
|
+
return {
|
|
14
|
+
...own,
|
|
15
|
+
...app
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The props Zag gives a component's root element, with the app's style laid over the one Zag
|
|
20
|
+
* sets: Zag's mergeProps merges the two, where a `style` after the spread would replace Zag's.
|
|
21
|
+
* Spread the result on the element.
|
|
22
|
+
*/
|
|
23
|
+
function withStyle(zag, style) {
|
|
24
|
+
return mergeProps(zag, () => ({ style: style() }));
|
|
25
|
+
}
|
|
26
|
+
export { layStyle, withStyle };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { mergeProps } from "@zag-js/solid";
|
|
2
|
+
import { createContext, useContext } from "solid-js";
|
|
3
|
+
// packages/ui-solid/src/trigger.ts
|
|
4
|
+
/** Not exported from the package: only this package's controls and overlays use it. */
|
|
5
|
+
var TriggerContext = createContext(null);
|
|
6
|
+
/**
|
|
7
|
+
* For an overlay: its trigger props, joined with those of any overlay around it, to provide
|
|
8
|
+
* as `<TriggerContext value={...}>` around the control. A Tooltip around a Menu's button gives
|
|
9
|
+
* the button both sets; the handlers of both run.
|
|
10
|
+
*/
|
|
11
|
+
function provideTrigger(own) {
|
|
12
|
+
const outer = useContext(TriggerContext);
|
|
13
|
+
const merged = mergeProps(() => outer?.() ?? {}, own);
|
|
14
|
+
return () => merged;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* For a control that can open an overlay: its own props, after those of the overlays it opens.
|
|
18
|
+
* Its own attributes win, its own handlers run first, and its class is added to theirs, so the
|
|
19
|
+
* own class must be a string. While `inert` is true, as for a loading button, the overlays get
|
|
20
|
+
* none of its events and so do not open. Spread the result on the element.
|
|
21
|
+
*/
|
|
22
|
+
function withTrigger(own, inert) {
|
|
23
|
+
const trigger = useContext(TriggerContext);
|
|
24
|
+
const overlays = () => {
|
|
25
|
+
const props = trigger?.() ?? {};
|
|
26
|
+
if (!inert?.()) return props;
|
|
27
|
+
return Object.fromEntries(Object.entries(props).filter(([key]) => !key.startsWith("on")));
|
|
28
|
+
};
|
|
29
|
+
return mergeProps(overlays, own);
|
|
30
|
+
}
|
|
31
|
+
export { TriggerContext, provideTrigger, withTrigger };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type AccordionBaseProps, type AccordionItemBase } from "@xds/core";
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
3
|
+
import { type Element } from "solid-js";
|
|
4
|
+
import { type RootProps } from "./root.ts";
|
|
5
|
+
export type AccordionItem<Value extends string = string> = AccordionItemBase<Value> & {
|
|
6
|
+
/** The body, shown under the title while the item is open. */
|
|
7
|
+
content: Element;
|
|
8
|
+
};
|
|
9
|
+
export type AccordionProps<Value extends string = string> = AccordionBaseProps<Value> & RootProps & {
|
|
10
|
+
items: readonly AccordionItem<Value>[];
|
|
11
|
+
onChange: (expanded: Value[]) => void;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Items whose bodies open and close under their titles, separated by hairlines. The chevron
|
|
15
|
+
* turns over when an item is open, so the state does not depend on color. Opening and closing
|
|
16
|
+
* animate the height, and do not for people who ask for less motion.
|
|
17
|
+
*
|
|
18
|
+
* Each title is a heading holding a button that says whether its body is expanded and which
|
|
19
|
+
* body it controls. A closed body is hidden, but the browser's find in page still opens it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function Accordion<Value extends string = string>(props: AccordionProps<Value>): JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ACCORDION_PARTS, classes, focusTitleOnClick, setPanelOpen, } from "@xds/core";
|
|
2
|
+
import * as accordion from "@zag-js/accordion";
|
|
3
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
|
|
4
|
+
import { createEffect, createMemo, createUniqueId, For, Show } from "solid-js";
|
|
5
|
+
import { Icon } from "./Icon.jsx";
|
|
6
|
+
import { withStyle } from "./root.js";
|
|
7
|
+
export function Accordion(props) {
|
|
8
|
+
const id = createUniqueId();
|
|
9
|
+
const service = useMachine(accordion.machine, () => ({
|
|
10
|
+
id,
|
|
11
|
+
value: [...props.expanded],
|
|
12
|
+
onValueChange: (details) => props.onChange(details.value),
|
|
13
|
+
multiple: props.multiple ?? false,
|
|
14
|
+
collapsible: true,
|
|
15
|
+
hiddenUntilFound: true,
|
|
16
|
+
}));
|
|
17
|
+
const api = createMemo(() => accordion.connect(service, normalizeProps));
|
|
18
|
+
const root = withStyle(() => api().getRootProps(), () => props.style);
|
|
19
|
+
const body = (value) => {
|
|
20
|
+
const { hidden: _hidden, ...attributes } = api().getItemContentProps({ value });
|
|
21
|
+
return attributes;
|
|
22
|
+
};
|
|
23
|
+
return (<div {...root} class={classes("xds-accordion", props.class)}>
|
|
24
|
+
<For each={props.items}>
|
|
25
|
+
{(item) => (<div {...api().getItemProps({ value: item.value })} class="xds-accordion__item">
|
|
26
|
+
<h3 {...api().getItemHeaderProps({ value: item.value })} class="xds-accordion__heading">
|
|
27
|
+
<button {...mergeProps(() => api().getItemTriggerProps({ value: item.value }), {
|
|
28
|
+
onClick: focusTitleOnClick,
|
|
29
|
+
})} class="xds-accordion__trigger group">
|
|
30
|
+
<span class={ACCORDION_PARTS.text}>
|
|
31
|
+
<span class={ACCORDION_PARTS.title}>{item.title}</span>
|
|
32
|
+
<Show when={item.description}>
|
|
33
|
+
{(description) => (<span class={ACCORDION_PARTS.description}>{description()}</span>)}
|
|
34
|
+
</Show>
|
|
35
|
+
</span>
|
|
36
|
+
<Icon name="chevron-down" size="sm" class={ACCORDION_PARTS.chevron}/>
|
|
37
|
+
</button>
|
|
38
|
+
</h3>
|
|
39
|
+
<Panel open={api().value.includes(item.value)} attributes={body(item.value)}>
|
|
40
|
+
{item.content}
|
|
41
|
+
</Panel>
|
|
42
|
+
</div>)}
|
|
43
|
+
</For>
|
|
44
|
+
</div>);
|
|
45
|
+
}
|
|
46
|
+
function Panel(props) {
|
|
47
|
+
let panel;
|
|
48
|
+
let rendered = false;
|
|
49
|
+
createEffect(() => props.open, (open) => {
|
|
50
|
+
const stop = setPanelOpen(panel, open, rendered);
|
|
51
|
+
rendered = true;
|
|
52
|
+
return stop;
|
|
53
|
+
});
|
|
54
|
+
return (<div {...props.attributes} ref={(element) => (panel = element)} role="group" aria-hidden={props.open ? undefined : "true"} class="xds-accordion__panel">
|
|
55
|
+
<div class="xds-accordion__body">{props.children}</div>
|
|
56
|
+
</div>);
|
|
57
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AvatarBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
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.
|
|
7
|
+
* Assistive technology gets the full name either way. The small size has room for one letter.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Avatar(props: AvatarProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { avatarClass, avatarInitials, classes, pictureClass, rootPart, } from "@xds/core";
|
|
2
|
+
import { Show } from "solid-js";
|
|
3
|
+
import { useDefaults } from "./Defaults.jsx";
|
|
4
|
+
import { createPicture } from "./picture.js";
|
|
5
|
+
const ROOT = rootPart("Avatar");
|
|
6
|
+
export function Avatar(props) {
|
|
7
|
+
const defaults = useDefaults("Avatar");
|
|
8
|
+
const size = () => props.size ?? defaults().size;
|
|
9
|
+
const picture = createPicture(() => props.src);
|
|
10
|
+
return (<span role="img" aria-label={props.name} class={classes(ROOT, avatarClass(size()), props.class)} style={props.style}>
|
|
11
|
+
{avatarInitials(props.name, size())}
|
|
12
|
+
<Show when={picture.loaded() !== false && props.src}>
|
|
13
|
+
{(src) => (<img src={src()} alt="" aria-hidden="true" class={pictureClass(picture.loaded() === true)} onLoad={() => picture.onLoad(src())} onError={() => picture.onError(src())}/>)}
|
|
14
|
+
</Show>
|
|
15
|
+
</span>);
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type AvatarStackBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type AvatarStackProps = AvatarStackBaseProps & RootProps;
|
|
4
|
+
/**
|
|
5
|
+
* Several people in the room of one. Assistive technology gets one image named after
|
|
6
|
+
* everyone in it, including those who did not fit.
|
|
7
|
+
*/
|
|
8
|
+
export declare function AvatarStack(props: AvatarStackProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { avatarStack, avatarStackClass, avatarStackItemClass, avatarStackRestClass, classes, rootPart, } from "@xds/core";
|
|
2
|
+
import { createMemo, For, Show } from "solid-js";
|
|
3
|
+
import { Avatar } from "./Avatar.jsx";
|
|
4
|
+
import { useDefaults } from "./Defaults.jsx";
|
|
5
|
+
const ROOT = rootPart("AvatarStack");
|
|
6
|
+
export function AvatarStack(props) {
|
|
7
|
+
const defaults = useDefaults("AvatarStack");
|
|
8
|
+
const size = () => props.size ?? defaults().size ?? "md";
|
|
9
|
+
const stack = createMemo(() => avatarStack(props.people, props.max, props.label));
|
|
10
|
+
return (<span role="img" aria-label={stack().name} class={classes(ROOT, avatarStackClass, props.class)} style={props.style}>
|
|
11
|
+
<For each={stack().shown}>
|
|
12
|
+
{(person) => (<span aria-hidden="true" class={avatarStackItemClass(size())}>
|
|
13
|
+
<Avatar name={person.name} src={person.src} size={size()}/>
|
|
14
|
+
</span>)}
|
|
15
|
+
</For>
|
|
16
|
+
<Show when={stack().rest > 0}>
|
|
17
|
+
<span aria-hidden="true" class={avatarStackRestClass(size())}>
|
|
18
|
+
+{stack().rest}
|
|
19
|
+
</span>
|
|
20
|
+
</Show>
|
|
21
|
+
</span>);
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type BadgeBaseProps } from "@xds/core";
|
|
2
|
+
import { type Element } from "solid-js";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type { BadgeTone } from "@xds/core";
|
|
5
|
+
export type BadgeProps = BadgeBaseProps & RootProps & {
|
|
6
|
+
children: Element;
|
|
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
|
|
11
|
+
* live states such as "connected", and `icon` a drawing in front of the words.
|
|
12
|
+
*/
|
|
13
|
+
export declare function Badge(props: BadgeProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { badgeClass, badgeDotClass, classes, rootPart } from "@xds/core";
|
|
2
|
+
import { Show } from "solid-js";
|
|
3
|
+
import { useDefaults } from "./Defaults.jsx";
|
|
4
|
+
import { Icon } from "./Icon.jsx";
|
|
5
|
+
const ROOT = rootPart("Badge");
|
|
6
|
+
export function Badge(props) {
|
|
7
|
+
const defaults = useDefaults("Badge");
|
|
8
|
+
return (<span class={classes(ROOT, badgeClass(props.tone ?? defaults().tone), props.class)} style={props.style}>
|
|
9
|
+
<Show when={props.dot}>
|
|
10
|
+
<span aria-hidden="true" class={badgeDotClass}/>
|
|
11
|
+
</Show>
|
|
12
|
+
<Show when={props.icon}>{(name) => <Icon name={name()} size="xs"/>}</Show>
|
|
13
|
+
{props.children}
|
|
14
|
+
</span>);
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type BannerBaseProps } from "@xds/core";
|
|
2
|
+
import { type Element } from "solid-js";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
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: Element;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A message about the whole view or a section of it. Each tone has its own icon shape, so the
|
|
20
|
+
* tone does not depend on color. Problems (`warning`, `danger`) interrupt a screen reader;
|
|
21
|
+
* `info` and `success` wait their turn.
|
|
22
|
+
*/
|
|
23
|
+
export declare function Banner(props: BannerProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BANNER_PARTS, bannerClass, bannerIconClass, bannerIconPath, bannerRole, classes, rootPart, } from "@xds/core";
|
|
2
|
+
import { Show } from "solid-js";
|
|
3
|
+
import { Button } from "./Button.jsx";
|
|
4
|
+
import { useDefaults } from "./Defaults.jsx";
|
|
5
|
+
import { IconButton } from "./IconButton.jsx";
|
|
6
|
+
const ROOT = rootPart("Banner");
|
|
7
|
+
export function Banner(props) {
|
|
8
|
+
const defaults = useDefaults("Banner");
|
|
9
|
+
const tone = () => props.tone ?? defaults().tone;
|
|
10
|
+
return (<div role={bannerRole(tone())} class={classes(ROOT, bannerClass(tone()), props.class)} style={props.style}>
|
|
11
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" class={bannerIconClass(tone())}>
|
|
12
|
+
<path fill="currentColor" d={bannerIconPath(tone())}/>
|
|
13
|
+
</svg>
|
|
14
|
+
<div class={BANNER_PARTS.body}>
|
|
15
|
+
<Show when={props.title}>{(title) => <p class={BANNER_PARTS.title}>{title()}</p>}</Show>
|
|
16
|
+
<div>{props.children}</div>
|
|
17
|
+
<Show when={props.action}>
|
|
18
|
+
{(action) => (<div class={BANNER_PARTS.action}>
|
|
19
|
+
|
|
20
|
+
<Button variant="secondary" size="sm" onPress={() => action().onPress()}>
|
|
21
|
+
{action().label}
|
|
22
|
+
</Button>
|
|
23
|
+
</div>)}
|
|
24
|
+
</Show>
|
|
25
|
+
</div>
|
|
26
|
+
<Show when={props.onDismiss}>
|
|
27
|
+
<div class={BANNER_PARTS.dismiss}>
|
|
28
|
+
<IconButton icon="x" label={props.dismissLabel ?? "Dismiss"} variant="ghost" size="sm" onPress={() => props.onDismiss?.()}/>
|
|
29
|
+
</div>
|
|
30
|
+
</Show>
|
|
31
|
+
</div>);
|
|
32
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ButtonBaseProps } from "@xds/core";
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
3
|
+
import { type Element } from "solid-js";
|
|
4
|
+
import type { RootProps } from "./root.ts";
|
|
5
|
+
export type { ButtonVariant, ControlSize } from "@xds/core";
|
|
6
|
+
export type ButtonProps = ButtonBaseProps & RootProps & {
|
|
7
|
+
onPress?: () => void;
|
|
8
|
+
/** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
|
|
9
|
+
children?: Element;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach
|
|
13
|
+
* it through context.
|
|
14
|
+
*/
|
|
15
|
+
export declare function Button(props: ButtonProps): JSX.Element;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BUTTON_ICON, buttonClass, classes, isHeld } from "@xds/core";
|
|
2
|
+
import { children, createMemo, Show } from "solid-js";
|
|
3
|
+
import { useDefaults } from "./Defaults.jsx";
|
|
4
|
+
import { Icon } from "./Icon.jsx";
|
|
5
|
+
import { Spinner } from "./Spinner.jsx";
|
|
6
|
+
import { withTrigger } from "./trigger.js";
|
|
7
|
+
export function Button(props) {
|
|
8
|
+
const label = children(() => props.children);
|
|
9
|
+
const defaults = useDefaults("Button");
|
|
10
|
+
const variant = () => props.variant ?? defaults().variant ?? "secondary";
|
|
11
|
+
const size = () => props.size ?? defaults().size ?? "md";
|
|
12
|
+
const icon = () => BUTTON_ICON[size()];
|
|
13
|
+
const held = () => isHeld({ variant: variant(), selected: props.selected, disabled: props.disabled });
|
|
14
|
+
const attributes = withTrigger(createMemo(() => ({
|
|
15
|
+
type: props.type ?? "button",
|
|
16
|
+
class: classes(buttonClass({
|
|
17
|
+
variant: variant(),
|
|
18
|
+
size: size(),
|
|
19
|
+
iconOnly: label() == null && (props.iconStart !== undefined || props.iconEnd !== undefined),
|
|
20
|
+
fullWidth: props.fullWidth ?? false,
|
|
21
|
+
}), props.class),
|
|
22
|
+
style: props.style,
|
|
23
|
+
disabled: props.disabled,
|
|
24
|
+
"aria-disabled": props.loading ? "true" : undefined,
|
|
25
|
+
"data-pending": props.loading ? "" : undefined,
|
|
26
|
+
"aria-pressed": props.selected === undefined ? undefined : props.selected ? "true" : "false",
|
|
27
|
+
"aria-label": props["aria-label"],
|
|
28
|
+
onClick: () => {
|
|
29
|
+
if (!props.loading)
|
|
30
|
+
props.onPress?.();
|
|
31
|
+
},
|
|
32
|
+
})), () => props.loading === true);
|
|
33
|
+
return (<button {...attributes}>
|
|
34
|
+
<Show when={props.loading}>
|
|
35
|
+
<Show when={props.iconStart} fallback={<Spinner size="sm"/>}>
|
|
36
|
+
|
|
37
|
+
<span class={icon().box}>
|
|
38
|
+
<Spinner size="sm"/>
|
|
39
|
+
</span>
|
|
40
|
+
</Show>
|
|
41
|
+
</Show>
|
|
42
|
+
<Show when={!props.loading && props.iconStart}>
|
|
43
|
+
{(name) => <Icon name={name()} size={icon().size} filled={held()}/>}
|
|
44
|
+
</Show>
|
|
45
|
+
{label()}
|
|
46
|
+
<Show when={props.iconEnd}>{(name) => <Icon name={name()} size={icon().size}/>}</Show>
|
|
47
|
+
</button>);
|
|
48
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CardBaseProps } from "@xds/core";
|
|
2
|
+
import { type Element } from "solid-js";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type CardProps = CardBaseProps & RootProps & {
|
|
5
|
+
/** Sit across from the title. A pressable card takes none: it is one button already. */
|
|
6
|
+
actions?: Element;
|
|
7
|
+
/** A picture or a drawing at the top, running edge to edge above the padding. */
|
|
8
|
+
media?: Element;
|
|
9
|
+
/** Makes the whole card one button. Put no other control inside it then. */
|
|
10
|
+
onPress?: () => void;
|
|
11
|
+
children?: Element;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A surface that groups related content. A hairline outline and a trace of shadow lift it off
|
|
15
|
+
* the page; in dark mode, where shadows barely show, the lighter fill does that. `title`
|
|
16
|
+
* renders as a heading; `actions` sit across from it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function Card(props: CardProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CARD_PARTS, cardClass, cardMediaClass, classes, rootPart, } from "@xds/core";
|
|
2
|
+
import { dynamic } from "@solidjs/web";
|
|
3
|
+
import { children, Show } from "solid-js";
|
|
4
|
+
const ROOT = rootPart("Card");
|
|
5
|
+
export function Card(props) {
|
|
6
|
+
const media = children(() => props.media);
|
|
7
|
+
const actions = children(() => props.actions);
|
|
8
|
+
const body = children(() => props.children);
|
|
9
|
+
const pressable = () => props.onPress !== undefined;
|
|
10
|
+
const Header = dynamic(() => (pressable() ? "span" : "header"));
|
|
11
|
+
const Box = dynamic(() => (pressable() ? "span" : "div"));
|
|
12
|
+
const Title = dynamic(() => (pressable() ? "span" : "h2"));
|
|
13
|
+
const Line = dynamic(() => (pressable() ? "span" : "p"));
|
|
14
|
+
const surface = () => classes(ROOT, cardClass({ selected: props.selected, flush: props.flush, pressable: pressable() }), props.class);
|
|
15
|
+
const parts = () => (<>
|
|
16
|
+
<Show when={media() != null}>
|
|
17
|
+
<Box class={cardMediaClass(props.flush)}>{media()}</Box>
|
|
18
|
+
</Show>
|
|
19
|
+
<Show when={props.title || (actions() != null && !pressable())}>
|
|
20
|
+
<Header class={CARD_PARTS.header}>
|
|
21
|
+
<Box class={CARD_PARTS.heading}>
|
|
22
|
+
<Show when={props.title}>
|
|
23
|
+
{(title) => <Title class={CARD_PARTS.title}>{title()}</Title>}
|
|
24
|
+
</Show>
|
|
25
|
+
<Show when={props.description}>
|
|
26
|
+
{(description) => <Line class={CARD_PARTS.description}>{description()}</Line>}
|
|
27
|
+
</Show>
|
|
28
|
+
</Box>
|
|
29
|
+
<Show when={actions() != null && !pressable()}>
|
|
30
|
+
<div class={CARD_PARTS.actions}>{actions()}</div>
|
|
31
|
+
</Show>
|
|
32
|
+
</Header>
|
|
33
|
+
</Show>
|
|
34
|
+
{body()}
|
|
35
|
+
</>);
|
|
36
|
+
const content = () => (<Show when={props.flush} fallback={parts()}>
|
|
37
|
+
<Box class={CARD_PARTS.flush}>{parts()}</Box>
|
|
38
|
+
</Show>);
|
|
39
|
+
return (<Show when={pressable()} fallback={<section aria-current={props.selected ? "true" : undefined} class={surface()} style={props.style}>
|
|
40
|
+
{content()}
|
|
41
|
+
</section>}>
|
|
42
|
+
<button type="button" onClick={() => props.onPress?.()} aria-pressed={props.selected === undefined ? undefined : props.selected ? "true" : "false"} class={surface()} style={props.style}>
|
|
43
|
+
{content()}
|
|
44
|
+
</button>
|
|
45
|
+
</Show>);
|
|
46
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CheckboxBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type CheckboxProps = CheckboxBaseProps & RootProps & {
|
|
4
|
+
onChange: (checked: boolean) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A choice that is applied later, with the form it belongs to. A native checkbox: the input is
|
|
8
|
+
* hidden and the box is drawn beside it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function Checkbox(props: CheckboxProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CHECKBOX_MARK, checkboxBoxClass, checkboxClass, checkboxLabelClass, checkboxMarkClass, classes, rootPart, } from "@xds/core";
|
|
2
|
+
import { Show } from "solid-js";
|
|
3
|
+
import { keepChecked } from "./controlled.js";
|
|
4
|
+
const ROOT = rootPart("Checkbox");
|
|
5
|
+
export function Checkbox(props) {
|
|
6
|
+
return (<label class={classes(ROOT, checkboxClass, props.class)} style={props.style}>
|
|
7
|
+
<input type="checkbox" aria-label={props["aria-label"]} class="peer sr-only" checked={props.checked} defaultChecked={props.checked} disabled={props.disabled} name={props.name || undefined} onChange={(event) => {
|
|
8
|
+
props.onChange(event.currentTarget.checked);
|
|
9
|
+
keepChecked(event.currentTarget, () => props.checked);
|
|
10
|
+
}}/>
|
|
11
|
+
<span class={checkboxBoxClass}>
|
|
12
|
+
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class={checkboxMarkClass}>
|
|
13
|
+
<path d={CHECKBOX_MARK} stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
14
|
+
</svg>
|
|
15
|
+
</span>
|
|
16
|
+
<Show when={props.label}>
|
|
17
|
+
<span class={checkboxLabelClass}>{props.label}</span>
|
|
18
|
+
</Show>
|
|
19
|
+
</label>);
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ChipBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type ChipProps = ChipBaseProps & RootProps & {
|
|
4
|
+
onPress?: () => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A choice that filters what is shown. Unlike a Badge it is pressed. A selected chip is tinted,
|
|
8
|
+
* outlined and marked with a check, so the state does not depend on color.
|
|
9
|
+
*
|
|
10
|
+
* It is a toggle button: assistive technology hears whether it is pressed.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Chip(props: ChipProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { chipClass, chipIcon, classes, rootPart } from "@xds/core";
|
|
2
|
+
import { Show } from "solid-js";
|
|
3
|
+
import { Icon } from "./Icon.jsx";
|
|
4
|
+
const ROOT = rootPart("Chip");
|
|
5
|
+
export function Chip(props) {
|
|
6
|
+
return (<button type="button" aria-pressed={props.selected ? "true" : "false"} disabled={props.disabled} onClick={() => props.onPress?.()} class={classes(ROOT, chipClass(props.selected), props.class)} style={props.style}>
|
|
7
|
+
<Show when={chipIcon({ selected: props.selected, iconStart: props.iconStart })}>
|
|
8
|
+
{(name) => <Icon name={name()} size="sm"/>}
|
|
9
|
+
</Show>
|
|
10
|
+
{props.label}
|
|
11
|
+
</button>);
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ChipBarBaseProps } from "@xds/core";
|
|
2
|
+
import type { Element } from "solid-js";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type ChipBarProps = ChipBarBaseProps & RootProps & {
|
|
5
|
+
/** The chips. Which of them are selected is the app's business: the bar holds no state. */
|
|
6
|
+
children: Element;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* One row of chips. It scrolls sideways when the chips do not fit and never wraps, so the
|
|
10
|
+
* content under it stays where it is.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ChipBar(props: ChipBarProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { chipBarClass, classes, rootPart } from "@xds/core";
|
|
2
|
+
const ROOT = rootPart("ChipBar");
|
|
3
|
+
export function ChipBar(props) {
|
|
4
|
+
return (<div role="group" aria-label={props.label} class={classes(ROOT, chipBarClass, props.class)} style={props.style}>
|
|
5
|
+
{props.children}
|
|
6
|
+
</div>);
|
|
7
|
+
}
|