wimui 0.47.9 → 0.48.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/ModelSelector/ModelSelector.cjs +1 -1
- package/dist/components/ai/ModelSelector/ModelSelector.js +42 -27
- package/dist/components/feedback/Snackbar/snackbar.module.cjs +1 -1
- package/dist/components/feedback/Snackbar/snackbar.module.js +7 -7
- package/dist/components/form/PhoneInput/PhoneInput.cjs +1 -1
- package/dist/components/form/PhoneInput/PhoneInput.js +77 -76
- package/dist/i18n/generated/keys.d.ts +1 -1
- package/dist/i18n/generated/resources.cjs +1 -1
- package/dist/i18n/generated/resources.js +3 -0
- package/dist/llms-full.txt +1 -1
- package/dist/llms.txt +1 -1
- package/dist/locales/en/form.json +2 -1
- package/dist/locales/ja/form.json +2 -1
- package/dist/locales/pt/form.json +2 -1
- package/dist/styles.css +2 -2
- package/dist/wimui.umd.css +1 -1
- package/dist/wimui.umd.js +2 -2
- package/package.json +5 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../layout/Transition/Transition.cjs"),n=require("../../../icon/check.cjs"),r=require("../../../icon/chevron-down.cjs"),i=require("../../media/Icon/Icon.cjs"),a=require("./model-selector.module.cjs");let o=require("react");o=e.__toESM(o,1);let s=require("classnames");s=e.__toESM(s,1);let c=require("react/jsx-runtime");var l=e=>e>=1e6?`${(e/1e6).toFixed(e%1e6==0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(e%1e3==0?0:1)}K`:String(e),u=(e,t=`$`)=>`${t}${e}`,d=o.default.forwardRef(({models:e,value:d,defaultValue:f,onChange:p,size:m=`md`,disabled:h=!1,fullWidth:g=!1,showPricing:_=!0,showContext:v=!0,labels:y,className:b,...x},S)=>{let{placeholder:C=`Select a model`,contextLabel:w=`Context`,inputLabel:T=`In`,outputLabel:E=`Out`,perTokensLabel:D=`/1M`,triggerAriaLabel:O=`Select a model`}=y??{},k=d!==void 0,[A,j]=(0,o.useState)(f),M=k?d:A,N=e.find(e=>e.id===M),[P,F]=(0,o.useState)(!1),[I,L]=(0,o.useState)(-1),R=(0,o.useRef)(null),z=(0,o.useRef)(null),B=(0,o.useId)(),V=`${B}-listbox`,H=(0,o.useCallback)(e=>{R.current=e,typeof S==`function`?S(e):S&&(S.current=e)},[S]);(0,o.useEffect)(()=>{if(!P)return;let e=e=>{R.current&&!R.current.contains(e.target)&&F(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[P]);let U=e=>{e.disabled||(k||j(e.id),p?.(e.id,e),F(!1))},W=t=>{
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../layout/Transition/Transition.cjs"),n=require("../../../icon/check.cjs"),r=require("../../../icon/chevron-down.cjs"),i=require("../../media/Icon/Icon.cjs"),a=require("./model-selector.module.cjs");let o=require("react");o=e.__toESM(o,1);let s=require("classnames");s=e.__toESM(s,1);let c=require("react/jsx-runtime");var l=e=>e>=1e6?`${(e/1e6).toFixed(e%1e6==0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(e%1e3==0?0:1)}K`:String(e),u=(e,t=`$`)=>`${t}${e}`,d=o.default.forwardRef(({models:e,value:d,defaultValue:f,onChange:p,size:m=`md`,disabled:h=!1,fullWidth:g=!1,showPricing:_=!0,showContext:v=!0,labels:y,className:b,...x},S)=>{let{placeholder:C=`Select a model`,contextLabel:w=`Context`,inputLabel:T=`In`,outputLabel:E=`Out`,perTokensLabel:D=`/1M`,triggerAriaLabel:O=`Select a model`}=y??{},k=d!==void 0,[A,j]=(0,o.useState)(f),M=k?d:A,N=e.find(e=>e.id===M),[P,F]=(0,o.useState)(!1),[I,L]=(0,o.useState)(-1),R=(0,o.useRef)(null),z=(0,o.useRef)(null),B=(0,o.useId)(),V=`${B}-listbox`,H=(0,o.useCallback)(e=>{R.current=e,typeof S==`function`?S(e):S&&(S.current=e)},[S]);(0,o.useEffect)(()=>{if(!P)return;let e=e=>{R.current&&!R.current.contains(e.target)&&F(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[P]);let U=e=>{e.disabled||(k||j(e.id),p?.(e.id,e),F(!1))},W=(t,n)=>{let r=t;for(let t=0;t<e.length;t++){if(!e[r]?.disabled)return r;r=(r+n+e.length)%e.length}return-1},G=t=>{let n=e.findIndex(e=>e.id===M);L(t??(n>=0?n:W(0,1))),F(!0)},K=t=>{L(n=>{let r=n;for(let n=0;n<e.length&&(r=(r+t+e.length)%e.length,e[r]?.disabled);n++);return r})},q=t=>{if(!h)switch(t.key){case`ArrowDown`:case`ArrowUp`:t.preventDefault(),P?K(t.key===`ArrowDown`?1:-1):G();break;case`Home`:case`End`:t.preventDefault(),t.key===`Home`?P?L(W(0,1)):G(W(0,1)):P?L(W(e.length-1,-1)):G(W(e.length-1,-1));break;case`Enter`:case` `:if(t.preventDefault(),!P)G();else{let t=e[I];t&&U(t)}break;case`Escape`:P&&(t.preventDefault(),F(!1));break;case`Tab`:F(!1)}};(0,o.useEffect)(()=>{P&&I>=0&&(z.current?.querySelectorAll(`[role="option"]`)?.[I])?.scrollIntoView({block:`nearest`})},[I,P]);let J=e=>{let t=[];if(v&&e.contextLength&&t.push((0,c.jsxs)(`span`,{className:a.default.meta,children:[w,` `,l(e.contextLength)]},`ctx`)),_&&e.pricing){let{input:n,output:r,currency:i}=e.pricing;n!==void 0&&t.push((0,c.jsxs)(`span`,{className:a.default.meta,children:[T,` `,u(n,i),D]},`in`)),r!==void 0&&t.push((0,c.jsxs)(`span`,{className:a.default.meta,children:[E,` `,u(r,i),D]},`out`))}return t.length===0?null:(0,c.jsx)(`span`,{className:a.default.metaRow,children:t})};return(0,c.jsxs)(`div`,{ref:H,className:(0,s.default)(`wim-model-selector`,a.default.root,a.default[m],g&&a.default.fullWidth,h&&a.default.disabled,b),...x,children:[(0,c.jsxs)(`button`,{type:`button`,role:`combobox`,className:a.default.trigger,"aria-haspopup":`listbox`,"aria-expanded":P,"aria-controls":P?V:void 0,"aria-activedescendant":P&&I>=0?`${B}-opt-${I}`:void 0,"aria-label":O,disabled:h,onClick:()=>{h||(P?F(!1):G())},onKeyDown:q,onKeyUp:e=>{e.key===` `&&e.preventDefault()},children:[(0,c.jsx)(`span`,{className:a.default.triggerLabel,children:N?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`span`,{className:a.default.triggerName,children:N.name}),N.badge&&(0,c.jsx)(`span`,{className:a.default.badge,children:N.badge})]}):(0,c.jsx)(`span`,{className:a.default.placeholder,children:C})}),(0,c.jsx)(i.Icon,{component:r.default,size:`sm`,className:(0,s.default)(a.default.chevron,P&&a.default.chevronOpen)})]}),(0,c.jsx)(t.Transition,{show:P,preset:`scale`,unmount:!0,className:a.default.dropdownWrapper,children:(0,c.jsx)(`ul`,{ref:z,id:V,role:`listbox`,"aria-label":O,className:a.default.dropdown,onMouseDown:e=>e.preventDefault(),children:e.map((e,t)=>{let r=e.id===M;return(0,c.jsxs)(`li`,{id:`${B}-opt-${t}`,role:`option`,"aria-selected":r,"aria-disabled":e.disabled||void 0,className:(0,s.default)(a.default.option,t===I&&a.default.active,e.disabled&&a.default.optionDisabled),onMouseEnter:()=>L(t),onClick:()=>U(e),children:[(0,c.jsx)(`span`,{className:a.default.check,"aria-hidden":`true`,children:r&&(0,c.jsx)(i.Icon,{component:n.default,size:`sm`})}),(0,c.jsxs)(`span`,{className:a.default.optionBody,children:[(0,c.jsxs)(`span`,{className:a.default.optionHeader,children:[(0,c.jsx)(`span`,{className:a.default.optionName,children:e.name}),e.badge&&(0,c.jsx)(`span`,{className:a.default.badge,children:e.badge})]}),e.description&&(0,c.jsx)(`span`,{className:a.default.description,children:e.description}),J(e)]})]},e.id)})})})]})});d.displayName=`ModelSelector`,exports.ModelSelector=d;
|
|
@@ -21,35 +21,50 @@ var h = (e) => e >= 1e6 ? `${(e / 1e6).toFixed(e % 1e6 == 0 ? 0 : 1)}M` : e >= 1
|
|
|
21
21
|
}, [B]);
|
|
22
22
|
let Y = (e) => {
|
|
23
23
|
e.disabled || (F || L(e.id), y?.(e.id, e), V(!1));
|
|
24
|
-
}, X = (e) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let e = a.findIndex((e) => e.id === R);
|
|
30
|
-
U(e >= 0 ? e : 0);
|
|
31
|
-
}
|
|
32
|
-
} else e.key === "Escape" && V(!1);
|
|
24
|
+
}, X = (e, t) => {
|
|
25
|
+
let n = e;
|
|
26
|
+
for (let e = 0; e < a.length; e++) {
|
|
27
|
+
if (!a[n]?.disabled) return n;
|
|
28
|
+
n = (n + t + a.length) % a.length;
|
|
33
29
|
}
|
|
30
|
+
return -1;
|
|
34
31
|
}, Z = (e) => {
|
|
32
|
+
let t = a.findIndex((e) => e.id === R);
|
|
33
|
+
U(e ?? (t >= 0 ? t : X(0, 1))), V(!0);
|
|
34
|
+
}, Q = (e) => {
|
|
35
35
|
U((t) => {
|
|
36
36
|
let n = t;
|
|
37
37
|
for (let t = 0; t < a.length && (n = (n + e + a.length) % a.length, a[n]?.disabled); t++);
|
|
38
38
|
return n;
|
|
39
39
|
});
|
|
40
|
-
},
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
}, $ = (e) => {
|
|
41
|
+
if (!x) switch (e.key) {
|
|
42
|
+
case "ArrowDown":
|
|
43
|
+
case "ArrowUp":
|
|
44
|
+
e.preventDefault(), B ? Q(e.key === "ArrowDown" ? 1 : -1) : Z();
|
|
45
|
+
break;
|
|
46
|
+
case "Home":
|
|
47
|
+
case "End":
|
|
48
|
+
e.preventDefault(), e.key === "Home" ? B ? U(X(0, 1)) : Z(X(0, 1)) : B ? U(X(a.length - 1, -1)) : Z(X(a.length - 1, -1));
|
|
49
|
+
break;
|
|
50
|
+
case "Enter":
|
|
51
|
+
case " ":
|
|
52
|
+
if (e.preventDefault(), !B) Z();
|
|
53
|
+
else {
|
|
54
|
+
let e = a[H];
|
|
55
|
+
e && Y(e);
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case "Escape":
|
|
59
|
+
B && (e.preventDefault(), V(!1));
|
|
60
|
+
break;
|
|
61
|
+
case "Tab": V(!1);
|
|
62
|
+
}
|
|
48
63
|
};
|
|
49
64
|
s(() => {
|
|
50
65
|
B && H >= 0 && (G.current?.querySelectorAll("[role=\"option\"]")?.[H])?.scrollIntoView({ block: "nearest" });
|
|
51
66
|
}, [H, B]);
|
|
52
|
-
let
|
|
67
|
+
let ee = (e) => {
|
|
53
68
|
let t = [];
|
|
54
69
|
if (w && e.contextLength && t.push(/* @__PURE__ */ m("span", {
|
|
55
70
|
className: i.meta,
|
|
@@ -89,19 +104,21 @@ var h = (e) => e >= 1e6 ? `${(e / 1e6).toFixed(e % 1e6 == 0 ? 0 : 1)}M` : e >= 1
|
|
|
89
104
|
...D,
|
|
90
105
|
children: [/* @__PURE__ */ m("button", {
|
|
91
106
|
type: "button",
|
|
107
|
+
role: "combobox",
|
|
92
108
|
className: i.trigger,
|
|
93
109
|
"aria-haspopup": "listbox",
|
|
94
110
|
"aria-expanded": B,
|
|
95
111
|
"aria-controls": B ? q : void 0,
|
|
112
|
+
"aria-activedescendant": B && H >= 0 ? `${K}-opt-${H}` : void 0,
|
|
96
113
|
"aria-label": P,
|
|
97
114
|
disabled: x,
|
|
98
115
|
onClick: () => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
116
|
+
x || (B ? V(!1) : Z());
|
|
117
|
+
},
|
|
118
|
+
onKeyDown: $,
|
|
119
|
+
onKeyUp: (e) => {
|
|
120
|
+
e.key === " " && e.preventDefault();
|
|
103
121
|
},
|
|
104
|
-
onKeyDown: X,
|
|
105
122
|
children: [/* @__PURE__ */ p("span", {
|
|
106
123
|
className: i.triggerLabel,
|
|
107
124
|
children: z ? /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("span", {
|
|
@@ -129,10 +146,8 @@ var h = (e) => e >= 1e6 ? `${(e / 1e6).toFixed(e % 1e6 == 0 ? 0 : 1)}M` : e >= 1
|
|
|
129
146
|
id: q,
|
|
130
147
|
role: "listbox",
|
|
131
148
|
"aria-label": P,
|
|
132
|
-
tabIndex: 0,
|
|
133
149
|
className: i.dropdown,
|
|
134
|
-
|
|
135
|
-
"aria-activedescendant": H >= 0 ? `${K}-opt-${H}` : void 0,
|
|
150
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
136
151
|
children: a.map((e, n) => {
|
|
137
152
|
let a = e.id === R;
|
|
138
153
|
return /* @__PURE__ */ m("li", {
|
|
@@ -167,7 +182,7 @@ var h = (e) => e >= 1e6 ? `${(e / 1e6).toFixed(e % 1e6 == 0 ? 0 : 1)}M` : e >= 1
|
|
|
167
182
|
className: i.description,
|
|
168
183
|
children: e.description
|
|
169
184
|
}),
|
|
170
|
-
|
|
185
|
+
ee(e)
|
|
171
186
|
]
|
|
172
187
|
})]
|
|
173
188
|
}, e.id);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var e=`
|
|
2
|
+
var e=`_wrapper_1n28t_3`,t=`_root_1n28t_41`,n=`_hasCloseButton_1n28t_64`,r=`_visible_1n28t_79`,i=`_content_1n28t_83`,a=`_icon_1n28t_89`,o=`_message_1n28t_97`,s=`_actions_1n28t_102`,c=`_actionButton_1n28t_108`,l=`_closeButton_1n28t_112`,u=`_success_1n28t_140`,d=`_danger_1n28t_144`,f=`_warning_1n28t_148`,p=`_info_1n28t_153`,m={wrapper:e,"top-left":`_top-left_1n28t_11`,"top-center":`_top-center_1n28t_16`,"top-right":`_top-right_1n28t_21`,"bottom-left":`_bottom-left_1n28t_26`,"bottom-center":`_bottom-center_1n28t_31`,"bottom-right":`_bottom-right_1n28t_36`,root:t,hasCloseButton:n,visible:r,content:i,icon:a,message:o,actions:s,actionButton:c,closeButton:l,success:u,danger:d,warning:f,info:p};exports.actionButton=c,exports.actions=s,exports.closeButton=l,exports.content=i,exports.danger=d,exports.default=m,exports.hasCloseButton=n,exports.icon=a,exports.info=p,exports.message=o,exports.root=t,exports.success=u,exports.visible=r,exports.warning=f,exports.wrapper=e;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
//#region src/components/feedback/Snackbar/snackbar.module.scss
|
|
3
|
-
var e = "
|
|
3
|
+
var e = "_wrapper_1n28t_3", t = "_root_1n28t_41", n = "_hasCloseButton_1n28t_64", r = "_visible_1n28t_79", i = "_content_1n28t_83", a = "_icon_1n28t_89", o = "_message_1n28t_97", s = "_actions_1n28t_102", c = "_actionButton_1n28t_108", l = "_closeButton_1n28t_112", u = "_success_1n28t_140", d = "_danger_1n28t_144", f = "_warning_1n28t_148", p = "_info_1n28t_153", m = {
|
|
4
4
|
wrapper: e,
|
|
5
|
-
"top-left": "_top-
|
|
6
|
-
"top-center": "_top-
|
|
7
|
-
"top-right": "_top-
|
|
8
|
-
"bottom-left": "_bottom-
|
|
9
|
-
"bottom-center": "_bottom-
|
|
10
|
-
"bottom-right": "_bottom-
|
|
5
|
+
"top-left": "_top-left_1n28t_11",
|
|
6
|
+
"top-center": "_top-center_1n28t_16",
|
|
7
|
+
"top-right": "_top-right_1n28t_21",
|
|
8
|
+
"bottom-left": "_bottom-left_1n28t_26",
|
|
9
|
+
"bottom-center": "_bottom-center_1n28t_31",
|
|
10
|
+
"bottom-right": "_bottom-right_1n28t_36",
|
|
11
11
|
root: t,
|
|
12
12
|
hasCloseButton: n,
|
|
13
13
|
visible: r,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../layout/Transition/Transition.cjs"),
|
|
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("../FieldTemplate/FieldTemplate.cjs"),o=require("./phone-input.module.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("classnames");c=e.__toESM(c,1);let l=require("react/jsx-runtime");var u=[{code:`US`,name:`United States`,dialCode:`1`,flag:`🇺🇸`},{code:`JP`,name:`Japan`,dialCode:`81`,flag:`🇯🇵`},{code:`GB`,name:`United Kingdom`,dialCode:`44`,flag:`🇬🇧`},{code:`AU`,name:`Australia`,dialCode:`61`,flag:`🇦🇺`},{code:`DE`,name:`Germany`,dialCode:`49`,flag:`🇩🇪`},{code:`FR`,name:`France`,dialCode:`33`,flag:`🇫🇷`},{code:`CN`,name:`China`,dialCode:`86`,flag:`🇨🇳`},{code:`KR`,name:`South Korea`,dialCode:`82`,flag:`🇰🇷`},{code:`IN`,name:`India`,dialCode:`91`,flag:`🇮🇳`},{code:`BR`,name:`Brazil`,dialCode:`55`,flag:`🇧🇷`}],d=(0,s.forwardRef)(({value:e=``,onChange:d,countryCode:f=`US`,onCountryChange:p,placeholder:m=`000-0000-0000`,disabled:h=!1,error:g,required:_=!1,label:v,layout:y=`vertical`,className:b,fullWidth:x=!1,...S},C)=>{let w=`wim-phone-input-${(0,s.useId)()}`,T=v?`${w}-label`:void 0,{t:E}=t.useWimTranslation(`form`),D=v?void 0:E(`phone.select_country`),O=g?`${w}-error`:void 0,[k,A]=(0,s.useState)(!1),j=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{j.current&&!j.current.contains(e.target)&&A(!1)};return k&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[k]);let M=u.find(e=>e.code===f)??u[0],N=e=>{d?.(e.target.value)};return(0,l.jsx)(a.FieldTemplate,{label:v,labelId:T,htmlFor:w,required:_,error:g,errorId:O,layout:y,className:b,children:(0,l.jsxs)(`div`,{ref:j,className:(0,c.default)(`wim-phone-input`,o.default.root,x&&o.default.fullWidth,h&&o.default.disabled,g&&o.default.danger),"data-testid":`phone-input-root`,...S,children:[(0,l.jsxs)(`div`,{className:o.default.countryWrapper,children:[(0,l.jsxs)(`button`,{type:`button`,className:o.default.countryTrigger,onClick:()=>!h&&A(!k),disabled:h,"aria-haspopup":`listbox`,"aria-expanded":k,"aria-labelledby":T,"aria-label":D,children:[(0,l.jsx)(`span`,{"aria-hidden":`true`,style:{fontSize:`1.2em`},children:M.flag}),(0,l.jsxs)(`span`,{children:[`+`,M.dialCode]}),(0,l.jsx)(i.Icon,{component:r.default,size:`sm`,className:(0,c.default)(o.default.chevron,k&&o.default.chevronOpen)})]}),(0,l.jsx)(n.Transition,{show:k,preset:`fade`,className:o.default.dropdown,children:(0,l.jsx)(`ul`,{className:o.default.countryList,role:`listbox`,"aria-labelledby":v?T:void 0,"aria-label":D,children:u.map(e=>(0,l.jsxs)(`li`,{className:(0,c.default)(o.default.countryOption,M.code===e.code&&o.default.selected),onClick:()=>{p?.(e.code),A(!1)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),p?.(e.code),A(!1))},tabIndex:0,role:`option`,"aria-selected":M.code===e.code,children:[(0,l.jsx)(`span`,{"aria-hidden":`true`,children:e.flag}),(0,l.jsx)(`span`,{className:o.default.countryName,children:e.name}),(0,l.jsxs)(`span`,{className:o.default.countryCode,children:[`+`,e.dialCode]})]},e.code))})})]}),(0,l.jsx)(`div`,{className:o.default.divider,"aria-hidden":`true`}),(0,l.jsx)(`input`,{id:w,ref:C,type:`tel`,value:e,onChange:N,placeholder:m,disabled:h,className:o.default.number,"aria-invalid":!!g,"aria-describedby":O})]})})});d.displayName=`PhoneInput`,exports.PHONE_COUNTRIES=u,exports.PhoneInput=d;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import t from "
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import i from "
|
|
7
|
-
import
|
|
8
|
-
import u from "
|
|
9
|
-
import
|
|
2
|
+
import { useWimTranslation as e } from "../../../i18n/useWimTranslation.js";
|
|
3
|
+
import { Transition as t } from "../../layout/Transition/Transition.js";
|
|
4
|
+
import n from "../../../icon/chevron-down.js";
|
|
5
|
+
import { Icon as r } from "../../media/Icon/Icon.js";
|
|
6
|
+
import { FieldTemplate as i } from "../FieldTemplate/FieldTemplate.js";
|
|
7
|
+
import a from "./phone-input.module.js";
|
|
8
|
+
import { forwardRef as o, useEffect as s, useId as c, useRef as l, useState as u } from "react";
|
|
9
|
+
import d from "classnames";
|
|
10
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
10
11
|
//#region src/components/form/PhoneInput/PhoneInput.tsx
|
|
11
|
-
var
|
|
12
|
+
var m = [
|
|
12
13
|
{
|
|
13
14
|
code: "US",
|
|
14
15
|
name: "United States",
|
|
@@ -69,89 +70,89 @@ var p = [
|
|
|
69
70
|
dialCode: "55",
|
|
70
71
|
flag: "🇧🇷"
|
|
71
72
|
}
|
|
72
|
-
],
|
|
73
|
-
let
|
|
74
|
-
|
|
73
|
+
], h = o(({ value: o = "", onChange: h, countryCode: g = "US", onCountryChange: _, placeholder: v = "000-0000-0000", disabled: y = !1, error: b, required: x = !1, label: S, layout: C = "vertical", className: w, fullWidth: T = !1, ...E }, D) => {
|
|
74
|
+
let O = `wim-phone-input-${c()}`, k = S ? `${O}-label` : void 0, { t: A } = e("form"), j = S ? void 0 : A("phone.select_country"), M = b ? `${O}-error` : void 0, [N, P] = u(!1), F = l(null);
|
|
75
|
+
s(() => {
|
|
75
76
|
let e = (e) => {
|
|
76
|
-
|
|
77
|
+
F.current && !F.current.contains(e.target) && P(!1);
|
|
77
78
|
};
|
|
78
|
-
return
|
|
79
|
+
return N && document.addEventListener("mousedown", e), () => {
|
|
79
80
|
document.removeEventListener("mousedown", e);
|
|
80
81
|
};
|
|
81
|
-
}, [
|
|
82
|
-
let
|
|
83
|
-
|
|
82
|
+
}, [N]);
|
|
83
|
+
let I = m.find((e) => e.code === g) ?? m[0], L = (e) => {
|
|
84
|
+
h?.(e.target.value);
|
|
84
85
|
};
|
|
85
|
-
return /* @__PURE__ */
|
|
86
|
-
label:
|
|
87
|
-
labelId:
|
|
88
|
-
htmlFor:
|
|
89
|
-
required:
|
|
90
|
-
error:
|
|
91
|
-
errorId:
|
|
92
|
-
layout:
|
|
93
|
-
className:
|
|
94
|
-
children: /* @__PURE__ */
|
|
95
|
-
ref:
|
|
96
|
-
className:
|
|
86
|
+
return /* @__PURE__ */ f(i, {
|
|
87
|
+
label: S,
|
|
88
|
+
labelId: k,
|
|
89
|
+
htmlFor: O,
|
|
90
|
+
required: x,
|
|
91
|
+
error: b,
|
|
92
|
+
errorId: M,
|
|
93
|
+
layout: C,
|
|
94
|
+
className: w,
|
|
95
|
+
children: /* @__PURE__ */ p("div", {
|
|
96
|
+
ref: F,
|
|
97
|
+
className: d("wim-phone-input", a.root, T && a.fullWidth, y && a.disabled, b && a.danger),
|
|
97
98
|
"data-testid": "phone-input-root",
|
|
98
|
-
...
|
|
99
|
+
...E,
|
|
99
100
|
children: [
|
|
100
|
-
/* @__PURE__ */
|
|
101
|
-
className:
|
|
102
|
-
children: [/* @__PURE__ */
|
|
101
|
+
/* @__PURE__ */ p("div", {
|
|
102
|
+
className: a.countryWrapper,
|
|
103
|
+
children: [/* @__PURE__ */ p("button", {
|
|
103
104
|
type: "button",
|
|
104
|
-
className:
|
|
105
|
-
onClick: () => !
|
|
106
|
-
disabled:
|
|
105
|
+
className: a.countryTrigger,
|
|
106
|
+
onClick: () => !y && P(!N),
|
|
107
|
+
disabled: y,
|
|
107
108
|
"aria-haspopup": "listbox",
|
|
108
|
-
"aria-expanded":
|
|
109
|
-
"aria-labelledby":
|
|
110
|
-
"aria-label":
|
|
109
|
+
"aria-expanded": N,
|
|
110
|
+
"aria-labelledby": k,
|
|
111
|
+
"aria-label": j,
|
|
111
112
|
children: [
|
|
112
|
-
/* @__PURE__ */
|
|
113
|
+
/* @__PURE__ */ f("span", {
|
|
113
114
|
"aria-hidden": "true",
|
|
114
115
|
style: { fontSize: "1.2em" },
|
|
115
|
-
children:
|
|
116
|
+
children: I.flag
|
|
116
117
|
}),
|
|
117
|
-
/* @__PURE__ */
|
|
118
|
-
/* @__PURE__ */
|
|
119
|
-
component:
|
|
118
|
+
/* @__PURE__ */ p("span", { children: ["+", I.dialCode] }),
|
|
119
|
+
/* @__PURE__ */ f(r, {
|
|
120
|
+
component: n,
|
|
120
121
|
size: "sm",
|
|
121
|
-
className:
|
|
122
|
+
className: d(a.chevron, N && a.chevronOpen)
|
|
122
123
|
})
|
|
123
124
|
]
|
|
124
|
-
}), /* @__PURE__ */
|
|
125
|
-
show:
|
|
125
|
+
}), /* @__PURE__ */ f(t, {
|
|
126
|
+
show: N,
|
|
126
127
|
preset: "fade",
|
|
127
|
-
className:
|
|
128
|
-
children: /* @__PURE__ */
|
|
129
|
-
className:
|
|
128
|
+
className: a.dropdown,
|
|
129
|
+
children: /* @__PURE__ */ f("ul", {
|
|
130
|
+
className: a.countryList,
|
|
130
131
|
role: "listbox",
|
|
131
|
-
"aria-labelledby":
|
|
132
|
-
"aria-label":
|
|
133
|
-
children:
|
|
134
|
-
className:
|
|
132
|
+
"aria-labelledby": S ? k : void 0,
|
|
133
|
+
"aria-label": j,
|
|
134
|
+
children: m.map((e) => /* @__PURE__ */ p("li", {
|
|
135
|
+
className: d(a.countryOption, I.code === e.code && a.selected),
|
|
135
136
|
onClick: () => {
|
|
136
|
-
|
|
137
|
+
_?.(e.code), P(!1);
|
|
137
138
|
},
|
|
138
139
|
onKeyDown: (t) => {
|
|
139
|
-
(t.key === "Enter" || t.key === " ") && (t.preventDefault(),
|
|
140
|
+
(t.key === "Enter" || t.key === " ") && (t.preventDefault(), _?.(e.code), P(!1));
|
|
140
141
|
},
|
|
141
142
|
tabIndex: 0,
|
|
142
143
|
role: "option",
|
|
143
|
-
"aria-selected":
|
|
144
|
+
"aria-selected": I.code === e.code,
|
|
144
145
|
children: [
|
|
145
|
-
/* @__PURE__ */
|
|
146
|
+
/* @__PURE__ */ f("span", {
|
|
146
147
|
"aria-hidden": "true",
|
|
147
148
|
children: e.flag
|
|
148
149
|
}),
|
|
149
|
-
/* @__PURE__ */
|
|
150
|
-
className:
|
|
150
|
+
/* @__PURE__ */ f("span", {
|
|
151
|
+
className: a.countryName,
|
|
151
152
|
children: e.name
|
|
152
153
|
}),
|
|
153
|
-
/* @__PURE__ */
|
|
154
|
-
className:
|
|
154
|
+
/* @__PURE__ */ p("span", {
|
|
155
|
+
className: a.countryCode,
|
|
155
156
|
children: ["+", e.dialCode]
|
|
156
157
|
})
|
|
157
158
|
]
|
|
@@ -159,26 +160,26 @@ var p = [
|
|
|
159
160
|
})
|
|
160
161
|
})]
|
|
161
162
|
}),
|
|
162
|
-
/* @__PURE__ */
|
|
163
|
-
className:
|
|
163
|
+
/* @__PURE__ */ f("div", {
|
|
164
|
+
className: a.divider,
|
|
164
165
|
"aria-hidden": "true"
|
|
165
166
|
}),
|
|
166
|
-
/* @__PURE__ */
|
|
167
|
-
id:
|
|
168
|
-
ref:
|
|
167
|
+
/* @__PURE__ */ f("input", {
|
|
168
|
+
id: O,
|
|
169
|
+
ref: D,
|
|
169
170
|
type: "tel",
|
|
170
|
-
value:
|
|
171
|
-
onChange:
|
|
172
|
-
placeholder:
|
|
173
|
-
disabled:
|
|
174
|
-
className:
|
|
175
|
-
"aria-invalid": !!
|
|
176
|
-
"aria-describedby":
|
|
171
|
+
value: o,
|
|
172
|
+
onChange: L,
|
|
173
|
+
placeholder: v,
|
|
174
|
+
disabled: y,
|
|
175
|
+
className: a.number,
|
|
176
|
+
"aria-invalid": !!b,
|
|
177
|
+
"aria-describedby": M
|
|
177
178
|
})
|
|
178
179
|
]
|
|
179
180
|
})
|
|
180
181
|
});
|
|
181
182
|
});
|
|
182
|
-
|
|
183
|
+
h.displayName = "PhoneInput";
|
|
183
184
|
//#endregion
|
|
184
|
-
export {
|
|
185
|
+
export { m as PHONE_COUNTRIES, h as PhoneInput };
|