@jirawatpyk/aura-react 4.7.2 → 4.9.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 +3 -3
- package/dist/aura.bundle.js +1075 -595
- package/dist/cjs/index.cjs +1074 -594
- package/dist/esm/Accordion.js +66 -0
- package/dist/esm/Alert.js +31 -0
- package/dist/esm/AppShell.js +55 -0
- package/dist/esm/Avatar.js +39 -0
- package/dist/esm/Badge.js +26 -0
- package/dist/esm/Breadcrumb.js +16 -0
- package/dist/esm/Card.js +26 -0
- package/dist/esm/Combobox.js +311 -236
- package/dist/esm/Container.js +18 -0
- package/dist/esm/DatePicker.js +1 -1
- package/dist/esm/Dialog.js +1 -1
- package/dist/esm/EmptyState.js +22 -0
- package/dist/esm/Field.js +46 -0
- package/dist/esm/FileUpload.js +1 -1
- package/dist/esm/Grid.js +21 -0
- package/dist/esm/NumberField.js +175 -0
- package/dist/esm/Pagination.js +94 -0
- package/dist/esm/Popover.js +131 -0
- package/dist/esm/Progress.js +40 -0
- package/dist/esm/RadioGroup.js +46 -0
- package/dist/esm/SegmentedControl.js +104 -0
- package/dist/esm/Select.js +48 -0
- package/dist/esm/SideNav.js +36 -0
- package/dist/esm/Skeleton.js +29 -0
- package/dist/esm/Stack.js +20 -0
- package/dist/esm/Stepper.js +54 -0
- package/dist/esm/Switch.js +30 -0
- package/dist/esm/Tabs.js +89 -0
- package/dist/esm/Tag.js +42 -0
- package/dist/esm/TextField.js +39 -0
- package/dist/esm/Textarea.js +38 -0
- package/dist/esm/TimePicker.js +1 -1
- package/dist/esm/Toaster.js +124 -0
- package/dist/esm/Tooltip.js +80 -0
- package/dist/esm/index.js +33 -5
- package/dist/esm/internal.js +5 -0
- package/dist/esm/locale.js +12 -0
- package/dist/esm/responsive.js +50 -0
- package/dist/index.d.ts +109 -10
- package/dist/styles.css +107 -0
- package/package.json +1 -1
- package/dist/esm/extra.js +0 -412
- package/dist/esm/feedback.js +0 -220
- package/dist/esm/forms.js +0 -212
- package/dist/esm/layout.js +0 -183
- package/dist/esm/layout2.js +0 -138
- /package/dist/esm/{overlay.js → useModal.js} +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { cx } from "./internal.js";
|
|
5
|
+
import { useStrings } from "./locale.js";
|
|
6
|
+
const h = React.createElement;
|
|
7
|
+
const Field = React.forwardRef(function Field2(props, ref) {
|
|
8
|
+
const t = useStrings();
|
|
9
|
+
return /* @__PURE__ */ React.createElement(
|
|
10
|
+
"div",
|
|
11
|
+
{
|
|
12
|
+
ref,
|
|
13
|
+
className: cx("aura-field", props.error && "is-invalid", props.disabled && "is-disabled", props.className)
|
|
14
|
+
},
|
|
15
|
+
props.label ? h(
|
|
16
|
+
props.labelAs || "label",
|
|
17
|
+
{ className: "aura-field__label", htmlFor: props.labelAs ? void 0 : props.id, id: props.labelId },
|
|
18
|
+
props.label,
|
|
19
|
+
props.required ? /* @__PURE__ */ React.createElement("span", { className: "aura-field__req", "aria-hidden": true }, " *") : null,
|
|
20
|
+
props.optional ? /* @__PURE__ */ React.createElement("span", { className: "aura-field__opt" }, " (" + t.optional + ")") : null
|
|
21
|
+
) : null,
|
|
22
|
+
props.children,
|
|
23
|
+
props.error ? /* @__PURE__ */ React.createElement("p", { className: "aura-field__error", id: props.id + "-error" }, /* @__PURE__ */ React.createElement(Icon, { name: "circle-alert", size: 14 }), props.error) : props.hint ? /* @__PURE__ */ React.createElement("p", { className: "aura-field__hint", id: props.id + "-hint" }, props.hint) : null
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
function describedBy(id, p) {
|
|
27
|
+
return p.error ? id + "-error" : p.hint ? id + "-hint" : void 0;
|
|
28
|
+
}
|
|
29
|
+
const FIELD_KEYS = [
|
|
30
|
+
"label",
|
|
31
|
+
"hint",
|
|
32
|
+
"error",
|
|
33
|
+
"required",
|
|
34
|
+
"optional",
|
|
35
|
+
"icon",
|
|
36
|
+
"className",
|
|
37
|
+
"id",
|
|
38
|
+
"suffix",
|
|
39
|
+
"options",
|
|
40
|
+
"placeholder"
|
|
41
|
+
];
|
|
42
|
+
export {
|
|
43
|
+
FIELD_KEYS,
|
|
44
|
+
Field,
|
|
45
|
+
describedBy
|
|
46
|
+
};
|
package/dist/esm/FileUpload.js
CHANGED
|
@@ -4,7 +4,7 @@ import { cx, uid, useMaybeControlled, useMergedRef } from "./internal.js";
|
|
|
4
4
|
import { useStrings } from "./locale.js";
|
|
5
5
|
import { Icon } from "./Icon.js";
|
|
6
6
|
import { IconButton } from "./IconButton.js";
|
|
7
|
-
import { Field } from "./
|
|
7
|
+
import { Field } from "./Field.js";
|
|
8
8
|
function formatBytes(n) {
|
|
9
9
|
if (n == null) return "";
|
|
10
10
|
if (n < 1024) return n + " B";
|
package/dist/esm/Grid.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cx } from "./internal.js";
|
|
4
|
+
import { respVars, space } from "./responsive.js";
|
|
5
|
+
const h = React.createElement;
|
|
6
|
+
const Grid = React.forwardRef(function Grid2(props, ref) {
|
|
7
|
+
const style = Object.assign(
|
|
8
|
+
{},
|
|
9
|
+
respVars("aura-grid-gap", props.gap == null ? 6 : props.gap, space),
|
|
10
|
+
props.minItemWidth ? { gridTemplateColumns: "repeat(auto-fill, minmax(min(" + props.minItemWidth + "px, 100%), 1fr))" } : respVars("aura-grid-cols", props.columns || 1),
|
|
11
|
+
props.style
|
|
12
|
+
);
|
|
13
|
+
return h(
|
|
14
|
+
props.as || "div",
|
|
15
|
+
{ ref, className: cx("aura-grid-layout", props.minItemWidth && "is-auto", props.className), style },
|
|
16
|
+
props.children
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
export {
|
|
20
|
+
Grid
|
|
21
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Field, describedBy } from "./Field.js";
|
|
4
|
+
import { Icon } from "./Icon.js";
|
|
5
|
+
import { cx, uid, useMaybeControlled } from "./internal.js";
|
|
6
|
+
import { useStrings } from "./locale.js";
|
|
7
|
+
function decimalsOf(n) {
|
|
8
|
+
const s = String(n);
|
|
9
|
+
const i = s.indexOf(".");
|
|
10
|
+
return i < 0 ? 0 : s.length - i - 1;
|
|
11
|
+
}
|
|
12
|
+
function parse(text) {
|
|
13
|
+
const s = text.replace(/[,\s ]/g, "");
|
|
14
|
+
if (!/^-?(\d+\.?\d*|\.\d+)$/.test(s)) return NaN;
|
|
15
|
+
return Number(s);
|
|
16
|
+
}
|
|
17
|
+
const NumberField = React.forwardRef(function NumberField2(props, ref) {
|
|
18
|
+
const t = useStrings();
|
|
19
|
+
const auto = uid(), id = props.id || auto;
|
|
20
|
+
const step = props.step || 1;
|
|
21
|
+
const decimals = props.decimals != null ? props.decimals : decimalsOf(step);
|
|
22
|
+
const st = useMaybeControlled(
|
|
23
|
+
props.value,
|
|
24
|
+
props.defaultValue == null ? null : props.defaultValue,
|
|
25
|
+
props.onChange
|
|
26
|
+
);
|
|
27
|
+
const value = st[0], setValue = st[1];
|
|
28
|
+
const draftState = React.useState(null), draft = draftState[0], setDraft = draftState[1];
|
|
29
|
+
function fmt(n) {
|
|
30
|
+
if (n == null || isNaN(n)) return "";
|
|
31
|
+
return n.toLocaleString("en", { minimumFractionDigits: decimals, maximumFractionDigits: decimals });
|
|
32
|
+
}
|
|
33
|
+
function fit(n) {
|
|
34
|
+
let v = n;
|
|
35
|
+
if (props.min != null && v < props.min) v = props.min;
|
|
36
|
+
if (props.max != null && v > props.max) v = props.max;
|
|
37
|
+
const f = Math.pow(10, decimals);
|
|
38
|
+
return Math.round(v * f) / f;
|
|
39
|
+
}
|
|
40
|
+
function nudge(by) {
|
|
41
|
+
if (props.disabled || props.readOnly) return;
|
|
42
|
+
const base = value == null ? props.min != null && props.min > 0 ? props.min - by : 0 : value;
|
|
43
|
+
const next = fit(base + by);
|
|
44
|
+
setValue(next);
|
|
45
|
+
setDraft(null);
|
|
46
|
+
}
|
|
47
|
+
function onKeyDown(e) {
|
|
48
|
+
const k = e.key;
|
|
49
|
+
let by = 0;
|
|
50
|
+
if (k === "ArrowUp") by = step;
|
|
51
|
+
else if (k === "ArrowDown") by = -step;
|
|
52
|
+
else if (k === "PageUp") by = step * 10;
|
|
53
|
+
else if (k === "PageDown") by = -step * 10;
|
|
54
|
+
else if (k === "Home" && props.min != null) {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
setValue(props.min);
|
|
57
|
+
setDraft(null);
|
|
58
|
+
return;
|
|
59
|
+
} else if (k === "End" && props.max != null) {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
setValue(props.max);
|
|
62
|
+
setDraft(null);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (by) {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
nudge(by);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const atMin = value != null && props.min != null && value <= props.min;
|
|
71
|
+
const atMax = value != null && props.max != null && value >= props.max;
|
|
72
|
+
const affixText = function(x) {
|
|
73
|
+
return typeof x === "string" || typeof x === "number" ? String(x) : "";
|
|
74
|
+
};
|
|
75
|
+
const valueText = value == null ? void 0 : [affixText(props.prefix), fmt(value), affixText(props.suffix)].join(" ").trim();
|
|
76
|
+
const stepper = props.stepper !== false && !props.readOnly;
|
|
77
|
+
return /* @__PURE__ */ React.createElement(
|
|
78
|
+
Field,
|
|
79
|
+
{
|
|
80
|
+
id,
|
|
81
|
+
label: props.label,
|
|
82
|
+
hint: props.hint,
|
|
83
|
+
error: props.error,
|
|
84
|
+
required: props.required,
|
|
85
|
+
optional: props.optional,
|
|
86
|
+
disabled: props.disabled,
|
|
87
|
+
className: props.className
|
|
88
|
+
},
|
|
89
|
+
/* @__PURE__ */ React.createElement("div", { className: cx("aura-input aura-number", stepper && "has-stepper") }, props.prefix != null ? /* @__PURE__ */ React.createElement("span", { className: "aura-number__affix", "aria-hidden": true }, props.prefix) : null, /* @__PURE__ */ React.createElement(
|
|
90
|
+
"input",
|
|
91
|
+
{
|
|
92
|
+
ref,
|
|
93
|
+
id,
|
|
94
|
+
type: "text",
|
|
95
|
+
role: "spinbutton",
|
|
96
|
+
inputMode: decimals > 0 || props.min != null && props.min < 0 ? "decimal" : "numeric",
|
|
97
|
+
autoComplete: "off",
|
|
98
|
+
className: "aura-input__control",
|
|
99
|
+
name: props.name,
|
|
100
|
+
placeholder: props.placeholder,
|
|
101
|
+
disabled: props.disabled,
|
|
102
|
+
readOnly: props.readOnly,
|
|
103
|
+
required: props.required,
|
|
104
|
+
"aria-valuenow": value == null ? void 0 : value,
|
|
105
|
+
"aria-valuemin": props.min,
|
|
106
|
+
"aria-valuemax": props.max,
|
|
107
|
+
"aria-valuetext": valueText,
|
|
108
|
+
"aria-invalid": props.error ? true : void 0,
|
|
109
|
+
"aria-describedby": describedBy(id, props),
|
|
110
|
+
value: draft != null ? draft : fmt(value),
|
|
111
|
+
onFocus: function() {
|
|
112
|
+
setDraft(fmt(value));
|
|
113
|
+
},
|
|
114
|
+
onChange: function(e) {
|
|
115
|
+
const text = e.target.value;
|
|
116
|
+
setDraft(text);
|
|
117
|
+
if (!text.trim()) setValue(null);
|
|
118
|
+
else {
|
|
119
|
+
const n = parse(text);
|
|
120
|
+
if (!isNaN(n)) setValue(n);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
onBlur: function(e) {
|
|
124
|
+
const n = draft == null ? value : !draft.trim() ? null : parse(draft);
|
|
125
|
+
if (n == null) {
|
|
126
|
+
if (value != null) setValue(null);
|
|
127
|
+
} else if (!isNaN(n)) {
|
|
128
|
+
const f = fit(n);
|
|
129
|
+
if (f !== value) setValue(f);
|
|
130
|
+
}
|
|
131
|
+
setDraft(null);
|
|
132
|
+
if (props.onBlur) props.onBlur(e);
|
|
133
|
+
},
|
|
134
|
+
onKeyDown
|
|
135
|
+
}
|
|
136
|
+
), props.suffix != null ? /* @__PURE__ */ React.createElement("span", { className: "aura-number__affix", "aria-hidden": true }, props.suffix) : null, stepper ? /* @__PURE__ */ React.createElement("span", { className: "aura-number__steps" }, /* @__PURE__ */ React.createElement(
|
|
137
|
+
"button",
|
|
138
|
+
{
|
|
139
|
+
type: "button",
|
|
140
|
+
tabIndex: -1,
|
|
141
|
+
className: "aura-number__step",
|
|
142
|
+
"aria-label": t.decrease,
|
|
143
|
+
"aria-controls": id,
|
|
144
|
+
disabled: props.disabled || atMin,
|
|
145
|
+
onPointerDown: function(e) {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
},
|
|
148
|
+
onClick: function() {
|
|
149
|
+
nudge(-step);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "minus" })
|
|
153
|
+
), /* @__PURE__ */ React.createElement(
|
|
154
|
+
"button",
|
|
155
|
+
{
|
|
156
|
+
type: "button",
|
|
157
|
+
tabIndex: -1,
|
|
158
|
+
className: "aura-number__step",
|
|
159
|
+
"aria-label": t.increase,
|
|
160
|
+
"aria-controls": id,
|
|
161
|
+
disabled: props.disabled || atMax,
|
|
162
|
+
onPointerDown: function(e) {
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
},
|
|
165
|
+
onClick: function() {
|
|
166
|
+
nudge(step);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "plus" })
|
|
170
|
+
)) : null)
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
export {
|
|
174
|
+
NumberField
|
|
175
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { IconButton } from "./IconButton.js";
|
|
4
|
+
import { cx, useMaybeControlled } from "./internal.js";
|
|
5
|
+
import { useStrings } from "./locale.js";
|
|
6
|
+
function pageList(page, count, sib) {
|
|
7
|
+
let out = [], lo = Math.max(2, page - sib), hi = Math.min(count - 1, page + sib);
|
|
8
|
+
if (page - sib <= 3) {
|
|
9
|
+
lo = 2;
|
|
10
|
+
hi = Math.min(count - 1, Math.max(hi, 3 + 2 * sib));
|
|
11
|
+
}
|
|
12
|
+
if (page + sib >= count - 2) {
|
|
13
|
+
hi = count - 1;
|
|
14
|
+
lo = Math.max(2, Math.min(lo, count - 2 - 2 * sib));
|
|
15
|
+
}
|
|
16
|
+
out.push(1);
|
|
17
|
+
if (lo === 3) out.push(2);
|
|
18
|
+
else if (lo > 3) out.push("\u2026a");
|
|
19
|
+
for (let i = lo; i <= hi; i++) out.push(i);
|
|
20
|
+
if (hi === count - 2) out.push(count - 1);
|
|
21
|
+
else if (hi < count - 2) out.push("\u2026b");
|
|
22
|
+
if (count > 1) out.push(count);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
const Pagination = React.forwardRef(function Pagination2(props, ref) {
|
|
26
|
+
const t = useStrings();
|
|
27
|
+
const count = Math.max(1, props.pageCount || 1);
|
|
28
|
+
const st = useMaybeControlled(props.page, props.defaultPage || 1, props.onChange);
|
|
29
|
+
const page = Math.min(count, Math.max(1, st[0]));
|
|
30
|
+
function go(p) {
|
|
31
|
+
if (p >= 1 && p <= count && p !== page) st[1](p);
|
|
32
|
+
}
|
|
33
|
+
const link = props.getHref;
|
|
34
|
+
function item(p, label, extra) {
|
|
35
|
+
const common = Object.assign(
|
|
36
|
+
{
|
|
37
|
+
className: cx("aura-page", p === page && "is-current"),
|
|
38
|
+
"aria-current": p === page ? "page" : void 0,
|
|
39
|
+
"aria-label": t.pageN(p)
|
|
40
|
+
},
|
|
41
|
+
extra
|
|
42
|
+
);
|
|
43
|
+
return link ? /* @__PURE__ */ React.createElement(
|
|
44
|
+
"a",
|
|
45
|
+
{
|
|
46
|
+
href: link(p),
|
|
47
|
+
onClick: function(e) {
|
|
48
|
+
if (props.onChange) {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
go(p);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
...common
|
|
54
|
+
},
|
|
55
|
+
label
|
|
56
|
+
) : /* @__PURE__ */ React.createElement(
|
|
57
|
+
"button",
|
|
58
|
+
{
|
|
59
|
+
type: "button",
|
|
60
|
+
onClick: function() {
|
|
61
|
+
go(p);
|
|
62
|
+
},
|
|
63
|
+
...common
|
|
64
|
+
},
|
|
65
|
+
label
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return /* @__PURE__ */ React.createElement("nav", { ref, className: cx("aura-pagination", props.className), "aria-label": props.label || t.pagination }, /* @__PURE__ */ React.createElement(
|
|
69
|
+
IconButton,
|
|
70
|
+
{
|
|
71
|
+
icon: "chevron-left",
|
|
72
|
+
label: t.prevPage,
|
|
73
|
+
disabled: page <= 1,
|
|
74
|
+
onClick: function() {
|
|
75
|
+
go(page - 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
), /* @__PURE__ */ React.createElement("ol", { className: "aura-pagination__list" }, pageList(page, count, props.siblingCount == null ? 1 : props.siblingCount).map(function(p) {
|
|
79
|
+
return typeof p === "number" ? /* @__PURE__ */ React.createElement("li", { key: p }, item(p, p)) : /* @__PURE__ */ React.createElement("li", { key: p, className: "aura-pagination__gap", "aria-hidden": true }, "\u2026");
|
|
80
|
+
})), /* @__PURE__ */ React.createElement("span", { className: "aura-pagination__compact", "aria-hidden": true }, t.page(page, count)), /* @__PURE__ */ React.createElement(
|
|
81
|
+
IconButton,
|
|
82
|
+
{
|
|
83
|
+
icon: "chevron-right",
|
|
84
|
+
label: t.nextPage,
|
|
85
|
+
disabled: page >= count,
|
|
86
|
+
onClick: function() {
|
|
87
|
+
go(page + 1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
));
|
|
91
|
+
});
|
|
92
|
+
export {
|
|
93
|
+
Pagination
|
|
94
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { IconButton } from "./IconButton.js";
|
|
4
|
+
import {
|
|
5
|
+
FOCUSABLE,
|
|
6
|
+
cx,
|
|
7
|
+
trapTab,
|
|
8
|
+
uid,
|
|
9
|
+
useIsoLayoutEffect,
|
|
10
|
+
useMaybeControlled,
|
|
11
|
+
useMergedRef,
|
|
12
|
+
useMounted
|
|
13
|
+
} from "./internal.js";
|
|
14
|
+
import { useStrings } from "./locale.js";
|
|
15
|
+
import { createPortal } from "react-dom";
|
|
16
|
+
function position(anchor, pop, placement) {
|
|
17
|
+
const r = anchor.getBoundingClientRect(), pw = pop.offsetWidth, ph = pop.offsetHeight, vw = window.innerWidth, vh = window.innerHeight, gap = 6;
|
|
18
|
+
let side = (placement || "bottom-start").split("-")[0], align = (placement || "bottom-start").split("-")[1] || "start";
|
|
19
|
+
if (side === "bottom" && r.bottom + gap + ph > vh - 8 && r.top - gap - ph > 8) side = "top";
|
|
20
|
+
else if (side === "top" && r.top - gap - ph < 8 && r.bottom + gap + ph < vh - 8) side = "bottom";
|
|
21
|
+
const top = side === "top" ? r.top - gap - ph : r.bottom + gap;
|
|
22
|
+
const left = align === "end" ? r.right - pw : align === "center" ? r.left + r.width / 2 - pw / 2 : r.left;
|
|
23
|
+
return { top: Math.max(8, top), left: Math.max(8, Math.min(left, vw - pw - 8)), side };
|
|
24
|
+
}
|
|
25
|
+
const Popover = React.forwardRef(function Popover2(props, ref) {
|
|
26
|
+
const t = useStrings();
|
|
27
|
+
const auto = uid(), id = props.id || auto;
|
|
28
|
+
const st = useMaybeControlled(props.open, !!props.defaultOpen, props.onOpenChange);
|
|
29
|
+
const open = !!st[0];
|
|
30
|
+
const wrap = React.useRef(null), pop = React.useRef(null), popMerged = useMergedRef(ref, pop);
|
|
31
|
+
const pos = React.useState(null), mounted = useMounted();
|
|
32
|
+
function trigger() {
|
|
33
|
+
return wrap.current && (wrap.current.querySelector('button, [role="button"], a, input') || wrap.current.firstElementChild);
|
|
34
|
+
}
|
|
35
|
+
function close(restore) {
|
|
36
|
+
st[1](false);
|
|
37
|
+
if (restore) {
|
|
38
|
+
const tr = trigger();
|
|
39
|
+
if (tr && tr.focus) tr.focus();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
useIsoLayoutEffect(
|
|
43
|
+
function() {
|
|
44
|
+
if (!open || !pop.current || !trigger()) return;
|
|
45
|
+
function place() {
|
|
46
|
+
if (pop.current && trigger()) pos[1](position(trigger(), pop.current, props.placement));
|
|
47
|
+
}
|
|
48
|
+
place();
|
|
49
|
+
window.addEventListener("resize", place);
|
|
50
|
+
window.addEventListener("scroll", place, true);
|
|
51
|
+
return function() {
|
|
52
|
+
window.removeEventListener("resize", place);
|
|
53
|
+
window.removeEventListener("scroll", place, true);
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
[open, mounted, props.placement]
|
|
57
|
+
);
|
|
58
|
+
React.useEffect(
|
|
59
|
+
function() {
|
|
60
|
+
if (!open || !mounted) return;
|
|
61
|
+
if (props.autoFocus !== false && pop.current) {
|
|
62
|
+
const f = pop.current.querySelector("[data-autofocus]") || pop.current.querySelector(FOCUSABLE);
|
|
63
|
+
(f || pop.current).focus();
|
|
64
|
+
}
|
|
65
|
+
function outside(e) {
|
|
66
|
+
if (pop.current && pop.current.contains(e.target)) return;
|
|
67
|
+
if (wrap.current && wrap.current.contains(e.target)) return;
|
|
68
|
+
close(false);
|
|
69
|
+
}
|
|
70
|
+
document.addEventListener("pointerdown", outside, true);
|
|
71
|
+
return function() {
|
|
72
|
+
document.removeEventListener("pointerdown", outside, true);
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
[open, mounted]
|
|
76
|
+
);
|
|
77
|
+
const child = React.Children.only(props.trigger);
|
|
78
|
+
const panel = open && mounted ? createPortal(
|
|
79
|
+
/* @__PURE__ */ React.createElement(
|
|
80
|
+
"div",
|
|
81
|
+
{
|
|
82
|
+
ref: popMerged,
|
|
83
|
+
id,
|
|
84
|
+
role: "dialog",
|
|
85
|
+
"aria-modal": false,
|
|
86
|
+
"aria-label": props.title ? void 0 : props.label,
|
|
87
|
+
"aria-labelledby": props.title ? id + "-title" : void 0,
|
|
88
|
+
tabIndex: -1,
|
|
89
|
+
className: cx("aura-popover", pos[0] && "is-" + pos[0].side, props.className),
|
|
90
|
+
style: Object.assign(
|
|
91
|
+
{ top: pos[0] ? pos[0].top : -9999, left: pos[0] ? pos[0].left : -9999 },
|
|
92
|
+
props.width ? { width: props.width } : null
|
|
93
|
+
),
|
|
94
|
+
onKeyDown: function(e) {
|
|
95
|
+
if (e.key === "Escape") {
|
|
96
|
+
e.stopPropagation();
|
|
97
|
+
close(true);
|
|
98
|
+
} else trapTab(e, pop.current);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
props.title ? /* @__PURE__ */ React.createElement("div", { className: "aura-popover__head" }, /* @__PURE__ */ React.createElement("p", { className: "aura-popover__title", id: id + "-title" }, props.title), /* @__PURE__ */ React.createElement(
|
|
102
|
+
IconButton,
|
|
103
|
+
{
|
|
104
|
+
icon: "x",
|
|
105
|
+
label: t.close,
|
|
106
|
+
onClick: function() {
|
|
107
|
+
close(true);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
)) : null,
|
|
111
|
+
/* @__PURE__ */ React.createElement("div", { className: "aura-popover__body" }, typeof props.children === "function" ? props.children({
|
|
112
|
+
close: function() {
|
|
113
|
+
close(true);
|
|
114
|
+
}
|
|
115
|
+
}) : props.children)
|
|
116
|
+
),
|
|
117
|
+
document.body
|
|
118
|
+
) : null;
|
|
119
|
+
return /* @__PURE__ */ React.createElement("span", { ref: wrap, className: "aura-popover-anchor" }, React.cloneElement(child, {
|
|
120
|
+
onClick: function(e) {
|
|
121
|
+
if (child.props.onClick) child.props.onClick(e);
|
|
122
|
+
st[1](!open);
|
|
123
|
+
},
|
|
124
|
+
"aria-haspopup": "dialog",
|
|
125
|
+
"aria-expanded": open,
|
|
126
|
+
"aria-controls": open ? id : void 0
|
|
127
|
+
}), panel);
|
|
128
|
+
});
|
|
129
|
+
export {
|
|
130
|
+
Popover
|
|
131
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cx, tone, uid } from "./internal.js";
|
|
4
|
+
const Progress = React.forwardRef(function Progress2(props, ref) {
|
|
5
|
+
const auto = uid(), id = props.id || auto;
|
|
6
|
+
const max = props.max || 100, det = props.value != null;
|
|
7
|
+
const pct = det ? Math.max(0, Math.min(100, props.value / max * 100)) : 0;
|
|
8
|
+
const shown = props.valueLabel != null ? props.valueLabel : det ? Math.round(pct) + "%" : null;
|
|
9
|
+
return /* @__PURE__ */ React.createElement(
|
|
10
|
+
"div",
|
|
11
|
+
{
|
|
12
|
+
ref,
|
|
13
|
+
className: cx(
|
|
14
|
+
"aura-progress",
|
|
15
|
+
"aura-progress--" + tone(props.tone || "accent"),
|
|
16
|
+
props.size === "sm" && "is-sm",
|
|
17
|
+
props.className
|
|
18
|
+
)
|
|
19
|
+
},
|
|
20
|
+
props.label || props.showValue && shown ? /* @__PURE__ */ React.createElement("div", { className: "aura-progress__head" }, props.label ? /* @__PURE__ */ React.createElement("span", { className: "aura-progress__label", id: id + "-label" }, props.label) : /* @__PURE__ */ React.createElement("span", null), props.showValue && shown ? /* @__PURE__ */ React.createElement("span", { className: "aura-progress__value" }, shown) : null) : null,
|
|
21
|
+
/* @__PURE__ */ React.createElement(
|
|
22
|
+
"div",
|
|
23
|
+
{
|
|
24
|
+
className: cx("aura-progress__track", !det && "is-indeterminate"),
|
|
25
|
+
role: "progressbar",
|
|
26
|
+
"aria-labelledby": props.label ? id + "-label" : void 0,
|
|
27
|
+
"aria-label": props.label ? void 0 : props["aria-label"],
|
|
28
|
+
"aria-valuemin": det ? 0 : void 0,
|
|
29
|
+
"aria-valuemax": det ? max : void 0,
|
|
30
|
+
"aria-valuenow": det ? props.value : void 0,
|
|
31
|
+
"aria-valuetext": det && props.valueLabel != null ? String(props.valueLabel) : void 0
|
|
32
|
+
},
|
|
33
|
+
/* @__PURE__ */ React.createElement("span", { className: "aura-progress__bar", style: det ? { width: pct + "%" } : void 0 })
|
|
34
|
+
),
|
|
35
|
+
props.hint ? /* @__PURE__ */ React.createElement("p", { className: "aura-progress__hint" }, props.hint) : null
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
export {
|
|
39
|
+
Progress
|
|
40
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { describedBy } from "./Field.js";
|
|
4
|
+
import { Icon } from "./Icon.js";
|
|
5
|
+
import { cx, uid, useMaybeControlled } from "./internal.js";
|
|
6
|
+
const RadioGroup = React.forwardRef(function RadioGroup2(props, ref) {
|
|
7
|
+
const auto = uid(), id = props.id || auto;
|
|
8
|
+
const st = useMaybeControlled(
|
|
9
|
+
props.value,
|
|
10
|
+
props.defaultValue,
|
|
11
|
+
props.onChange
|
|
12
|
+
);
|
|
13
|
+
const name = props.name || id;
|
|
14
|
+
return /* @__PURE__ */ React.createElement(
|
|
15
|
+
"fieldset",
|
|
16
|
+
{
|
|
17
|
+
ref,
|
|
18
|
+
className: cx("aura-field aura-radio-group", props.error && "is-invalid", props.className),
|
|
19
|
+
"aria-describedby": describedBy(id, props),
|
|
20
|
+
"aria-invalid": props.error ? true : void 0,
|
|
21
|
+
disabled: props.disabled
|
|
22
|
+
},
|
|
23
|
+
props.label ? /* @__PURE__ */ React.createElement("legend", { className: "aura-field__label" }, props.label, props.required ? /* @__PURE__ */ React.createElement("span", { className: "aura-field__req", "aria-hidden": true }, " *") : null) : null,
|
|
24
|
+
/* @__PURE__ */ React.createElement("div", { className: cx("aura-radio-group__list", props.orientation === "horizontal" && "is-horizontal") }, (props.options || []).map(function(o) {
|
|
25
|
+
const v = typeof o === "object" ? o : { value: o, label: o };
|
|
26
|
+
return /* @__PURE__ */ React.createElement("label", { key: v.value, className: cx("aura-choice", v.disabled && "is-disabled") }, /* @__PURE__ */ React.createElement(
|
|
27
|
+
"input",
|
|
28
|
+
{
|
|
29
|
+
type: "radio",
|
|
30
|
+
className: "aura-radio",
|
|
31
|
+
name,
|
|
32
|
+
value: v.value,
|
|
33
|
+
disabled: v.disabled,
|
|
34
|
+
checked: st[0] === v.value,
|
|
35
|
+
onChange: function() {
|
|
36
|
+
st[1](v.value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
), /* @__PURE__ */ React.createElement("span", { className: "aura-choice__text" }, /* @__PURE__ */ React.createElement("span", { className: "aura-choice__label" }, v.label), v.description ? /* @__PURE__ */ React.createElement("span", { className: "aura-choice__desc" }, v.description) : null));
|
|
40
|
+
})),
|
|
41
|
+
props.error ? /* @__PURE__ */ React.createElement("p", { className: "aura-field__error", id: id + "-error" }, /* @__PURE__ */ React.createElement(Icon, { name: "circle-alert", size: 14 }), props.error) : props.hint ? /* @__PURE__ */ React.createElement("p", { className: "aura-field__hint", id: id + "-hint" }, props.hint) : null
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
export {
|
|
45
|
+
RadioGroup
|
|
46
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { cx, uid, useMaybeControlled } from "./internal.js";
|
|
5
|
+
function toOpt(o) {
|
|
6
|
+
return typeof o === "object" ? o : { value: o, label: o };
|
|
7
|
+
}
|
|
8
|
+
const SegmentedControl = React.forwardRef(
|
|
9
|
+
function SegmentedControl2(props, ref) {
|
|
10
|
+
const options = (props.options || []).map(toOpt);
|
|
11
|
+
const firstEnabled = options.filter(function(o) {
|
|
12
|
+
return !o.disabled;
|
|
13
|
+
})[0];
|
|
14
|
+
const st = useMaybeControlled(
|
|
15
|
+
props.value,
|
|
16
|
+
props.defaultValue != null ? props.defaultValue : firstEnabled ? firstEnabled.value : void 0,
|
|
17
|
+
props.onChange
|
|
18
|
+
);
|
|
19
|
+
const value = st[0], setValue = st[1];
|
|
20
|
+
const auto = uid(), id = props.id || auto;
|
|
21
|
+
const refs = React.useRef([]);
|
|
22
|
+
const selIdx = options.findIndex(function(o) {
|
|
23
|
+
return o.value === value;
|
|
24
|
+
});
|
|
25
|
+
const tabIdx = selIdx >= 0 && !options[selIdx].disabled ? selIdx : options.indexOf(firstEnabled);
|
|
26
|
+
function move(from, dir) {
|
|
27
|
+
const n = options.length;
|
|
28
|
+
for (let k = 1; k <= n; k++) {
|
|
29
|
+
const i = ((from + dir * k) % n + n) % n;
|
|
30
|
+
if (!options[i].disabled) {
|
|
31
|
+
setValue(options[i].value);
|
|
32
|
+
const el = refs.current[i];
|
|
33
|
+
if (el) el.focus();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function onKeyDown(e, i) {
|
|
39
|
+
const k = e.key;
|
|
40
|
+
if (k === "ArrowRight" || k === "ArrowDown") {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
move(i, 1);
|
|
43
|
+
} else if (k === "ArrowLeft" || k === "ArrowUp") {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
move(i, -1);
|
|
46
|
+
} else if (k === "Home") {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
move(-1, 1);
|
|
49
|
+
} else if (k === "End") {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
move(options.length, -1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return /* @__PURE__ */ React.createElement(
|
|
55
|
+
"div",
|
|
56
|
+
{
|
|
57
|
+
ref,
|
|
58
|
+
id,
|
|
59
|
+
role: "radiogroup",
|
|
60
|
+
"aria-label": props.label,
|
|
61
|
+
"aria-disabled": props.disabled || void 0,
|
|
62
|
+
className: cx(
|
|
63
|
+
"aura-segmented",
|
|
64
|
+
props.size === "sm" && "aura-segmented--sm",
|
|
65
|
+
props.fullWidth && "is-full",
|
|
66
|
+
props.disabled && "is-disabled",
|
|
67
|
+
props.className
|
|
68
|
+
)
|
|
69
|
+
},
|
|
70
|
+
options.map(function(o, i) {
|
|
71
|
+
const on = o.value === value;
|
|
72
|
+
const off = props.disabled || o.disabled;
|
|
73
|
+
return /* @__PURE__ */ React.createElement(
|
|
74
|
+
"button",
|
|
75
|
+
{
|
|
76
|
+
key: o.value,
|
|
77
|
+
ref: function(el) {
|
|
78
|
+
refs.current[i] = el;
|
|
79
|
+
},
|
|
80
|
+
type: "button",
|
|
81
|
+
role: "radio",
|
|
82
|
+
"aria-checked": on,
|
|
83
|
+
"aria-label": o.iconOnly ? o.label : void 0,
|
|
84
|
+
title: o.iconOnly ? o.label : void 0,
|
|
85
|
+
tabIndex: i === tabIdx && !props.disabled ? 0 : -1,
|
|
86
|
+
disabled: off,
|
|
87
|
+
className: cx("aura-segmented__option", on && "is-selected", o.iconOnly && "is-icon"),
|
|
88
|
+
onClick: function() {
|
|
89
|
+
setValue(o.value);
|
|
90
|
+
},
|
|
91
|
+
onKeyDown: function(e) {
|
|
92
|
+
onKeyDown(e, i);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
o.icon ? /* @__PURE__ */ React.createElement(Icon, { name: o.icon }) : null,
|
|
96
|
+
o.iconOnly ? null : /* @__PURE__ */ React.createElement("span", null, o.label)
|
|
97
|
+
);
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
export {
|
|
103
|
+
SegmentedControl
|
|
104
|
+
};
|