@starasia/input 6.0.1 → 6.0.3
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/input.es.js +3 -3
- package/dist/input.umd.js +3 -3
- package/package.json +1 -1
package/dist/input.es.js
CHANGED
|
@@ -102,7 +102,7 @@ const $n = `
|
|
|
102
102
|
.sa-tf-optional {
|
|
103
103
|
background: var(--sa-input-accent-subtle);
|
|
104
104
|
border: 1px solid var(--sa-input-border-subtle);
|
|
105
|
-
border-radius: 4px;
|
|
105
|
+
border-radius: var(--sa-radii-xs, 4px);
|
|
106
106
|
padding: 0 8px;
|
|
107
107
|
font-size: 10px;
|
|
108
108
|
font-weight: 500;
|
|
@@ -662,8 +662,8 @@ const Tn = mn(
|
|
|
662
662
|
padding: "8px",
|
|
663
663
|
boxSizing: "border-box",
|
|
664
664
|
boxShadow: "0px 8px 12px 0px var(--sa-color-black-alpha-a8, #00000014)",
|
|
665
|
-
borderRadius: "8px",
|
|
666
|
-
background: "
|
|
665
|
+
borderRadius: "var(--sa-radii-md, 8px)",
|
|
666
|
+
background: "var(--sa-background-primary, #ffffff)",
|
|
667
667
|
overflow: "auto",
|
|
668
668
|
zIndex: 5e4
|
|
669
669
|
},
|
package/dist/input.umd.js
CHANGED
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
.sa-tf-optional {
|
|
101
101
|
background: var(--sa-input-accent-subtle);
|
|
102
102
|
border: 1px solid var(--sa-input-border-subtle);
|
|
103
|
-
border-radius: 4px;
|
|
103
|
+
border-radius: var(--sa-radii-xs, 4px);
|
|
104
104
|
padding: 0 8px;
|
|
105
105
|
font-size: 10px;
|
|
106
106
|
font-weight: 500;
|
|
@@ -611,7 +611,7 @@
|
|
|
611
611
|
.sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
|
|
612
612
|
min-height: 80px;
|
|
613
613
|
}
|
|
614
|
-
`,y=
|
|
614
|
+
`,y=s=>s==="lg"||s==="xl"?18:s==="xs"?14:16,j={default:"var(--sa-color-gray-800, #505258)",error:"var(--sa-text-error, #a4133c)",success:"var(--sa-text-success, #186742)",disable:"var(--sa-icon-disable, #181a198f)"},Q=(s,e)=>e?j.disable:j[s]??j.default;function hn(s){return Number(s.replace(/\./g,""))}function F(s){let e=s.replace(/[^\d]/g,"");return e=e.replace(/^0+(?=\d)/,""),e.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function vn(s,e){if(e<=0)return 0;let r=0;for(let l=0;l<s.length;l++)if(/\d/.test(s[l])&&(r+=1,r===e))return l+1;return s.length}const mn=o.forwardRef(({options:s,value:e,setValue:r,isComponentVisible:l,onOptionChange:d},f)=>{const[c,T]=o.useState([]),u=o.useRef(null),p=()=>{if(f!=null&&f.current&&u.current){const h=window.innerHeight,x=f==null?void 0:f.current.getBoundingClientRect(),m=u.current.getBoundingClientRect(),w=x.bottom+m.height;u.current.style.left=`${x.left}px`,u.current.style.width=`${x.width}px`,w>=h-10?u.current.style.top=`${x.top-m.height-5}px`:u.current.style.top=`${x.top+x.height}px`}};return o.useEffect(()=>(window.addEventListener("scroll",p),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p),window.removeEventListener("resize",p)}),[f,u]),o.useEffect(()=>{p()},[l]),o.useEffect(()=>{T((s==null?void 0:s.filter(h=>h.toLowerCase().startsWith(e.toLowerCase())))||[])},[e,s]),n.jsx("div",{ref:u,style:{position:"fixed",padding:"8px",boxSizing:"border-box",boxShadow:"0px 8px 12px 0px var(--sa-color-black-alpha-a8, #00000014)",borderRadius:"var(--sa-radii-md, 8px)",background:"var(--sa-background-primary, #ffffff)",overflow:"auto",zIndex:5e4},children:c==null?void 0:c.map(h=>wn(h,e,r,d))})}),wn=(s,e,r,l)=>{const d=s.toLowerCase().indexOf(e.toLowerCase());return n.jsxs("p",{style:{fontFamily:'var(--sa-font-family, "Inter", sans-serif)',color:"var(--sa-color-gray-400, #b7b9be)",fontWeight:500,padding:"8px 14px",cursor:"pointer"},onClick:()=>{r(s),l&&l(s)},children:[s.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:s.slice(d,d+e.length)}),s.slice(d+e.length)]})};function kn(s){const[e,r]=o.useState(s),l=o.useRef(null),d=f=>{l.current&&!l.current.contains(f.target)&&r(!1)};return o.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:l,isComponentVisible:e,setIsComponentVisible:r}}const Z="sa-input-styles";(s=>{if(!(typeof document>"u")&&!document.getElementById(Z)){const e=document.createElement("style");e.id=Z,e.textContent=s,document.head.appendChild(e)}})(gn);const yn=s=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...s,children:[n.jsx("circle",{cx:"8",cy:"8",r:"6.5",stroke:"currentColor",strokeWidth:"1.2"}),n.jsx("path",{d:"M5.2 8.2l1.8 1.8 3.8-4.2",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]}),zn=s=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...s,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),R=o.forwardRef((s,e)=>{const{size:r="sm",variant:l="outline",status:d="default",label:f,labelPosition:c="outside-top",required:T,optional:u,description:p,helperText:h,errorText:x,leftIcon:m,rightIcon:w,leftAddons:S,rightAddons:B,onClickLeftIcon:tn,onClickRightIcon:O,fullWidth:In=!0,highlightPlaceholder:V,currency:E,options:L,onOptionChange:Y,clearable:Sn=!0,onClear:A,...a}=s,M=a.value!==void 0,[W,z]=o.useState(()=>{const t=a.value!==void 0?String(a.value??""):String(a.defaultValue??"");return E?F(t):t}),[en,an]=o.useState(!1),[Bn,rn]=o.useState(""),C=o.useRef(null),N=o.useRef(null);o.useImperativeHandle(e,()=>N.current);const on=o.useRef(a.id??`sa-input-${Math.random().toString(36).slice(2,9)}`),{isComponentVisible:ln,ref:_,setIsComponentVisible:En}=kn(!1);o.useLayoutEffect(()=>{if(!M)return;const t=a.value===void 0||a.value===null?"":String(a.value),i=E?F(t):t;z(g=>g===i?g:i)},[a.value,E,M]),o.useLayoutEffect(()=>{if(C.current===null)return;const t=N.current,i=C.current;if(C.current=null,!!t)try{t.setSelectionRange(i,i)}catch{}},[W]);const I=W,$=I!==""&&I!==void 0,k=d==="disable"||a.disabled,q=k?"disable":d,H=c==="inside",Ln=H&&($||en),K=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${r}`,`sa-tf-status-${q}`,`sa-tf-label-${c}`,en?"sa-tf-focused":"",k?"sa-tf-disabled":"",Ln?"sa-tf-floating":"",f?"":"sa-tf-no-label",In?"sa-tf-fullwidth":""].filter(Boolean).join(" "),$n=()=>{var t;return(t=N.current)==null?void 0:t.focus()},Dn=t=>{var bn,xn;if(!E){const D=t.target.selectionStart;D!==null&&(C.current=D),z(t.target.value),(bn=a.onChange)==null||bn.call(a,t);return}const i=t.target.value;let g=i,v=t.target.selectionStart??i.length;if(Bn==="Backspace"){const D=W.replace(/\D/g,""),Vn=i.replace(/\D/g,"");D.length===Vn.length&&v>0&&(g=i.slice(0,v-1)+i.slice(v),v-=1)}const J=F(g),Tn=g.slice(0,v).replace(/\D/g,"").length,On=vn(J,Tn);C.current=On,z(J),(xn=a.onChange)==null||xn.call(a,{...t,target:{...t.target,value:String(hn(J)),name:t.target.name}}),rn("")},P=t=>f?n.jsxs("div",{className:t,children:[n.jsx("label",{htmlFor:on.current,style:{cursor:k?"not-allowed":"pointer"},children:f}),u?n.jsx("span",{className:"sa-tf-optional",children:"Optional"}):null,T?n.jsx("span",{className:"sa-tf-required","aria-hidden":"true",children:"*"}):null]}):null,U=n.jsxs(n.Fragment,{children:[h?n.jsx("p",{className:"sa-tf-helper",children:h}):null,x&&d==="error"?n.jsx("p",{className:"sa-tf-error",children:x}):null]}),X=(t,i)=>n.jsx("span",{className:`sa-tf-icon${i?" sa-tf-icon-clickable":""}`,onClick:i,children:o.cloneElement(t,{width:y(r),height:y(r),color:Q(q,k),style:{color:Q(q,k)}})}),dn=()=>{var i;return w==null?null:!o.isValidElement(w)||((i=w.type)==null?void 0:i.__saRaw)===!0?n.jsx("span",{className:`sa-tf-icon${O?" sa-tf-icon-clickable":""}`,onClick:O,children:w}):X(w,O)},fn=d==="success"?n.jsx("span",{className:"sa-tf-icon sa-tf-success-mark","aria-hidden":"true",children:n.jsx(yn,{width:y(r),height:y(r)})}):null,jn=t=>{var g;t.stopPropagation(),M||z("");const i={target:{value:"",name:a.name},currentTarget:{value:"",name:a.name}};(g=a.onChange)==null||g.call(a,i),A==null||A(),C.current=0,requestAnimationFrame(()=>{var v;return(v=N.current)==null?void 0:v.focus()})},cn=Sn&&!k?n.jsx("button",{type:"button",className:`sa-tf-icon sa-tf-clear${$?"":" sa-tf-clear-hidden"}`,"aria-label":"Clear input","aria-hidden":!$,tabIndex:-1,onClick:jn,onMouseDown:t=>t.preventDefault(),children:n.jsx(zn,{width:y(r),height:y(r)})}):null,Fn=!$&&!!a.placeholder&&!!V,un=n.jsxs("div",{className:"sa-tf-field-wrap",children:[n.jsx("input",{...a,id:on.current,ref:N,className:"sa-tf-input",disabled:k,placeholder:V?"":a.placeholder,value:I,onFocus:t=>{var i;an(!0),En(!0),(i=a.onFocus)==null||i.call(a,t)},onBlur:t=>{var i;an(!1),(i=a.onBlur)==null||i.call(a,t)},onKeyDown:t=>{var i;t.key==="Backspace"&&rn(t.key),(i=a.onKeyDown)==null||i.call(a,t)},onChange:Dn}),Fn?Cn(a.placeholder,V):null]}),pn=I&&ln&&(L!=null&&L.length)?n.jsx(mn,{options:L,value:I,setValue:z,ref:_,isComponentVisible:ln,onOptionChange:t=>{Y==null||Y(t),z(t)}}):null,G=H?n.jsxs("div",{className:"sa-tf-box",ref:_,onClick:$n,children:[S?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-left",children:S}):null,n.jsxs("div",{className:"sa-tf-box-content",children:[m?X(m,tn):null,n.jsxs("div",{className:"sa-tf-inside-stack",children:[P("sa-tf-inside-label-row"),n.jsx("div",{className:"sa-tf-inside-row",children:un})]}),cn,fn,dn()]}),B?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:B}):null,pn]}):n.jsxs("div",{className:"sa-tf-box",ref:_,children:[S?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-left",children:S}):null,n.jsxs("div",{className:"sa-tf-box-content",children:[m?X(m,tn):null,un,cn,fn,dn()]}),B?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:B}):null,pn]});return c==="outside-left"?n.jsxs("div",{className:K,children:[n.jsxs("div",{className:"sa-tf-label-col",children:[P("sa-tf-label"),p?n.jsx("p",{className:"sa-tf-desc-top",children:p}):null]}),n.jsxs("div",{className:"sa-tf-input-col",children:[G,U]})]}):H?n.jsxs("div",{className:K,children:[G,U]}):n.jsxs("div",{className:K,children:[P("sa-tf-label"),p?n.jsx("p",{className:"sa-tf-desc-top",children:p}):null,G,U]})}),Cn=(s,e)=>{if(!s)return null;if(!e)return n.jsx("p",{className:"sa-tf-placeholder",children:s});const r=s.toLowerCase().indexOf(e.toLowerCase());return r===-1?n.jsx("p",{className:"sa-tf-placeholder",children:s}):n.jsxs("p",{className:"sa-tf-placeholder",children:[s.slice(0,r),n.jsx("span",{className:"sa-tf-placeholder-highlight",children:s.slice(r,r+e.length)}),s.slice(r+e.length)]})};R.displayName="Input";const Nn=`.sa-kbd {
|
|
615
615
|
display: inline-flex;
|
|
616
616
|
align-items: center;
|
|
617
617
|
gap: var(--sa-spacing-4, 4px);
|
|
@@ -689,4 +689,4 @@
|
|
|
689
689
|
.sa-kbd-size-lg .sa-kbd-sep {
|
|
690
690
|
font-size: 16px;
|
|
691
691
|
}
|
|
692
|
-
`,nn="sa-kbd-styles";(
|
|
692
|
+
`,nn="sa-kbd-styles";(s=>{if(!(typeof document>"u")&&!document.getElementById(nn)){const e=document.createElement("style");e.id=nn,e.textContent=s,document.head.appendChild(e)}})(Nn);function sn({keys:s,separator:e,size:r="sm",className:l,...d}){return n.jsx("span",{className:`sa-kbd sa-kbd-size-${r}${l?` ${l}`:""}`,...d,children:s.map((f,c)=>n.jsxs(o.Fragment,{children:[c>0&&e!=null?n.jsx("span",{className:"sa-kbd-sep","aria-hidden":"true",children:e}):null,n.jsx("kbd",{className:"sa-kbd-key",children:f})]},c))})}sn.__saRaw=!0,b.Input=R,b.Kbd=sn,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|