@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.
Files changed (50) hide show
  1. package/README.md +3 -3
  2. package/dist/aura.bundle.js +1075 -595
  3. package/dist/cjs/index.cjs +1074 -594
  4. package/dist/esm/Accordion.js +66 -0
  5. package/dist/esm/Alert.js +31 -0
  6. package/dist/esm/AppShell.js +55 -0
  7. package/dist/esm/Avatar.js +39 -0
  8. package/dist/esm/Badge.js +26 -0
  9. package/dist/esm/Breadcrumb.js +16 -0
  10. package/dist/esm/Card.js +26 -0
  11. package/dist/esm/Combobox.js +311 -236
  12. package/dist/esm/Container.js +18 -0
  13. package/dist/esm/DatePicker.js +1 -1
  14. package/dist/esm/Dialog.js +1 -1
  15. package/dist/esm/EmptyState.js +22 -0
  16. package/dist/esm/Field.js +46 -0
  17. package/dist/esm/FileUpload.js +1 -1
  18. package/dist/esm/Grid.js +21 -0
  19. package/dist/esm/NumberField.js +175 -0
  20. package/dist/esm/Pagination.js +94 -0
  21. package/dist/esm/Popover.js +131 -0
  22. package/dist/esm/Progress.js +40 -0
  23. package/dist/esm/RadioGroup.js +46 -0
  24. package/dist/esm/SegmentedControl.js +104 -0
  25. package/dist/esm/Select.js +48 -0
  26. package/dist/esm/SideNav.js +36 -0
  27. package/dist/esm/Skeleton.js +29 -0
  28. package/dist/esm/Stack.js +20 -0
  29. package/dist/esm/Stepper.js +54 -0
  30. package/dist/esm/Switch.js +30 -0
  31. package/dist/esm/Tabs.js +89 -0
  32. package/dist/esm/Tag.js +42 -0
  33. package/dist/esm/TextField.js +39 -0
  34. package/dist/esm/Textarea.js +38 -0
  35. package/dist/esm/TimePicker.js +1 -1
  36. package/dist/esm/Toaster.js +124 -0
  37. package/dist/esm/Tooltip.js +80 -0
  38. package/dist/esm/index.js +33 -5
  39. package/dist/esm/internal.js +5 -0
  40. package/dist/esm/locale.js +12 -0
  41. package/dist/esm/responsive.js +50 -0
  42. package/dist/index.d.ts +109 -10
  43. package/dist/styles.css +107 -0
  44. package/package.json +1 -1
  45. package/dist/esm/extra.js +0 -412
  46. package/dist/esm/feedback.js +0 -220
  47. package/dist/esm/forms.js +0 -212
  48. package/dist/esm/layout.js +0 -183
  49. package/dist/esm/layout2.js +0 -138
  50. /package/dist/esm/{overlay.js → useModal.js} +0 -0
