@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.
@@ -2,14 +2,14 @@
2
2
  import * as React from "react";
3
3
  import { cx, omit } from "./internal.js";
4
4
  import { Icon } from "./Icon.js";
5
- const h = React.createElement;
6
5
  const Button = React.forwardRef(function Button2(props, ref) {
7
- var variant = props.variant || "primary";
8
- var loading = !!props.loading;
9
- var rest = omit(props, ["variant", "className", "children", "type", "icon", "iconRight", "loading", "onClick"]);
10
- return h(
6
+ const variant = props.variant || "primary";
7
+ const loading = !!props.loading;
8
+ const rest = omit(props, ["variant", "className", "children", "type", "icon", "iconRight", "loading", "onClick"]);
9
+ return /* @__PURE__ */ React.createElement(
11
10
  "button",
12
- Object.assign({}, rest, {
11
+ {
12
+ ...rest,
13
13
  ref,
14
14
  type: props.type || "button",
15
15
  className: cx("aura-btn", "aura-btn--" + variant, loading && "is-loading", props.className),
@@ -18,10 +18,10 @@ const Button = React.forwardRef(function Button2(props, ref) {
18
18
  onClick: loading ? function(e) {
19
19
  e.preventDefault();
20
20
  } : props.onClick
21
- }),
22
- loading ? h(Icon, { name: "loader-circle", className: "aura-spin" }) : props.icon ? h(Icon, { name: props.icon }) : null,
21
+ },
22
+ loading ? /* @__PURE__ */ React.createElement(Icon, { name: "loader-circle", className: "aura-spin" }) : props.icon ? /* @__PURE__ */ React.createElement(Icon, { name: props.icon }) : null,
23
23
  props.children,
24
- props.iconRight && !loading ? h(Icon, { name: props.iconRight }) : null
24
+ props.iconRight && !loading ? /* @__PURE__ */ React.createElement(Icon, { name: props.iconRight }) : null
25
25
  );
26
26
  });
27
27
  export {
@@ -2,46 +2,54 @@
2
2
  import * as React from "react";
3
3
  import { cx, omit, useMergedRef, useMaybeControlled } from "./internal.js";
4
4
  import { Icon } from "./Icon.js";
5
- const h = React.createElement;
6
5
  const Checkbox = React.forwardRef(function Checkbox2(props, ref) {
7
- var own = React.useRef(null), merged = useMergedRef(ref, own);
8
- var st = useMaybeControlled(props.checked, !!props.defaultChecked, props.onChange);
9
- var on = !!st[0];
6
+ const own = React.useRef(null), merged = useMergedRef(ref, own);
7
+ const st = useMaybeControlled(props.checked, !!props.defaultChecked, props.onChange);
8
+ const on = !!st[0];
10
9
  React.useEffect(function() {
11
10
  if (own.current) own.current.indeterminate = !!props.indeterminate;
12
11
  });
13
- var rest = omit(props, ["checked", "defaultChecked", "onChange", "indeterminate", "label", "children", "description", "className", "tabIndex", "disabled"]);
14
- var labelled = props.children != null;
15
- var descId = props.description && props.id ? props.id + "-desc" : void 0;
16
- return h(
12
+ const rest = omit(props, [
13
+ "checked",
14
+ "defaultChecked",
15
+ "onChange",
16
+ "indeterminate",
17
17
  "label",
18
- { className: cx("aura-check", labelled && "aura-check--labelled", props.disabled && "is-disabled", props.className), onClick: function(e) {
19
- e.stopPropagation();
20
- } },
21
- h("input", Object.assign({}, rest, {
22
- ref: merged,
23
- type: "checkbox",
24
- className: "aura-check__input",
25
- checked: on,
26
- tabIndex: props.tabIndex,
27
- disabled: props.disabled,
28
- "aria-describedby": descId,
29
- "aria-label": labelled ? void 0 : props.label,
30
- onChange: function(e) {
31
- st[1](e.target.checked);
18
+ "children",
19
+ "description",
20
+ "className",
21
+ "tabIndex",
22
+ "disabled"
23
+ ]);
24
+ const labelled = props.children != null;
25
+ const descId = props.description && props.id ? props.id + "-desc" : void 0;
26
+ return /* @__PURE__ */ React.createElement(
27
+ "label",
28
+ {
29
+ className: cx("aura-check", labelled && "aura-check--labelled", props.disabled && "is-disabled", props.className),
30
+ onClick: function(e) {
31
+ e.stopPropagation();
32
+ }
33
+ },
34
+ /* @__PURE__ */ React.createElement(
35
+ "input",
36
+ {
37
+ ...rest,
38
+ ref: merged,
39
+ type: "checkbox",
40
+ className: "aura-check__input",
41
+ checked: on,
42
+ tabIndex: props.tabIndex,
43
+ disabled: props.disabled,
44
+ "aria-describedby": descId,
45
+ "aria-label": labelled ? void 0 : props.label,
46
+ onChange: function(e) {
47
+ st[1](e.target.checked);
48
+ }
32
49
  }
33
- })),
34
- h(
35
- "span",
36
- { className: "aura-check__box", "aria-hidden": true },
37
- props.indeterminate ? h(Icon, { name: "minus", size: 12, strokeWidth: 3 }) : on ? h(Icon, { name: "check", size: 12, strokeWidth: 3 }) : null
38
50
  ),
39
- labelled ? h(
40
- "span",
41
- { className: "aura-check__text" },
42
- h("span", { className: "aura-check__label" }, props.children),
43
- props.description ? h("span", { className: "aura-check__desc", id: descId }, props.description) : null
44
- ) : null
51
+ /* @__PURE__ */ React.createElement("span", { className: "aura-check__box", "aria-hidden": true }, props.indeterminate ? /* @__PURE__ */ React.createElement(Icon, { name: "minus", size: 12, strokeWidth: 3 }) : on ? /* @__PURE__ */ React.createElement(Icon, { name: "check", size: 12, strokeWidth: 3 }) : null),
52
+ labelled ? /* @__PURE__ */ React.createElement("span", { className: "aura-check__text" }, /* @__PURE__ */ React.createElement("span", { className: "aura-check__label" }, props.children), props.description ? /* @__PURE__ */ React.createElement("span", { className: "aura-check__desc", id: descId }, props.description) : null) : null
45
53
  );
46
54
  });
47
55
  export {
@@ -5,7 +5,6 @@ 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
7
  import { Field } from "./forms.js";
8
- const h = React.createElement;
9
8
  function norm(s) {
10
9
  return String(s == null ? "" : s).normalize("NFC").toLocaleLowerCase("th");
11
10
  }
@@ -13,72 +12,91 @@ function toOpt(o) {
13
12
  return typeof o === "object" ? o : { value: String(o), label: String(o) };
14
13
  }
15
14
  function defaultFilter(option, query) {
16
- var q = norm(query).trim();
15
+ const q = norm(query).trim();
17
16
  if (!q) return true;
18
17
  return norm(option.label).indexOf(q) >= 0 || !!option.description && norm(option.description).indexOf(q) >= 0 || (option.keywords || []).some(function(k) {
19
18
  return norm(k).indexOf(q) >= 0;
20
19
  });
21
20
  }
22
21
  const Combobox = React.forwardRef(function Combobox2(props, ref) {
23
- var t = useStrings();
24
- var auto = uid(), id = props.id || auto, listId = id + "-list";
25
- var options = (props.options || []).map(toOpt);
26
- var st = useMaybeControlled(props.value, props.defaultValue == null ? null : props.defaultValue, props.onChange);
27
- var value = st[0], setValue = st[1];
28
- var selected = options.filter(function(o) {
22
+ const t = useStrings();
23
+ const auto = uid(), id = props.id || auto, listId = id + "-list";
24
+ const options = (props.options || []).map(toOpt);
25
+ const st = useMaybeControlled(
26
+ props.value,
27
+ props.defaultValue == null ? null : props.defaultValue,
28
+ props.onChange
29
+ );
30
+ const value = st[0], setValue = st[1];
31
+ const selected = options.filter(function(o) {
29
32
  return o.value === value;
30
33
  })[0] || null;
31
- var openState = React.useState(false), open = openState[0], setOpen = openState[1];
32
- var qState = React.useState(null), query = qState[0], setQuery = qState[1];
33
- var aState = React.useState(0), active = aState[0], setActive = aState[1];
34
- var posState = React.useState(null);
35
- var inputRef = React.useRef(null), inputMerged = useMergedRef(ref, inputRef), boxRef = React.useRef(null), listRef = React.useRef(null);
36
- var mounted = useMounted();
37
- var limit = props.limit || 200;
38
- var filter = props.filter || defaultFilter;
39
- var shown = props.onSearch || query == null ? options : options.filter(function(o) {
34
+ const openState = React.useState(false), open = openState[0], setOpen = openState[1];
35
+ const qState = React.useState(null), query = qState[0], setQuery = qState[1];
36
+ const aState = React.useState(0), active = aState[0], setActive = aState[1];
37
+ const posState = React.useState(null);
38
+ const inputRef = React.useRef(null), inputMerged = useMergedRef(ref, inputRef), boxRef = React.useRef(null), listRef = React.useRef(null);
39
+ const mounted = useMounted();
40
+ const limit = props.limit || 200;
41
+ const filter = props.filter || defaultFilter;
42
+ let shown = props.onSearch || query == null ? options : options.filter(function(o) {
40
43
  return filter(o, query);
41
44
  });
42
- var more = shown.length > limit;
45
+ const more = shown.length > limit;
43
46
  shown = shown.slice(0, limit);
44
- var activeIdx = Math.min(active, shown.length - 1);
47
+ const activeIdx = Math.min(active, shown.length - 1);
45
48
  function place() {
46
49
  if (!boxRef.current) return;
47
- var r = boxRef.current.getBoundingClientRect();
48
- var maxH = 320, below = window.innerHeight - r.bottom - 8, up = below < 200 && r.top > below;
49
- posState[1]({ left: r.left, width: r.width, top: up ? void 0 : r.bottom + 4, bottom: up ? window.innerHeight - r.top + 4 : void 0, maxHeight: Math.min(maxH, (up ? r.top : below) - 8) });
50
+ const r = boxRef.current.getBoundingClientRect();
51
+ const maxH = 320, below = window.innerHeight - r.bottom - 8, up = below < 200 && r.top > below;
52
+ posState[1]({
53
+ left: r.left,
54
+ width: r.width,
55
+ top: up ? void 0 : r.bottom + 4,
56
+ bottom: up ? window.innerHeight - r.top + 4 : void 0,
57
+ maxHeight: Math.min(maxH, (up ? r.top : below) - 8)
58
+ });
50
59
  }
51
- useIsoLayoutEffect(function() {
52
- if (open) place();
53
- }, [open, shown.length]);
54
- React.useEffect(function() {
55
- if (!open) return;
56
- function outside(e) {
57
- if (boxRef.current && boxRef.current.contains(e.target)) return;
58
- if (listRef.current && listRef.current.contains(e.target)) return;
59
- close(false);
60
- }
61
- function onScroll(e) {
62
- if (!listRef.current || !listRef.current.contains(e.target)) place();
63
- }
64
- document.addEventListener("pointerdown", outside, true);
65
- window.addEventListener("scroll", onScroll, true);
66
- window.addEventListener("resize", place);
67
- return function() {
68
- document.removeEventListener("pointerdown", outside, true);
69
- window.removeEventListener("scroll", onScroll, true);
70
- window.removeEventListener("resize", place);
71
- };
72
- }, [open]);
73
- React.useEffect(function() {
74
- if (!open || !listRef.current) return;
75
- var el = listRef.current.querySelector('[data-idx="' + activeIdx + '"]');
76
- if (el && el.scrollIntoView) el.scrollIntoView({ block: "nearest" });
77
- }, [activeIdx, open]);
60
+ useIsoLayoutEffect(
61
+ function() {
62
+ if (open) place();
63
+ },
64
+ [open, shown.length]
65
+ );
66
+ React.useEffect(
67
+ function() {
68
+ if (!open) return;
69
+ function outside(e) {
70
+ if (boxRef.current && boxRef.current.contains(e.target)) return;
71
+ if (listRef.current && listRef.current.contains(e.target)) return;
72
+ close(false);
73
+ }
74
+ function onScroll(e) {
75
+ if (!listRef.current || !listRef.current.contains(e.target)) place();
76
+ }
77
+ document.addEventListener("pointerdown", outside, true);
78
+ window.addEventListener("scroll", onScroll, true);
79
+ window.addEventListener("resize", place);
80
+ return function() {
81
+ document.removeEventListener("pointerdown", outside, true);
82
+ window.removeEventListener("scroll", onScroll, true);
83
+ window.removeEventListener("resize", place);
84
+ };
85
+ },
86
+ [open]
87
+ );
88
+ React.useEffect(
89
+ function() {
90
+ if (!open || !listRef.current) return;
91
+ const el = listRef.current.querySelector('[data-idx="' + activeIdx + '"]');
92
+ if (el && el.scrollIntoView) el.scrollIntoView({ block: "nearest" });
93
+ },
94
+ [activeIdx, open]
95
+ );
78
96
  function openList() {
79
97
  if (!open && !props.disabled && !props.readOnly) {
80
98
  setOpen(true);
81
- var i = selected ? shown.indexOf(selected) : 0;
99
+ const i = selected ? shown.indexOf(selected) : 0;
82
100
  setActive(i < 0 ? 0 : i);
83
101
  }
84
102
  }
@@ -94,7 +112,7 @@ const Combobox = React.forwardRef(function Combobox2(props, ref) {
94
112
  if (inputRef.current) inputRef.current.focus();
95
113
  }
96
114
  function onKeyDown(e) {
97
- var k = e.key;
115
+ const k = e.key;
98
116
  if (k === "ArrowDown") {
99
117
  e.preventDefault();
100
118
  if (!open) openList();
@@ -126,62 +144,60 @@ const Combobox = React.forwardRef(function Combobox2(props, ref) {
126
144
  if (open) close();
127
145
  }
128
146
  }
129
- var text = query != null ? query : selected ? selected.label : "";
130
- var optId = function(i) {
147
+ const text = query != null ? query : selected ? selected.label : "";
148
+ const optId = function(i) {
131
149
  return id + "-opt-" + i;
132
150
  };
133
- var list = open && mounted && posState[0] ? createPortal(
134
- h(
135
- "div",
136
- { ref: listRef, className: "aura-combo__popover", style: posState[0] },
137
- h(
138
- "ul",
139
- { id: listId, role: "listbox", "aria-label": props.label, className: "aura-combo__list" },
140
- props.loading ? h("li", { className: "aura-combo__note", role: "presentation" }, h(Icon, { name: "loader-circle", className: "aura-spin" }), props.loadingText || t.searching) : !shown.length ? h("li", { className: "aura-combo__note", role: "presentation" }, props.emptyText || t.noMatches) : shown.map(function(o, i) {
141
- var isSel = selected && o.value === selected.value;
142
- return h(
143
- "li",
144
- {
145
- key: o.value,
146
- id: optId(i),
147
- role: "option",
148
- "data-idx": i,
149
- "aria-selected": isSel,
150
- "aria-disabled": o.disabled || void 0,
151
- className: cx("aura-combo__option", i === activeIdx && "is-active", isSel && "is-selected", o.disabled && "is-disabled"),
152
- onPointerDown: function(e) {
153
- e.preventDefault();
154
- },
155
- onClick: function() {
156
- choose(o);
157
- },
158
- onPointerMove: function() {
159
- if (activeIdx !== i) setActive(i);
160
- }
161
- },
162
- o.icon ? h(Icon, { name: o.icon }) : null,
163
- h(
164
- "span",
165
- { className: "aura-combo__text" },
166
- h("span", { className: "aura-combo__label" }, o.label),
167
- o.description ? h("span", { className: "aura-combo__desc" }, o.description) : null
168
- ),
169
- isSel ? h(Icon, { name: "check", className: "aura-combo__check" }) : null
170
- );
171
- }),
172
- more && !props.loading ? h("li", { className: "aura-combo__note", role: "presentation" }, t.keepTyping((props.options || []).length)) : null
173
- )
174
- ),
151
+ const list = open && mounted && posState[0] ? createPortal(
152
+ /* @__PURE__ */ React.createElement("div", { ref: listRef, className: "aura-combo__popover", style: posState[0] }, /* @__PURE__ */ React.createElement("ul", { id: listId, role: "listbox", "aria-label": props.label, className: "aura-combo__list" }, props.loading ? /* @__PURE__ */ React.createElement("li", { className: "aura-combo__note", role: "presentation" }, /* @__PURE__ */ React.createElement(Icon, { name: "loader-circle", className: "aura-spin" }), props.loadingText || t.searching) : !shown.length ? /* @__PURE__ */ React.createElement("li", { className: "aura-combo__note", role: "presentation" }, props.emptyText || t.noMatches) : shown.map(function(o, i) {
153
+ const isSel = selected && o.value === selected.value;
154
+ return /* @__PURE__ */ React.createElement(
155
+ "li",
156
+ {
157
+ key: o.value,
158
+ id: optId(i),
159
+ role: "option",
160
+ "data-idx": i,
161
+ "aria-selected": isSel,
162
+ "aria-disabled": o.disabled || void 0,
163
+ className: cx(
164
+ "aura-combo__option",
165
+ i === activeIdx && "is-active",
166
+ isSel && "is-selected",
167
+ o.disabled && "is-disabled"
168
+ ),
169
+ onPointerDown: function(e) {
170
+ e.preventDefault();
171
+ },
172
+ onClick: function() {
173
+ choose(o);
174
+ },
175
+ onPointerMove: function() {
176
+ if (activeIdx !== i) setActive(i);
177
+ }
178
+ },
179
+ o.icon ? /* @__PURE__ */ React.createElement(Icon, { name: o.icon }) : null,
180
+ /* @__PURE__ */ React.createElement("span", { className: "aura-combo__text" }, /* @__PURE__ */ React.createElement("span", { className: "aura-combo__label" }, o.label), o.description ? /* @__PURE__ */ React.createElement("span", { className: "aura-combo__desc" }, o.description) : null),
181
+ isSel ? /* @__PURE__ */ React.createElement(Icon, { name: "check", className: "aura-combo__check" }) : null
182
+ );
183
+ }), more && !props.loading ? /* @__PURE__ */ React.createElement("li", { className: "aura-combo__note", role: "presentation" }, t.keepTyping((props.options || []).length)) : null)),
175
184
  document.body
176
185
  ) : null;
177
- return h(
186
+ return /* @__PURE__ */ React.createElement(
178
187
  Field,
179
- { id, label: props.label, hint: props.hint, error: props.error, required: props.required, optional: props.optional, disabled: props.disabled, className: props.className },
180
- h(
181
- "div",
182
- { ref: boxRef, className: cx("aura-input aura-combo has-icon", open && "is-open") },
183
- h(Icon, { name: props.icon || "search", className: "aura-input__icon" }),
184
- h("input", {
188
+ {
189
+ id,
190
+ label: props.label,
191
+ hint: props.hint,
192
+ error: props.error,
193
+ required: props.required,
194
+ optional: props.optional,
195
+ disabled: props.disabled,
196
+ className: props.className
197
+ },
198
+ /* @__PURE__ */ React.createElement("div", { ref: boxRef, className: cx("aura-input aura-combo has-icon", open && "is-open") }, /* @__PURE__ */ React.createElement(Icon, { name: props.icon || "search", className: "aura-input__icon" }), /* @__PURE__ */ React.createElement(
199
+ "input",
200
+ {
185
201
  ref: inputMerged,
186
202
  id,
187
203
  type: "text",
@@ -215,8 +231,10 @@ const Combobox = React.forwardRef(function Combobox2(props, ref) {
215
231
  setQuery(null);
216
232
  }, 0);
217
233
  }
218
- }),
219
- props.clearable !== false && value != null && !props.disabled ? h("button", {
234
+ }
235
+ ), props.clearable !== false && value != null && !props.disabled ? /* @__PURE__ */ React.createElement(
236
+ "button",
237
+ {
220
238
  type: "button",
221
239
  className: "aura-combo__clear",
222
240
  "aria-label": t.clear(props.label),
@@ -226,28 +244,28 @@ const Combobox = React.forwardRef(function Combobox2(props, ref) {
226
244
  setQuery(null);
227
245
  if (inputRef.current) inputRef.current.focus();
228
246
  }
229
- }, h(Icon, { name: "x" })) : null,
230
- h(
231
- "button",
232
- {
233
- type: "button",
234
- tabIndex: -1,
235
- "aria-hidden": true,
236
- className: "aura-combo__toggle",
237
- onPointerDown: function(e) {
238
- e.preventDefault();
239
- },
240
- onClick: function() {
241
- if (open) close();
242
- else {
243
- openList();
244
- inputRef.current && inputRef.current.focus();
245
- }
246
- }
247
+ },
248
+ /* @__PURE__ */ React.createElement(Icon, { name: "x" })
249
+ ) : null, /* @__PURE__ */ React.createElement(
250
+ "button",
251
+ {
252
+ type: "button",
253
+ tabIndex: -1,
254
+ "aria-hidden": true,
255
+ className: "aura-combo__toggle",
256
+ onPointerDown: function(e) {
257
+ e.preventDefault();
247
258
  },
248
- h(Icon, { name: "chevron-down" })
249
- )
250
- ),
259
+ onClick: function() {
260
+ if (open) close();
261
+ else {
262
+ openList();
263
+ inputRef.current && inputRef.current.focus();
264
+ }
265
+ }
266
+ },
267
+ /* @__PURE__ */ React.createElement(Icon, { name: "chevron-down" })
268
+ )),
251
269
  list
252
270
  );
253
271
  });