@jirawatpyk/aura-react 4.7.2 → 4.8.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 (45) hide show
  1. package/README.md +1 -1
  2. package/dist/aura.bundle.js +451 -379
  3. package/dist/cjs/index.cjs +451 -379
  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 +1 -1
  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/Pagination.js +94 -0
  20. package/dist/esm/Popover.js +131 -0
  21. package/dist/esm/Progress.js +40 -0
  22. package/dist/esm/RadioGroup.js +46 -0
  23. package/dist/esm/Select.js +48 -0
  24. package/dist/esm/SideNav.js +36 -0
  25. package/dist/esm/Skeleton.js +29 -0
  26. package/dist/esm/Stack.js +20 -0
  27. package/dist/esm/Switch.js +30 -0
  28. package/dist/esm/Tabs.js +89 -0
  29. package/dist/esm/Tag.js +42 -0
  30. package/dist/esm/TextField.js +39 -0
  31. package/dist/esm/Textarea.js +38 -0
  32. package/dist/esm/TimePicker.js +1 -1
  33. package/dist/esm/Toaster.js +124 -0
  34. package/dist/esm/Tooltip.js +80 -0
  35. package/dist/esm/index.js +27 -5
  36. package/dist/esm/internal.js +5 -0
  37. package/dist/esm/responsive.js +50 -0
  38. package/dist/index.d.ts +8 -8
  39. package/package.json +1 -1
  40. package/dist/esm/extra.js +0 -412
  41. package/dist/esm/feedback.js +0 -220
  42. package/dist/esm/forms.js +0 -212
  43. package/dist/esm/layout.js +0 -183
  44. package/dist/esm/layout2.js +0 -138
  45. /package/dist/esm/{overlay.js → useModal.js} +0 -0
