@jirawatpyk/aura-react 4.4.2 → 4.5.1

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/dist/esm/Menu.js CHANGED
@@ -3,44 +3,52 @@ import * as React from "react";
3
3
  import { createPortal } from "react-dom";
4
4
  import { cx, useIsoLayoutEffect, useMounted, useMergedRef } from "./internal.js";
5
5
  import { Icon } from "./Icon.js";
6
- const h = React.createElement;
7
6
  const Menu = React.forwardRef(function Menu2(props, ref) {
8
- var own = React.useRef(null), merged = useMergedRef(ref, own);
9
- var posState = React.useState(null);
10
- var pos = posState[0], setPos = posState[1];
11
- var items = props.items || [];
12
- var mounted = useMounted();
13
- useIsoLayoutEffect(function() {
14
- var a = props.anchor, m = own.current;
15
- if (!a || !m) return;
16
- var r = a.getBoundingClientRect(), mh = m.offsetHeight, mw = m.offsetWidth;
17
- var top = r.bottom + 4;
18
- if (top + mh > window.innerHeight - 8 && r.top - mh - 4 > 8) top = r.top - mh - 4;
19
- var left = Math.max(8, Math.min(r.right - mw, window.innerWidth - mw - 8));
20
- setPos({ top, left });
21
- }, [props.anchor, mounted]);
22
- React.useEffect(function() {
23
- if (!mounted) return;
24
- var first = own.current && own.current.querySelector('[role^="menuitem"]:not([disabled])');
25
- if (first && props.autoFocus !== false) first.focus();
26
- function outside(e) {
27
- if (own.current && !own.current.contains(e.target) && !(props.anchor && props.anchor.contains(e.target))) props.onClose(false);
28
- }
29
- function onScroll(e) {
30
- if (own.current && !own.current.contains(e.target)) props.onClose(false);
31
- }
32
- document.addEventListener("pointerdown", outside, true);
33
- window.addEventListener("scroll", onScroll, true);
34
- window.addEventListener("resize", onScroll);
35
- return function() {
36
- document.removeEventListener("pointerdown", outside, true);
37
- window.removeEventListener("scroll", onScroll, true);
38
- window.removeEventListener("resize", onScroll);
39
- };
40
- }, [mounted]);
7
+ const own = React.useRef(null), merged = useMergedRef(ref, own);
8
+ const posState = React.useState(null);
9
+ const pos = posState[0], setPos = posState[1];
10
+ const items = props.items || [];
11
+ const mounted = useMounted();
12
+ useIsoLayoutEffect(
13
+ function() {
14
+ const a = props.anchor, m = own.current;
15
+ if (!a || !m) return;
16
+ const r = a.getBoundingClientRect(), mh = m.offsetHeight, mw = m.offsetWidth;
17
+ let top = r.bottom + 4;
18
+ if (top + mh > window.innerHeight - 8 && r.top - mh - 4 > 8) top = r.top - mh - 4;
19
+ const left = Math.max(8, Math.min(r.right - mw, window.innerWidth - mw - 8));
20
+ setPos({ top, left });
21
+ },
22
+ [props.anchor, mounted]
23
+ );
24
+ React.useEffect(
25
+ function() {
26
+ if (!mounted) return;
27
+ const first = own.current && own.current.querySelector('[role^="menuitem"]:not([disabled])');
28
+ if (first && props.autoFocus !== false) first.focus();
29
+ function outside(e) {
30
+ if (own.current && !own.current.contains(e.target) && !(props.anchor && props.anchor.contains(e.target)))
31
+ props.onClose(false);
32
+ }
33
+ function onScroll(e) {
34
+ if (own.current && !own.current.contains(e.target)) props.onClose(false);
35
+ }
36
+ document.addEventListener("pointerdown", outside, true);
37
+ window.addEventListener("scroll", onScroll, true);
38
+ window.addEventListener("resize", onScroll);
39
+ return function() {
40
+ document.removeEventListener("pointerdown", outside, true);
41
+ window.removeEventListener("scroll", onScroll, true);
42
+ window.removeEventListener("resize", onScroll);
43
+ };
44
+ },
45
+ [mounted]
46
+ );
41
47
  function onKeyDown(e) {
42
- var list = Array.prototype.slice.call(own.current.querySelectorAll('[role^="menuitem"]:not([disabled])'));
43
- var i = list.indexOf(document.activeElement);
48
+ const list = Array.prototype.slice.call(
49
+ own.current.querySelectorAll('[role^="menuitem"]:not([disabled])')
50
+ );
51
+ const i = list.indexOf(document.activeElement);
44
52
  if (e.key === "ArrowDown") {
45
53
  e.preventDefault();
46
54
  list[(i + 1) % list.length].focus();
@@ -61,36 +69,40 @@ const Menu = React.forwardRef(function Menu2(props, ref) {
61
69
  }
62
70
  e.stopPropagation();
63
71
  }
64
- var el = h("div", {
65
- ref: merged,
66
- role: "menu",
67
- "aria-label": props.label,
68
- className: "aura-menu",
69
- onKeyDown,
70
- style: { top: pos ? pos.top : -9999, left: pos ? pos.left : -9999 }
71
- }, items.map(function(it, i) {
72
- if (it.separator) return h("div", { key: "s" + i, role: "separator", className: "aura-menu__sep" });
73
- var isCheck = it.checked !== void 0;
74
- return h(
75
- "button",
76
- {
77
- key: i,
78
- type: "button",
79
- tabIndex: -1,
80
- disabled: it.disabled,
81
- role: isCheck ? "menuitemcheckbox" : "menuitem",
82
- "aria-checked": isCheck ? !!it.checked : void 0,
83
- className: "aura-menu__item",
84
- onClick: function() {
85
- it.onSelect();
86
- if (!it.keepOpen) props.onClose(true);
87
- }
88
- },
89
- isCheck ? h("span", { className: cx("aura-menu__check", it.checked && "is-on") }, it.checked ? h(Icon, { name: "check", size: 12, strokeWidth: 3 }) : null) : it.icon ? h(Icon, { name: it.icon }) : h("span", { className: "aura-menu__blank" }),
90
- h("span", { className: "aura-menu__label" }, it.label),
91
- it.hint ? h("span", { className: "aura-menu__hint" }, it.hint) : null
92
- );
93
- }));
72
+ const el = /* @__PURE__ */ React.createElement(
73
+ "div",
74
+ {
75
+ ref: merged,
76
+ role: "menu",
77
+ "aria-label": props.label,
78
+ className: "aura-menu",
79
+ onKeyDown,
80
+ style: { top: pos ? pos.top : -9999, left: pos ? pos.left : -9999 }
81
+ },
82
+ items.map(function(it, i) {
83
+ if (it.separator) return /* @__PURE__ */ React.createElement("div", { key: "s" + i, role: "separator", className: "aura-menu__sep" });
84
+ const isCheck = it.checked !== void 0;
85
+ return /* @__PURE__ */ React.createElement(
86
+ "button",
87
+ {
88
+ key: i,
89
+ type: "button",
90
+ tabIndex: -1,
91
+ disabled: it.disabled,
92
+ role: isCheck ? "menuitemcheckbox" : "menuitem",
93
+ "aria-checked": isCheck ? !!it.checked : void 0,
94
+ className: "aura-menu__item",
95
+ onClick: function() {
96
+ it.onSelect();
97
+ if (!it.keepOpen) props.onClose(true);
98
+ }
99
+ },
100
+ isCheck ? /* @__PURE__ */ React.createElement("span", { className: cx("aura-menu__check", it.checked && "is-on") }, it.checked ? /* @__PURE__ */ React.createElement(Icon, { name: "check", size: 12, strokeWidth: 3 }) : null) : it.icon ? /* @__PURE__ */ React.createElement(Icon, { name: it.icon }) : /* @__PURE__ */ React.createElement("span", { className: "aura-menu__blank" }),
101
+ /* @__PURE__ */ React.createElement("span", { className: "aura-menu__label" }, it.label),
102
+ it.hint ? /* @__PURE__ */ React.createElement("span", { className: "aura-menu__hint" }, it.hint) : null
103
+ );
104
+ })
105
+ );
94
106
  return mounted ? createPortal(el, document.body) : null;
95
107
  });
96
108
  export {
package/dist/esm/Stat.js CHANGED
@@ -2,14 +2,13 @@
2
2
  import * as React from "react";
3
3
  import { cx } from "./internal.js";
4
4
  import { Icon } from "./Icon.js";
5
- const h = React.createElement;
6
5
  const Stat = React.forwardRef(function Stat2(props, ref) {
7
- var ch = props.change;
8
- var dir = ch && (ch.direction || "flat");
9
- var tone = ch && (ch.tone || (dir === "up" ? "positive" : dir === "down" ? "negative" : "neutral"));
10
- var Tag = props.href ? "a" : props.onClick ? "button" : "div";
11
- var interactive = Tag !== "div";
12
- return h(
6
+ const ch = props.change;
7
+ const dir = ch && (ch.direction || "flat");
8
+ const tone = ch && (ch.tone || (dir === "up" ? "positive" : dir === "down" ? "negative" : "neutral"));
9
+ const Tag = props.href ? "a" : props.onClick ? "button" : "div";
10
+ const interactive = Tag !== "div";
11
+ return /* @__PURE__ */ React.createElement(
13
12
  Tag,
14
13
  {
15
14
  ref,
@@ -19,25 +18,9 @@ const Stat = React.forwardRef(function Stat2(props, ref) {
19
18
  type: Tag === "button" ? "button" : void 0,
20
19
  "aria-busy": props.loading || void 0
21
20
  },
22
- h(
23
- "span",
24
- { className: "aura-stat__head" },
25
- h("span", { className: "aura-stat__label" }, props.label),
26
- props.icon ? h("span", { className: "aura-stat__icon" }, h(Icon, { name: props.icon })) : null
27
- ),
28
- props.loading ? h("span", { className: "aura-stat__value" }, h("span", { className: "aura-skel aura-stat__skel" })) : h("span", { className: "aura-stat__value" }, props.value, props.unit ? h("span", { className: "aura-stat__unit" }, props.unit) : null),
29
- ch && !props.loading || props.caption ? h(
30
- "span",
31
- { className: "aura-stat__foot" },
32
- ch && !props.loading ? h(
33
- "span",
34
- { className: cx("aura-stat__change", "is-" + tone) },
35
- h(Icon, { name: dir === "up" ? "trending-up" : dir === "down" ? "trending-down" : "minus", size: 14 }),
36
- h("span", null, ch.value)
37
- ) : null,
38
- ch && ch.label && !props.loading ? h("span", { className: "aura-stat__caption" }, ch.label) : null,
39
- props.caption ? h("span", { className: "aura-stat__caption" }, props.caption) : null
40
- ) : null
21
+ /* @__PURE__ */ React.createElement("span", { className: "aura-stat__head" }, /* @__PURE__ */ React.createElement("span", { className: "aura-stat__label" }, props.label), props.icon ? /* @__PURE__ */ React.createElement("span", { className: "aura-stat__icon" }, /* @__PURE__ */ React.createElement(Icon, { name: props.icon })) : null),
22
+ props.loading ? /* @__PURE__ */ React.createElement("span", { className: "aura-stat__value" }, /* @__PURE__ */ React.createElement("span", { className: "aura-skel aura-stat__skel" })) : /* @__PURE__ */ React.createElement("span", { className: "aura-stat__value" }, props.value, props.unit ? /* @__PURE__ */ React.createElement("span", { className: "aura-stat__unit" }, props.unit) : null),
23
+ ch && !props.loading || props.caption ? /* @__PURE__ */ React.createElement("span", { className: "aura-stat__foot" }, ch && !props.loading ? /* @__PURE__ */ React.createElement("span", { className: cx("aura-stat__change", "is-" + tone) }, /* @__PURE__ */ React.createElement(Icon, { name: dir === "up" ? "trending-up" : dir === "down" ? "trending-down" : "minus", size: 14 }), /* @__PURE__ */ React.createElement("span", null, ch.value)) : null, ch && ch.label && !props.loading ? /* @__PURE__ */ React.createElement("span", { className: "aura-stat__caption" }, ch.label) : null, props.caption ? /* @__PURE__ */ React.createElement("span", { className: "aura-stat__caption" }, props.caption) : null) : null
41
24
  );
42
25
  });
43
26
  export {
@@ -2,27 +2,26 @@
2
2
  import * as React from "react";
3
3
  import { cx } from "./internal.js";
4
4
  import { Icon } from "./Icon.js";
5
- const h = React.createElement;
6
- var TONE_ICON = { neutral: "circle", progress: "circle-dot-dashed", ready: "circle-check", blocked: "ban" };
7
- var TONE_WORDS = {
5
+ const TONE_ICON = {
6
+ neutral: "circle",
7
+ progress: "circle-dot-dashed",
8
+ ready: "circle-check",
9
+ blocked: "ban"
10
+ };
11
+ const TONE_WORDS = {
8
12
  ready: ["ready", "done", "complete", "completed", "approved", "live", "passed"],
9
13
  progress: ["in progress", "in review", "review", "syncing", "running", "pending"],
10
14
  blocked: ["blocked", "failed", "error", "rejected", "on hold", "cancelled"]
11
15
  };
12
16
  function toneFor(status) {
13
- var s = String(status == null ? "" : status).trim().toLowerCase();
14
- for (var t in TONE_WORDS) if (TONE_WORDS[t].indexOf(s) >= 0) return t;
17
+ const s = String(status == null ? "" : status).trim().toLowerCase();
18
+ for (const t in TONE_WORDS) if (TONE_WORDS[t].indexOf(s) >= 0) return t;
15
19
  return "neutral";
16
20
  }
17
- var TONE_ORDER = { neutral: 0, progress: 1, ready: 2, blocked: 3 };
21
+ const TONE_ORDER = { neutral: 0, progress: 1, ready: 2, blocked: 3 };
18
22
  const StatusPill = React.forwardRef(function StatusPill2(props, ref) {
19
- var tone = props.tone || toneFor(props.children);
20
- return h(
21
- "span",
22
- { ref, className: cx("aura-pill", "aura-pill--" + tone, props.className) },
23
- h(Icon, { name: TONE_ICON[tone] || "circle", size: 12 }),
24
- props.children
25
- );
23
+ const tone = props.tone || toneFor(props.children);
24
+ return /* @__PURE__ */ React.createElement("span", { ref, className: cx("aura-pill", "aura-pill--" + tone, props.className) }, /* @__PURE__ */ React.createElement(Icon, { name: TONE_ICON[tone] || "circle", size: 12 }), props.children);
26
25
  });
27
26
  export {
28
27
  StatusPill,
@@ -3,19 +3,23 @@ import * as React from "react";
3
3
  import { cx, omit } from "./internal.js";
4
4
  const h = React.createElement;
5
5
  const Surface = React.forwardRef(function Surface2(props, ref) {
6
- var t = props.texture || "mesh";
7
- var rest = omit(props, ["texture", "className", "children", "as"]);
8
- return h(props.as || "div", Object.assign({}, rest, {
9
- ref,
10
- /* Textures stay light in every theme, so everything on them uses the light tokens. */
11
- "data-theme": "light",
12
- className: cx(
13
- "aura-surface",
14
- (t === "mesh" || t === "mesh-grain") && "aura-mesh",
15
- (t === "grain" || t === "mesh-grain") && "aura-grain",
16
- props.className
17
- )
18
- }), props.children);
6
+ const t = props.texture || "mesh";
7
+ const rest = omit(props, ["texture", "className", "children", "as"]);
8
+ return h(
9
+ props.as || "div",
10
+ Object.assign({}, rest, {
11
+ ref,
12
+ /* Textures stay light in every theme, so everything on them uses the light tokens. */
13
+ "data-theme": "light",
14
+ className: cx(
15
+ "aura-surface",
16
+ (t === "mesh" || t === "mesh-grain") && "aura-mesh",
17
+ (t === "grain" || t === "mesh-grain") && "aura-grain",
18
+ props.className
19
+ )
20
+ }),
21
+ props.children
22
+ );
19
23
  });
20
24
  export {
21
25
  Surface
@@ -1,12 +1,16 @@
1
1
  'use client';
2
2
  import * as React from "react";
3
3
  import { createTheme } from "./theme.js";
4
- const h = React.createElement;
5
4
  function ThemeStyle(props) {
6
- var css = React.useMemo(function() {
7
- return createTheme({ brand: props.brand, signal: props.signal, primary: props.primary, name: props.name }).css(props.selector);
8
- }, [props.brand, props.signal, props.primary, props.name, props.selector]);
9
- return h("style", { "data-aura-theme": props.name || props.brand, dangerouslySetInnerHTML: { __html: css } });
5
+ const css = React.useMemo(
6
+ function() {
7
+ return createTheme({ brand: props.brand, signal: props.signal, primary: props.primary, name: props.name }).css(
8
+ props.selector
9
+ );
10
+ },
11
+ [props.brand, props.signal, props.primary, props.name, props.selector]
12
+ );
13
+ return /* @__PURE__ */ React.createElement("style", { "data-aura-theme": props.name || props.brand, dangerouslySetInnerHTML: { __html: css } });
10
14
  }
11
15
  export {
12
16
  ThemeStyle