package/dist/esm/extra.js DELETED
@@ -1,412 +0,0 @@
1
- 'use client';
2
- import * as React from "react";
3
- import { createPortal } from "react-dom";
4
- import {
5
- cx,
6
- omit,
7
- uid,
8
- useMaybeControlled,
9
- useMergedRef,
10
- useMounted,
11
- useIsoLayoutEffect,
12
- trapTab,
13
- FOCUSABLE
14
- } from "./internal.js";
15
- import { useStrings } from "./locale.js";
16
- import { Icon } from "./Icon.js";
17
- import { IconButton } from "./IconButton.js";
18
- const TONES = ["neutral", "accent", "success", "warning", "danger"];
19
- function tone(t) {
20
- return TONES.indexOf(t) >= 0 ? t : "neutral";
21
- }
22
- const Badge = React.forwardRef(function Badge2(props, ref) {
23
- const rest = omit(props, ["tone", "variant", "icon", "className", "children"]);
24
- return /* @__PURE__ */ React.createElement(
25
- "span",
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,
38
- props.children
39
- );
40
- });
41
- const Tag = React.forwardRef(function Tag2(props, ref) {
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
- ];
49
- if (selectable) {
50
- return /* @__PURE__ */ React.createElement(
51
- "button",
52
- {
53
- ...rest,
54
- ref,
55
- type: "button",
56
- "aria-pressed": !!props.selected,
57
- disabled: props.disabled,
58
- className: cx("aura-tag is-selectable", props.selected && "is-selected", props.className)
59
- },
60
- props.selected ? /* @__PURE__ */ React.createElement(Icon, { name: "check", size: 14 }) : inner[0],
61
- inner[1]
62
- );
63
- }
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);
74
- });
75
- const Progress = React.forwardRef(function Progress2(props, ref) {
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(
81
- "div",
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(
93
- "div",
94
- {
95
- className: cx("aura-progress__track", !det && "is-indeterminate"),
96
- role: "progressbar",
97
- "aria-labelledby": props.label ? id + "-label" : void 0,
98
- "aria-label": props.label ? void 0 : props["aria-label"],
99
- "aria-valuemin": det ? 0 : void 0,
100
- "aria-valuemax": det ? max : void 0,
101
- "aria-valuenow": det ? props.value : void 0,
102
- "aria-valuetext": det && props.valueLabel != null ? String(props.valueLabel) : void 0
103
- },
104
- /* @__PURE__ */ React.createElement("span", { className: "aura-progress__bar", style: det ? { width: pct + "%" } : void 0 })
105
- ),
106
- props.hint ? /* @__PURE__ */ React.createElement("p", { className: "aura-progress__hint" }, props.hint) : null
107
- );
108
- });
109
- const Skeleton = React.forwardRef(function Skeleton2(props, ref) {
110
- const v = props.variant || "text";
111
- if (v === "text" && (props.lines || 1) > 1) {
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
- );
125
- }
126
- const style = { width: props.width, height: props.height };
127
- if (v === "circle") {
128
- style.width = style.height = props.size || props.width || 40;
129
- }
130
- return /* @__PURE__ */ React.createElement("span", { ref, "aria-hidden": true, className: cx("aura-skel", "aura-skel--" + v, props.className), style });
131
- });
132
- const EmptyState = React.forwardRef(function EmptyState2(props, ref) {
133
- const HT = "h" + (props.headingLevel || 3);
134
- return /* @__PURE__ */ React.createElement(
135
- "div",
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
144
- );
145
- });
146
- function pageList(page, count, sib) {
147
- let out = [], lo = Math.max(2, page - sib), hi = Math.min(count - 1, page + sib);
148
- if (page - sib <= 3) {
149
- lo = 2;
150
- hi = Math.min(count - 1, Math.max(hi, 3 + 2 * sib));
151
- }
152
- if (page + sib >= count - 2) {
153
- hi = count - 1;
154
- lo = Math.max(2, Math.min(lo, count - 2 - 2 * sib));
155
- }
156
- out.push(1);
157
- if (lo === 3) out.push(2);
158
- else if (lo > 3) out.push("\u2026a");
159
- for (let i = lo; i <= hi; i++) out.push(i);
160
- if (hi === count - 2) out.push(count - 1);
161
- else if (hi < count - 2) out.push("\u2026b");
162
- if (count > 1) out.push(count);
163
- return out;
164
- }
165
- const Pagination = React.forwardRef(function Pagination2(props, ref) {
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]));
170
- function go(p) {
171
- if (p >= 1 && p <= count && p !== page) st[1](p);
172
- }
173
- const link = props.getHref;
174
- function item(p, label, extra) {
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
- );
207
- }
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
- ));
231
- });
232
- const Accordion = React.forwardRef(function Accordion2(props, ref) {
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 || [];
243
- function toggle(id) {
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
- );
251
- else st[1](isOpen ? props.collapsible === false ? id : null : id);
252
- }
253
- function onKey(e) {
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;
260
- if (i < 0) return;
261
- if (k === "ArrowDown") n = btns[(i + 1) % btns.length];
262
- else if (k === "ArrowUp") n = btns[(i - 1 + btns.length) % btns.length];
263
- else if (k === "Home") n = btns[0];
264
- else if (k === "End") n = btns[btns.length - 1];
265
- if (n) {
266
- e.preventDefault();
267
- n.focus();
268
- }
269
- }
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
- }));
289
- });
290
- function position(anchor, pop, placement) {
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";
293
- if (side === "bottom" && r.bottom + gap + ph > vh - 8 && r.top - gap - ph > 8) side = "top";
294
- else if (side === "top" && r.top - gap - ph < 8 && r.bottom + gap + ph < vh - 8) side = "bottom";
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;
297
- return { top: Math.max(8, top), left: Math.max(8, Math.min(left, vw - pw - 8)), side };
298
- }
299
- const Popover = React.forwardRef(function Popover2(props, ref) {
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();
306
- function trigger() {
307
- return wrap.current && (wrap.current.querySelector('button, [role="button"], a, input') || wrap.current.firstElementChild);
308
- }
309
- function close(restore) {
310
- st[1](false);
311
- if (restore) {
312
- const tr = trigger();
313
- if (tr && tr.focus) tr.focus();
314
- }
315
- }
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(
354
- "div",
355
- {
356
- ref: popMerged,
357
- id,
358
- role: "dialog",
359
- "aria-modal": false,
360
- "aria-label": props.title ? void 0 : props.label,
361
- "aria-labelledby": props.title ? id + "-title" : void 0,
362
- tabIndex: -1,
363
- className: cx("aura-popover", pos[0] && "is-" + pos[0].side, props.className),
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
- ),
368
- onKeyDown: function(e) {
369
- if (e.key === "Escape") {
370
- e.stopPropagation();
371
- close(true);
372
- } else trapTab(e, pop.current);
373
- }
374
- },
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() {
387
- close(true);
388
- }
389
- }) : props.children)
390
- ),
391
- document.body
392
- ) : null;
393
- return /* @__PURE__ */ React.createElement("span", { ref: wrap, className: "aura-popover-anchor" }, React.cloneElement(child, {
394
- onClick: function(e) {
395
- if (child.props.onClick) child.props.onClick(e);
396
- st[1](!open);
397
- },
398
- "aria-haspopup": "dialog",
399
- "aria-expanded": open,
400
- "aria-controls": open ? id : void 0
401
- }), panel);
402
- });
403
- export {
404
- Accordion,
405
- Badge,
406
- EmptyState,
407
- Pagination,
408
- Popover,
409
- Progress,
410
- Skeleton,
411
- Tag
412
- };
@@ -1,220 +0,0 @@
1
- 'use client';
2
- import * as React from "react";
3
- import { useStrings } from "./locale.js";
4
- import { createPortal } from "react-dom";
5
- import { cx, uid, useMounted, useIsoLayoutEffect, useMergedRef } from "./internal.js";
6
- import { Icon } from "./Icon.js";
7
- import { IconButton } from "./IconButton.js";
8
- const ALERT_ICON = {
9
- info: "info",
10
- success: "circle-check",
11
- warning: "triangle-alert",
12
- danger: "circle-alert"
13
- };
14
- const Alert = React.forwardRef(function Alert2(props, ref) {
15
- const t = useStrings();
16
- const tone = props.tone || "info";
17
- return /* @__PURE__ */ React.createElement(
18
- "div",
19
- {
20
- ref,
21
- className: cx("aura-alert", "aura-alert--" + tone, props.className),
22
- role: tone === "danger" || tone === "warning" ? "alert" : "status"
23
- },
24
- /* @__PURE__ */ React.createElement(Icon, { name: ALERT_ICON[tone], className: "aura-alert__icon" }),
25
- /* @__PURE__ */ React.createElement("div", { className: "aura-alert__body" }, props.title ? /* @__PURE__ */ React.createElement("p", { className: "aura-alert__title" }, props.title) : null, props.children ? /* @__PURE__ */ React.createElement("div", { className: "aura-alert__text" }, props.children) : null, props.action ? /* @__PURE__ */ React.createElement("div", { className: "aura-alert__action" }, props.action) : null),
26
- props.onDismiss ? /* @__PURE__ */ React.createElement(IconButton, { icon: "x", label: t.dismiss, className: "aura-alert__close", onClick: props.onDismiss }) : null
27
- );
28
- });
29
- const toastState = {
30
- list: [],
31
- subs: [],
32
- n: 0
33
- };
34
- function emitToasts() {
35
- toastState.subs.forEach(function(f) {
36
- f(toastState.list.slice());
37
- });
38
- }
39
- function toast(opts) {
40
- if (typeof opts === "string") opts = { title: opts };
41
- const id = opts.id || "t" + ++toastState.n;
42
- toastState.list = toastState.list.filter(function(t) {
43
- return t.id !== id;
44
- }).concat([Object.assign({ tone: "info" }, opts, { id })]).slice(-3);
45
- emitToasts();
46
- return id;
47
- }
48
- toast.dismiss = function(id) {
49
- toastState.list = toastState.list.filter(function(t) {
50
- return t.id !== id;
51
- });
52
- emitToasts();
53
- };
54
- function ToastItem(props) {
55
- const str = useStrings();
56
- const t = props.toast, timer = React.useRef(null), left = React.useRef(t.duration || 5e3), since = React.useRef(0);
57
- function start() {
58
- if (left.current === Infinity) return;
59
- since.current = Date.now();
60
- timer.current = setTimeout(function() {
61
- toast.dismiss(t.id);
62
- }, left.current);
63
- }
64
- function pause() {
65
- if (timer.current) {
66
- clearTimeout(timer.current);
67
- timer.current = null;
68
- left.current -= Date.now() - since.current;
69
- }
70
- }
71
- React.useEffect(function() {
72
- start();
73
- return pause;
74
- }, []);
75
- return /* @__PURE__ */ React.createElement(
76
- "div",
77
- {
78
- className: cx("aura-toast", "aura-toast--" + t.tone),
79
- role: t.tone === "danger" ? "alert" : "status",
80
- onMouseEnter: pause,
81
- onMouseLeave: start,
82
- onFocus: pause,
83
- onBlur: start
84
- },
85
- /* @__PURE__ */ React.createElement(Icon, { name: ALERT_ICON[t.tone] || "info", className: "aura-toast__icon" }),
86
- /* @__PURE__ */ React.createElement("div", { className: "aura-toast__body" }, /* @__PURE__ */ React.createElement("p", { className: "aura-toast__title" }, t.title), t.description ? /* @__PURE__ */ React.createElement("p", { className: "aura-toast__text" }, t.description) : null),
87
- t.action ? /* @__PURE__ */ React.createElement(
88
- "button",
89
- {
90
- type: "button",
91
- className: "aura-toast__action",
92
- onClick: function() {
93
- t.action.onClick && t.action.onClick();
94
- toast.dismiss(t.id);
95
- }
96
- },
97
- t.action.label
98
- ) : null,
99
- /* @__PURE__ */ React.createElement(
100
- IconButton,
101
- {
102
- icon: "x",
103
- label: str.dismissToast,
104
- className: "aura-toast__close",
105
- onClick: function() {
106
- toast.dismiss(t.id);
107
- }
108
- }
109
- )
110
- );
111
- }
112
- function Toaster(props) {
113
- const t = useStrings();
114
- const mounted = useMounted();
115
- const s = React.useState(toastState.list);
116
- React.useEffect(function() {
117
- toastState.subs.push(s[1]);
118
- return function() {
119
- toastState.subs = toastState.subs.filter(function(f) {
120
- return f !== s[1];
121
- });
122
- };
123
- }, []);
124
- if (!mounted) return null;
125
- return createPortal(
126
- /* @__PURE__ */ React.createElement(
127
- "div",
128
- {
129
- className: cx("aura-toaster", props && props.position === "top" && "is-top"),
130
- role: "region",
131
- "aria-live": "polite",
132
- "aria-label": t.notifications
133
- },
134
- s[0].map(function(t2) {
135
- return /* @__PURE__ */ React.createElement(ToastItem, { key: t2.id, toast: t2 });
136
- })
137
- ),
138
- document.body
139
- );
140
- }
141
- const Tooltip = React.forwardRef(function Tooltip2(props, ref) {
142
- const id = uid(), st = React.useState(false), open = props.open !== void 0 ? props.open : st[0], set = st[1];
143
- const anchor = React.useRef(null), anchorMerged = useMergedRef(ref, anchor), tip = React.useRef(null), timer = React.useRef(void 0);
144
- const pos = React.useState(null);
145
- function show(now) {
146
- clearTimeout(timer.current);
147
- timer.current = setTimeout(
148
- function() {
149
- set(true);
150
- },
151
- now ? 0 : props.delay == null ? 400 : props.delay
152
- );
153
- }
154
- function hide() {
155
- clearTimeout(timer.current);
156
- set(false);
157
- }
158
- useIsoLayoutEffect(
159
- function() {
160
- if (!open || !anchor.current || !tip.current) return;
161
- const r = anchor.current.getBoundingClientRect(), t = tip.current.getBoundingClientRect();
162
- let side = props.side || "top", top = side === "top" ? r.top - t.height - 8 : r.bottom + 8;
163
- if (side === "top" && top < 8) top = r.bottom + 8;
164
- const left = Math.max(8, Math.min(r.left + r.width / 2 - t.width / 2, window.innerWidth - t.width - 8));
165
- pos[1]({ top, left });
166
- },
167
- [open]
168
- );
169
- React.useEffect(
170
- function() {
171
- if (!open) return;
172
- function esc(e) {
173
- if (e.key === "Escape") hide();
174
- }
175
- document.addEventListener("keydown", esc);
176
- return function() {
177
- document.removeEventListener("keydown", esc);
178
- };
179
- },
180
- [open]
181
- );
182
- const child = React.Children.only(props.children);
183
- const trigger = /* @__PURE__ */ React.createElement(
184
- "span",
185
- {
186
- ref: anchorMerged,
187
- className: "aura-tooltip-anchor",
188
- onMouseEnter: function() {
189
- show(false);
190
- },
191
- onMouseLeave: hide,
192
- onFocus: function() {
193
- show(true);
194
- },
195
- onBlur: hide
196
- },
197
- React.cloneElement(child, { "aria-describedby": open ? id : child.props["aria-describedby"] })
198
- );
199
- return /* @__PURE__ */ React.createElement(React.Fragment, null, trigger, open ? createPortal(
200
- /* @__PURE__ */ React.createElement(
201
- "div",
202
- {
203
- ref: tip,
204
- id,
205
- role: "tooltip",
206
- className: "aura-tooltip",
207
- style: { top: pos[0] ? pos[0].top : -9999, left: pos[0] ? pos[0].left : -9999 }
208
- },
209
- props.content
210
- ),
211
- document.body
212
- ) : null);
213
- });
214
- export {
215
- ALERT_ICON,
216
- Alert,
217
- Toaster,
218
- Tooltip,
219
- toast
220
- };