@@ -0,0 +1,66 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { Icon } from "./Icon.js";
4
+ import { cx, uid, useMaybeControlled } from "./internal.js";
5
+ const h = React.createElement;
6
+ const Accordion = React.forwardRef(function Accordion2(props, ref) {
7
+ const auto = uid(), base = props.id || auto;
8
+ const multiple = props.type === "multiple";
9
+ const st = useMaybeControlled(
10
+ props.value,
11
+ props.defaultValue != null ? props.defaultValue : multiple ? [] : null,
12
+ props.onChange
13
+ );
14
+ const open = multiple ? st[0] || [] : st[0] ? [st[0]] : [];
15
+ const HT = "h" + (props.headingLevel || 3);
16
+ const items = props.items || [];
17
+ function toggle(id) {
18
+ const isOpen = open.indexOf(id) >= 0;
19
+ if (multiple)
20
+ st[1](
21
+ isOpen ? open.filter(function(x) {
22
+ return x !== id;
23
+ }) : open.concat([id])
24
+ );
25
+ else st[1](isOpen ? props.collapsible === false ? id : null : id);
26
+ }
27
+ function onKey(e) {
28
+ const btns = Array.prototype.slice.call(
29
+ e.currentTarget.querySelectorAll(
30
+ ":scope > .aura-accordion__item > .aura-accordion__heading > button:not([disabled])"
31
+ )
32
+ );
33
+ let i = btns.indexOf(document.activeElement), k = e.key, n = null;
34
+ if (i < 0) return;
35
+ if (k === "ArrowDown") n = btns[(i + 1) % btns.length];
36
+ else if (k === "ArrowUp") n = btns[(i - 1 + btns.length) % btns.length];
37
+ else if (k === "Home") n = btns[0];
38
+ else if (k === "End") n = btns[btns.length - 1];
39
+ if (n) {
40
+ e.preventDefault();
41
+ n.focus();
42
+ }
43
+ }
44
+ return /* @__PURE__ */ React.createElement("div", { ref, className: cx("aura-accordion", props.className), onKeyDown: onKey }, items.map(function(it) {
45
+ const on = open.indexOf(it.id) >= 0, bid = base + "-btn-" + it.id, pid = base + "-panel-" + it.id;
46
+ 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(
47
+ "button",
48
+ {
49
+ type: "button",
50
+ id: bid,
51
+ "aria-expanded": on,
52
+ "aria-controls": pid,
53
+ disabled: it.disabled,
54
+ onClick: function() {
55
+ toggle(it.id);
56
+ }
57
+ },
58
+ it.icon ? /* @__PURE__ */ React.createElement(Icon, { name: it.icon, className: "aura-accordion__lead" }) : null,
59
+ /* @__PURE__ */ React.createElement("span", { className: "aura-accordion__title" }, it.title, it.description ? /* @__PURE__ */ React.createElement("span", { className: "aura-accordion__desc" }, it.description) : null),
60
+ /* @__PURE__ */ React.createElement(Icon, { name: "chevron-down", className: "aura-accordion__chevron" })
61
+ )), /* @__PURE__ */ React.createElement("div", { id: pid, role: "region", "aria-labelledby": bid, className: "aura-accordion__panel", hidden: !on }, it.content));
62
+ }));
63
+ });
64
+ export {
65
+ Accordion
66
+ };
@@ -0,0 +1,31 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { Icon } from "./Icon.js";
4
+ import { IconButton } from "./IconButton.js";
5
+ import { cx } from "./internal.js";
6
+ import { useStrings } from "./locale.js";
7
+ const ALERT_ICON = {
8
+ info: "info",
9
+ success: "circle-check",
10
+ warning: "triangle-alert",
11
+ danger: "circle-alert"
12
+ };
13
+ const Alert = React.forwardRef(function Alert2(props, ref) {
14
+ const t = useStrings();
15
+ const tone = props.tone || "info";
16
+ return /* @__PURE__ */ React.createElement(
17
+ "div",
18
+ {
19
+ ref,
20
+ className: cx("aura-alert", "aura-alert--" + tone, props.className),
21
+ role: tone === "danger" || tone === "warning" ? "alert" : "status"
22
+ },
23
+ /* @__PURE__ */ React.createElement(Icon, { name: ALERT_ICON[tone], className: "aura-alert__icon" }),
24
+ /* @__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),
25
+ props.onDismiss ? /* @__PURE__ */ React.createElement(IconButton, { icon: "x", label: t.dismiss, className: "aura-alert__close", onClick: props.onDismiss }) : null
26
+ );
27
+ });
28
+ export {
29
+ ALERT_ICON,
30
+ Alert
31
+ };
@@ -0,0 +1,55 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { Drawer } from "./Dialog.js";
4
+ import { IconButton } from "./IconButton.js";
5
+ import { cx } from "./internal.js";
6
+ import { useStrings } from "./locale.js";
7
+ import { useBreakpoint } from "./responsive.js";
8
+ const AppShell = React.forwardRef(function AppShell2(props, ref) {
9
+ const t = useStrings();
10
+ const bp = useBreakpoint();
11
+ const compact = bp === "base" || bp === "sm" || bp === "md";
12
+ const st = React.useState(false), open = st[0], setOpen = st[1];
13
+ React.useEffect(
14
+ function() {
15
+ if (!compact) setOpen(false);
16
+ },
17
+ [compact]
18
+ );
19
+ const navEl = props.nav;
20
+ const nav = props.nav && React.isValidElement(props.nav) && compact ? React.cloneElement(navEl, {
21
+ onChange: function(id) {
22
+ if (navEl.props.onChange) navEl.props.onChange(id);
23
+ setOpen(false);
24
+ },
25
+ className: cx(navEl.props.className, "is-in-drawer")
26
+ }) : props.nav;
27
+ return /* @__PURE__ */ React.createElement("div", { ref, className: cx("aura-shell", compact && "is-compact", props.className) }, !compact ? /* @__PURE__ */ React.createElement("div", { className: "aura-shell__nav" }, nav) : null, compact ? /* @__PURE__ */ React.createElement(
28
+ Drawer,
29
+ {
30
+ open,
31
+ onClose: function() {
32
+ setOpen(false);
33
+ },
34
+ side: "left",
35
+ size: "nav",
36
+ "aria-label": props.navLabel || t.navigation,
37
+ dismissible: true
38
+ },
39
+ nav
40
+ ) : null, /* @__PURE__ */ React.createElement("div", { className: "aura-shell__main" }, props.header || compact ? /* @__PURE__ */ React.createElement("header", { className: "aura-shell__bar" }, compact ? /* @__PURE__ */ React.createElement(
41
+ IconButton,
42
+ {
43
+ icon: "menu",
44
+ label: props.menuLabel || t.openNav,
45
+ size: "md",
46
+ onClick: function() {
47
+ setOpen(true);
48
+ },
49
+ "aria-expanded": open
50
+ }
51
+ ) : null, /* @__PURE__ */ React.createElement("div", { className: "aura-shell__bar-content" }, props.header)) : null, /* @__PURE__ */ React.createElement("main", { className: "aura-shell__content", id: props.mainId || "main" }, props.children)));
52
+ });
53
+ export {
54
+ AppShell
55
+ };
@@ -0,0 +1,39 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { cx } from "./internal.js";
4
+ const AVATAR_TONES = ["progress", "ready", "neutral", "warning"];
5
+ function initials(name) {
6
+ const parts = String(name || "?").trim().split(/\s+/);
7
+ return ((parts[0] || "?")[0] + (parts.length > 1 ? parts[parts.length - 1][0] : parts[0][1] || "")).toUpperCase();
8
+ }
9
+ const Avatar = React.forwardRef(function Avatar2(props, ref) {
10
+ const size = props.size || "md", errState = React.useState(false);
11
+ let hash = 0;
12
+ String(props.name || "").split("").forEach(function(ch) {
13
+ hash = hash * 31 + ch.charCodeAt(0) >>> 0;
14
+ });
15
+ const tone = AVATAR_TONES[hash % AVATAR_TONES.length];
16
+ return /* @__PURE__ */ React.createElement(
17
+ "span",
18
+ {
19
+ ref,
20
+ className: cx("aura-avatar", "aura-avatar--" + size, "aura-avatar--" + tone, props.className),
21
+ role: "img",
22
+ "aria-label": props.name + (props.status ? ", " + props.status : "")
23
+ },
24
+ props.src && !errState[0] ? /* @__PURE__ */ React.createElement(
25
+ "img",
26
+ {
27
+ src: props.src,
28
+ alt: "",
29
+ onError: function() {
30
+ errState[1](true);
31
+ }
32
+ }
33
+ ) : /* @__PURE__ */ React.createElement("span", { "aria-hidden": true }, initials(props.name)),
34
+ props.status === "online" ? /* @__PURE__ */ React.createElement("span", { className: "aura-avatar__status", "aria-hidden": true }) : null
35
+ );
36
+ });
37
+ export {
38
+ Avatar
39
+ };
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { Icon } from "./Icon.js";
4
+ import { cx, omit, tone } from "./internal.js";
5
+ const Badge = React.forwardRef(function Badge2(props, ref) {
6
+ const rest = omit(props, ["tone", "variant", "icon", "className", "children"]);
7
+ return /* @__PURE__ */ React.createElement(
8
+ "span",
9
+ {
10
+ ...rest,
11
+ ref,
12
+ className: cx(
13
+ "aura-badge",
14
+ "aura-badge--" + tone(props.tone),
15
+ props.variant === "solid" && "is-solid",
16
+ props.variant === "outline" && "is-outline",
17
+ props.className
18
+ )
19
+ },
20
+ props.icon ? /* @__PURE__ */ React.createElement(Icon, { name: props.icon, size: 12 }) : null,
21
+ props.children
22
+ );
23
+ });
24
+ export {
25
+ Badge
26
+ };
@@ -0,0 +1,16 @@
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 Breadcrumb = React.forwardRef(function Breadcrumb2(props, ref) {
7
+ const t = useStrings();
8
+ const items = props.items || [];
9
+ return /* @__PURE__ */ React.createElement("nav", { ref, "aria-label": props.label || t.breadcrumb, className: cx("aura-crumbs", props.className) }, /* @__PURE__ */ React.createElement("ol", null, items.map(function(it, i) {
10
+ const last = i === items.length - 1;
11
+ return /* @__PURE__ */ React.createElement("li", { key: i }, last ? /* @__PURE__ */ React.createElement("span", { "aria-current": "page", className: "aura-crumbs__current" }, it.label) : it.href ? /* @__PURE__ */ React.createElement("a", { href: it.href, onClick: it.onClick }, it.label) : /* @__PURE__ */ React.createElement("button", { type: "button", onClick: it.onClick }, it.label), last ? null : /* @__PURE__ */ React.createElement(Icon, { name: "chevron-right", size: 12, className: "aura-crumbs__sep" }));
12
+ })));
13
+ });
14
+ export {
15
+ Breadcrumb
16
+ };
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { cx } from "./internal.js";
4
+ const h = React.createElement;
5
+ const Card = React.forwardRef(function Card2(props, ref) {
6
+ const creative = props.variant === "creative";
7
+ return h(
8
+ props.as || "section",
9
+ {
10
+ ref,
11
+ className: cx(
12
+ "aura-card",
13
+ creative && "aura-card--creative",
14
+ props.interactive && "is-interactive",
15
+ props.className
16
+ ),
17
+ "aria-labelledby": props.title && props.titleId ? props.titleId : void 0
18
+ },
19
+ props.title || props.actions ? /* @__PURE__ */ React.createElement("div", { className: "aura-card__head" }, /* @__PURE__ */ React.createElement("div", { className: "aura-card__heading" }, props.title ? h("h" + (props.headingLevel || 3), { className: "aura-card__title", id: props.titleId }, props.title) : null, props.description ? /* @__PURE__ */ React.createElement("p", { className: "aura-card__desc" }, props.description) : null), props.actions ? /* @__PURE__ */ React.createElement("div", { className: "aura-card__actions" }, props.actions) : null) : null,
20
+ props.children ? /* @__PURE__ */ React.createElement("div", { className: "aura-card__body" }, props.children) : null,
21
+ props.footer ? /* @__PURE__ */ React.createElement("div", { className: "aura-card__foot" }, props.footer) : null
22
+ );
23
+ });
24
+ export {
25
+ Card
26
+ };
@@ -4,7 +4,7 @@ import { useStrings } from "./locale.js";
4
4
  import { createPortal } from "react-dom";
