@xds/a2ui-react 0.2.0 → 1.0.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/README.md +1 -1
- package/dist/basic.js +39 -8
- package/dist/cases.js +2 -2
- package/dist/implementations.d.ts +1 -1
- package/dist/implementations.js +25 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
The xds design system as an [A2UI](https://a2ui.org) catalog: the surfaces an agent sends are drawn with the components of `@xds/react`, in the app's theme.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
npm install @xds/a2ui-react
|
|
6
|
+
npm install @xds/a2ui-react @xds/react @a2ui/react @a2ui/web_core zod
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
```js
|
package/dist/basic.js
CHANGED
|
@@ -83,7 +83,7 @@ const text = createComponentImplementation(TextApi, ({ props }) => {
|
|
|
83
83
|
return props.variant === "caption" ? (_jsx(Text, { variant: "footnote", tone: "secondary", style: weighted(props.weight), children: value })) : (_jsx(Text, { as: rendersMarkdown ? "div" : "p", variant: "body", tone: "primary", style: weighted(props.weight), children: _jsx(Markdown, { text: value }) }));
|
|
84
84
|
});
|
|
85
85
|
const BUTTON_VARIANT = { default: "secondary", primary: "primary", borderless: "ghost" };
|
|
86
|
-
const button = createComponentImplementation(ButtonApi, ({ props, buildChild }) => (_jsx(Button, { variant: BUTTON_VARIANT[props.variant ?? "default"],
|
|
86
|
+
const button = createComponentImplementation(ButtonApi, ({ props, buildChild }) => (_jsx(Button, { variant: BUTTON_VARIANT[props.variant ?? "default"], disabled: props.isValid === false, "aria-label": named(props), onPress: () => void props.action?.(), style: weighted(props.weight), children: _jsx(InButton, { value: true, children: buildChild(props.child) }) })));
|
|
87
87
|
const FIELD_TYPE = {
|
|
88
88
|
shortText: { type: "text" },
|
|
89
89
|
longText: { type: "text", multiline: true },
|
|
@@ -100,7 +100,7 @@ function CheckError({ message, id }) {
|
|
|
100
100
|
const checkBox = createComponentImplementation(CheckBoxApi, ({ props }) => {
|
|
101
101
|
const errorId = useId();
|
|
102
102
|
const error = firstError(props);
|
|
103
|
-
return (_jsxs("div", { className: "xds-a2ui-field", style: weighted(props.weight), children: [_jsx(Checkbox, { label: props.label, checked: props.value ?? false, onChange: props.setValue }), _jsx(CheckError, { message: error, id: errorId })] }));
|
|
103
|
+
return (_jsxs("div", { className: "xds-a2ui-field", "aria-describedby": error === undefined ? undefined : errorId, "aria-invalid": error === undefined ? undefined : true, style: weighted(props.weight), children: [_jsx(Checkbox, { label: props.label, checked: props.value ?? false, onChange: props.setValue }), _jsx(CheckError, { message: error, id: errorId })] }));
|
|
104
104
|
});
|
|
105
105
|
const choicePicker = createComponentImplementation(ChoicePickerApi, ({ props }) => {
|
|
106
106
|
const [filter, setFilter] = useState("");
|
|
@@ -119,7 +119,7 @@ const choicePicker = createComponentImplementation(ChoicePickerApi, ({ props })
|
|
|
119
119
|
: [value]);
|
|
120
120
|
const search = props.filterable ? (_jsx(SearchField, { label: label, value: filter, onChange: setFilter })) : null;
|
|
121
121
|
if (props.displayStyle === "chips") {
|
|
122
|
-
return (_jsxs("div", { className: "xds-a2ui-field", style: weighted(props.weight), children: [props.label === undefined ? null : (_jsx(Text, { as: "span", variant: "label", tone: "primary", children: props.label })), search, _jsx(ChipBar, { label: label, children: options.map((option) => (_jsx(Chip, { label: option.label ?? option.value, selected: selected.includes(option.value), onPress: () => toggle(option.value) }, option.value))) }), _jsx(CheckError, { message: error, id: errorId })] }));
|
|
122
|
+
return (_jsxs("div", { role: "group", className: "xds-a2ui-field", "aria-labelledby": props.label === undefined ? undefined : labelId, "aria-describedby": error === undefined ? undefined : errorId, "aria-invalid": error === undefined ? undefined : true, style: weighted(props.weight), children: [props.label === undefined ? null : (_jsx("span", { id: labelId, children: _jsx(Text, { as: "span", variant: "label", tone: "primary", children: props.label }) })), search, _jsx(ChipBar, { label: label, children: options.map((option) => (_jsx(Chip, { label: option.label ?? option.value, selected: selected.includes(option.value), onPress: () => toggle(option.value) }, option.value))) }), _jsx(CheckError, { message: error, id: errorId })] }));
|
|
123
123
|
}
|
|
124
124
|
if (!multiple) {
|
|
125
125
|
return (_jsxs("div", { className: "xds-a2ui-field", style: weighted(props.weight), children: [search, _jsx(RadioGroup, { label: label, options: options.map((option) => ({
|
|
@@ -130,14 +130,39 @@ const choicePicker = createComponentImplementation(ChoicePickerApi, ({ props })
|
|
|
130
130
|
return (_jsxs("div", { role: "group", className: "xds-a2ui-field", "aria-labelledby": labelId, "aria-describedby": error === undefined ? undefined : errorId, "aria-invalid": error === undefined ? undefined : true, style: weighted(props.weight), children: [_jsx("span", { id: labelId, children: _jsx(Text, { as: "span", variant: "label", tone: "primary", children: label }) }), search, options.map((option) => (_jsx(Checkbox, { label: option.label ?? option.value, checked: selected.includes(option.value), onChange: () => toggle(option.value) }, option.value))), _jsx(CheckError, { message: error, id: errorId })] }));
|
|
131
131
|
});
|
|
132
132
|
const slider = createComponentImplementation(SliderApi, ({ props }) => {
|
|
133
|
+
const errorId = useId();
|
|
134
|
+
const error = firstError(props);
|
|
133
135
|
const min = props.min ?? 0;
|
|
134
136
|
const max = props.max;
|
|
135
137
|
const step = props.steps !== undefined && props.steps > 0 ? (max - min) / props.steps : undefined;
|
|
136
|
-
return (_jsx(Slider, { label: props.label ?? named(props) ?? "", value: props.value ?? min, onChange: props.setValue, min: min, max: max, step: step, showValue: true,
|
|
138
|
+
return (_jsxs("div", { className: "xds-a2ui-field", "aria-describedby": error === undefined ? undefined : errorId, "aria-invalid": error === undefined ? undefined : true, style: weighted(props.weight), children: [_jsx(Slider, { label: props.label ?? named(props) ?? "", value: props.value ?? min, onChange: props.setValue, min: min, max: max, step: step, showValue: true }), _jsx(CheckError, { message: error, id: errorId })] }));
|
|
137
139
|
});
|
|
138
140
|
const day = (value) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
if (value === undefined)
|
|
142
|
+
return undefined;
|
|
143
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})/.exec(value);
|
|
144
|
+
if (!match)
|
|
145
|
+
return undefined;
|
|
146
|
+
const year = Number(match[1]);
|
|
147
|
+
const month = Number(match[2]);
|
|
148
|
+
const d = Number(match[3]);
|
|
149
|
+
const check = new Date(Date.UTC(year, month - 1, d));
|
|
150
|
+
return check.getUTCFullYear() === year &&
|
|
151
|
+
check.getUTCMonth() === month - 1 &&
|
|
152
|
+
check.getUTCDate() === d
|
|
153
|
+
? `${match[1]}-${match[2]}-${match[3]}`
|
|
154
|
+
: undefined;
|
|
155
|
+
};
|
|
156
|
+
const timePart = (value) => {
|
|
157
|
+
const iso = /T(\d{2}:\d{2})/.exec(value);
|
|
158
|
+
if (iso?.[1])
|
|
159
|
+
return iso[1];
|
|
160
|
+
const bare = /^(\d{2}:\d{2})/.exec(value);
|
|
161
|
+
return bare?.[1] ?? "";
|
|
162
|
+
};
|
|
163
|
+
const dateTimePart = (value) => {
|
|
164
|
+
const match = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})/.exec(value);
|
|
165
|
+
return match?.[1] ?? "";
|
|
141
166
|
};
|
|
142
167
|
const dateTimeInput = createComponentImplementation(DateTimeInputApi, ({ props }) => {
|
|
143
168
|
const enableTime = props.enableTime ?? false;
|
|
@@ -147,7 +172,7 @@ const dateTimeInput = createComponentImplementation(DateTimeInputApi, ({ props }
|
|
|
147
172
|
if (enableDate && !enableTime) {
|
|
148
173
|
return (_jsx(DatePicker, { label: label, value: day(value), onChange: props.setValue, min: day(props.min), max: day(props.max), error: firstError(props), style: weighted(props.weight) }));
|
|
149
174
|
}
|
|
150
|
-
return (_jsx(TextField, { label: label, value: enableDate ? value
|
|
175
|
+
return (_jsx(TextField, { label: label, value: enableDate ? dateTimePart(value) : timePart(value), onChange: (next) => props.setValue(enableDate && next !== "" ? `${next}:00` : next), type: enableDate ? "datetime-local" : "time", error: firstError(props), style: weighted(props.weight) }));
|
|
151
176
|
});
|
|
152
177
|
const card = createComponentImplementation(CardApi, ({ props, buildChild }) => (_jsx(Card, { style: weighted(props.weight), children: buildChild(props.child) })));
|
|
153
178
|
const divider = createComponentImplementation(DividerApi, ({ props }) => (_jsx(Divider, { className: props.axis === "vertical" ? "xds-a2ui-divider--vertical" : undefined, style: weighted(props.weight) })));
|
|
@@ -181,7 +206,13 @@ function nameOf(event) {
|
|
|
181
206
|
}
|
|
182
207
|
const modal = createComponentImplementation(ModalApi, ({ props, buildChild }) => {
|
|
183
208
|
const [opened, setOpened] = useState(undefined);
|
|
184
|
-
|
|
209
|
+
const [everOpened, setEverOpened] = useState(false);
|
|
210
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { className: props.weight === undefined ? "xds-a2ui-trigger" : undefined, onClick: (event) => {
|
|
211
|
+
if (event.target.closest("[disabled], [aria-disabled='true']"))
|
|
212
|
+
return;
|
|
213
|
+
setEverOpened(true);
|
|
214
|
+
setOpened(nameOf(event));
|
|
215
|
+
}, style: weighted(props.weight), children: buildChild(props.trigger) }), _jsx(Dialog, { open: opened !== undefined, title: named(props) ?? opened ?? "", onClose: () => setOpened(undefined), children: everOpened ? buildChild(props.content) : null })] }));
|
|
185
216
|
});
|
|
186
217
|
const REPLACED = {
|
|
187
218
|
Text: text,
|
package/dist/cases.js
CHANGED
|
@@ -281,7 +281,7 @@ export const CASES = [
|
|
|
281
281
|
{ clickText: "Sync across devices" },
|
|
282
282
|
{ click: { role: "button", name: "Unread" } },
|
|
283
283
|
{ click: { role: "button", name: "Advanced", exact: false } },
|
|
284
|
-
{ fill: { role: "
|
|
284
|
+
{ fill: { role: "searchbox", name: "Search settings" }, text: "fonts" },
|
|
285
285
|
{ press: "Enter" },
|
|
286
286
|
],
|
|
287
287
|
after: [
|
|
@@ -942,7 +942,7 @@ export const CASES = [
|
|
|
942
942
|
{ see: { role: "dialog", name: "House details" } },
|
|
943
943
|
{ press: "Escape" },
|
|
944
944
|
{ click: { role: "tab", name: "Rules" } },
|
|
945
|
-
{ fill: { role: "
|
|
945
|
+
{ fill: { role: "searchbox", name: "Tags" }, text: "sea" },
|
|
946
946
|
{ click: { role: "button", name: "Sea view" } },
|
|
947
947
|
{ click: { role: "button", name: "Share" } },
|
|
948
948
|
],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactComponentImplementation } from "@a2ui/react";
|
|
2
|
-
import type
|
|
2
|
+
import { type ComponentApi } from "@a2ui/web_core";
|
|
3
3
|
import { type ReactNode } from "react";
|
|
4
4
|
import type { CoreComponent, PointerComponent, ResolvedProps } from "./generated/catalogs.ts";
|
|
5
5
|
type BuildChild = (id: string, basePath?: string) => ReactNode;
|
package/dist/implementations.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createComponentImplementation } from "@a2ui/react";
|
|
3
|
+
import { sanitizeMediaUrl } from "@a2ui/web_core";
|
|
3
4
|
import { Accordion, Avatar, AvatarStack, Badge, Banner, Button, Card, Checkbox, Chip, ChipBar, CountBadge, DatePicker, DateRangePicker, Dialog, Divider, EmptyState, Icon, IconButton, ListRow, MediaCard, Menu, ProgressBar, RadioGroup, SearchField, SectionHeader, SegmentedControl, Select, Slider, Spinner, Switch, Tabs, Text, TextField, Thumbnail, Tooltip, } from "@xds/react";
|
|
4
5
|
import { Fragment } from "react";
|
|
5
6
|
const child = (buildChild, id) => id === undefined ? undefined : buildChild(id);
|
|
@@ -9,7 +10,22 @@ function children(buildChild, list) {
|
|
|
9
10
|
return list.map((entry) => typeof entry === "string" ? (_jsx(Fragment, { children: buildChild(entry) }, entry)) : (_jsx(Fragment, { children: buildChild(entry.id, entry.basePath) }, `${entry.id} ${entry.basePath}`)));
|
|
10
11
|
}
|
|
11
12
|
const send = (action) => action === undefined ? undefined : () => void action();
|
|
12
|
-
const day = (value) =>
|
|
13
|
+
const day = (value) => {
|
|
14
|
+
if (value === undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
17
|
+
if (!match)
|
|
18
|
+
return undefined;
|
|
19
|
+
const year = Number(match[1]);
|
|
20
|
+
const month = Number(match[2]);
|
|
21
|
+
const d = Number(match[3]);
|
|
22
|
+
const check = new Date(Date.UTC(year, month - 1, d));
|
|
23
|
+
return check.getUTCFullYear() === year &&
|
|
24
|
+
check.getUTCMonth() === month - 1 &&
|
|
25
|
+
check.getUTCDate() === d
|
|
26
|
+
? value
|
|
27
|
+
: undefined;
|
|
28
|
+
};
|
|
13
29
|
const fieldError = (props) => props.validationErrors?.[0] ?? props.error;
|
|
14
30
|
const blocked = (props) => props.disabled === true || props.isValid === false;
|
|
15
31
|
const toggle = (props) => () => {
|
|
@@ -36,8 +52,11 @@ export const CORE_VIEWS = {
|
|
|
36
52
|
value: option.value ?? "",
|
|
37
53
|
label: option.label ?? "",
|
|
38
54
|
})), value: props.value ?? "", onChange: props.setValue, "aria-label": props.label ?? "", fullWidth: props.fullWidth })),
|
|
39
|
-
Avatar: ({ props }) => _jsx(Avatar, { name: props.name ?? "", src: props.src, size: props.size }),
|
|
40
|
-
AvatarStack: ({ props }) => (_jsx(AvatarStack, { people: (props.people ?? []).map((person) => ({
|
|
55
|
+
Avatar: ({ props }) => (_jsx(Avatar, { name: props.name ?? "", src: sanitizeMediaUrl(props.src), size: props.size })),
|
|
56
|
+
AvatarStack: ({ props }) => (_jsx(AvatarStack, { people: (props.people ?? []).map((person) => ({
|
|
57
|
+
name: person.name ?? "",
|
|
58
|
+
src: sanitizeMediaUrl(person.src),
|
|
59
|
+
})), max: props.max, label: props.label, size: props.size })),
|
|
41
60
|
ProgressBar: ({ props }) => _jsx(ProgressBar, { value: props.value ?? 0, label: props.label ?? "" }),
|
|
42
61
|
Icon: ({ props }) => props.name === undefined ? null : (_jsx(Icon, { name: props.name, label: props.label, size: props.size, filled: props.filled })),
|
|
43
62
|
ListRow: ({ props, buildChild }) => (_jsx(ListRow, { title: props.title ?? "", description: props.description, leading: child(buildChild, props.leading), trailing: child(buildChild, props.trailing), onPress: send(props.onPress), chevron: props.chevron, disabled: props.disabled, selected: props.selected, compact: props.compact })),
|
|
@@ -78,11 +97,11 @@ export const CORE_VIEWS = {
|
|
|
78
97
|
DateRangePicker: ({ props }) => {
|
|
79
98
|
const start = day(props.value?.start);
|
|
80
99
|
const end = day(props.value?.end);
|
|
81
|
-
return (_jsx(DateRangePicker, { label: props.label ?? "", value: start && end ? { start, end } : undefined, onChange: props.setValue, min: day(props.min), max: day(props.max), minLength: props.minLength, maxLength: props.maxLength, placeholder: props.placeholder, description: props.description, error: fieldError(props), startLabel: props.startLabel, endLabel: props.endLabel, previousLabel: props.previousLabel, nextLabel: props.nextLabel, disabled: props.disabled }));
|
|
100
|
+
return (_jsx(DateRangePicker, { label: props.label ?? "", value: start && end && start <= end ? { start, end } : undefined, onChange: props.setValue, min: day(props.min), max: day(props.max), minLength: props.minLength, maxLength: props.maxLength, placeholder: props.placeholder, description: props.description, error: fieldError(props), startLabel: props.startLabel, endLabel: props.endLabel, previousLabel: props.previousLabel, nextLabel: props.nextLabel, disabled: props.disabled }));
|
|
82
101
|
},
|
|
83
102
|
Slider: ({ props }) => (_jsx(Slider, { label: props.label ?? "", value: props.value ?? props.min ?? 0, onChange: props.setValue, min: props.min, max: props.max, step: props.step, disabled: props.disabled, showValue: props.showValue })),
|
|
84
|
-
Thumbnail: ({ props }) => (_jsx(Thumbnail, { src: props.src, alt: props.alt ?? "", ratio: props.ratio, badge: props.badge, progress: props.progress })),
|
|
85
|
-
MediaCard: ({ props, buildChild }) => (_jsx(MediaCard, { layout: props.layout, src: props.src, alt: props.alt, ratio: props.ratio, badge: props.badge, progress: props.progress, title: props.title ?? "", meta: props.meta, leading: child(buildChild, props.leading), action: child(buildChild, props.action), onPress: send(props.onPress) })),
|
|
103
|
+
Thumbnail: ({ props }) => (_jsx(Thumbnail, { src: sanitizeMediaUrl(props.src), alt: props.alt ?? "", ratio: props.ratio, badge: props.badge, progress: props.progress })),
|
|
104
|
+
MediaCard: ({ props, buildChild }) => (_jsx(MediaCard, { layout: props.layout, src: sanitizeMediaUrl(props.src), alt: props.alt, ratio: props.ratio, badge: props.badge, progress: props.progress, title: props.title ?? "", meta: props.meta, leading: child(buildChild, props.leading), action: child(buildChild, props.action), onPress: send(props.onPress) })),
|
|
86
105
|
SectionHeader: ({ props }) => (_jsx(SectionHeader, { title: props.title ?? "", description: props.description, icon: props.icon, level: props.level, action: props.action && {
|
|
87
106
|
label: props.action.label ?? "",
|
|
88
107
|
onPress: () => void props.action?.onPress?.(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xds/a2ui-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "The xds design system as an A2UI catalog: an agent's surfaces drawn with @xds/react.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design-system",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@a2ui/react": "^0.17.0",
|
|
43
43
|
"@a2ui/web_core": "^0.17.0",
|
|
44
|
-
"@xds/react": "^0.
|
|
44
|
+
"@xds/react": "^1.0.0",
|
|
45
45
|
"react": "^19.3.0",
|
|
46
46
|
"react-dom": "^19.3.0",
|
|
47
47
|
"zod": "^3.25.76"
|