@jirawatpyk/aura-react 4.5.0 → 4.6.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 +19 -4
- package/dist/aura.bundle.js +2644 -2043
- package/dist/cjs/index.cjs +2642 -2043
- package/dist/esm/Button.js +9 -9
- package/dist/esm/Checkbox.js +41 -33
- package/dist/esm/Combobox.js +143 -125
- package/dist/esm/DataTable.js +629 -495
- package/dist/esm/DatePicker.js +378 -305
- package/dist/esm/Dialog.js +48 -59
- package/dist/esm/DropdownMenu.js +9 -12
- package/dist/esm/FileUpload.js +91 -73
- package/dist/esm/Icon.js +27 -22
- package/dist/esm/IconButton.js +13 -9
- package/dist/esm/Menu.js +78 -66
- package/dist/esm/Stat.js +9 -26
- package/dist/esm/StatusPill.js +12 -13
- package/dist/esm/Surface.js +17 -13
- package/dist/esm/ThemeStyle.js +9 -5
- package/dist/esm/TimePicker.js +155 -127
- package/dist/esm/colorScheme.js +106 -0
- package/dist/esm/extra.js +270 -186
- package/dist/esm/feedback.js +112 -84
- package/dist/esm/forms.js +144 -113
- package/dist/esm/index.js +5 -0
- package/dist/esm/internal.js +33 -23
- package/dist/esm/layout.js +113 -128
- package/dist/esm/layout2.js +67 -45
- package/dist/esm/locale.js +23 -9
- package/dist/esm/overlay.js +21 -18
- package/dist/esm/theme.js +103 -50
- package/dist/index.d.ts +37 -7
- package/package.json +6 -3
package/dist/esm/extra.js
CHANGED
|
@@ -1,69 +1,95 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
cx,
|
|
6
|
+
omit,
|
|
7
|
+
uid,
|
|
8
|
+
useMaybeControlled,
|
|
9
|
+
useMergedRef,
|
|
10
|
+
useMounted,
|
|
11
|
+
useIsoLayoutEffect,
|
|
12
|
+
trapTab,
|
|
13
|
+
FOCUSABLE
|
|
14
|
+
} from "./internal.js";
|
|
5
15
|
import { useStrings } from "./locale.js";
|
|
6
16
|
import { Icon } from "./Icon.js";
|
|
7
17
|
import { IconButton } from "./IconButton.js";
|
|
8
|
-
const
|
|
9
|
-
var TONES = ["neutral", "accent", "success", "warning", "danger"];
|
|
18
|
+
const TONES = ["neutral", "accent", "success", "warning", "danger"];
|
|
10
19
|
function tone(t) {
|
|
11
20
|
return TONES.indexOf(t) >= 0 ? t : "neutral";
|
|
12
21
|
}
|
|
13
22
|
const Badge = React.forwardRef(function Badge2(props, ref) {
|
|
14
|
-
|
|
15
|
-
return
|
|
23
|
+
const rest = omit(props, ["tone", "variant", "icon", "className", "children"]);
|
|
24
|
+
return /* @__PURE__ */ React.createElement(
|
|
16
25
|
"span",
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
{
|
|
27
|
+
...rest,
|
|
28
|
+
ref,
|
|
29
|
+
className: cx(
|
|
30
|
+
"aura-badge",
|
|
31
|
+
"aura-badge--" + tone(props.tone),
|
|
32
|
+
props.variant === "solid" && "is-solid",
|
|
33
|
+
props.variant === "outline" && "is-outline",
|
|
34
|
+
props.className
|
|
35
|
+
)
|
|
36
|
+
},
|
|
37
|
+
props.icon ? /* @__PURE__ */ React.createElement(Icon, { name: props.icon, size: 12 }) : null,
|
|
19
38
|
props.children
|
|
20
39
|
);
|
|
21
40
|
});
|
|
22
41
|
const Tag = React.forwardRef(function Tag2(props, ref) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
const t = useStrings();
|
|
43
|
+
const selectable = props.onClick != null || props.selected != null;
|
|
44
|
+
const rest = omit(props, ["onRemove", "selected", "icon", "className", "children", "disabled", "removeLabel"]);
|
|
45
|
+
const inner = [
|
|
46
|
+
props.icon ? /* @__PURE__ */ React.createElement(Icon, { key: "i", name: props.icon, size: 14 }) : null,
|
|
47
|
+
/* @__PURE__ */ React.createElement("span", { key: "t", className: "aura-tag__text" }, props.children)
|
|
48
|
+
];
|
|
27
49
|
if (selectable) {
|
|
28
|
-
return
|
|
50
|
+
return /* @__PURE__ */ React.createElement(
|
|
29
51
|
"button",
|
|
30
|
-
|
|
52
|
+
{
|
|
53
|
+
...rest,
|
|
31
54
|
ref,
|
|
32
55
|
type: "button",
|
|
33
56
|
"aria-pressed": !!props.selected,
|
|
34
57
|
disabled: props.disabled,
|
|
35
58
|
className: cx("aura-tag is-selectable", props.selected && "is-selected", props.className)
|
|
36
|
-
}
|
|
37
|
-
props.selected ?
|
|
59
|
+
},
|
|
60
|
+
props.selected ? /* @__PURE__ */ React.createElement(Icon, { name: "check", size: 14 }) : inner[0],
|
|
38
61
|
inner[1]
|
|
39
62
|
);
|
|
40
63
|
}
|
|
41
|
-
return
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
);
|
|
64
|
+
return /* @__PURE__ */ React.createElement("span", { ...rest, ref, className: cx("aura-tag", props.disabled && "is-disabled", props.className) }, inner, props.onRemove && !props.disabled ? /* @__PURE__ */ React.createElement(
|
|
65
|
+
"button",
|
|
66
|
+
{
|
|
67
|
+
type: "button",
|
|
68
|
+
className: "aura-tag__remove",
|
|
69
|
+
"aria-label": props.removeLabel || t.remove(typeof props.children === "string" ? props.children : ""),
|
|
70
|
+
onClick: props.onRemove
|
|
71
|
+
},
|
|
72
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "x", size: 12 })
|
|
73
|
+
) : null);
|
|
51
74
|
});
|
|
52
75
|
const Progress = React.forwardRef(function Progress2(props, ref) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return
|
|
76
|
+
const auto = uid(), id = props.id || auto;
|
|
77
|
+
const max = props.max || 100, det = props.value != null;
|
|
78
|
+
const pct = det ? Math.max(0, Math.min(100, props.value / max * 100)) : 0;
|
|
79
|
+
const shown = props.valueLabel != null ? props.valueLabel : det ? Math.round(pct) + "%" : null;
|
|
80
|
+
return /* @__PURE__ */ React.createElement(
|
|
58
81
|
"div",
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
{
|
|
83
|
+
ref,
|
|
84
|
+
className: cx(
|
|
85
|
+
"aura-progress",
|
|
86
|
+
"aura-progress--" + tone(props.tone || "accent"),
|
|
87
|
+
props.size === "sm" && "is-sm",
|
|
88
|
+
props.className
|
|
89
|
+
)
|
|
90
|
+
},
|
|
91
|
+
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,
|
|
92
|
+
/* @__PURE__ */ React.createElement(
|
|
67
93
|
"div",
|
|
68
94
|
{
|
|
69
95
|
className: cx("aura-progress__track", !det && "is-indeterminate"),
|
|
@@ -75,37 +101,50 @@ const Progress = React.forwardRef(function Progress2(props, ref) {
|
|
|
75
101
|
"aria-valuenow": det ? props.value : void 0,
|
|
76
102
|
"aria-valuetext": det && props.valueLabel != null ? String(props.valueLabel) : void 0
|
|
77
103
|
},
|
|
78
|
-
|
|
104
|
+
/* @__PURE__ */ React.createElement("span", { className: "aura-progress__bar", style: det ? { width: pct + "%" } : void 0 })
|
|
79
105
|
),
|
|
80
|
-
props.hint ?
|
|
106
|
+
props.hint ? /* @__PURE__ */ React.createElement("p", { className: "aura-progress__hint" }, props.hint) : null
|
|
81
107
|
);
|
|
82
108
|
});
|
|
83
109
|
const Skeleton = React.forwardRef(function Skeleton2(props, ref) {
|
|
84
|
-
|
|
110
|
+
const v = props.variant || "text";
|
|
85
111
|
if (v === "text" && (props.lines || 1) > 1) {
|
|
86
|
-
|
|
87
|
-
for (
|
|
88
|
-
|
|
112
|
+
const n = props.lines, rows = [];
|
|
113
|
+
for (let i = 0; i < n; i++)
|
|
114
|
+
rows.push(/* @__PURE__ */ React.createElement("span", { key: i, className: "aura-skel aura-skel--text", style: { width: i === n - 1 ? "60%" : "100%" } }));
|
|
115
|
+
return /* @__PURE__ */ React.createElement(
|
|
116
|
+
"span",
|
|
117
|
+
{
|
|
118
|
+
ref,
|
|
119
|
+
className: cx("aura-skel-lines", props.className),
|
|
120
|
+
"aria-hidden": true,
|
|
121
|
+
style: props.width ? { width: props.width } : void 0
|
|
122
|
+
},
|
|
123
|
+
rows
|
|
124
|
+
);
|
|
89
125
|
}
|
|
90
|
-
|
|
126
|
+
const style = { width: props.width, height: props.height };
|
|
91
127
|
if (v === "circle") {
|
|
92
128
|
style.width = style.height = props.size || props.width || 40;
|
|
93
129
|
}
|
|
94
|
-
return
|
|
130
|
+
return /* @__PURE__ */ React.createElement("span", { ref, "aria-hidden": true, className: cx("aura-skel", "aura-skel--" + v, props.className), style });
|
|
95
131
|
});
|
|
96
132
|
const EmptyState = React.forwardRef(function EmptyState2(props, ref) {
|
|
97
|
-
|
|
98
|
-
return
|
|
133
|
+
const HT = "h" + (props.headingLevel || 3);
|
|
134
|
+
return /* @__PURE__ */ React.createElement(
|
|
99
135
|
"div",
|
|
100
|
-
{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
136
|
+
{
|
|
137
|
+
ref,
|
|
138
|
+
className: cx("aura-empty", props.size === "sm" && "is-sm", props.bordered && "is-bordered", props.className)
|
|
139
|
+
},
|
|
140
|
+
/* @__PURE__ */ React.createElement("span", { className: "aura-empty__icon", "aria-hidden": true }, /* @__PURE__ */ React.createElement(Icon, { name: props.icon || "inbox", size: props.size === "sm" ? "md" : "lg" })),
|
|
141
|
+
/* @__PURE__ */ React.createElement(HT, { className: "aura-empty__title" }, props.title),
|
|
142
|
+
props.description ? /* @__PURE__ */ React.createElement("p", { className: "aura-empty__text" }, props.description) : null,
|
|
143
|
+
props.action ? /* @__PURE__ */ React.createElement("div", { className: "aura-empty__action" }, props.action) : null
|
|
105
144
|
);
|
|
106
145
|
});
|
|
107
146
|
function pageList(page, count, sib) {
|
|
108
|
-
|
|
147
|
+
let out = [], lo = Math.max(2, page - sib), hi = Math.min(count - 1, page + sib);
|
|
109
148
|
if (page - sib <= 3) {
|
|
110
149
|
lo = 2;
|
|
111
150
|
hi = Math.min(count - 1, Math.max(hi, 3 + 2 * sib));
|
|
@@ -117,64 +156,107 @@ function pageList(page, count, sib) {
|
|
|
117
156
|
out.push(1);
|
|
118
157
|
if (lo === 3) out.push(2);
|
|
119
158
|
else if (lo > 3) out.push("\u2026a");
|
|
120
|
-
for (
|
|
159
|
+
for (let i = lo; i <= hi; i++) out.push(i);
|
|
121
160
|
if (hi === count - 2) out.push(count - 1);
|
|
122
161
|
else if (hi < count - 2) out.push("\u2026b");
|
|
123
162
|
if (count > 1) out.push(count);
|
|
124
163
|
return out;
|
|
125
164
|
}
|
|
126
165
|
const Pagination = React.forwardRef(function Pagination2(props, ref) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
166
|
+
const t = useStrings();
|
|
167
|
+
const count = Math.max(1, props.pageCount || 1);
|
|
168
|
+
const st = useMaybeControlled(props.page, props.defaultPage || 1, props.onChange);
|
|
169
|
+
const page = Math.min(count, Math.max(1, st[0]));
|
|
131
170
|
function go(p) {
|
|
132
171
|
if (p >= 1 && p <= count && p !== page) st[1](p);
|
|
133
172
|
}
|
|
134
|
-
|
|
173
|
+
const link = props.getHref;
|
|
135
174
|
function item(p, label, extra) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
175
|
+
const common = Object.assign(
|
|
176
|
+
{
|
|
177
|
+
className: cx("aura-page", p === page && "is-current"),
|
|
178
|
+
"aria-current": p === page ? "page" : void 0,
|
|
179
|
+
"aria-label": t.pageN(p)
|
|
180
|
+
},
|
|
181
|
+
extra
|
|
182
|
+
);
|
|
183
|
+
return link ? /* @__PURE__ */ React.createElement(
|
|
184
|
+
"a",
|
|
185
|
+
{
|
|
186
|
+
href: link(p),
|
|
187
|
+
onClick: function(e) {
|
|
188
|
+
if (props.onChange) {
|
|
189
|
+
e.preventDefault();
|
|
190
|
+
go(p);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
...common
|
|
194
|
+
},
|
|
195
|
+
label
|
|
196
|
+
) : /* @__PURE__ */ React.createElement(
|
|
197
|
+
"button",
|
|
198
|
+
{
|
|
199
|
+
type: "button",
|
|
200
|
+
onClick: function() {
|
|
201
|
+
go(p);
|
|
202
|
+
},
|
|
203
|
+
...common
|
|
204
|
+
},
|
|
205
|
+
label
|
|
206
|
+
);
|
|
145
207
|
}
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
{
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
208
|
+
return /* @__PURE__ */ React.createElement("nav", { ref, className: cx("aura-pagination", props.className), "aria-label": props.label || t.pagination }, /* @__PURE__ */ React.createElement(
|
|
209
|
+
IconButton,
|
|
210
|
+
{
|
|
211
|
+
icon: "chevron-left",
|
|
212
|
+
label: t.prevPage,
|
|
213
|
+
disabled: page <= 1,
|
|
214
|
+
onClick: function() {
|
|
215
|
+
go(page - 1);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
), /* @__PURE__ */ React.createElement("ol", { className: "aura-pagination__list" }, pageList(page, count, props.siblingCount == null ? 1 : props.siblingCount).map(function(p) {
|
|
219
|
+
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");
|
|
220
|
+
})), /* @__PURE__ */ React.createElement("span", { className: "aura-pagination__compact", "aria-hidden": true }, t.page(page, count)), /* @__PURE__ */ React.createElement(
|
|
221
|
+
IconButton,
|
|
222
|
+
{
|
|
223
|
+
icon: "chevron-right",
|
|
224
|
+
label: t.nextPage,
|
|
225
|
+
disabled: page >= count,
|
|
226
|
+
onClick: function() {
|
|
227
|
+
go(page + 1);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
));
|
|
160
231
|
});
|
|
161
232
|
const Accordion = React.forwardRef(function Accordion2(props, ref) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
233
|
+
const auto = uid(), base = props.id || auto;
|
|
234
|
+
const multiple = props.type === "multiple";
|
|
235
|
+
const st = useMaybeControlled(
|
|
236
|
+
props.value,
|
|
237
|
+
props.defaultValue != null ? props.defaultValue : multiple ? [] : null,
|
|
238
|
+
props.onChange
|
|
239
|
+
);
|
|
240
|
+
const open = multiple ? st[0] || [] : st[0] ? [st[0]] : [];
|
|
241
|
+
const HT = "h" + (props.headingLevel || 3);
|
|
242
|
+
const items = props.items || [];
|
|
168
243
|
function toggle(id) {
|
|
169
|
-
|
|
170
|
-
if (multiple)
|
|
171
|
-
|
|
172
|
-
|
|
244
|
+
const isOpen = open.indexOf(id) >= 0;
|
|
245
|
+
if (multiple)
|
|
246
|
+
st[1](
|
|
247
|
+
isOpen ? open.filter(function(x) {
|
|
248
|
+
return x !== id;
|
|
249
|
+
}) : open.concat([id])
|
|
250
|
+
);
|
|
173
251
|
else st[1](isOpen ? props.collapsible === false ? id : null : id);
|
|
174
252
|
}
|
|
175
253
|
function onKey(e) {
|
|
176
|
-
|
|
177
|
-
|
|
254
|
+
const btns = Array.prototype.slice.call(
|
|
255
|
+
e.currentTarget.querySelectorAll(
|
|
256
|
+
":scope > .aura-accordion__item > .aura-accordion__heading > button:not([disabled])"
|
|
257
|
+
)
|
|
258
|
+
);
|
|
259
|
+
let i = btns.indexOf(document.activeElement), k = e.key, n = null;
|
|
178
260
|
if (i < 0) return;
|
|
179
261
|
if (k === "ArrowDown") n = btns[(i + 1) % btns.length];
|
|
180
262
|
else if (k === "ArrowUp") n = btns[(i - 1 + btns.length) % btns.length];
|
|
@@ -185,95 +267,90 @@ const Accordion = React.forwardRef(function Accordion2(props, ref) {
|
|
|
185
267
|
n.focus();
|
|
186
268
|
}
|
|
187
269
|
}
|
|
188
|
-
return
|
|
189
|
-
"
|
|
190
|
-
{
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
{ className: "aura-accordion__title" },
|
|
208
|
-
it.title,
|
|
209
|
-
it.description ? h("span", { className: "aura-accordion__desc" }, it.description) : null
|
|
210
|
-
),
|
|
211
|
-
h(Icon, { name: "chevron-down", className: "aura-accordion__chevron" })
|
|
212
|
-
)
|
|
213
|
-
),
|
|
214
|
-
h("div", { id: pid, role: "region", "aria-labelledby": bid, className: "aura-accordion__panel", hidden: !on }, it.content)
|
|
215
|
-
);
|
|
216
|
-
})
|
|
217
|
-
);
|
|
270
|
+
return /* @__PURE__ */ React.createElement("div", { ref, className: cx("aura-accordion", props.className), onKeyDown: onKey }, items.map(function(it) {
|
|
271
|
+
const on = open.indexOf(it.id) >= 0, bid = base + "-btn-" + it.id, pid = base + "-panel-" + it.id;
|
|
272
|
+
return /* @__PURE__ */ React.createElement("div", { key: it.id, className: cx("aura-accordion__item", on && "is-open") }, /* @__PURE__ */ React.createElement(HT, { className: "aura-accordion__heading" }, /* @__PURE__ */ React.createElement(
|
|
273
|
+
"button",
|
|
274
|
+
{
|
|
275
|
+
type: "button",
|
|
276
|
+
id: bid,
|
|
277
|
+
"aria-expanded": on,
|
|
278
|
+
"aria-controls": pid,
|
|
279
|
+
disabled: it.disabled,
|
|
280
|
+
onClick: function() {
|
|
281
|
+
toggle(it.id);
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
it.icon ? /* @__PURE__ */ React.createElement(Icon, { name: it.icon, className: "aura-accordion__lead" }) : null,
|
|
285
|
+
/* @__PURE__ */ React.createElement("span", { className: "aura-accordion__title" }, it.title, it.description ? /* @__PURE__ */ React.createElement("span", { className: "aura-accordion__desc" }, it.description) : null),
|
|
286
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "chevron-down", className: "aura-accordion__chevron" })
|
|
287
|
+
)), /* @__PURE__ */ React.createElement("div", { id: pid, role: "region", "aria-labelledby": bid, className: "aura-accordion__panel", hidden: !on }, it.content));
|
|
288
|
+
}));
|
|
218
289
|
});
|
|
219
290
|
function position(anchor, pop, placement) {
|
|
220
|
-
|
|
221
|
-
|
|
291
|
+
const r = anchor.getBoundingClientRect(), pw = pop.offsetWidth, ph = pop.offsetHeight, vw = window.innerWidth, vh = window.innerHeight, gap = 6;
|
|
292
|
+
let side = (placement || "bottom-start").split("-")[0], align = (placement || "bottom-start").split("-")[1] || "start";
|
|
222
293
|
if (side === "bottom" && r.bottom + gap + ph > vh - 8 && r.top - gap - ph > 8) side = "top";
|
|
223
294
|
else if (side === "top" && r.top - gap - ph < 8 && r.bottom + gap + ph < vh - 8) side = "bottom";
|
|
224
|
-
|
|
225
|
-
|
|
295
|
+
const top = side === "top" ? r.top - gap - ph : r.bottom + gap;
|
|
296
|
+
const left = align === "end" ? r.right - pw : align === "center" ? r.left + r.width / 2 - pw / 2 : r.left;
|
|
226
297
|
return { top: Math.max(8, top), left: Math.max(8, Math.min(left, vw - pw - 8)), side };
|
|
227
298
|
}
|
|
228
299
|
const Popover = React.forwardRef(function Popover2(props, ref) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
300
|
+
const t = useStrings();
|
|
301
|
+
const auto = uid(), id = props.id || auto;
|
|
302
|
+
const st = useMaybeControlled(props.open, !!props.defaultOpen, props.onOpenChange);
|
|
303
|
+
const open = !!st[0];
|
|
304
|
+
const wrap = React.useRef(null), pop = React.useRef(null), popMerged = useMergedRef(ref, pop);
|
|
305
|
+
const pos = React.useState(null), mounted = useMounted();
|
|
235
306
|
function trigger() {
|
|
236
307
|
return wrap.current && (wrap.current.querySelector('button, [role="button"], a, input') || wrap.current.firstElementChild);
|
|
237
308
|
}
|
|
238
309
|
function close(restore) {
|
|
239
310
|
st[1](false);
|
|
240
311
|
if (restore) {
|
|
241
|
-
|
|
312
|
+
const tr = trigger();
|
|
242
313
|
if (tr && tr.focus) tr.focus();
|
|
243
314
|
}
|
|
244
315
|
}
|
|
245
|
-
useIsoLayoutEffect(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
316
|
+
useIsoLayoutEffect(
|
|
317
|
+
function() {
|
|
318
|
+
if (!open || !pop.current || !trigger()) return;
|
|
319
|
+
function place() {
|
|
320
|
+
if (pop.current && trigger()) pos[1](position(trigger(), pop.current, props.placement));
|
|
321
|
+
}
|
|
322
|
+
place();
|
|
323
|
+
window.addEventListener("resize", place);
|
|
324
|
+
window.addEventListener("scroll", place, true);
|
|
325
|
+
return function() {
|
|
326
|
+
window.removeEventListener("resize", place);
|
|
327
|
+
window.removeEventListener("scroll", place, true);
|
|
328
|
+
};
|
|
329
|
+
},
|
|
330
|
+
[open, mounted, props.placement]
|
|
331
|
+
);
|
|
332
|
+
React.useEffect(
|
|
333
|
+
function() {
|
|
334
|
+
if (!open || !mounted) return;
|
|
335
|
+
if (props.autoFocus !== false && pop.current) {
|
|
336
|
+
const f = pop.current.querySelector("[data-autofocus]") || pop.current.querySelector(FOCUSABLE);
|
|
337
|
+
(f || pop.current).focus();
|
|
338
|
+
}
|
|
339
|
+
function outside(e) {
|
|
340
|
+
if (pop.current && pop.current.contains(e.target)) return;
|
|
341
|
+
if (wrap.current && wrap.current.contains(e.target)) return;
|
|
342
|
+
close(false);
|
|
343
|
+
}
|
|
344
|
+
document.addEventListener("pointerdown", outside, true);
|
|
345
|
+
return function() {
|
|
346
|
+
document.removeEventListener("pointerdown", outside, true);
|
|
347
|
+
};
|
|
348
|
+
},
|
|
349
|
+
[open, mounted]
|
|
350
|
+
);
|
|
351
|
+
const child = React.Children.only(props.trigger);
|
|
352
|
+
const panel = open && mounted ? createPortal(
|
|
353
|
+
/* @__PURE__ */ React.createElement(
|
|
277
354
|
"div",
|
|
278
355
|
{
|
|
279
356
|
ref: popMerged,
|
|
@@ -284,7 +361,10 @@ const Popover = React.forwardRef(function Popover2(props, ref) {
|
|
|
284
361
|
"aria-labelledby": props.title ? id + "-title" : void 0,
|
|
285
362
|
tabIndex: -1,
|
|
286
363
|
className: cx("aura-popover", pos[0] && "is-" + pos[0].side, props.className),
|
|
287
|
-
style: Object.assign(
|
|
364
|
+
style: Object.assign(
|
|
365
|
+
{ top: pos[0] ? pos[0].top : -9999, left: pos[0] ? pos[0].left : -9999 },
|
|
366
|
+
props.width ? { width: props.width } : null
|
|
367
|
+
),
|
|
288
368
|
onKeyDown: function(e) {
|
|
289
369
|
if (e.key === "Escape") {
|
|
290
370
|
e.stopPropagation();
|
|
@@ -292,29 +372,33 @@ const Popover = React.forwardRef(function Popover2(props, ref) {
|
|
|
292
372
|
} else trapTab(e, pop.current);
|
|
293
373
|
}
|
|
294
374
|
},
|
|
295
|
-
props.title ?
|
|
296
|
-
|
|
297
|
-
{
|
|
298
|
-
|
|
299
|
-
|
|
375
|
+
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(
|
|
376
|
+
IconButton,
|
|
377
|
+
{
|
|
378
|
+
icon: "x",
|
|
379
|
+
label: t.close,
|
|
380
|
+
onClick: function() {
|
|
381
|
+
close(true);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
)) : null,
|
|
385
|
+
/* @__PURE__ */ React.createElement("div", { className: "aura-popover__body" }, typeof props.children === "function" ? props.children({
|
|
386
|
+
close: function() {
|
|
300
387
|
close(true);
|
|
301
|
-
}
|
|
302
|
-
) :
|
|
303
|
-
h("div", { className: "aura-popover__body" }, typeof props.children === "function" ? props.children({ close: function() {
|
|
304
|
-
close(true);
|
|
305
|
-
} }) : props.children)
|
|
388
|
+
}
|
|
389
|
+
}) : props.children)
|
|
306
390
|
),
|
|
307
391
|
document.body
|
|
308
392
|
) : null;
|
|
309
|
-
return
|
|
310
|
-
|
|
311
|
-
{ ref: wrap, className: "aura-popover-anchor" },
|
|
312
|
-
React.cloneElement(child, { onClick: function(e) {
|
|
393
|
+
return /* @__PURE__ */ React.createElement("span", { ref: wrap, className: "aura-popover-anchor" }, React.cloneElement(child, {
|
|
394
|
+
onClick: function(e) {
|
|
313
395
|
if (child.props.onClick) child.props.onClick(e);
|
|
314
396
|
st[1](!open);
|
|
315
|
-
},
|
|
316
|
-
|
|
317
|
-
|
|
397
|
+
},
|
|
398
|
+
"aria-haspopup": "dialog",
|
|
399
|
+
"aria-expanded": open,
|
|
400
|
+
"aria-controls": open ? id : void 0
|
|
401
|
+
}), panel);
|
|
318
402
|
});
|
|
319
403
|
export {
|
|
320
404
|
Accordion,
|