@starasia/input 4.3.0 → 6.0.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/input.es.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { jsx as a, jsxs as l, Fragment as Ln } from "react/jsx-runtime";
2
2
  import Z, { forwardRef as mn, useState as I, useRef as R, useEffect as F, useImperativeHandle as En, useLayoutEffect as bn } from "react";
3
- const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
4
-
3
+ const $n = `
5
4
  :root {
6
5
  /* Layer 3 — references Layer 2 semantic tokens */
7
6
  --sa-input-text-primary: var(--sa-text-primary, #292a2e);
@@ -44,7 +43,7 @@ const $n = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
44
43
  flex-direction: column;
45
44
  align-items: stretch;
46
45
  gap: 8px;
47
- font-family: "Poppins", sans-serif;
46
+ font-family: var(--sa-font-family, "Inter", sans-serif);
48
47
  width: max-content;
49
48
  }
50
49
  .sa-tf *,
@@ -680,7 +679,7 @@ const Tn = mn(
680
679
  "p",
681
680
  {
682
681
  style: {
683
- fontFamily: "Poppins",
682
+ fontFamily: 'var(--sa-font-family, "Inter", sans-serif)',
684
683
  color: "var(--sa-color-gray-400, #b7b9be)",
685
684
  fontWeight: 500,
686
685
  padding: "8px 14px",
@@ -807,7 +806,7 @@ const Yn = (n) => /* @__PURE__ */ l(
807
806
  } catch {
808
807
  }
809
808
  }, [W]);
810
- const N = W, $ = N !== "" && N !== void 0, w = d === "disable" || s.disabled, M = w ? "disable" : d, P = c === "inside", zn = P && ($ || tn), H = [
809
+ const N = W, $ = N !== "" && N !== void 0, w = d === "disable" || s.disabled, M = w ? "disable" : d, H = c === "inside", zn = H && ($ || tn), q = [
811
810
  "sa-tf",
812
811
  `sa-tf-variant-${o}`,
813
812
  `sa-tf-size-${r}`,
@@ -843,7 +842,7 @@ const Yn = (n) => /* @__PURE__ */ l(
843
842
  name: t.target.name
844
843
  }
845
844
  }), sn("");
846
- }, q = (t) => f ? /* @__PURE__ */ l("div", { className: t, children: [
845
+ }, K = (t) => f ? /* @__PURE__ */ l("div", { className: t, children: [
847
846
  /* @__PURE__ */ a(
848
847
  "label",
849
848
  {
@@ -854,7 +853,7 @@ const Yn = (n) => /* @__PURE__ */ l(
854
853
  ),
855
854
  u ? /* @__PURE__ */ a("span", { className: "sa-tf-optional", children: "Optional" }) : null,
856
855
  T ? /* @__PURE__ */ a("span", { className: "sa-tf-required", "aria-hidden": "true", children: "*" }) : null
857
- ] }) : null, K = /* @__PURE__ */ l(Ln, { children: [
856
+ ] }) : null, P = /* @__PURE__ */ l(Ln, { children: [
858
857
  g ? /* @__PURE__ */ a("p", { className: "sa-tf-helper", children: g }) : null,
859
858
  b && d === "error" ? /* @__PURE__ */ a("p", { className: "sa-tf-error", children: b }) : null
860
859
  ] }), U = (t, i) => /* @__PURE__ */ a(
@@ -953,7 +952,7 @@ const Yn = (n) => /* @__PURE__ */ l(
953
952
  j == null || j(t), k(t);
954
953
  }
955
954
  }
956
- ) : null, X = P ? /* @__PURE__ */ l(
955
+ ) : null, X = H ? /* @__PURE__ */ l(
957
956
  "div",
958
957
  {
959
958
  className: "sa-tf-box",
@@ -964,7 +963,7 @@ const Yn = (n) => /* @__PURE__ */ l(
964
963
  /* @__PURE__ */ l("div", { className: "sa-tf-box-content", children: [
965
964
  m ? U(m, nn) : null,
966
965
  /* @__PURE__ */ l("div", { className: "sa-tf-inside-stack", children: [
967
- q("sa-tf-inside-label-row"),
966
+ K("sa-tf-inside-label-row"),
968
967
  /* @__PURE__ */ a("div", { className: "sa-tf-inside-row", children: fn })
969
968
  ] }),
970
969
  dn,
@@ -987,23 +986,23 @@ const Yn = (n) => /* @__PURE__ */ l(
987
986
  S ? /* @__PURE__ */ a("div", { className: "sa-tf-addon sa-tf-addon-right", children: S }) : null,
988
987
  cn
989
988
  ] });
990
- return c === "outside-left" ? /* @__PURE__ */ l("div", { className: H, children: [
989
+ return c === "outside-left" ? /* @__PURE__ */ l("div", { className: q, children: [
991
990
  /* @__PURE__ */ l("div", { className: "sa-tf-label-col", children: [
992
- q("sa-tf-label"),
991
+ K("sa-tf-label"),
993
992
  p ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: p }) : null
994
993
  ] }),
995
994
  /* @__PURE__ */ l("div", { className: "sa-tf-input-col", children: [
996
995
  X,
997
- K
996
+ P
998
997
  ] })
999
- ] }) : P ? /* @__PURE__ */ l("div", { className: H, children: [
998
+ ] }) : H ? /* @__PURE__ */ l("div", { className: q, children: [
1000
999
  X,
1001
- K
1002
- ] }) : /* @__PURE__ */ l("div", { className: H, children: [
1003
- q("sa-tf-label"),
1000
+ P
1001
+ ] }) : /* @__PURE__ */ l("div", { className: q, children: [
1002
+ K("sa-tf-label"),
1004
1003
  p ? /* @__PURE__ */ a("p", { className: "sa-tf-desc-top", children: p }) : null,
1005
1004
  X,
1006
- K
1005
+ P
1007
1006
  ] });
1008
1007
  }
1009
1008
  ), _n = (n, e) => {
@@ -1038,7 +1037,7 @@ const Mn = `.sa-kbd {
1038
1037
  color: var(--sa-text-subtle, #505258);
1039
1038
  font-family: inherit;
1040
1039
  font-size: var(--sa-font-size-sm, 12px);
1041
- font-weight: var(--sa-font-weight-medium, 400);
1040
+ font-weight: var(--sa-font-weight-medium, 500);
1042
1041
  line-height: 1.6;
1043
1042
  white-space: nowrap;
1044
1043
  }
@@ -1097,14 +1096,14 @@ const Mn = `.sa-kbd {
1097
1096
  .sa-kbd-size-lg .sa-kbd-sep {
1098
1097
  font-size: 16px;
1099
1098
  }
1100
- `, hn = "sa-kbd-styles", Pn = (n) => {
1099
+ `, hn = "sa-kbd-styles", Hn = (n) => {
1101
1100
  if (!(typeof document > "u") && !document.getElementById(hn)) {
1102
1101
  const e = document.createElement("style");
1103
1102
  e.id = hn, e.textContent = n, document.head.appendChild(e);
1104
1103
  }
1105
1104
  };
1106
- Pn(Mn);
1107
- function Hn({ keys: n, separator: e, size: r = "sm", className: o, ...d }) {
1105
+ Hn(Mn);
1106
+ function qn({ keys: n, separator: e, size: r = "sm", className: o, ...d }) {
1108
1107
  return /* @__PURE__ */ a(
1109
1108
  "span",
1110
1109
  {
@@ -1117,8 +1116,8 @@ function Hn({ keys: n, separator: e, size: r = "sm", className: o, ...d }) {
1117
1116
  }
1118
1117
  );
1119
1118
  }
1120
- Hn.__saRaw = !0;
1119
+ qn.__saRaw = !0;
1121
1120
  export {
1122
1121
  Wn as Input,
1123
- Hn as Kbd
1122
+ qn as Kbd
1124
1123
  };
package/dist/input.umd.js CHANGED
@@ -1,5 +1,4 @@
1
- (function(b,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(b=typeof globalThis<"u"?globalThis:b||self,n(b.Input={},b.jsxRuntime,b.React))})(this,function(b,n,o){"use strict";const gn=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
2
-
1
+ (function(b,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(b=typeof globalThis<"u"?globalThis:b||self,n(b.Input={},b.jsxRuntime,b.React))})(this,function(b,n,o){"use strict";const gn=`
3
2
  :root {
4
3
  /* Layer 3 — references Layer 2 semantic tokens */
5
4
  --sa-input-text-primary: var(--sa-text-primary, #292a2e);
@@ -42,7 +41,7 @@
42
41
  flex-direction: column;
43
42
  align-items: stretch;
44
43
  gap: 8px;
45
- font-family: "Poppins", sans-serif;
44
+ font-family: var(--sa-font-family, "Inter", sans-serif);
46
45
  width: max-content;
47
46
  }
48
47
  .sa-tf *,
@@ -612,7 +611,7 @@
612
611
  .sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
613
612
  min-height: 80px;
614
613
  }
615
- `,y=t=>t==="lg"||t==="xl"?18:t==="xs"?14:16,j={default:"var(--sa-color-gray-800, #505258)",error:"var(--sa-text-error, #a4133c)",success:"var(--sa-text-success, #208958)",disable:"var(--sa-icon-disable, #181a198f)"},Q=(t,e)=>e?j.disable:j[t]??j.default;function hn(t){return Number(t.replace(/\./g,""))}function F(t){let e=t.replace(/[^\d]/g,"");return e=e.replace(/^0+(?=\d)/,""),e.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function vn(t,e){if(e<=0)return 0;let r=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(r+=1,r===e))return l+1;return t.length}const mn=o.forwardRef(({options:t,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((t==null?void 0:t.filter(h=>h.toLowerCase().startsWith(e.toLowerCase())))||[])},[e,t]),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:"8px",background:"white",overflow:"auto",zIndex:5e4},children:c==null?void 0:c.map(h=>wn(h,e,r,d))})}),wn=(t,e,r,l)=>{const d=t.toLowerCase().indexOf(e.toLowerCase());return n.jsxs("p",{style:{fontFamily:"Poppins",color:"var(--sa-color-gray-400, #b7b9be)",fontWeight:500,padding:"8px 14px",cursor:"pointer"},onClick:()=>{r(t),l&&l(t)},children:[t.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:t.slice(d,d+e.length)}),t.slice(d+e.length)]})};function kn(t){const[e,r]=o.useState(t),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";(t=>{if(!(typeof document>"u")&&!document.getElementById(Z)){const e=document.createElement("style");e.id=Z,e.textContent=t,document.head.appendChild(e)}})(gn);const yn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,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=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,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((t,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:sn,onClickRightIcon:O,fullWidth:In=!0,highlightPlaceholder:V,currency:E,options:L,onOptionChange:Y,clearable:Sn=!0,onClear:A,...a}=t,M=a.value!==void 0,[P,z]=o.useState(()=>{const s=a.value!==void 0?String(a.value??""):String(a.defaultValue??"");return E?F(s):s}),[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:W,setIsComponentVisible:En}=kn(!1);o.useLayoutEffect(()=>{if(!M)return;const s=a.value===void 0||a.value===null?"":String(a.value),i=E?F(s):s;z(g=>g===i?g:i)},[a.value,E,M]),o.useLayoutEffect(()=>{if(C.current===null)return;const s=N.current,i=C.current;if(C.current=null,!!s)try{s.setSelectionRange(i,i)}catch{}},[P]);const I=P,$=I!==""&&I!==void 0,k=d==="disable"||a.disabled,_=k?"disable":d,q=c==="inside",Ln=q&&($||en),H=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${r}`,`sa-tf-status-${_}`,`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 s;return(s=N.current)==null?void 0:s.focus()},Dn=s=>{var bn,xn;if(!E){const D=s.target.selectionStart;D!==null&&(C.current=D),z(s.target.value),(bn=a.onChange)==null||bn.call(a,s);return}const i=s.target.value;let g=i,v=s.target.selectionStart??i.length;if(Bn==="Backspace"){const D=P.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,{...s,target:{...s.target,value:String(hn(J)),name:s.target.name}}),rn("")},K=s=>f?n.jsxs("div",{className:s,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=(s,i)=>n.jsx("span",{className:`sa-tf-icon${i?" sa-tf-icon-clickable":""}`,onClick:i,children:o.cloneElement(s,{width:y(r),height:y(r),color:Q(_,k),style:{color: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=s=>{var g;s.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:s=>s.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:s=>{var i;an(!0),En(!0),(i=a.onFocus)==null||i.call(a,s)},onBlur:s=>{var i;an(!1),(i=a.onBlur)==null||i.call(a,s)},onKeyDown:s=>{var i;s.key==="Backspace"&&rn(s.key),(i=a.onKeyDown)==null||i.call(a,s)},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:W,isComponentVisible:ln,onOptionChange:s=>{Y==null||Y(s),z(s)}}):null,G=q?n.jsxs("div",{className:"sa-tf-box",ref:W,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,sn):null,n.jsxs("div",{className:"sa-tf-inside-stack",children:[K("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:W,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,sn):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:H,children:[n.jsxs("div",{className:"sa-tf-label-col",children:[K("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]})]}):q?n.jsxs("div",{className:H,children:[G,U]}):n.jsxs("div",{className:H,children:[K("sa-tf-label"),p?n.jsx("p",{className:"sa-tf-desc-top",children:p}):null,G,U]})}),Cn=(t,e)=>{if(!t)return null;if(!e)return n.jsx("p",{className:"sa-tf-placeholder",children:t});const r=t.toLowerCase().indexOf(e.toLowerCase());return r===-1?n.jsx("p",{className:"sa-tf-placeholder",children:t}):n.jsxs("p",{className:"sa-tf-placeholder",children:[t.slice(0,r),n.jsx("span",{className:"sa-tf-placeholder-highlight",children:t.slice(r,r+e.length)}),t.slice(r+e.length)]})};R.displayName="Input";const Nn=`.sa-kbd {
614
+ `,y=t=>t==="lg"||t==="xl"?18:t==="xs"?14:16,j={default:"var(--sa-color-gray-800, #505258)",error:"var(--sa-text-error, #a4133c)",success:"var(--sa-text-success, #208958)",disable:"var(--sa-icon-disable, #181a198f)"},Q=(t,e)=>e?j.disable:j[t]??j.default;function hn(t){return Number(t.replace(/\./g,""))}function F(t){let e=t.replace(/[^\d]/g,"");return e=e.replace(/^0+(?=\d)/,""),e.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function vn(t,e){if(e<=0)return 0;let r=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(r+=1,r===e))return l+1;return t.length}const mn=o.forwardRef(({options:t,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((t==null?void 0:t.filter(h=>h.toLowerCase().startsWith(e.toLowerCase())))||[])},[e,t]),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:"8px",background:"white",overflow:"auto",zIndex:5e4},children:c==null?void 0:c.map(h=>wn(h,e,r,d))})}),wn=(t,e,r,l)=>{const d=t.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(t),l&&l(t)},children:[t.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:t.slice(d,d+e.length)}),t.slice(d+e.length)]})};function kn(t){const[e,r]=o.useState(t),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";(t=>{if(!(typeof document>"u")&&!document.getElementById(Z)){const e=document.createElement("style");e.id=Z,e.textContent=t,document.head.appendChild(e)}})(gn);const yn=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,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=t=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,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((t,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:sn,onClickRightIcon:O,fullWidth:In=!0,highlightPlaceholder:V,currency:E,options:L,onOptionChange:Y,clearable:Sn=!0,onClear:A,...a}=t,M=a.value!==void 0,[W,z]=o.useState(()=>{const s=a.value!==void 0?String(a.value??""):String(a.defaultValue??"");return E?F(s):s}),[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 s=a.value===void 0||a.value===null?"":String(a.value),i=E?F(s):s;z(g=>g===i?g:i)},[a.value,E,M]),o.useLayoutEffect(()=>{if(C.current===null)return;const s=N.current,i=C.current;if(C.current=null,!!s)try{s.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 s;return(s=N.current)==null?void 0:s.focus()},Dn=s=>{var bn,xn;if(!E){const D=s.target.selectionStart;D!==null&&(C.current=D),z(s.target.value),(bn=a.onChange)==null||bn.call(a,s);return}const i=s.target.value;let g=i,v=s.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,{...s,target:{...s.target,value:String(hn(J)),name:s.target.name}}),rn("")},P=s=>f?n.jsxs("div",{className:s,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=(s,i)=>n.jsx("span",{className:`sa-tf-icon${i?" sa-tf-icon-clickable":""}`,onClick:i,children:o.cloneElement(s,{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=s=>{var g;s.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:s=>s.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:s=>{var i;an(!0),En(!0),(i=a.onFocus)==null||i.call(a,s)},onBlur:s=>{var i;an(!1),(i=a.onBlur)==null||i.call(a,s)},onKeyDown:s=>{var i;s.key==="Backspace"&&rn(s.key),(i=a.onKeyDown)==null||i.call(a,s)},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:s=>{Y==null||Y(s),z(s)}}):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,sn):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,sn):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=(t,e)=>{if(!t)return null;if(!e)return n.jsx("p",{className:"sa-tf-placeholder",children:t});const r=t.toLowerCase().indexOf(e.toLowerCase());return r===-1?n.jsx("p",{className:"sa-tf-placeholder",children:t}):n.jsxs("p",{className:"sa-tf-placeholder",children:[t.slice(0,r),n.jsx("span",{className:"sa-tf-placeholder-highlight",children:t.slice(r,r+e.length)}),t.slice(r+e.length)]})};R.displayName="Input";const Nn=`.sa-kbd {
616
615
  display: inline-flex;
617
616
  align-items: center;
618
617
  gap: var(--sa-spacing-4, 4px);
@@ -631,7 +630,7 @@
631
630
  color: var(--sa-text-subtle, #505258);
632
631
  font-family: inherit;
633
632
  font-size: var(--sa-font-size-sm, 12px);
634
- font-weight: var(--sa-font-weight-medium, 400);
633
+ font-weight: var(--sa-font-weight-medium, 500);
635
634
  line-height: 1.6;
636
635
  white-space: nowrap;
637
636
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/input",
3
- "version": "4.3.0",
3
+ "version": "6.0.0",
4
4
  "description": "input component for starasia UI",
5
5
  "author": "Rizki Izzul Haq",
6
6
  "main": "dist/input.umd.js",