5
5
  import { cx, uid, useMaybeControlled, useMounted, useIsoLayoutEffect, useMergedRef } from "./internal.js";
6
6
  import { Icon } from "./Icon.js";
7
- import { Field } from "./forms.js";
7
+ import { Field } from "./Field.js";
8
8
  function norm(s) {
9
9
  return String(s == null ? "" : s).normalize("NFC").toLocaleLowerCase("th");
10
10
  }
@@ -0,0 +1,18 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { cx } from "./internal.js";
4
+ const h = React.createElement;
5
+ const Container = React.forwardRef(function Container2(props, ref) {
6
+ return h(
7
+ props.as || "div",
8
+ {
9
+ ref,
10
+ className: cx("aura-container", props.size === "narrow" && "is-narrow", props.className),
11
+ style: props.style
12
+ },
13
+ props.children
14
+ );
15
+ });
16
+ export {
17
+ Container
18
+ };
@@ -5,7 +5,7 @@ import { createPortal } from "react-dom";
5
5
  import { cx, uid, useMaybeControlled, useMounted, useIsoLayoutEffect, trapTab, useMergedRef } from "./internal.js";
6
6
  import { Icon } from "./Icon.js";
7
7
  import { IconButton } from "./IconButton.js";
8
- import { Field } from "./forms.js";
8
+ import { Field } from "./Field.js";
9
9
  const ERA = /^พ\.ศ\.\s?|\s?(BE|พ\.ศ\.)$/g;
