@xds/solid 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/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,172 @@
|
|
|
1
|
+
import { keepValue } from "./controlled.js";
|
|
2
|
+
import { className, createComponent, effect, insert, memo, readShallow, ref, setAttribute, spread, style, template } from "@solidjs/web";
|
|
3
|
+
import { classes } from "@xds/core";
|
|
4
|
+
import { Show, children, createUniqueId, onSettled } from "solid-js";
|
|
5
|
+
// packages/ui-solid/src/TextField.tsx
|
|
6
|
+
var _tmpl$ = /* @__PURE__ */ template(`<textarea>`);
|
|
7
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<input>`);
|
|
8
|
+
var _tmpl$3 = /* @__PURE__ */ template(`<div class="xds-text-field__control xds-text-field__group"><!><!><!>`);
|
|
9
|
+
var _tmpl$4 = /* @__PURE__ */ template(`<span class=xds-text-field__description>`);
|
|
10
|
+
var _tmpl$5 = /* @__PURE__ */ template(`<span class="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums">/<!>`);
|
|
11
|
+
var _tmpl$6 = /* @__PURE__ */ template(`<div><label class=xds-text-field__label></label><div class=xds-text-field__footer><span class=xds-text-field__error aria-live=polite></span><!>`);
|
|
12
|
+
var _tmpl$7 = /* @__PURE__ */ template(`<span class="xds-text-field__slot xds-text-field__slot--leading">`);
|
|
13
|
+
var _tmpl$8 = /* @__PURE__ */ template(`<span class="xds-text-field__slot xds-text-field__slot--trailing">`);
|
|
14
|
+
/**
|
|
15
|
+
* A labelled text field, of one line or several. The label, the description and the error
|
|
16
|
+
* message are tied to the input for assistive technology, and the error is announced when it
|
|
17
|
+
* appears.
|
|
18
|
+
*
|
|
19
|
+
* An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
|
|
20
|
+
* the person edits the value.
|
|
21
|
+
*/
|
|
22
|
+
function TextField(props) {
|
|
23
|
+
const id = createUniqueId();
|
|
24
|
+
const descriptionId = `${id}-description`;
|
|
25
|
+
const errorId = `${id}-error`;
|
|
26
|
+
const leading = children(() => props.leading);
|
|
27
|
+
const trailing = children(() => props.trailing);
|
|
28
|
+
const invalid = () => props.error !== void 0;
|
|
29
|
+
let input;
|
|
30
|
+
onSettled(() => {
|
|
31
|
+
if (input instanceof HTMLTextAreaElement) input.setSelectionRange(0, 0);
|
|
32
|
+
if (props.autoFocus) input.focus();
|
|
33
|
+
});
|
|
34
|
+
const shared = (box) => ({
|
|
35
|
+
id,
|
|
36
|
+
class: box ? "xds-text-field__input xds-text-field__control" : "xds-text-field__input",
|
|
37
|
+
value: props.value,
|
|
38
|
+
defaultValue: props.value,
|
|
39
|
+
placeholder: props.placeholder,
|
|
40
|
+
name: props.name,
|
|
41
|
+
maxlength: props.maxLength,
|
|
42
|
+
inputmode: props.inputMode,
|
|
43
|
+
autocomplete: props.autoComplete,
|
|
44
|
+
required: props.required,
|
|
45
|
+
disabled: props.disabled,
|
|
46
|
+
"aria-invalid": invalid() ? "true" : void 0,
|
|
47
|
+
"aria-errormessage": invalid() ? errorId : void 0,
|
|
48
|
+
"aria-describedby": invalid() ? errorId : props.description ? descriptionId : void 0,
|
|
49
|
+
onInput: (event) => {
|
|
50
|
+
props.onChange(event.currentTarget.value);
|
|
51
|
+
if (!event.isComposing) keepValue(event.currentTarget, () => props.value);
|
|
52
|
+
},
|
|
53
|
+
onCompositionEnd: (event) => keepValue(event.currentTarget, () => props.value)
|
|
54
|
+
});
|
|
55
|
+
const field = (box) => props.multiline ? (() => {
|
|
56
|
+
var _el$ = _tmpl$();
|
|
57
|
+
spread(_el$, [{ get rows() {
|
|
58
|
+
return props.rows ?? 3;
|
|
59
|
+
} }, () => {
|
|
60
|
+
return shared(box);
|
|
61
|
+
}], false);
|
|
62
|
+
ref(() => {
|
|
63
|
+
return (element) => input = element;
|
|
64
|
+
}, _el$);
|
|
65
|
+
return _el$;
|
|
66
|
+
})() : (() => {
|
|
67
|
+
var _el$2 = _tmpl$2();
|
|
68
|
+
spread(_el$2, [{ get type() {
|
|
69
|
+
return props.type ?? "text";
|
|
70
|
+
} }, () => {
|
|
71
|
+
return shared(box);
|
|
72
|
+
}], false);
|
|
73
|
+
ref(() => {
|
|
74
|
+
return (element) => input = element;
|
|
75
|
+
}, _el$2);
|
|
76
|
+
return _el$2;
|
|
77
|
+
})();
|
|
78
|
+
var _el$3 = _tmpl$6();
|
|
79
|
+
var _el$4 = _el$3.firstChild;
|
|
80
|
+
var _el$9 = _el$4.nextSibling;
|
|
81
|
+
var _el$11 = _el$9.firstChild;
|
|
82
|
+
var _el$15 = _el$11.nextSibling;
|
|
83
|
+
setAttribute(_el$4, "for", id);
|
|
84
|
+
insert(_el$4, () => {
|
|
85
|
+
return props.label;
|
|
86
|
+
});
|
|
87
|
+
insert(_el$3, createComponent(Show, {
|
|
88
|
+
get when() {
|
|
89
|
+
return leading() != null || trailing() != null;
|
|
90
|
+
},
|
|
91
|
+
get fallback() {
|
|
92
|
+
return field(true);
|
|
93
|
+
},
|
|
94
|
+
get children() {
|
|
95
|
+
var _el$5 = _tmpl$3();
|
|
96
|
+
var _el$6 = _el$5.firstChild;
|
|
97
|
+
var _el$7 = _el$6.nextSibling;
|
|
98
|
+
var _el$8 = _el$7.nextSibling;
|
|
99
|
+
insert(_el$5, createComponent(Show, {
|
|
100
|
+
get when() {
|
|
101
|
+
return leading();
|
|
102
|
+
},
|
|
103
|
+
children: (content) => (() => {
|
|
104
|
+
var _el$16 = _tmpl$7();
|
|
105
|
+
insert(_el$16, content);
|
|
106
|
+
return _el$16;
|
|
107
|
+
})()
|
|
108
|
+
}), _el$6);
|
|
109
|
+
insert(_el$5, () => {
|
|
110
|
+
return field(false);
|
|
111
|
+
}, _el$7);
|
|
112
|
+
insert(_el$5, createComponent(Show, {
|
|
113
|
+
get when() {
|
|
114
|
+
return trailing();
|
|
115
|
+
},
|
|
116
|
+
children: (content) => (() => {
|
|
117
|
+
var _el$17 = _tmpl$8();
|
|
118
|
+
insert(_el$17, content);
|
|
119
|
+
return _el$17;
|
|
120
|
+
})()
|
|
121
|
+
}), _el$8);
|
|
122
|
+
return _el$5;
|
|
123
|
+
}
|
|
124
|
+
}), _el$9);
|
|
125
|
+
insert(_el$9, createComponent(Show, {
|
|
126
|
+
get when() {
|
|
127
|
+
return memo(() => {
|
|
128
|
+
return !invalid();
|
|
129
|
+
})() && props.description;
|
|
130
|
+
},
|
|
131
|
+
get children() {
|
|
132
|
+
var _el$10 = _tmpl$4();
|
|
133
|
+
setAttribute(_el$10, "id", descriptionId);
|
|
134
|
+
insert(_el$10, () => {
|
|
135
|
+
return props.description;
|
|
136
|
+
});
|
|
137
|
+
return _el$10;
|
|
138
|
+
}
|
|
139
|
+
}), _el$11);
|
|
140
|
+
setAttribute(_el$11, "id", errorId);
|
|
141
|
+
insert(_el$11, () => {
|
|
142
|
+
return props.error;
|
|
143
|
+
});
|
|
144
|
+
insert(_el$9, createComponent(Show, {
|
|
145
|
+
get when() {
|
|
146
|
+
return props.maxLength !== void 0;
|
|
147
|
+
},
|
|
148
|
+
get children() {
|
|
149
|
+
var _el$12 = _tmpl$5();
|
|
150
|
+
var _el$13 = _el$12.firstChild;
|
|
151
|
+
var _el$14 = _el$13.nextSibling;
|
|
152
|
+
insert(_el$12, () => {
|
|
153
|
+
return props.value.length;
|
|
154
|
+
}, _el$13);
|
|
155
|
+
insert(_el$12, () => {
|
|
156
|
+
return props.maxLength;
|
|
157
|
+
}, _el$14);
|
|
158
|
+
return _el$12;
|
|
159
|
+
}
|
|
160
|
+
}), _el$15);
|
|
161
|
+
effect(() => {
|
|
162
|
+
return {
|
|
163
|
+
e: readShallow(classes("xds-text-field", props.class)),
|
|
164
|
+
t: readShallow(props.style)
|
|
165
|
+
};
|
|
166
|
+
}, ({ e, t }, _p$) => {
|
|
167
|
+
className(_el$3, e, _p$?.e);
|
|
168
|
+
style(_el$3, t, _p$?.t);
|
|
169
|
+
});
|
|
170
|
+
return _el$3;
|
|
171
|
+
}
|
|
172
|
+
export { TextField };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Badge } from "./Badge.js";
|
|
2
|
+
import { useDefaults } from "./Defaults.js";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { createPicture } from "./picture.js";
|
|
5
|
+
import { className, createComponent, effect, insert, memo, readShallow, setAttribute, setStyleProperty, style, template } from "@solidjs/web";
|
|
6
|
+
import { THUMBNAIL_PARTS, classes, pictureClass, rootPart, thumbnailBadgeClass, thumbnailClass, thumbnailWatched } from "@xds/core";
|
|
7
|
+
import { Show } from "solid-js";
|
|
8
|
+
// packages/ui-solid/src/Thumbnail.tsx
|
|
9
|
+
var _tmpl$ = /* @__PURE__ */ template(`<span aria-hidden=true><span>`);
|
|
10
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<span><span><!><!></span><!><!>`);
|
|
11
|
+
var _tmpl$3 = /* @__PURE__ */ template(`<img alt aria-hidden=true>`);
|
|
12
|
+
var _tmpl$4 = /* @__PURE__ */ template(`<span>`);
|
|
13
|
+
var ROOT = rootPart("Thumbnail");
|
|
14
|
+
/**
|
|
15
|
+
* A picture in a fixed shape, for a video, an article or a product. It fills the width it is
|
|
16
|
+
* given and takes its height from `ratio`, and crops the picture to fill it.
|
|
17
|
+
*/
|
|
18
|
+
function Thumbnail(props) {
|
|
19
|
+
const defaults = useDefaults("Thumbnail");
|
|
20
|
+
const picture = createPicture(() => props.src);
|
|
21
|
+
const watched = () => thumbnailWatched(props.progress);
|
|
22
|
+
var _el$ = _tmpl$2();
|
|
23
|
+
var _el$2 = _el$.firstChild;
|
|
24
|
+
var _el$3 = _el$2.firstChild;
|
|
25
|
+
var _el$4 = _el$3.nextSibling;
|
|
26
|
+
var _el$5 = _el$2.nextSibling;
|
|
27
|
+
var _el$8 = _el$5.nextSibling;
|
|
28
|
+
insert(_el$2, createComponent(Show, {
|
|
29
|
+
get when() {
|
|
30
|
+
return picture.loaded() !== true;
|
|
31
|
+
},
|
|
32
|
+
get children() {
|
|
33
|
+
return createComponent(Icon, {
|
|
34
|
+
name: "image",
|
|
35
|
+
size: "lg"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}), _el$3);
|
|
39
|
+
insert(_el$2, createComponent(Show, {
|
|
40
|
+
get when() {
|
|
41
|
+
return memo(() => {
|
|
42
|
+
return picture.loaded() !== false;
|
|
43
|
+
})() && props.src;
|
|
44
|
+
},
|
|
45
|
+
children: (src) => (() => {
|
|
46
|
+
var _el$9 = _tmpl$3();
|
|
47
|
+
_el$9.addEventListener("error", () => picture.onError(src()));
|
|
48
|
+
_el$9.addEventListener("load", () => picture.onLoad(src()));
|
|
49
|
+
effect(() => {
|
|
50
|
+
return {
|
|
51
|
+
e: src(),
|
|
52
|
+
t: readShallow(pictureClass(picture.loaded() === true))
|
|
53
|
+
};
|
|
54
|
+
}, ({ e, t }, _p$) => {
|
|
55
|
+
e !== _p$?.e && setAttribute(_el$9, "src", e);
|
|
56
|
+
className(_el$9, t, _p$?.t);
|
|
57
|
+
});
|
|
58
|
+
return _el$9;
|
|
59
|
+
})()
|
|
60
|
+
}), _el$4);
|
|
61
|
+
insert(_el$, createComponent(Show, {
|
|
62
|
+
get when() {
|
|
63
|
+
return props.badge;
|
|
64
|
+
},
|
|
65
|
+
children: (badge) => (() => {
|
|
66
|
+
var _el$10 = _tmpl$4();
|
|
67
|
+
insert(_el$10, createComponent(Badge, {
|
|
68
|
+
tone: "overlay",
|
|
69
|
+
get children() {
|
|
70
|
+
return badge();
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
effect(() => readShallow(thumbnailBadgeClass(watched())), (_v$, _$p) => {
|
|
74
|
+
className(_el$10, _v$, _$p);
|
|
75
|
+
});
|
|
76
|
+
return _el$10;
|
|
77
|
+
})()
|
|
78
|
+
}), _el$5);
|
|
79
|
+
insert(_el$, createComponent(Show, {
|
|
80
|
+
get when() {
|
|
81
|
+
return watched() > 0;
|
|
82
|
+
},
|
|
83
|
+
get children() {
|
|
84
|
+
var _el$6 = _tmpl$();
|
|
85
|
+
var _el$7 = _el$6.firstChild;
|
|
86
|
+
effect(() => {
|
|
87
|
+
return {
|
|
88
|
+
e: readShallow(THUMBNAIL_PARTS.track),
|
|
89
|
+
t: readShallow(THUMBNAIL_PARTS.fill),
|
|
90
|
+
a: `${watched() * 100}%`
|
|
91
|
+
};
|
|
92
|
+
}, ({ e, t, a }, _p$) => {
|
|
93
|
+
className(_el$6, e, _p$?.e);
|
|
94
|
+
className(_el$7, t, _p$?.t);
|
|
95
|
+
a !== _p$?.a && setStyleProperty(_el$7, "width", a);
|
|
96
|
+
});
|
|
97
|
+
return _el$6;
|
|
98
|
+
}
|
|
99
|
+
}), _el$8);
|
|
100
|
+
effect(() => {
|
|
101
|
+
return {
|
|
102
|
+
e: readShallow(classes(ROOT, thumbnailClass(props.ratio ?? defaults().ratio), props.class)),
|
|
103
|
+
t: readShallow(props.style),
|
|
104
|
+
a: readShallow(THUMBNAIL_PARTS.placeholder),
|
|
105
|
+
o: props.alt ? "img" : void 0,
|
|
106
|
+
i: props.alt || void 0,
|
|
107
|
+
n: props.alt ? void 0 : "true"
|
|
108
|
+
};
|
|
109
|
+
}, ({ e, t, a, o, i, n }, _p$) => {
|
|
110
|
+
className(_el$, e, _p$?.e);
|
|
111
|
+
style(_el$, t, _p$?.t);
|
|
112
|
+
className(_el$2, a, _p$?.a);
|
|
113
|
+
o !== _p$?.o && setAttribute(_el$2, "role", o);
|
|
114
|
+
i !== _p$?.i && setAttribute(_el$2, "aria-label", i);
|
|
115
|
+
n !== _p$?.n && setAttribute(_el$2, "aria-hidden", n);
|
|
116
|
+
});
|
|
117
|
+
return _el$;
|
|
118
|
+
}
|
|
119
|
+
export { Thumbnail };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { className, createComponent, delegateEvents, effect, insert, readShallow, ref, style, template } from "@solidjs/web";
|
|
2
|
+
import { TOAST_PARTS, classes, rootPart } from "@xds/core";
|
|
3
|
+
import { Show, createEffect, createSignal, onSettled } from "solid-js";
|
|
4
|
+
import { motion } from "@xds/tokens";
|
|
5
|
+
// packages/ui-solid/src/Toast.tsx
|
|
6
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div><span>`);
|
|
7
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<div role=status popover=manual>`);
|
|
8
|
+
var _tmpl$3 = /* @__PURE__ */ template(`<button type=button>`);
|
|
9
|
+
var ROOT = rootPart("Toast");
|
|
10
|
+
/**
|
|
11
|
+
* A short message about what just happened, which leaves on its own. It sits at the bottom
|
|
12
|
+
* center of the window, above everything else, and is announced politely without taking
|
|
13
|
+
* focus. The time does not run while the pointer is over it or focus is inside it.
|
|
14
|
+
*
|
|
15
|
+
* Do not put the only way to do something in a toast: it is gone in a few seconds.
|
|
16
|
+
*
|
|
17
|
+
* Its `class` and `style` are the toast's surface's, which is in the page only while it is open.
|
|
18
|
+
*/
|
|
19
|
+
function Toast(props) {
|
|
20
|
+
let region;
|
|
21
|
+
const [hovered, setHovered] = createSignal();
|
|
22
|
+
const [focused, setFocused] = createSignal();
|
|
23
|
+
const inPage = (toast) => toast?.isConnected === true;
|
|
24
|
+
onSettled(() => {
|
|
25
|
+
if (!region.showPopover) return;
|
|
26
|
+
region.showPopover();
|
|
27
|
+
return () => region.hidePopover();
|
|
28
|
+
});
|
|
29
|
+
createEffect(() => ({
|
|
30
|
+
open: props.open,
|
|
31
|
+
held: inPage(hovered()) || inPage(focused()),
|
|
32
|
+
duration: props.duration ?? motion.duration.toast
|
|
33
|
+
}), ({ open, held, duration }) => {
|
|
34
|
+
if (!open || held || duration <= 0) return;
|
|
35
|
+
const timer = setTimeout(() => props.onClose(), duration);
|
|
36
|
+
return () => clearTimeout(timer);
|
|
37
|
+
});
|
|
38
|
+
var _el$ = _tmpl$2();
|
|
39
|
+
ref(() => {
|
|
40
|
+
return (element) => region = element;
|
|
41
|
+
}, _el$);
|
|
42
|
+
insert(_el$, createComponent(Show, {
|
|
43
|
+
get when() {
|
|
44
|
+
return props.open;
|
|
45
|
+
},
|
|
46
|
+
get children() {
|
|
47
|
+
var _el$2 = _tmpl$();
|
|
48
|
+
var _el$3 = _el$2.firstChild;
|
|
49
|
+
_el$2._$$focusout = () => setFocused(void 0);
|
|
50
|
+
_el$2._$$focusin = (event) => setFocused(event.currentTarget);
|
|
51
|
+
_el$2.addEventListener("pointerleave", () => setHovered(void 0));
|
|
52
|
+
_el$2.addEventListener("pointerenter", (event) => setHovered(event.currentTarget));
|
|
53
|
+
insert(_el$3, () => {
|
|
54
|
+
return props.message;
|
|
55
|
+
});
|
|
56
|
+
insert(_el$2, createComponent(Show, {
|
|
57
|
+
get when() {
|
|
58
|
+
return props.action;
|
|
59
|
+
},
|
|
60
|
+
children: (action) => (() => {
|
|
61
|
+
var _el$4 = _tmpl$3();
|
|
62
|
+
_el$4._$$click = () => {
|
|
63
|
+
action().onPress();
|
|
64
|
+
props.onClose();
|
|
65
|
+
};
|
|
66
|
+
insert(_el$4, () => {
|
|
67
|
+
return action().label;
|
|
68
|
+
});
|
|
69
|
+
effect(() => readShallow(TOAST_PARTS.action), (_v$, _$p) => {
|
|
70
|
+
className(_el$4, _v$, _$p);
|
|
71
|
+
});
|
|
72
|
+
return _el$4;
|
|
73
|
+
})()
|
|
74
|
+
}), null);
|
|
75
|
+
effect(() => {
|
|
76
|
+
return {
|
|
77
|
+
e: readShallow(classes(ROOT, TOAST_PARTS.toast, props.class)),
|
|
78
|
+
t: readShallow(props.style),
|
|
79
|
+
a: readShallow(TOAST_PARTS.message)
|
|
80
|
+
};
|
|
81
|
+
}, ({ e, t, a }, _p$) => {
|
|
82
|
+
className(_el$2, e, _p$?.e);
|
|
83
|
+
style(_el$2, t, _p$?.t);
|
|
84
|
+
className(_el$3, a, _p$?.a);
|
|
85
|
+
});
|
|
86
|
+
return _el$2;
|
|
87
|
+
}
|
|
88
|
+
}));
|
|
89
|
+
effect(() => readShallow(TOAST_PARTS.region), (_v$, _$p) => {
|
|
90
|
+
className(_el$, _v$, _$p);
|
|
91
|
+
});
|
|
92
|
+
return _el$;
|
|
93
|
+
}
|
|
94
|
+
delegateEvents([
|
|
95
|
+
"focusin",
|
|
96
|
+
"focusout",
|
|
97
|
+
"click"
|
|
98
|
+
]);
|
|
99
|
+
export { Toast };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createPresence } from "./presence.js";
|
|
2
|
+
import { withStyle } from "./root.js";
|
|
3
|
+
import { TriggerContext, provideTrigger } from "./trigger.js";
|
|
4
|
+
import { Portal, createComponent, insert, ref, spread, template } from "@solidjs/web";
|
|
5
|
+
import { classes, tooltipEndSide } from "@xds/core";
|
|
6
|
+
import { normalizeProps, useMachine } from "@zag-js/solid";
|
|
7
|
+
import { Show, createMemo, createUniqueId } from "solid-js";
|
|
8
|
+
import { motion, space } from "@xds/tokens";
|
|
9
|
+
import * as tooltip from "@zag-js/tooltip";
|
|
10
|
+
// packages/ui-solid/src/Tooltip.tsx
|
|
11
|
+
var _tmpl$ = /* @__PURE__ */ template(`<div><div><!><!>`);
|
|
12
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<kbd class=xds-tooltip__shortcut>`);
|
|
13
|
+
/**
|
|
14
|
+
* Names a control when the pointer rests on it or the keyboard focuses it. It appears after a
|
|
15
|
+
* short wait under a pointer and at once on keyboard focus, and goes when the pointer leaves,
|
|
16
|
+
* focus leaves, or Escape is pressed.
|
|
17
|
+
*
|
|
18
|
+
* It describes the control and is not its name: an IconButton still needs its `label`. It
|
|
19
|
+
* never holds anything pressable, and touch input has no hover, so nothing may depend on it.
|
|
20
|
+
*
|
|
21
|
+
* Its `class` and `style` are the tooltip's, not the control's, and it is in the page only
|
|
22
|
+
* while it shows.
|
|
23
|
+
*/
|
|
24
|
+
function Tooltip(props) {
|
|
25
|
+
return createComponent(Overlay, {
|
|
26
|
+
get label() {
|
|
27
|
+
return props.label;
|
|
28
|
+
},
|
|
29
|
+
get shortcut() {
|
|
30
|
+
return props.shortcut;
|
|
31
|
+
},
|
|
32
|
+
placement: () => props.placement ?? "top",
|
|
33
|
+
get "class"() {
|
|
34
|
+
return props.class;
|
|
35
|
+
},
|
|
36
|
+
get style() {
|
|
37
|
+
return props.style;
|
|
38
|
+
},
|
|
39
|
+
get children() {
|
|
40
|
+
return props.children;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A Tooltip at the end edge of its control instead of above or below it: a collapsed Sidebar
|
|
46
|
+
* names its icons on the side of the content, where they do not cover their neighbours. Only
|
|
47
|
+
* for this package's own components: the index does not export it.
|
|
48
|
+
*/
|
|
49
|
+
function TooltipBeside(props) {
|
|
50
|
+
return createComponent(Overlay, {
|
|
51
|
+
get label() {
|
|
52
|
+
return props.label;
|
|
53
|
+
},
|
|
54
|
+
placement: tooltipEndSide,
|
|
55
|
+
get children() {
|
|
56
|
+
return props.children;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** The root element is the tooltip itself, which is in the page only while it shows. */
|
|
61
|
+
function Overlay(props) {
|
|
62
|
+
const id = createUniqueId();
|
|
63
|
+
const service = useMachine(tooltip.machine, () => ({
|
|
64
|
+
id,
|
|
65
|
+
openDelay: motion.duration.tooltipDelay,
|
|
66
|
+
closeDelay: 0,
|
|
67
|
+
closeOnScroll: false,
|
|
68
|
+
positioning: {
|
|
69
|
+
placement: props.placement(),
|
|
70
|
+
gutter: space[1]
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
const api = createMemo(() => tooltip.connect(service, normalizeProps));
|
|
74
|
+
const trigger = provideTrigger(() => api().getTriggerProps());
|
|
75
|
+
const contentProps = withStyle(() => api().getContentProps(), () => props.style);
|
|
76
|
+
let content;
|
|
77
|
+
const present = createPresence(() => api().open, () => [content]);
|
|
78
|
+
return [createComponent(TriggerContext, {
|
|
79
|
+
value: trigger,
|
|
80
|
+
get children() {
|
|
81
|
+
return props.children;
|
|
82
|
+
}
|
|
83
|
+
}), createComponent(Show, {
|
|
84
|
+
get when() {
|
|
85
|
+
return present();
|
|
86
|
+
},
|
|
87
|
+
get children() {
|
|
88
|
+
return createComponent(Portal, { get children() {
|
|
89
|
+
return createComponent(TriggerContext, {
|
|
90
|
+
value: null,
|
|
91
|
+
get children() {
|
|
92
|
+
var _el$ = _tmpl$();
|
|
93
|
+
var _el$2 = _el$.firstChild;
|
|
94
|
+
var _el$3 = _el$2.firstChild;
|
|
95
|
+
var _el$4 = _el$3.nextSibling;
|
|
96
|
+
spread(_el$, [() => {
|
|
97
|
+
return api().getPositionerProps();
|
|
98
|
+
}, { class: "xds-tooltip__positioner" }], true);
|
|
99
|
+
spread(_el$2, [contentProps, {
|
|
100
|
+
hidden: false,
|
|
101
|
+
get "class"() {
|
|
102
|
+
return classes("xds-tooltip", props.class);
|
|
103
|
+
}
|
|
104
|
+
}], true);
|
|
105
|
+
ref(() => {
|
|
106
|
+
return (element) => content = element;
|
|
107
|
+
}, _el$2);
|
|
108
|
+
insert(_el$2, () => {
|
|
109
|
+
return props.label;
|
|
110
|
+
}, _el$3);
|
|
111
|
+
insert(_el$2, createComponent(Show, {
|
|
112
|
+
get when() {
|
|
113
|
+
return props.shortcut;
|
|
114
|
+
},
|
|
115
|
+
children: (shortcut) => (() => {
|
|
116
|
+
var _el$5 = _tmpl$2();
|
|
117
|
+
insert(_el$5, shortcut);
|
|
118
|
+
return _el$5;
|
|
119
|
+
})()
|
|
120
|
+
}), _el$4);
|
|
121
|
+
return _el$;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
} });
|
|
125
|
+
}
|
|
126
|
+
})];
|
|
127
|
+
}
|
|
128
|
+
export { Tooltip, TooltipBeside };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { flush } from "solid-js";
|
|
2
|
+
// packages/ui-solid/src/controlled.ts
|
|
3
|
+
/** After `onChange`: puts the parent's value back into a field that did not take the edit. */
|
|
4
|
+
function keepValue(element, value) {
|
|
5
|
+
flush();
|
|
6
|
+
if (element.value !== value()) element.value = value();
|
|
7
|
+
}
|
|
8
|
+
/** After `onChange`: puts the parent's state back into a checkbox or radio that did not take it. */
|
|
9
|
+
function keepChecked(element, checked) {
|
|
10
|
+
flush();
|
|
11
|
+
if (element.checked !== checked()) element.checked = checked();
|
|
12
|
+
}
|
|
13
|
+
export { keepChecked, keepValue };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Accordion } from "./Accordion.js";
|
|
2
|
+
import { Avatar } from "./Avatar.js";
|
|
3
|
+
import { AvatarStack } from "./AvatarStack.js";
|
|
4
|
+
import { Badge } from "./Badge.js";
|
|
5
|
+
import { Banner } from "./Banner.js";
|
|
6
|
+
import { Button } from "./Button.js";
|
|
7
|
+
import { Card } from "./Card.js";
|
|
8
|
+
import { Checkbox } from "./Checkbox.js";
|
|
9
|
+
import { Chip } from "./Chip.js";
|
|
10
|
+
import { ChipBar } from "./ChipBar.js";
|
|
11
|
+
import { CountBadge } from "./CountBadge.js";
|
|
12
|
+
import { DatePicker } from "./DatePicker.js";
|
|
13
|
+
import { DateRangePicker } from "./DateRangePicker.js";
|
|
14
|
+
import { Defaults } from "./Defaults.js";
|
|
15
|
+
import { Dialog } from "./Dialog.js";
|
|
16
|
+
import { Divider } from "./Divider.js";
|
|
17
|
+
import { EmptyState } from "./EmptyState.js";
|
|
18
|
+
import { Icon } from "./Icon.js";
|
|
19
|
+
import { IconButton } from "./IconButton.js";
|
|
20
|
+
import { ListRow } from "./ListRow.js";
|
|
21
|
+
import { MediaCard } from "./MediaCard.js";
|
|
22
|
+
import { Menu } from "./Menu.js";
|
|
23
|
+
import { ProgressBar } from "./ProgressBar.js";
|
|
24
|
+
import { RadioGroup } from "./RadioGroup.js";
|
|
25
|
+
import { SearchField } from "./SearchField.js";
|
|
26
|
+
import { SectionHeader } from "./SectionHeader.js";
|
|
27
|
+
import { SegmentedControl } from "./SegmentedControl.js";
|
|
28
|
+
import { Select } from "./Select.js";
|
|
29
|
+
import { Sidebar } from "./Sidebar.js";
|
|
30
|
+
import { Skeleton } from "./Skeleton.js";
|
|
31
|
+
import { Slider } from "./Slider.js";
|
|
32
|
+
import { Spinner } from "./Spinner.js";
|
|
33
|
+
import { Switch } from "./Switch.js";
|
|
34
|
+
import { Tabs } from "./Tabs.js";
|
|
35
|
+
import { Text } from "./Text.js";
|
|
36
|
+
import { TextField } from "./TextField.js";
|
|
37
|
+
import { Thumbnail } from "./Thumbnail.js";
|
|
38
|
+
import { Toast } from "./Toast.js";
|
|
39
|
+
import { Tooltip } from "./Tooltip.js";
|
|
40
|
+
export { 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 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createEffect } from "solid-js";
|
|
2
|
+
import { ariaHidden } from "@zag-js/aria-hidden";
|
|
3
|
+
import { preventBodyScroll } from "@zag-js/remove-scroll";
|
|
4
|
+
// packages/ui-solid/src/modal-popover.ts
|
|
5
|
+
/**
|
|
6
|
+
* Makes an open Menu or Select list modal while `open()` is true: the rest of the page is
|
|
7
|
+
* hidden from assistive technology, so a screen reader's cursor stays in the popup, where the
|
|
8
|
+
* focus is held too, and the page does not scroll. The popup's underlay keeps the pointer off
|
|
9
|
+
* the page. Zag does all of this around a dialog, but not around a menu or a select.
|
|
10
|
+
*/
|
|
11
|
+
function modalPopover(open, popup) {
|
|
12
|
+
createEffect(open, (isOpen) => {
|
|
13
|
+
if (!isOpen) return;
|
|
14
|
+
const unlock = preventBodyScroll(document);
|
|
15
|
+
const reveal = ariaHidden(() => [popup() ?? null], { defer: true });
|
|
16
|
+
return () => {
|
|
17
|
+
reveal();
|
|
18
|
+
unlock();
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export { modalPopover };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createSignal } from "solid-js";
|
|
2
|
+
// packages/ui-solid/src/picture.ts
|
|
3
|
+
/**
|
|
4
|
+
* Follows the loading of the picture at `src()`. `loaded()` is undefined while it loads, then
|
|
5
|
+
* true or false. The result is remembered with the address it belongs to, so a new `src` starts
|
|
6
|
+
* over without an effect.
|
|
7
|
+
*
|
|
8
|
+
* A picture that is in the cache still reports its load in a later task, after the handlers
|
|
9
|
+
* are attached, so no check of `complete` is needed on a page rendered in the browser.
|
|
10
|
+
*/
|
|
11
|
+
function createPicture(src) {
|
|
12
|
+
const [picture, setPicture] = createSignal();
|
|
13
|
+
const loaded = () => {
|
|
14
|
+
const current = picture();
|
|
15
|
+
return current !== void 0 && current.src === src() ? current.loaded : void 0;
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
loaded,
|
|
19
|
+
onLoad: (address) => setPicture({
|
|
20
|
+
src: address,
|
|
21
|
+
loaded: true
|
|
22
|
+
}),
|
|
23
|
+
onError: (address) => setPicture({
|
|
24
|
+
src: address,
|
|
25
|
+
loaded: false
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export { createPicture };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { afterAnimations } from "@xds/core";
|
|
2
|
+
import { createEffect, createMemo, createSignal } from "solid-js";
|
|
3
|
+
// packages/ui-solid/src/presence.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether an overlay is on the page: from when it opens until the exit animation that its
|
|
6
|
+
* stylesheet starts on `[data-state="closed"]` has finished. Zag hides a closed part at once.
|
|
7
|
+
* `parts` are the elements that animate.
|
|
8
|
+
*/
|
|
9
|
+
function createPresence(open, parts) {
|
|
10
|
+
const [exited, setExited] = createSignal(true);
|
|
11
|
+
createEffect(open, (isOpen) => {
|
|
12
|
+
if (isOpen) {
|
|
13
|
+
setExited(false);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
return afterAnimations(parts(), () => setExited(true));
|
|
17
|
+
});
|
|
18
|
+
return createMemo(() => open() || !exited());
|
|
19
|
+
}
|
|
20
|
+
export { createPresence };
|