@jirawatpyk/aura-react 4.11.0 → 4.13.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 +17 -3
- package/dist/aura.bundle.js +955 -433
- package/dist/cjs/index.cjs +954 -432
- package/dist/esm/Command.js +213 -0
- package/dist/esm/DatePicker.js +18 -1
- package/dist/esm/FilterBar.js +112 -0
- package/dist/esm/FormErrorSummary.js +76 -0
- package/dist/esm/PasswordField.js +38 -0
- package/dist/esm/Toaster.js +60 -14
- package/dist/esm/index.js +10 -1
- package/dist/esm/locale.js +39 -0
- package/dist/index.d.ts +114 -1
- package/dist/styles.css +100 -0
- package/package.json +1 -1
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import { Icon } from "./Icon.js";
|
|
5
|
+
import { defaultFilter } from "./Combobox.js";
|
|
6
|
+
import { cx, uid } from "./internal.js";
|
|
7
|
+
import { useStrings } from "./locale.js";
|
|
8
|
+
import { useModal } from "./useModal.js";
|
|
9
|
+
function isMac() {
|
|
10
|
+
return typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
|
|
11
|
+
}
|
|
12
|
+
function Command(props) {
|
|
13
|
+
const t = useStrings();
|
|
14
|
+
const id = uid(), listId = id + "-list";
|
|
15
|
+
const box = React.useRef(null);
|
|
16
|
+
const input = React.useRef(null);
|
|
17
|
+
const q = React.useState(""), act = React.useState(0);
|
|
18
|
+
const openRef = React.useRef(props.open);
|
|
19
|
+
openRef.current = props.open;
|
|
20
|
+
const close = function() {
|
|
21
|
+
props.onOpenChange(false);
|
|
22
|
+
};
|
|
23
|
+
const modal = useModal(props.open, box, { onEscape: close });
|
|
24
|
+
React.useEffect(
|
|
25
|
+
function() {
|
|
26
|
+
if (props.hotkey === false) return;
|
|
27
|
+
function onKey2(e) {
|
|
28
|
+
if ((e.metaKey || e.ctrlKey) && !e.altKey && !e.shiftKey && (e.key === "k" || e.key === "K")) {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
props.onOpenChange(!openRef.current);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
document.addEventListener("keydown", onKey2, true);
|
|
34
|
+
return function() {
|
|
35
|
+
document.removeEventListener("keydown", onKey2, true);
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
[props.hotkey, props.onOpenChange]
|
|
39
|
+
);
|
|
40
|
+
React.useEffect(
|
|
41
|
+
function() {
|
|
42
|
+
if (!props.open) {
|
|
43
|
+
q[1]("");
|
|
44
|
+
act[1](0);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[props.open]
|
|
48
|
+
);
|
|
49
|
+
const filter = props.filter || defaultFilter;
|
|
50
|
+
const shown = (props.items || []).filter(function(it) {
|
|
51
|
+
return filter(it, q[0]);
|
|
52
|
+
});
|
|
53
|
+
const groups = [];
|
|
54
|
+
shown.forEach(function(it) {
|
|
55
|
+
const name = it.group || "";
|
|
56
|
+
let g = groups.filter(function(x) {
|
|
57
|
+
return x.name === name;
|
|
58
|
+
})[0];
|
|
59
|
+
if (!g) groups.push(g = { name, items: [] });
|
|
60
|
+
g.items.push(it);
|
|
61
|
+
});
|
|
62
|
+
const flat = [];
|
|
63
|
+
groups.forEach(function(g) {
|
|
64
|
+
g.items.forEach(function(it) {
|
|
65
|
+
flat.push(it);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
const enabled = flat.map(function(it, i2) {
|
|
69
|
+
return it.disabled ? -1 : i2;
|
|
70
|
+
}).filter(function(i2) {
|
|
71
|
+
return i2 >= 0;
|
|
72
|
+
});
|
|
73
|
+
const active = enabled.indexOf(act[0]) >= 0 ? act[0] : enabled.length ? enabled[0] : -1;
|
|
74
|
+
const optId = function(i2) {
|
|
75
|
+
return id + "-o" + i2;
|
|
76
|
+
};
|
|
77
|
+
React.useEffect(
|
|
78
|
+
function() {
|
|
79
|
+
if (!box.current || active < 0) return;
|
|
80
|
+
const el = box.current.querySelector("#" + CSS.escape(optId(active)));
|
|
81
|
+
if (el && el.scrollIntoView) el.scrollIntoView({ block: "nearest" });
|
|
82
|
+
},
|
|
83
|
+
[active]
|
|
84
|
+
);
|
|
85
|
+
function run(it) {
|
|
86
|
+
if (it.disabled) return;
|
|
87
|
+
close();
|
|
88
|
+
if (it.onSelect) it.onSelect();
|
|
89
|
+
if (props.onSelect) props.onSelect(it);
|
|
90
|
+
}
|
|
91
|
+
function move(dir) {
|
|
92
|
+
if (!enabled.length) return;
|
|
93
|
+
const at = enabled.indexOf(active);
|
|
94
|
+
let n;
|
|
95
|
+
if (dir === "first") n = 0;
|
|
96
|
+
else if (dir === "last") n = enabled.length - 1;
|
|
97
|
+
else n = (at + dir + enabled.length) % enabled.length;
|
|
98
|
+
act[1](enabled[n]);
|
|
99
|
+
}
|
|
100
|
+
function onKey(e) {
|
|
101
|
+
if (e.key === "ArrowDown") {
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
move(1);
|
|
104
|
+
} else if (e.key === "ArrowUp") {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
move(-1);
|
|
107
|
+
} else if (e.key === "Home" && e.ctrlKey) {
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
move("first");
|
|
110
|
+
} else if (e.key === "End" && e.ctrlKey) {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
move("last");
|
|
113
|
+
} else if (e.key === "Enter") {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
if (active >= 0) run(flat[active]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!modal.ready) return null;
|
|
119
|
+
let i = -1;
|
|
120
|
+
return createPortal(
|
|
121
|
+
/* @__PURE__ */ React.createElement(
|
|
122
|
+
"div",
|
|
123
|
+
{
|
|
124
|
+
className: "aura-dialog-layer aura-command-layer",
|
|
125
|
+
onKeyDown: function(e) {
|
|
126
|
+
modal.onKeyDown(e);
|
|
127
|
+
e.stopPropagation();
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
/* @__PURE__ */ React.createElement("div", { className: "aura-scrim", onClick: close, "aria-hidden": true }),
|
|
131
|
+
/* @__PURE__ */ React.createElement(
|
|
132
|
+
"div",
|
|
133
|
+
{
|
|
134
|
+
ref: box,
|
|
135
|
+
role: "dialog",
|
|
136
|
+
"aria-modal": true,
|
|
137
|
+
"aria-label": props.label || t.commandMenu,
|
|
138
|
+
tabIndex: -1,
|
|
139
|
+
className: cx("aura-command", props.className)
|
|
140
|
+
},
|
|
141
|
+
/* @__PURE__ */ React.createElement("div", { className: "aura-command__search" }, /* @__PURE__ */ React.createElement(Icon, { name: "search", className: "aura-command__search-icon" }), /* @__PURE__ */ React.createElement(
|
|
142
|
+
"input",
|
|
143
|
+
{
|
|
144
|
+
ref: input,
|
|
145
|
+
"data-autofocus": "",
|
|
146
|
+
type: "text",
|
|
147
|
+
role: "combobox",
|
|
148
|
+
"aria-expanded": true,
|
|
149
|
+
"aria-controls": listId,
|
|
150
|
+
"aria-autocomplete": "list",
|
|
151
|
+
"aria-activedescendant": active >= 0 ? optId(active) : void 0,
|
|
152
|
+
"aria-label": props.label || t.commandMenu,
|
|
153
|
+
placeholder: props.placeholder || t.commandPlaceholder,
|
|
154
|
+
className: "aura-command__input",
|
|
155
|
+
value: q[0],
|
|
156
|
+
autoComplete: "off",
|
|
157
|
+
spellCheck: false,
|
|
158
|
+
onChange: function(e) {
|
|
159
|
+
q[1](e.target.value);
|
|
160
|
+
act[1](0);
|
|
161
|
+
},
|
|
162
|
+
onKeyDown: onKey
|
|
163
|
+
}
|
|
164
|
+
), /* @__PURE__ */ React.createElement("kbd", { className: "aura-command__kbd" }, "Esc")),
|
|
165
|
+
/* @__PURE__ */ React.createElement("div", { className: "aura-command__list", id: listId, role: "listbox", "aria-label": props.label || t.commandMenu }, !flat.length ? /* @__PURE__ */ React.createElement("p", { className: "aura-command__empty", role: "presentation" }, props.emptyText || t.noMatches) : groups.map(function(g, gi) {
|
|
166
|
+
const gid = id + "-g" + gi;
|
|
167
|
+
return /* @__PURE__ */ React.createElement(
|
|
168
|
+
"div",
|
|
169
|
+
{
|
|
170
|
+
key: g.name || gi,
|
|
171
|
+
role: "group",
|
|
172
|
+
"aria-labelledby": g.name ? gid : void 0,
|
|
173
|
+
className: "aura-command__group"
|
|
174
|
+
},
|
|
175
|
+
g.name ? /* @__PURE__ */ React.createElement("div", { className: "aura-command__heading", id: gid, role: "presentation" }, g.name) : null,
|
|
176
|
+
g.items.map(function(it) {
|
|
177
|
+
i++;
|
|
178
|
+
const n = i;
|
|
179
|
+
return /* @__PURE__ */ React.createElement(
|
|
180
|
+
"div",
|
|
181
|
+
{
|
|
182
|
+
key: it.id,
|
|
183
|
+
id: optId(n),
|
|
184
|
+
role: "option",
|
|
185
|
+
"aria-selected": n === active,
|
|
186
|
+
"aria-disabled": it.disabled || void 0,
|
|
187
|
+
className: cx("aura-command__item", n === active && "is-active", it.disabled && "is-disabled"),
|
|
188
|
+
onPointerDown: function(e) {
|
|
189
|
+
e.preventDefault();
|
|
190
|
+
},
|
|
191
|
+
onPointerMove: function() {
|
|
192
|
+
if (!it.disabled && act[0] !== n) act[1](n);
|
|
193
|
+
},
|
|
194
|
+
onClick: function() {
|
|
195
|
+
run(it);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
it.icon ? /* @__PURE__ */ React.createElement(Icon, { name: it.icon }) : null,
|
|
199
|
+
/* @__PURE__ */ React.createElement("span", { className: "aura-command__text" }, /* @__PURE__ */ React.createElement("span", { className: "aura-command__label" }, it.label), it.description ? /* @__PURE__ */ React.createElement("span", { className: "aura-command__desc" }, it.description) : null),
|
|
200
|
+
it.shortcut ? /* @__PURE__ */ React.createElement("kbd", { className: "aura-command__kbd" }, it.shortcut) : null
|
|
201
|
+
);
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
})),
|
|
205
|
+
/* @__PURE__ */ React.createElement("div", { className: "aura-command__foot", "aria-hidden": true }, t.commandHint, /* @__PURE__ */ React.createElement("span", { className: "aura-command__mod" }, isMac() ? "\u2318K" : "Ctrl K"))
|
|
206
|
+
)
|
|
207
|
+
),
|
|
208
|
+
document.body
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
export {
|
|
212
|
+
Command
|
|
213
|
+
};
|
package/dist/esm/DatePicker.js
CHANGED
|
@@ -111,6 +111,22 @@ function formatDate(iso, opts) {
|
|
|
111
111
|
const loc = o.locale || "th";
|
|
112
112
|
return fmt(localeTag(loc, o.calendar || defaultCalendar(loc)), f, d).replace(ERA, "");
|
|
113
113
|
}
|
|
114
|
+
function useFormatDate() {
|
|
115
|
+
const ctx = useAuraLocale(), locale = ctx.locale || "en", calendar = ctx.calendar;
|
|
116
|
+
return React.useCallback(
|
|
117
|
+
function(iso, opts) {
|
|
118
|
+
const o = opts || {}, loc = o.locale || locale;
|
|
119
|
+
return formatDate(
|
|
120
|
+
iso,
|
|
121
|
+
Object.assign({}, o, {
|
|
122
|
+
locale: loc,
|
|
123
|
+
calendar: o.calendar || (o.locale ? void 0 : calendar) || defaultCalendar(loc)
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
[locale, calendar]
|
|
128
|
+
);
|
|
129
|
+
}
|
|
114
130
|
let MONTHS = null;
|
|
115
131
|
function monthIndex(word) {
|
|
116
132
|
if (!MONTHS) {
|
|
@@ -708,5 +724,6 @@ export {
|
|
|
708
724
|
formatDate,
|
|
709
725
|
fromISO,
|
|
710
726
|
parseDate,
|
|
711
|
-
toISO
|
|
727
|
+
toISO,
|
|
728
|
+
useFormatDate
|
|
712
729
|
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { IconButton } from "./IconButton.js";
|
|
5
|
+
import { Tag } from "./Tag.js";
|
|
6
|
+
import { cx, uid } from "./internal.js";
|
|
7
|
+
import { useStrings } from "./locale.js";
|
|
8
|
+
const FilterBar = React.forwardRef(function FilterBar2(props, ref) {
|
|
9
|
+
const t = useStrings();
|
|
10
|
+
const id = uid();
|
|
11
|
+
const hasSearch = !!props.onSearchChange;
|
|
12
|
+
const draft = React.useState(props.search || "");
|
|
13
|
+
const timer = React.useRef(null);
|
|
14
|
+
const sent = React.useRef(props.search || "");
|
|
15
|
+
const onChange = React.useRef(props.onSearchChange);
|
|
16
|
+
onChange.current = props.onSearchChange;
|
|
17
|
+
React.useEffect(
|
|
18
|
+
function() {
|
|
19
|
+
if ((props.search || "") !== sent.current) {
|
|
20
|
+
sent.current = props.search || "";
|
|
21
|
+
draft[1](props.search || "");
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
[props.search]
|
|
25
|
+
);
|
|
26
|
+
React.useEffect(function() {
|
|
27
|
+
return function() {
|
|
28
|
+
if (timer.current) clearTimeout(timer.current);
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
function send(v) {
|
|
32
|
+
if (timer.current) clearTimeout(timer.current);
|
|
33
|
+
timer.current = null;
|
|
34
|
+
if (v === sent.current) return;
|
|
35
|
+
sent.current = v;
|
|
36
|
+
if (onChange.current) onChange.current(v);
|
|
37
|
+
}
|
|
38
|
+
function type(v) {
|
|
39
|
+
draft[1](v);
|
|
40
|
+
if (timer.current) clearTimeout(timer.current);
|
|
41
|
+
timer.current = setTimeout(
|
|
42
|
+
function() {
|
|
43
|
+
send(v);
|
|
44
|
+
},
|
|
45
|
+
props.searchDelay == null ? 300 : props.searchDelay
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const filters = props.filters || [];
|
|
49
|
+
const anything = filters.length > 0 || !!(props.search || draft[0]);
|
|
50
|
+
const count = props.resultCount == null ? null : typeof props.resultCount === "number" ? t.results(props.resultCount) : props.resultCount;
|
|
51
|
+
return /* @__PURE__ */ React.createElement(
|
|
52
|
+
"div",
|
|
53
|
+
{
|
|
54
|
+
ref,
|
|
55
|
+
role: "region",
|
|
56
|
+
"aria-label": props.label || t.filters,
|
|
57
|
+
className: cx("aura-filterbar", props.className)
|
|
58
|
+
},
|
|
59
|
+
/* @__PURE__ */ React.createElement("div", { className: "aura-filterbar__row" }, hasSearch ? /* @__PURE__ */ React.createElement("div", { className: "aura-input has-icon aura-filterbar__search" }, /* @__PURE__ */ React.createElement(Icon, { name: "search", className: "aura-input__icon" }), /* @__PURE__ */ React.createElement(
|
|
60
|
+
"input",
|
|
61
|
+
{
|
|
62
|
+
id,
|
|
63
|
+
type: "search",
|
|
64
|
+
className: "aura-input__control",
|
|
65
|
+
"aria-label": props.searchLabel || t.search,
|
|
66
|
+
placeholder: props.searchPlaceholder || props.searchLabel || t.search,
|
|
67
|
+
value: draft[0],
|
|
68
|
+
onChange: function(e) {
|
|
69
|
+
type(e.target.value);
|
|
70
|
+
},
|
|
71
|
+
onKeyDown: function(e) {
|
|
72
|
+
if (e.key === "Enter") send(draft[0]);
|
|
73
|
+
if (e.key === "Escape" && draft[0]) {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
draft[1]("");
|
|
76
|
+
send("");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
), draft[0] ? /* @__PURE__ */ React.createElement(
|
|
81
|
+
IconButton,
|
|
82
|
+
{
|
|
83
|
+
icon: "x",
|
|
84
|
+
label: t.clear((props.searchLabel || t.search).toLowerCase()),
|
|
85
|
+
className: "aura-filterbar__clear-search",
|
|
86
|
+
onClick: function() {
|
|
87
|
+
draft[1]("");
|
|
88
|
+
send("");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
) : null) : null, props.children ? /* @__PURE__ */ React.createElement("div", { className: "aura-filterbar__controls" }, props.children) : null, /* @__PURE__ */ React.createElement("span", { className: "aura-filterbar__spacer" }), count != null ? /* @__PURE__ */ React.createElement("span", { className: "aura-filterbar__count", "aria-live": "polite" }, count) : null, props.actions ? /* @__PURE__ */ React.createElement("div", { className: "aura-filterbar__actions" }, props.actions) : null),
|
|
92
|
+
filters.length || props.onClearAll && anything ? /* @__PURE__ */ React.createElement("div", { className: "aura-filterbar__chips" }, filters.map(function(f) {
|
|
93
|
+
return /* @__PURE__ */ React.createElement(Tag, { key: f.id, onRemove: f.onRemove }, f.label);
|
|
94
|
+
}), props.onClearAll && anything ? /* @__PURE__ */ React.createElement(
|
|
95
|
+
"button",
|
|
96
|
+
{
|
|
97
|
+
type: "button",
|
|
98
|
+
className: "aura-filterbar__clear",
|
|
99
|
+
onClick: function() {
|
|
100
|
+
draft[1]("");
|
|
101
|
+
sent.current = "";
|
|
102
|
+
if (timer.current) clearTimeout(timer.current);
|
|
103
|
+
props.onClearAll();
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
t.clearFilters
|
|
107
|
+
) : null) : null
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
export {
|
|
111
|
+
FilterBar
|
|
112
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { cx, uid } from "./internal.js";
|
|
5
|
+
import { useStrings } from "./locale.js";
|
|
6
|
+
function items(errors) {
|
|
7
|
+
if (Array.isArray(errors)) return errors;
|
|
8
|
+
const out = [];
|
|
9
|
+
for (const k in errors || {}) {
|
|
10
|
+
const e = errors[k];
|
|
11
|
+
if (e && e.message) out.push({ field: k, message: e.message });
|
|
12
|
+
}
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
function fieldElement(field) {
|
|
16
|
+
if (typeof document === "undefined") return null;
|
|
17
|
+
return document.getElementById(field) || document.querySelector('[name="' + field.replace(/"/g, '\\"') + '"]');
|
|
18
|
+
}
|
|
19
|
+
const FormErrorSummary = React.forwardRef(
|
|
20
|
+
function FormErrorSummary2(props, ref) {
|
|
21
|
+
const t = useStrings();
|
|
22
|
+
const auto = uid(), id = props.id || auto;
|
|
23
|
+
const list = items(props.errors);
|
|
24
|
+
const box = React.useRef(null);
|
|
25
|
+
React.useEffect(
|
|
26
|
+
function() {
|
|
27
|
+
const has = list.length > 0;
|
|
28
|
+
if (has && box.current) box.current.focus();
|
|
29
|
+
},
|
|
30
|
+
/* focus when errors first appear, and again whenever focusKey changes (each submit) */
|
|
31
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
|
+
[list.length > 0, props.focusKey]
|
|
33
|
+
);
|
|
34
|
+
if (!list.length) return null;
|
|
35
|
+
return /* @__PURE__ */ React.createElement(
|
|
36
|
+
"div",
|
|
37
|
+
{
|
|
38
|
+
ref: function(el) {
|
|
39
|
+
box.current = el;
|
|
40
|
+
if (typeof ref === "function") ref(el);
|
|
41
|
+
else if (ref) ref.current = el;
|
|
42
|
+
},
|
|
43
|
+
id,
|
|
44
|
+
tabIndex: -1,
|
|
45
|
+
role: "alert",
|
|
46
|
+
"aria-labelledby": id + "-title",
|
|
47
|
+
className: cx("aura-alert aura-alert--danger aura-error-summary", props.className)
|
|
48
|
+
},
|
|
49
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "circle-alert", className: "aura-alert__icon" }),
|
|
50
|
+
/* @__PURE__ */ React.createElement("div", { className: "aura-alert__body" }, /* @__PURE__ */ React.createElement("h2", { className: "aura-alert__title", id: id + "-title" }, props.title || t.errorSummary(list.length)), /* @__PURE__ */ React.createElement("ul", { className: "aura-error-summary__list" }, list.map(function(e) {
|
|
51
|
+
return /* @__PURE__ */ React.createElement("li", { key: e.field }, /* @__PURE__ */ React.createElement(
|
|
52
|
+
"a",
|
|
53
|
+
{
|
|
54
|
+
href: "#" + e.field,
|
|
55
|
+
onClick: function(ev) {
|
|
56
|
+
ev.preventDefault();
|
|
57
|
+
if (props.onSelect) {
|
|
58
|
+
props.onSelect(e.field);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const el = fieldElement(e.field);
|
|
62
|
+
if (el) {
|
|
63
|
+
el.scrollIntoView({ block: "center" });
|
|
64
|
+
el.focus();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
e.message
|
|
69
|
+
));
|
|
70
|
+
})))
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
export {
|
|
75
|
+
FormErrorSummary
|
|
76
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { TextField } from "./TextField.js";
|
|
4
|
+
import { IconButton } from "./IconButton.js";
|
|
5
|
+
import { cx, omit } from "./internal.js";
|
|
6
|
+
import { useStrings } from "./locale.js";
|
|
7
|
+
const PasswordField = React.forwardRef(function PasswordField2(props, ref) {
|
|
8
|
+
const t = useStrings();
|
|
9
|
+
const shown = React.useState(false);
|
|
10
|
+
const rest = omit(props, ["toggle", "className"]);
|
|
11
|
+
return /* @__PURE__ */ React.createElement(
|
|
12
|
+
TextField,
|
|
13
|
+
{
|
|
14
|
+
autoComplete: "current-password",
|
|
15
|
+
...rest,
|
|
16
|
+
ref,
|
|
17
|
+
type: shown[0] ? "text" : "password",
|
|
18
|
+
spellCheck: false,
|
|
19
|
+
autoCapitalize: "none",
|
|
20
|
+
className: cx("aura-password", props.className),
|
|
21
|
+
suffix: props.toggle === false ? void 0 : /* @__PURE__ */ React.createElement(
|
|
22
|
+
IconButton,
|
|
23
|
+
{
|
|
24
|
+
icon: shown[0] ? "eye-off" : "eye",
|
|
25
|
+
label: t.showPassword,
|
|
26
|
+
"aria-pressed": shown[0],
|
|
27
|
+
disabled: props.disabled,
|
|
28
|
+
onClick: function() {
|
|
29
|
+
shown[1](!shown[0]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
export {
|
|
37
|
+
PasswordField
|
|
38
|
+
};
|
package/dist/esm/Toaster.js
CHANGED
|
@@ -16,15 +16,40 @@ function emitToasts() {
|
|
|
16
16
|
f(toastState.list.slice());
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
if (typeof opts === "string") opts = { title: opts };
|
|
19
|
+
function show(opts) {
|
|
21
20
|
const id = opts.id || "t" + ++toastState.n;
|
|
22
|
-
|
|
23
|
-
return t.id
|
|
24
|
-
})
|
|
21
|
+
const at = toastState.list.findIndex(function(t) {
|
|
22
|
+
return t.id === id;
|
|
23
|
+
});
|
|
24
|
+
const entry = Object.assign({ tone: "info" }, opts, {
|
|
25
|
+
id,
|
|
26
|
+
loading: !!opts.loading,
|
|
27
|
+
rev: at >= 0 ? toastState.list[at].rev + 1 : 0
|
|
28
|
+
});
|
|
29
|
+
if (at >= 0) {
|
|
30
|
+
toastState.list = toastState.list.slice();
|
|
31
|
+
toastState.list[at] = entry;
|
|
32
|
+
} else toastState.list = toastState.list.concat([entry]).slice(-3);
|
|
25
33
|
emitToasts();
|
|
26
34
|
return id;
|
|
27
35
|
}
|
|
36
|
+
function toast(opts) {
|
|
37
|
+
return show(typeof opts === "string" ? { title: opts } : opts);
|
|
38
|
+
}
|
|
39
|
+
function shorthand(tone) {
|
|
40
|
+
return function(title, opts) {
|
|
41
|
+
return show(Object.assign({}, opts, { title, tone }));
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
toast.success = shorthand("success");
|
|
45
|
+
toast.error = shorthand("danger");
|
|
46
|
+
toast.warning = shorthand("warning");
|
|
47
|
+
toast.info = shorthand("info");
|
|
48
|
+
toast.loading = function(title, opts) {
|
|
49
|
+
return show(
|
|
50
|
+
Object.assign({}, opts, { title, tone: "info", loading: true, duration: Infinity })
|
|
51
|
+
);
|
|
52
|
+
};
|
|
28
53
|
toast.dismiss = function(id) {
|
|
29
54
|
toastState.list = toastState.list.filter(function(t) {
|
|
30
55
|
return t.id !== id;
|
|
@@ -34,35 +59,56 @@ toast.dismiss = function(id) {
|
|
|
34
59
|
function ToastItem(props) {
|
|
35
60
|
const str = useStrings();
|
|
36
61
|
const t = props.toast, timer = React.useRef(null), left = React.useRef(t.duration || 5e3), since = React.useRef(0);
|
|
62
|
+
const hover = React.useRef(false);
|
|
37
63
|
function start() {
|
|
38
|
-
if (left.current === Infinity) return;
|
|
64
|
+
if (left.current === Infinity || timer.current) return;
|
|
39
65
|
since.current = Date.now();
|
|
40
66
|
timer.current = setTimeout(function() {
|
|
41
67
|
toast.dismiss(t.id);
|
|
42
68
|
}, left.current);
|
|
43
69
|
}
|
|
70
|
+
function resume() {
|
|
71
|
+
hover.current = false;
|
|
72
|
+
start();
|
|
73
|
+
}
|
|
44
74
|
function pause() {
|
|
75
|
+
hover.current = true;
|
|
45
76
|
if (timer.current) {
|
|
46
77
|
clearTimeout(timer.current);
|
|
47
78
|
timer.current = null;
|
|
48
79
|
left.current -= Date.now() - since.current;
|
|
49
80
|
}
|
|
50
81
|
}
|
|
51
|
-
React.useEffect(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
82
|
+
React.useEffect(
|
|
83
|
+
function() {
|
|
84
|
+
if (timer.current) clearTimeout(timer.current);
|
|
85
|
+
timer.current = null;
|
|
86
|
+
left.current = t.duration || 5e3;
|
|
87
|
+
if (!hover.current) start();
|
|
88
|
+
return function() {
|
|
89
|
+
if (timer.current) clearTimeout(timer.current);
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
[t.rev]
|
|
93
|
+
);
|
|
55
94
|
return /* @__PURE__ */ React.createElement(
|
|
56
95
|
"div",
|
|
57
96
|
{
|
|
58
|
-
className: cx("aura-toast", "aura-toast--" + t.tone),
|
|
97
|
+
className: cx("aura-toast", "aura-toast--" + t.tone, t.loading && "is-loading"),
|
|
59
98
|
role: t.tone === "danger" ? "alert" : "status",
|
|
99
|
+
"aria-busy": t.loading || void 0,
|
|
60
100
|
onMouseEnter: pause,
|
|
61
|
-
onMouseLeave:
|
|
101
|
+
onMouseLeave: resume,
|
|
62
102
|
onFocus: pause,
|
|
63
|
-
onBlur:
|
|
103
|
+
onBlur: resume
|
|
64
104
|
},
|
|
65
|
-
/* @__PURE__ */ React.createElement(
|
|
105
|
+
/* @__PURE__ */ React.createElement(
|
|
106
|
+
Icon,
|
|
107
|
+
{
|
|
108
|
+
name: t.loading ? "loader-circle" : ALERT_ICON[t.tone] || "info",
|
|
109
|
+
className: cx("aura-toast__icon", t.loading && "aura-spin")
|
|
110
|
+
}
|
|
111
|
+
),
|
|
66
112
|
/* @__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),
|
|
67
113
|
t.action ? /* @__PURE__ */ React.createElement(
|
|
68
114
|
"button",
|
package/dist/esm/index.js
CHANGED
|
@@ -13,9 +13,13 @@ import { Select } from "./Select.js";
|
|
|
13
13
|
import { RadioGroup } from "./RadioGroup.js";
|
|
14
14
|
import { Switch } from "./Switch.js";
|
|
15
15
|
import { Combobox, defaultFilter } from "./Combobox.js";
|
|
16
|
-
import { DatePicker, DateRangePicker, Calendar, formatDate, parseDate } from "./DatePicker.js";
|
|
16
|
+
import { DatePicker, DateRangePicker, Calendar, formatDate, parseDate, useFormatDate } from "./DatePicker.js";
|
|
17
17
|
import { Alert } from "./Alert.js";
|
|
18
18
|
import { Toaster, toast } from "./Toaster.js";
|
|
19
|
+
import { PasswordField } from "./PasswordField.js";
|
|
20
|
+
import { FormErrorSummary } from "./FormErrorSummary.js";
|
|
21
|
+
import { FilterBar } from "./FilterBar.js";
|
|
22
|
+
import { Command } from "./Command.js";
|
|
19
23
|
import { Tooltip } from "./Tooltip.js";
|
|
20
24
|
import { Dialog, Drawer } from "./Dialog.js";
|
|
21
25
|
import { DataTable } from "./DataTable.js";
|
|
@@ -63,6 +67,7 @@ export {
|
|
|
63
67
|
ColorSchemeScript,
|
|
64
68
|
ColorSchemeToggle,
|
|
65
69
|
Combobox,
|
|
70
|
+
Command,
|
|
66
71
|
Container,
|
|
67
72
|
DataTable,
|
|
68
73
|
DatePicker,
|
|
@@ -73,6 +78,8 @@ export {
|
|
|
73
78
|
EmptyState,
|
|
74
79
|
Field,
|
|
75
80
|
FileUpload,
|
|
81
|
+
FilterBar,
|
|
82
|
+
FormErrorSummary,
|
|
76
83
|
Grid,
|
|
77
84
|
ICONS,
|
|
78
85
|
Icon,
|
|
@@ -80,6 +87,7 @@ export {
|
|
|
80
87
|
Menu,
|
|
81
88
|
NumberField,
|
|
82
89
|
Pagination,
|
|
90
|
+
PasswordField,
|
|
83
91
|
Popover,
|
|
84
92
|
Progress,
|
|
85
93
|
RadioGroup,
|
|
@@ -118,5 +126,6 @@ export {
|
|
|
118
126
|
useAuraLocale,
|
|
119
127
|
useBreakpoint,
|
|
120
128
|
useColorScheme,
|
|
129
|
+
useFormatDate,
|
|
121
130
|
useResponsive
|
|
122
131
|
};
|
package/dist/esm/locale.js
CHANGED
|
@@ -11,6 +11,19 @@ const STRINGS = {
|
|
|
11
11
|
close: "Close",
|
|
12
12
|
dismiss: "Dismiss",
|
|
13
13
|
dismissToast: "Dismiss notification",
|
|
14
|
+
showPassword: "Show password",
|
|
15
|
+
filters: "Filters",
|
|
16
|
+
search: "Search",
|
|
17
|
+
clearFilters: "Clear all",
|
|
18
|
+
results: function(n2) {
|
|
19
|
+
return n2 === 1 ? "1 result" : n2.toLocaleString("en") + " results";
|
|
20
|
+
},
|
|
21
|
+
commandMenu: "Command menu",
|
|
22
|
+
commandPlaceholder: "Type a command or search\u2026",
|
|
23
|
+
commandHint: "\u2191\u2193 to move \xB7 Enter to open \xB7 Esc to close",
|
|
24
|
+
errorSummary: function(n2) {
|
|
25
|
+
return n2 === 1 ? "Fix 1 field to continue" : "Fix " + n2 + " fields to continue";
|
|
26
|
+
},
|
|
14
27
|
notifications: "Notifications",
|
|
15
28
|
mainNav: "Main",
|
|
16
29
|
breadcrumb: "Breadcrumb",
|
|
@@ -109,6 +122,19 @@ const STRINGS = {
|
|
|
109
122
|
close: "\u0E1B\u0E34\u0E14",
|
|
110
123
|
dismiss: "\u0E1B\u0E34\u0E14",
|
|
111
124
|
dismissToast: "\u0E1B\u0E34\u0E14\u0E01\u0E32\u0E23\u0E41\u0E08\u0E49\u0E07\u0E40\u0E15\u0E37\u0E2D\u0E19",
|
|
125
|
+
showPassword: "\u0E41\u0E2A\u0E14\u0E07\u0E23\u0E2B\u0E31\u0E2A\u0E1C\u0E48\u0E32\u0E19",
|
|
126
|
+
filters: "\u0E15\u0E31\u0E27\u0E01\u0E23\u0E2D\u0E07",
|
|
127
|
+
search: "\u0E04\u0E49\u0E19\u0E2B\u0E32",
|
|
128
|
+
clearFilters: "\u0E25\u0E49\u0E32\u0E07\u0E17\u0E31\u0E49\u0E07\u0E2B\u0E21\u0E14",
|
|
129
|
+
results: function(n2) {
|
|
130
|
+
return n2.toLocaleString("en") + " \u0E23\u0E32\u0E22\u0E01\u0E32\u0E23";
|
|
131
|
+
},
|
|
132
|
+
commandMenu: "\u0E40\u0E21\u0E19\u0E39\u0E04\u0E33\u0E2A\u0E31\u0E48\u0E07",
|
|
133
|
+
commandPlaceholder: "\u0E1E\u0E34\u0E21\u0E1E\u0E4C\u0E04\u0E33\u0E2A\u0E31\u0E48\u0E07\u0E2B\u0E23\u0E37\u0E2D\u0E04\u0E49\u0E19\u0E2B\u0E32\u2026",
|
|
134
|
+
commandHint: "\u2191\u2193 \u0E40\u0E25\u0E37\u0E48\u0E2D\u0E19 \xB7 Enter \u0E40\u0E1B\u0E34\u0E14 \xB7 Esc \u0E1B\u0E34\u0E14",
|
|
135
|
+
errorSummary: function(n2) {
|
|
136
|
+
return "\u0E41\u0E01\u0E49\u0E44\u0E02 " + n2 + " \u0E0A\u0E48\u0E2D\u0E07\u0E01\u0E48\u0E2D\u0E19\u0E44\u0E1B\u0E15\u0E48\u0E2D";
|
|
137
|
+
},
|
|
112
138
|
notifications: "\u0E01\u0E32\u0E23\u0E41\u0E08\u0E49\u0E07\u0E40\u0E15\u0E37\u0E2D\u0E19",
|
|
113
139
|
mainNav: "\u0E40\u0E21\u0E19\u0E39\u0E2B\u0E25\u0E31\u0E01",
|
|
114
140
|
breadcrumb: "\u0E40\u0E2A\u0E49\u0E19\u0E17\u0E32\u0E07",
|
|
@@ -207,6 +233,19 @@ const STRINGS = {
|
|
|
207
233
|
close: "St\xE4ng",
|
|
208
234
|
dismiss: "St\xE4ng",
|
|
209
235
|
dismissToast: "St\xE4ng aviseringen",
|
|
236
|
+
showPassword: "Visa l\xF6senord",
|
|
237
|
+
filters: "Filter",
|
|
238
|
+
search: "S\xF6k",
|
|
239
|
+
clearFilters: "Rensa alla",
|
|
240
|
+
results: function(n2) {
|
|
241
|
+
return n2 === 1 ? "1 tr\xE4ff" : n2.toLocaleString("sv-SE") + " tr\xE4ffar";
|
|
242
|
+
},
|
|
243
|
+
commandMenu: "Kommandomeny",
|
|
244
|
+
commandPlaceholder: "Skriv ett kommando eller s\xF6k\u2026",
|
|
245
|
+
commandHint: "\u2191\u2193 flytta \xB7 Enter \xF6ppna \xB7 Esc st\xE4ng",
|
|
246
|
+
errorSummary: function(n2) {
|
|
247
|
+
return n2 === 1 ? "R\xE4tta 1 f\xE4lt f\xF6r att forts\xE4tta" : "R\xE4tta " + n2 + " f\xE4lt f\xF6r att forts\xE4tta";
|
|
248
|
+
},
|
|
210
249
|
notifications: "Aviseringar",
|
|
211
250
|
mainNav: "Huvudmeny",
|
|
212
251
|
breadcrumb: "Br\xF6dsmulor",
|