wimui 0.56.1 → 0.57.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/dist/components/ai/ThoughtProcess/ThoughtProcess.cjs +1 -1
- package/dist/components/ai/ThoughtProcess/ThoughtProcess.d.ts +10 -1
- package/dist/components/ai/ThoughtProcess/ThoughtProcess.js +12 -12
- package/dist/components/feedback/LoadingOverlay/LoadingOverlay.cjs +1 -1
- package/dist/components/feedback/LoadingOverlay/LoadingOverlay.js +0 -1
- package/dist/components/feedback/Toast/Toast.cjs +1 -1
- package/dist/components/feedback/Toast/Toast.js +1 -1
- package/dist/components/feedback/Toast/toast.module.cjs +1 -1
- package/dist/components/feedback/Toast/toast.module.js +8 -8
- package/dist/components/form/Cascader/Cascader.cjs +1 -1
- package/dist/components/form/Cascader/Cascader.d.ts +1 -1
- package/dist/components/form/Cascader/Cascader.js +54 -54
- package/dist/components/form/DateRangePicker/DateRangePicker.cjs +1 -1
- package/dist/components/form/DateRangePicker/DateRangePicker.d.ts +7 -1
- package/dist/components/form/DateRangePicker/DateRangePicker.js +9 -8
- package/dist/components/form/InlineEdit/InlineEdit.cjs +1 -1
- package/dist/components/form/InlineEdit/InlineEdit.js +33 -29
- package/dist/components/form/Mentions/Mentions.cjs +1 -1
- package/dist/components/form/Mentions/Mentions.js +62 -60
- package/dist/components/form/OtpInput/OtpInput.cjs +1 -1
- package/dist/components/form/OtpInput/OtpInput.js +36 -35
- package/dist/components/form/PhoneInput/PhoneInput.cjs +1 -1
- package/dist/components/form/PhoneInput/PhoneInput.d.ts +6 -0
- package/dist/components/form/PhoneInput/PhoneInput.js +59 -57
- package/dist/components/form/RangeSlider/RangeSlider.cjs +1 -1
- package/dist/components/form/RangeSlider/RangeSlider.d.ts +1 -1
- package/dist/components/form/RangeSlider/RangeSlider.js +66 -64
- package/dist/components/form/SegmentedControl/SegmentedControl.cjs +1 -1
- package/dist/components/form/SegmentedControl/SegmentedControl.d.ts +6 -0
- package/dist/components/form/SegmentedControl/SegmentedControl.js +18 -17
- package/dist/components/form/Slider/Slider.cjs +1 -1
- package/dist/components/form/Slider/Slider.js +44 -44
- package/dist/components/form/Transfer/Transfer.cjs +1 -1
- package/dist/components/form/Transfer/Transfer.d.ts +7 -1
- package/dist/components/form/Transfer/Transfer.js +50 -49
- package/dist/components/layout/Dashboard/Dashboard.cjs +1 -1
- package/dist/components/layout/Dashboard/Dashboard.d.ts +6 -1
- package/dist/components/layout/Dashboard/Dashboard.js +2 -2
- package/dist/llms-full.txt +21 -2
- package/dist/llms.txt +1 -1
- package/dist/styles.css +1 -1
- package/dist/wimui.umd.css +1 -1
- package/dist/wimui.umd.js +2 -2
- package/package.json +1 -1
|
@@ -9,38 +9,40 @@ import o, { useEffect as s, useRef as c, useState as l } from "react";
|
|
|
9
9
|
import u from "classnames";
|
|
10
10
|
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
11
11
|
//#region src/components/form/InlineEdit/InlineEdit.tsx
|
|
12
|
-
var p = o.forwardRef(({ value: o, defaultValue: p, onChange: m, onSave: h, onCancel: g, onEdit: _, placeholder: v, disabled: y = !1, fullWidth: b = !1, label: x, className: S, "aria-label": C,
|
|
13
|
-
let { t:
|
|
14
|
-
y || (
|
|
15
|
-
},
|
|
16
|
-
y || (
|
|
17
|
-
},
|
|
18
|
-
y || (
|
|
19
|
-
},
|
|
12
|
+
var p = o.forwardRef(({ value: o, defaultValue: p, onChange: m, onSave: h, onCancel: g, onEdit: _, placeholder: v, disabled: y = !1, fullWidth: b = !1, label: x, className: S, "aria-label": C, "aria-labelledby": w, "aria-describedby": T, ...E }, D) => {
|
|
13
|
+
let { t: O } = e(t), [k, A] = l(!1), [j, M] = l(p ?? ""), [N, P] = l(p ?? ""), F = c(null), I = o !== void 0, L = I ? o : N, R = () => {
|
|
14
|
+
y || (I || P(j), A(!0), _?.());
|
|
15
|
+
}, z = () => {
|
|
16
|
+
y || (I || M(L), A(!1), h?.(L));
|
|
17
|
+
}, B = () => {
|
|
18
|
+
y || (I || P(j), A(!1), g?.());
|
|
19
|
+
}, V = (e) => {
|
|
20
20
|
let t = e.target.value;
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
e.key === "Enter" ? (e.preventDefault(),
|
|
21
|
+
I || P(t), m?.(t);
|
|
22
|
+
}, H = (e) => {
|
|
23
|
+
e.key === "Enter" ? (e.preventDefault(), z()) : e.key === "Escape" && (e.preventDefault(), B());
|
|
24
24
|
};
|
|
25
25
|
return s(() => {
|
|
26
|
-
|
|
27
|
-
}, [
|
|
26
|
+
k && F.current && F.current.focus();
|
|
27
|
+
}, [k]), /* @__PURE__ */ d(n, {
|
|
28
28
|
label: x,
|
|
29
29
|
className: S,
|
|
30
30
|
children: /* @__PURE__ */ d("div", {
|
|
31
|
-
ref:
|
|
31
|
+
ref: D,
|
|
32
32
|
className: u("wim-inline-edit", a.root, b && a.fullWidth, y && a.disabled),
|
|
33
|
-
...
|
|
34
|
-
children:
|
|
33
|
+
...E,
|
|
34
|
+
children: k ? /* @__PURE__ */ f("div", {
|
|
35
35
|
className: a.editWrapper,
|
|
36
36
|
children: [/* @__PURE__ */ d(r, {
|
|
37
|
-
ref:
|
|
38
|
-
value:
|
|
39
|
-
onChange:
|
|
40
|
-
onKeyDown:
|
|
37
|
+
ref: F,
|
|
38
|
+
value: L,
|
|
39
|
+
onChange: V,
|
|
40
|
+
onKeyDown: H,
|
|
41
41
|
disabled: y,
|
|
42
42
|
placeholder: v,
|
|
43
43
|
"aria-label": C,
|
|
44
|
+
"aria-labelledby": w,
|
|
45
|
+
"aria-describedby": T,
|
|
44
46
|
fullWidth: b,
|
|
45
47
|
className: a.input
|
|
46
48
|
}), /* @__PURE__ */ f("div", {
|
|
@@ -49,31 +51,33 @@ var p = o.forwardRef(({ value: o, defaultValue: p, onChange: m, onSave: h, onCan
|
|
|
49
51
|
iconName: "CheckIcon",
|
|
50
52
|
intent: "success",
|
|
51
53
|
variant: "outline",
|
|
52
|
-
"aria-label":
|
|
53
|
-
onClick:
|
|
54
|
+
"aria-label": O("action.save"),
|
|
55
|
+
onClick: z,
|
|
54
56
|
disabled: y
|
|
55
57
|
}), /* @__PURE__ */ d(i, {
|
|
56
58
|
iconName: "CloseIcon",
|
|
57
59
|
intent: "default",
|
|
58
60
|
variant: "outline",
|
|
59
|
-
"aria-label":
|
|
60
|
-
onClick:
|
|
61
|
+
"aria-label": O("action.cancel"),
|
|
62
|
+
onClick: B,
|
|
61
63
|
disabled: y
|
|
62
64
|
})]
|
|
63
65
|
})]
|
|
64
66
|
}) : /* @__PURE__ */ f("div", {
|
|
65
67
|
className: a.preview,
|
|
66
|
-
onClick:
|
|
68
|
+
onClick: R,
|
|
67
69
|
onKeyDown: (e) => {
|
|
68
|
-
(e.key === "Enter" || e.key === " ") && (e.preventDefault(),
|
|
70
|
+
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), R());
|
|
69
71
|
},
|
|
70
72
|
tabIndex: y ? -1 : 0,
|
|
71
73
|
role: "button",
|
|
72
74
|
"aria-label": C,
|
|
75
|
+
"aria-labelledby": w,
|
|
76
|
+
"aria-describedby": T,
|
|
73
77
|
"aria-disabled": y,
|
|
74
78
|
children: [/* @__PURE__ */ d("span", {
|
|
75
|
-
className: u(a.text, !
|
|
76
|
-
children:
|
|
79
|
+
className: u(a.text, !L && a.placeholder),
|
|
80
|
+
children: L || v || "\xA0"
|
|
77
81
|
}), /* @__PURE__ */ d("span", {
|
|
78
82
|
className: a.editIconWrapper,
|
|
79
83
|
children: /* @__PURE__ */ d(i, {
|
|
@@ -81,7 +85,7 @@ var p = o.forwardRef(({ value: o, defaultValue: p, onChange: m, onSave: h, onCan
|
|
|
81
85
|
variant: "ghost",
|
|
82
86
|
size: "sm",
|
|
83
87
|
tabIndex: -1,
|
|
84
|
-
"aria-label":
|
|
88
|
+
"aria-label": O("action.edit"),
|
|
85
89
|
"aria-hidden": "true",
|
|
86
90
|
asChild: !0,
|
|
87
91
|
children: /* @__PURE__ */ d("span", {})
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../_internal/BaseListItem/BaseListItem.cjs"),r=require("../../_internal/mergeRefs.cjs"),i=require("../Textarea/Textarea.cjs"),a=require("./mentions.module.cjs");let o=require("react");o=e.__toESM(o,1);let s=require("react/jsx-runtime");var c=(0,o.forwardRef)(({options:e,trigger:c=`@`,value:l,defaultValue:
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../_internal/BaseListItem/BaseListItem.cjs"),r=require("../../_internal/mergeRefs.cjs"),i=require("../Textarea/Textarea.cjs"),a=require("./mentions.module.cjs");let o=require("react");o=e.__toESM(o,1);let s=require("react/jsx-runtime");var c=(0,o.forwardRef)(({options:e,trigger:c=`@`,value:l,defaultValue:ee,onChange:u,onSelect:d,asChild:f=!1,children:p,intent:m,variant:h,fullWidth:g,fieldSizing:_,label:v,error:y,required:te,layout:b,width:x,placeholder:S,rows:C,cols:w,onCopy:T,onCut:E,onPaste:D,...O},k)=>{let A=(0,o.useId)(),j=O.id||`wim-mentions-${A}`,[M,N]=(0,o.useState)(ee||``),P=l!==void 0,F=P?l:M,[I,L]=(0,o.useState)(!1),[R,z]=(0,o.useState)(``),[B,V]=(0,o.useState)(0),[H,U]=(0,o.useState)(-1),[W,G]=(0,o.useState)(0),K=(0,o.useRef)(null),q=(0,o.useRef)(null),J=r.mergeRefs(q,k),Y=e.filter(e=>e.display.toLowerCase().includes(R.toLowerCase())),X=e=>{let t=e.target.value,n=e.target.selectionStart;V(n),P||N(t),u&&u(e);let r=t.slice(0,n),i=r.lastIndexOf(c);if(i!==-1){let e=r.slice(i+c.length);if(!e.includes(` `)){U(i),z(e),L(!0),G(0);return}}L(!1),U(-1)},Z=e=>{let t=F.slice(0,H),n=F.slice(B),r=`${t}${c}${e.display} ${n}`;P||N(r),u&&u({target:{value:r}}),d&&d(e),L(!1),U(-1),setTimeout(()=>{if(K.current){K.current.focus();let n=t.length+c.length+e.display.length+1;K.current.setSelectionRange(n,n)}},0)},ne=e=>{I&&Y.length>0&&(e.key===`ArrowDown`?(e.preventDefault(),G(e=>e>=Y.length-1?0:e+1)):e.key===`ArrowUp`?(e.preventDefault(),G(e=>e<=0?Y.length-1:e-1)):e.key===`Enter`||e.key===`Tab`?W>=0&&Y[W]&&(e.preventDefault(),Z(Y[W])):e.key===`Escape`&&L(!1))},re=f?t.Root:`div`,Q={intent:m,variant:h,fullWidth:g,fieldSizing:_,label:v,error:y,required:te,layout:b,width:x,placeholder:S,rows:C,cols:w,onCopy:T,onCut:E,onPaste:D},$={...O};delete $[`aria-label`],delete $[`aria-labelledby`],delete $[`aria-describedby`];let ie=f?{...Q,...O}:$;return(0,s.jsxs)(re,{className:`wim-mentions ${a.default.container}`,ref:J,...ie,children:[(0,s.jsxs)(t.Slottable,{children:[(0,s.jsx)(i.Textarea,{...O,...Q,ref:K,value:F,onChange:X,onKeyDown:ne,"aria-autocomplete":`list`,"aria-controls":I?`${j}-list`:void 0,onBlur:e=>{q.current?.contains(e.relatedTarget)||L(!1)}}),I&&Y.length>0&&(0,s.jsx)(`div`,{id:`${j}-list`,className:a.default.list,role:`listbox`,children:Y.map((e,t)=>(0,s.jsx)(n.BaseListItem,{active:t===W,onMouseDown:e=>e.preventDefault(),onClick:()=>Z(e),onMouseEnter:()=>G(t),role:`option`,"aria-selected":t===W,tabIndex:-1,children:e.display},e.id))})]}),f?p:null]})});c.displayName=`Mentions`,exports.Mentions=c,exports.default=c;
|
|
@@ -4,86 +4,88 @@ import { BaseListItem as n } from "../../_internal/BaseListItem/BaseListItem.js"
|
|
|
4
4
|
import { mergeRefs as r } from "../../_internal/mergeRefs.js";
|
|
5
5
|
import { Textarea as i } from "../Textarea/Textarea.js";
|
|
6
6
|
import a from "./mentions.module.js";
|
|
7
|
-
import { forwardRef as o, useId as
|
|
8
|
-
import { jsx as
|
|
7
|
+
import { forwardRef as o, useId as ee, useRef as s, useState as c } from "react";
|
|
8
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
9
9
|
//#region src/components/form/Mentions/Mentions.tsx
|
|
10
|
-
var
|
|
11
|
-
let
|
|
10
|
+
var d = o(({ options: o, trigger: d = "@", value: f, defaultValue: te, onChange: p, onSelect: m, asChild: h = !1, children: g, intent: _, variant: v, fullWidth: y, fieldSizing: b, label: x, error: S, required: C, layout: w, width: T, placeholder: E, rows: D, cols: O, onCopy: k, onCut: ne, onPaste: re, ...A }, j) => {
|
|
11
|
+
let M = ee(), N = A.id || `wim-mentions-${M}`, [P, F] = c(te || ""), I = f !== void 0, L = I ? f : P, [R, z] = c(!1), [B, V] = c(""), [H, U] = c(0), [W, G] = c(-1), [K, q] = c(0), J = s(null), Y = s(null), ie = r(Y, j), X = o.filter((e) => e.display.toLowerCase().includes(B.toLowerCase())), ae = (e) => {
|
|
12
12
|
let t = e.target.value, n = e.target.selectionStart;
|
|
13
|
-
|
|
14
|
-
let r = t.slice(0, n), i = r.lastIndexOf(
|
|
13
|
+
U(n), I || F(t), p && p(e);
|
|
14
|
+
let r = t.slice(0, n), i = r.lastIndexOf(d);
|
|
15
15
|
if (i !== -1) {
|
|
16
|
-
let e = r.slice(i +
|
|
16
|
+
let e = r.slice(i + d.length);
|
|
17
17
|
if (!e.includes(" ")) {
|
|
18
|
-
|
|
18
|
+
G(i), V(e), z(!0), q(0);
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
let t =
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
let n = t.length +
|
|
29
|
-
|
|
22
|
+
z(!1), G(-1);
|
|
23
|
+
}, Z = (e) => {
|
|
24
|
+
let t = L.slice(0, W), n = L.slice(H), r = `${t}${d}${e.display} ${n}`;
|
|
25
|
+
I || F(r), p && p({ target: { value: r } }), m && m(e), z(!1), G(-1), setTimeout(() => {
|
|
26
|
+
if (J.current) {
|
|
27
|
+
J.current.focus();
|
|
28
|
+
let n = t.length + d.length + e.display.length + 1;
|
|
29
|
+
J.current.setSelectionRange(n, n);
|
|
30
30
|
}
|
|
31
31
|
}, 0);
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
intent:
|
|
36
|
-
variant:
|
|
37
|
-
fullWidth:
|
|
38
|
-
fieldSizing:
|
|
39
|
-
label:
|
|
40
|
-
error:
|
|
41
|
-
required:
|
|
42
|
-
layout:
|
|
43
|
-
width:
|
|
44
|
-
placeholder:
|
|
45
|
-
rows:
|
|
46
|
-
cols:
|
|
47
|
-
onCopy:
|
|
48
|
-
onCut:
|
|
49
|
-
onPaste:
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
32
|
+
}, oe = (e) => {
|
|
33
|
+
R && X.length > 0 && (e.key === "ArrowDown" ? (e.preventDefault(), q((e) => e >= X.length - 1 ? 0 : e + 1)) : e.key === "ArrowUp" ? (e.preventDefault(), q((e) => e <= 0 ? X.length - 1 : e - 1)) : e.key === "Enter" || e.key === "Tab" ? K >= 0 && X[K] && (e.preventDefault(), Z(X[K])) : e.key === "Escape" && z(!1));
|
|
34
|
+
}, se = h ? e : "div", Q = {
|
|
35
|
+
intent: _,
|
|
36
|
+
variant: v,
|
|
37
|
+
fullWidth: y,
|
|
38
|
+
fieldSizing: b,
|
|
39
|
+
label: x,
|
|
40
|
+
error: S,
|
|
41
|
+
required: C,
|
|
42
|
+
layout: w,
|
|
43
|
+
width: T,
|
|
44
|
+
placeholder: E,
|
|
45
|
+
rows: D,
|
|
46
|
+
cols: O,
|
|
47
|
+
onCopy: k,
|
|
48
|
+
onCut: ne,
|
|
49
|
+
onPaste: re
|
|
50
|
+
}, $ = { ...A };
|
|
51
|
+
delete $["aria-label"], delete $["aria-labelledby"], delete $["aria-describedby"];
|
|
52
|
+
let ce = h ? {
|
|
53
|
+
...Q,
|
|
54
|
+
...A
|
|
55
|
+
} : $;
|
|
56
|
+
return /* @__PURE__ */ u(se, {
|
|
55
57
|
className: `wim-mentions ${a.container}`,
|
|
56
|
-
ref:
|
|
57
|
-
...
|
|
58
|
-
children: [/* @__PURE__ */
|
|
59
|
-
...
|
|
60
|
-
|
|
61
|
-
ref:
|
|
62
|
-
value:
|
|
63
|
-
onChange:
|
|
64
|
-
onKeyDown:
|
|
58
|
+
ref: ie,
|
|
59
|
+
...ce,
|
|
60
|
+
children: [/* @__PURE__ */ u(t, { children: [/* @__PURE__ */ l(i, {
|
|
61
|
+
...A,
|
|
62
|
+
...Q,
|
|
63
|
+
ref: J,
|
|
64
|
+
value: L,
|
|
65
|
+
onChange: ae,
|
|
66
|
+
onKeyDown: oe,
|
|
65
67
|
"aria-autocomplete": "list",
|
|
66
|
-
"aria-controls":
|
|
68
|
+
"aria-controls": R ? `${N}-list` : void 0,
|
|
67
69
|
onBlur: (e) => {
|
|
68
|
-
|
|
70
|
+
Y.current?.contains(e.relatedTarget) || z(!1);
|
|
69
71
|
}
|
|
70
|
-
}),
|
|
71
|
-
id: `${
|
|
72
|
+
}), R && X.length > 0 && /* @__PURE__ */ l("div", {
|
|
73
|
+
id: `${N}-list`,
|
|
72
74
|
className: a.list,
|
|
73
75
|
role: "listbox",
|
|
74
|
-
children:
|
|
75
|
-
active: t ===
|
|
76
|
+
children: X.map((e, t) => /* @__PURE__ */ l(n, {
|
|
77
|
+
active: t === K,
|
|
76
78
|
onMouseDown: (e) => e.preventDefault(),
|
|
77
|
-
onClick: () =>
|
|
78
|
-
onMouseEnter: () =>
|
|
79
|
+
onClick: () => Z(e),
|
|
80
|
+
onMouseEnter: () => q(t),
|
|
79
81
|
role: "option",
|
|
80
|
-
"aria-selected": t ===
|
|
82
|
+
"aria-selected": t === K,
|
|
81
83
|
tabIndex: -1,
|
|
82
84
|
children: e.display
|
|
83
85
|
}, e.id))
|
|
84
|
-
})] }),
|
|
86
|
+
})] }), h ? g : null]
|
|
85
87
|
});
|
|
86
88
|
});
|
|
87
|
-
|
|
89
|
+
d.displayName = "Mentions";
|
|
88
90
|
//#endregion
|
|
89
|
-
export {
|
|
91
|
+
export { d as Mentions, d as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../FieldTemplate/FieldTemplate.cjs"),r=require("./otp-input.module.cjs");let i=require("react");i=e.__toESM(i,1);let a=require("classnames");a=e.__toESM(a,1);let o=require("react/jsx-runtime");var s=(e,t)=>{let n=e.split(``).slice(0,t);return Array(t).fill(``).map((e,t)=>n[t]??``)},c=(0,i.forwardRef)(({length:e=6,value:c=``,onChange:l,disabled:u=!1,error:d,required:f,label:p,layout:m,className:h,labels:g={},asChild:_=!1,fullWidth:v=!1,children:y,...
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../FieldTemplate/FieldTemplate.cjs"),r=require("./otp-input.module.cjs");let i=require("react");i=e.__toESM(i,1);let a=require("classnames");a=e.__toESM(a,1);let o=require("react/jsx-runtime");var s=(e,t)=>{let n=e.split(``).slice(0,t);return Array(t).fill(``).map((e,t)=>n[t]??``)},c=(0,i.forwardRef)(({length:e=6,value:c=``,onChange:l,disabled:u=!1,error:d,required:f,label:p,layout:m,className:h,labels:g={},asChild:_=!1,fullWidth:v=!1,children:y,"aria-label":b,"aria-labelledby":x,"aria-describedby":S,...C},w)=>{let{digitAriaLabel:T=e=>`Digit ${e}`}=g,[E,D]=(0,i.useState)(()=>s(c,e)),[O,k]=(0,i.useState)(c),A=(0,i.useRef)([]),j=`wim-otp-input-${(0,i.useId)()}`,M=p?`${j}-label`:void 0,N=d?`${j}-error`:void 0,P=M??x,F=[S,N].filter(Boolean).join(` `)||void 0;c!==O&&(k(c),D(s(c,e)));let I=e=>{let t=e.join(``);l&&l(t)},L=(t,n)=>{let r=t.target.value.slice(-1),i=[...E];i[n]=r,D(i),I(i),r&&n<e-1&&A.current[n+1]?.focus()},R=(t,n)=>{if(t.key===`Backspace`){if(!E[n]&&n>0){let e=[...E];e[n-1]=``,D(e),I(e),A.current[n-1]?.focus()}else if(E[n]){let e=[...E];e[n]=``,D(e),I(e)}}else t.key===`ArrowLeft`&&n>0?(t.preventDefault(),A.current[n-1]?.focus()):t.key===`ArrowRight`&&n<e-1&&(t.preventDefault(),A.current[n+1]?.focus())},z=t=>{t.preventDefault();let n=t.clipboardData.getData(`text`).slice(0,e).split(``),r=[...E];n.forEach((t,n)=>{n<e&&(r[n]=t)}),D(r),I(r);let i=Math.min(n.length,e-1);A.current[i]?.focus()},B=_?t.Root:`div`;return(0,o.jsx)(n.FieldTemplate,{label:p,error:d,required:f,layout:m,labelId:M,htmlFor:j,errorId:N,className:(0,a.default)(h,v&&r.default.fullWidth),children:(0,o.jsxs)(B,{className:(0,a.default)(`wim-otp-input`,r.default.root,v&&r.default.fullWidth),ref:w,...C,children:[(0,o.jsx)(t.Slottable,{children:(0,o.jsx)(`div`,{className:(0,a.default)(r.default.container,u&&r.default.disabled),role:`group`,"aria-labelledby":P,"aria-label":P?void 0:b,"data-testid":`otp-input-container`,"data-disabled":u,children:Array.from({length:e}).map((e,t)=>(0,o.jsx)(`input`,{id:t===0?j:void 0,ref:e=>{A.current[t]=e},"data-testid":`otp-input`,className:(0,a.default)(r.default.input,d&&r.default.danger,u&&r.default.disabled),type:`text`,maxLength:1,value:E[t],onChange:e=>L(e,t),onKeyDown:e=>R(e,t),onPaste:z,disabled:u,"aria-label":T(t+1),"aria-invalid":d?`true`:`false`,"aria-describedby":F,"aria-required":f?`true`:void 0},t))})}),y]})})});c.displayName=`OtpInput`,exports.OtpInput=c,exports.default=c;
|
|
@@ -9,70 +9,71 @@ import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
|
9
9
|
var d = (e, t) => {
|
|
10
10
|
let n = e.split("").slice(0, t);
|
|
11
11
|
return Array(t).fill("").map((e, t) => n[t] ?? "");
|
|
12
|
-
}, f = i(({ length: i = 6, value: f = "", onChange: p, disabled: m = !1, error: h, required: g, label: _, layout: v, className: y, labels: b = {}, asChild: x = !1, fullWidth: S = !1, children: C,
|
|
13
|
-
let { digitAriaLabel:
|
|
14
|
-
f !==
|
|
15
|
-
let
|
|
12
|
+
}, f = i(({ length: i = 6, value: f = "", onChange: p, disabled: m = !1, error: h, required: g, label: _, layout: v, className: y, labels: b = {}, asChild: x = !1, fullWidth: S = !1, children: C, "aria-label": w, "aria-labelledby": T, "aria-describedby": E, ...D }, O) => {
|
|
13
|
+
let { digitAriaLabel: k = (e) => `Digit ${e}` } = b, [A, j] = s(() => d(f, i)), [M, N] = s(f), P = o([]), F = `wim-otp-input-${a()}`, I = _ ? `${F}-label` : void 0, L = h ? `${F}-error` : void 0, R = I ?? T, z = [E, L].filter(Boolean).join(" ") || void 0;
|
|
14
|
+
f !== M && (N(f), j(d(f, i)));
|
|
15
|
+
let B = (e) => {
|
|
16
16
|
let t = e.join("");
|
|
17
17
|
p && p(t);
|
|
18
|
-
},
|
|
19
|
-
let n = e.target.value.slice(-1), r = [...
|
|
20
|
-
r[t] = n,
|
|
21
|
-
},
|
|
18
|
+
}, V = (e, t) => {
|
|
19
|
+
let n = e.target.value.slice(-1), r = [...A];
|
|
20
|
+
r[t] = n, j(r), B(r), n && t < i - 1 && P.current[t + 1]?.focus();
|
|
21
|
+
}, H = (e, t) => {
|
|
22
22
|
if (e.key === "Backspace") {
|
|
23
|
-
if (!
|
|
24
|
-
let e = [...
|
|
25
|
-
e[t - 1] = "",
|
|
26
|
-
} else if (
|
|
27
|
-
let e = [...
|
|
28
|
-
e[t] = "",
|
|
23
|
+
if (!A[t] && t > 0) {
|
|
24
|
+
let e = [...A];
|
|
25
|
+
e[t - 1] = "", j(e), B(e), P.current[t - 1]?.focus();
|
|
26
|
+
} else if (A[t]) {
|
|
27
|
+
let e = [...A];
|
|
28
|
+
e[t] = "", j(e), B(e);
|
|
29
29
|
}
|
|
30
|
-
} else e.key === "ArrowLeft" && t > 0 ? (e.preventDefault(),
|
|
31
|
-
},
|
|
30
|
+
} else e.key === "ArrowLeft" && t > 0 ? (e.preventDefault(), P.current[t - 1]?.focus()) : e.key === "ArrowRight" && t < i - 1 && (e.preventDefault(), P.current[t + 1]?.focus());
|
|
31
|
+
}, U = (e) => {
|
|
32
32
|
e.preventDefault();
|
|
33
|
-
let t = e.clipboardData.getData("text").slice(0, i).split(""), n = [...
|
|
33
|
+
let t = e.clipboardData.getData("text").slice(0, i).split(""), n = [...A];
|
|
34
34
|
t.forEach((e, t) => {
|
|
35
35
|
t < i && (n[t] = e);
|
|
36
|
-
}),
|
|
36
|
+
}), j(n), B(n);
|
|
37
37
|
let r = Math.min(t.length, i - 1);
|
|
38
|
-
|
|
39
|
-
},
|
|
38
|
+
P.current[r]?.focus();
|
|
39
|
+
}, W = x ? e : "div";
|
|
40
40
|
return /* @__PURE__ */ l(n, {
|
|
41
41
|
label: _,
|
|
42
42
|
error: h,
|
|
43
43
|
required: g,
|
|
44
44
|
layout: v,
|
|
45
|
-
labelId:
|
|
46
|
-
htmlFor:
|
|
47
|
-
errorId:
|
|
45
|
+
labelId: I,
|
|
46
|
+
htmlFor: F,
|
|
47
|
+
errorId: L,
|
|
48
48
|
className: c(y, S && r.fullWidth),
|
|
49
|
-
children: /* @__PURE__ */ u(
|
|
49
|
+
children: /* @__PURE__ */ u(W, {
|
|
50
50
|
className: c("wim-otp-input", r.root, S && r.fullWidth),
|
|
51
|
-
ref:
|
|
52
|
-
...
|
|
51
|
+
ref: O,
|
|
52
|
+
...D,
|
|
53
53
|
children: [/* @__PURE__ */ l(t, { children: /* @__PURE__ */ l("div", {
|
|
54
54
|
className: c(r.container, m && r.disabled),
|
|
55
55
|
role: "group",
|
|
56
|
-
"aria-labelledby":
|
|
56
|
+
"aria-labelledby": R,
|
|
57
|
+
"aria-label": R ? void 0 : w,
|
|
57
58
|
"data-testid": "otp-input-container",
|
|
58
59
|
"data-disabled": m,
|
|
59
60
|
children: Array.from({ length: i }).map((e, t) => /* @__PURE__ */ l("input", {
|
|
60
|
-
id: t === 0 ?
|
|
61
|
+
id: t === 0 ? F : void 0,
|
|
61
62
|
ref: (e) => {
|
|
62
|
-
|
|
63
|
+
P.current[t] = e;
|
|
63
64
|
},
|
|
64
65
|
"data-testid": "otp-input",
|
|
65
66
|
className: c(r.input, h && r.danger, m && r.disabled),
|
|
66
67
|
type: "text",
|
|
67
68
|
maxLength: 1,
|
|
68
|
-
value:
|
|
69
|
-
onChange: (e) =>
|
|
70
|
-
onKeyDown: (e) =>
|
|
71
|
-
onPaste:
|
|
69
|
+
value: A[t],
|
|
70
|
+
onChange: (e) => V(e, t),
|
|
71
|
+
onKeyDown: (e) => H(e, t),
|
|
72
|
+
onPaste: U,
|
|
72
73
|
disabled: m,
|
|
73
|
-
"aria-label":
|
|
74
|
+
"aria-label": k(t + 1),
|
|
74
75
|
"aria-invalid": h ? "true" : "false",
|
|
75
|
-
"aria-describedby":
|
|
76
|
+
"aria-describedby": z,
|
|
76
77
|
"aria-required": g ? "true" : void 0
|
|
77
78
|
}, t))
|
|
78
79
|
}) }), C]
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../layout/Transition/Transition.cjs"),r=require("../../../icon/chevron-down.cjs"),i=require("../../media/Icon/Icon.cjs"),a=require("../../../i18n/generated/form.cjs"),o=require("../FieldTemplate/FieldTemplate.cjs"),s=require("./phone-input.module.cjs");let c=require("react");c=e.__toESM(c,1);let l=require("classnames");l=e.__toESM(l,1);let u=require("react/jsx-runtime");var d=[{code:`US`,dialCode:`1`,flag:`🇺🇸`},{code:`JP`,dialCode:`81`,flag:`🇯🇵`},{code:`GB`,dialCode:`44`,flag:`🇬🇧`},{code:`AU`,dialCode:`61`,flag:`🇦🇺`},{code:`DE`,dialCode:`49`,flag:`🇩🇪`},{code:`FR`,dialCode:`33`,flag:`🇫🇷`},{code:`CN`,dialCode:`86`,flag:`🇨🇳`},{code:`KR`,dialCode:`82`,flag:`🇰🇷`},{code:`IN`,dialCode:`91`,flag:`🇮🇳`},{code:`BR`,dialCode:`55`,flag:`🇧🇷`}],f=(0,c.forwardRef)(({value:e=``,onChange:f,countryCode:p=`US`,onCountryChange:m,placeholder:h=`000-0000-0000`,disabled:g=!1,error:_,required:v=!1,label:y,layout:b=`vertical`,className:x,fullWidth:S=!1,...
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../layout/Transition/Transition.cjs"),r=require("../../../icon/chevron-down.cjs"),i=require("../../media/Icon/Icon.cjs"),a=require("../../../i18n/generated/form.cjs"),o=require("../FieldTemplate/FieldTemplate.cjs"),s=require("./phone-input.module.cjs");let c=require("react");c=e.__toESM(c,1);let l=require("classnames");l=e.__toESM(l,1);let u=require("react/jsx-runtime");var d=[{code:`US`,dialCode:`1`,flag:`🇺🇸`},{code:`JP`,dialCode:`81`,flag:`🇯🇵`},{code:`GB`,dialCode:`44`,flag:`🇬🇧`},{code:`AU`,dialCode:`61`,flag:`🇦🇺`},{code:`DE`,dialCode:`49`,flag:`🇩🇪`},{code:`FR`,dialCode:`33`,flag:`🇫🇷`},{code:`CN`,dialCode:`86`,flag:`🇨🇳`},{code:`KR`,dialCode:`82`,flag:`🇰🇷`},{code:`IN`,dialCode:`91`,flag:`🇮🇳`},{code:`BR`,dialCode:`55`,flag:`🇧🇷`}],f=(0,c.forwardRef)(({value:e=``,onChange:f,countryCode:p=`US`,onCountryChange:m,placeholder:h=`000-0000-0000`,disabled:g=!1,error:_,required:v=!1,label:y,layout:b=`vertical`,className:x,fullWidth:S=!1,"aria-label":C,"aria-labelledby":w,"aria-describedby":T,...E},D)=>{let O=`wim-phone-input-${(0,c.useId)()}`,k=y?`${O}-label`:void 0,{t:A}=t.useWimTranslation(a.formNs),j=A(`phone.select_country`),M=`${O}-countries`,N=e=>`${O}-country-${e}`,P=_?`${O}-error`:void 0,[F,I]=(0,c.useState)(!1),[L,R]=(0,c.useState)(-1),z=(0,c.useRef)(null),B=(0,c.useRef)(null),V=(0,c.useRef)({text:``,timer:null});(0,c.useEffect)(()=>{let e=e=>{z.current&&!z.current.contains(e.target)&&I(!1)};return F&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[F]);let H=d.find(e=>e.code===p)??d[0],U=e=>{f?.(e.target.value)},W=d.length-1,G=e=>{let t=d.findIndex(e=>e.code===H.code);R(e??Math.max(t,0)),I(!0)},K=e=>{let t=d[e];t&&(m?.(t.code),I(!1))},q=e=>A(`phone.countries.${e.code}`),J=e=>a.formNs.resources.en?.phone?.countries?.[e.code]??``,Y=(e,t)=>{let n=e.toLowerCase().replace(/^\+/,``);if(n===``)return-1;let r=/^[0-9]+$/.test(n),i=!r&&n.length>1&&n.split(``).every(e=>e===n[0]),a=i?n[0]:n,o=i||n.length===1?t+1:t,s=r?[e=>e.dialCode]:[e=>q(e).toLowerCase(),e=>J(e).toLowerCase(),e=>e.code.toLowerCase()];for(let e of s)for(let t=0;t<d.length;t++){let n=(Math.max(o,0)+t)%d.length;if(e(d[n]).startsWith(a))return n}return-1},X=e=>{let t=V.current;t.timer&&clearTimeout(t.timer),t.text+=e,t.timer=setTimeout(()=>{t.text=``,t.timer=null},500);let n=Y(t.text,F?L:-1);n<0||(F?R(n):G(n))},Z=e=>{if(!g)switch(e.key){case`ArrowDown`:case`ArrowUp`:if(e.preventDefault(),!F)G();else{let t=e.key===`ArrowDown`?1:-1;R(e=>(e+t+d.length)%d.length)}break;case`Home`:case`End`:e.preventDefault(),F?R(e.key===`Home`?0:W):G(e.key===`Home`?0:W);break;case`Enter`:case` `:e.preventDefault(),e.key===` `&&V.current.text!==``?X(` `):F?K(L):G();break;case`Escape`:F&&(e.preventDefault(),I(!1));break;case`Tab`:I(!1);break;default:e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&(e.preventDefault(),X(e.key))}};return(0,c.useEffect)(()=>{let e=V.current;return()=>{e.timer&&clearTimeout(e.timer)}},[]),(0,c.useEffect)(()=>{F&&L>=0&&(B.current?.querySelectorAll(`[role="option"]`)?.[L])?.scrollIntoView?.({block:`nearest`})},[L,F]),(0,u.jsx)(o.FieldTemplate,{label:y,labelId:k,htmlFor:O,required:v,error:_,errorId:P,layout:b,className:x,children:(0,u.jsxs)(`div`,{ref:z,className:(0,l.default)(`wim-phone-input`,s.default.root,S&&s.default.fullWidth,g&&s.default.disabled,_&&s.default.danger),"data-testid":`phone-input-root`,...E,children:[(0,u.jsxs)(`div`,{className:s.default.countryWrapper,children:[(0,u.jsxs)(`button`,{type:`button`,role:`combobox`,className:s.default.countryTrigger,onClick:()=>{g||(F?I(!1):G())},onKeyDown:Z,onKeyUp:e=>{e.key===` `&&e.preventDefault()},disabled:g,"aria-haspopup":`listbox`,"aria-expanded":F,"aria-controls":F?M:void 0,"aria-activedescendant":F&&L>=0?N(L):void 0,"aria-label":j,children:[(0,u.jsx)(`span`,{"aria-hidden":`true`,style:{fontSize:`1.2em`},children:H.flag}),(0,u.jsxs)(`span`,{children:[`+`,H.dialCode]}),(0,u.jsx)(i.Icon,{component:r.default,size:`sm`,className:(0,l.default)(s.default.chevron,F&&s.default.chevronOpen)})]}),(0,u.jsx)(n.Transition,{show:F,preset:`fade`,className:s.default.dropdown,children:(0,u.jsx)(`ul`,{ref:B,id:M,className:s.default.countryList,role:`listbox`,"aria-label":j,tabIndex:-1,onMouseDown:e=>e.preventDefault(),children:d.map((e,t)=>(0,u.jsxs)(`li`,{id:N(t),className:(0,l.default)(s.default.countryOption,t===L&&s.default.active,H.code===e.code&&s.default.selected),onMouseEnter:()=>R(t),onClick:()=>K(t),role:`option`,"aria-selected":H.code===e.code,children:[(0,u.jsx)(`span`,{"aria-hidden":`true`,children:e.flag}),(0,u.jsx)(`span`,{className:s.default.countryName,children:q(e)}),` `,(0,u.jsxs)(`span`,{className:s.default.countryCode,children:[`+`,e.dialCode]})]},e.code))})})]}),(0,u.jsx)(`div`,{className:s.default.divider,"aria-hidden":`true`}),(0,u.jsx)(`input`,{id:O,ref:D,type:`tel`,value:e,onChange:U,placeholder:h,disabled:g,className:s.default.number,"aria-invalid":!!_,"aria-label":y?void 0:C,"aria-labelledby":y?void 0:w,"aria-describedby":[T,P].filter(Boolean).join(` `)||void 0})]})})});f.displayName=`PhoneInput`,exports.PHONE_COUNTRIES=d,exports.PhoneInput=f;
|
|
@@ -31,6 +31,12 @@ export type PhoneInputProps = {
|
|
|
31
31
|
className?: string;
|
|
32
32
|
/** Whether to take full width of parent. */
|
|
33
33
|
fullWidth?: boolean;
|
|
34
|
+
/** Accessible name for the phone number input when no visible `label` is provided. */
|
|
35
|
+
"aria-label"?: string;
|
|
36
|
+
/** ID of the element that labels the phone number input when no visible `label` is provided. */
|
|
37
|
+
"aria-labelledby"?: string;
|
|
38
|
+
/** ID of the element that describes the phone number input. Announced together with the error message. */
|
|
39
|
+
"aria-describedby"?: string;
|
|
34
40
|
};
|
|
35
41
|
/**
|
|
36
42
|
* Component combining a country dial-code selector with a phone number input.
|