10
10
  const pad = function(n) {
11
11
  return (n < 10 ? "0" : "") + n;
@@ -4,7 +4,7 @@ import { useStrings } from "./locale.js";
4
4
  import { createPortal } from "react-dom";
5
5
  import { cx, uid, useMergedRef } from "./internal.js";
6
6
  import { IconButton } from "./IconButton.js";
7
- import { useModal } from "./overlay.js";
7
+ import { useModal } from "./useModal.js";
8
8
  const Dialog = React.forwardRef(function Dialog2(props, ref) {
9
9
  const t = useStrings();
10
10
  const own = React.useRef(null), merged = useMergedRef(ref, own), titleId = uid(), descId = uid();
@@ -0,0 +1,22 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { Icon } from "./Icon.js";
4
+ import { cx } from "./internal.js";
5
+ const h = React.createElement;
6
+ const EmptyState = React.forwardRef(function EmptyState2(props, ref) {
7
+ const HT = "h" + (props.headingLevel || 3);
8
+ return /* @__PURE__ */ React.createElement(
9
+ "div",
10
+ {
11
+ ref,
12
+ className: cx("aura-empty", props.size === "sm" && "is-sm", props.bordered && "is-bordered", props.className)
13
+ },
14
+ /* @__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" })),
15
+ /* @__PURE__ */ React.createElement(HT, { className: "aura-empty__title" }, props.title),
16
+ props.description ? /* @__PURE__ */ React.createElement("p", { className: "aura-empty__text" }, props.description) : null,
17
+ props.action ? /* @__PURE__ */ React.createElement("div", { className: "aura-empty__action" }, props.action) : null
18
+ );
19
+ });
20
+ export {
21
+ EmptyState
22
+ };
@@ -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
+ };
@@ -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 "./forms.js";
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";
@@ -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,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
+ };