@starasia/input 3.0.2 → 3.0.4
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 +20 -17
- package/dist/input.umd.js +5 -2
- package/package.json +6 -6
package/dist/input.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as s, jsxs as o, Fragment as Ln } from "react/jsx-runtime";
|
|
2
|
-
import Bn, { forwardRef as
|
|
2
|
+
import Bn, { forwardRef as xn, useState as I, useRef as L, useEffect as O, useImperativeHandle as Rn, useLayoutEffect as un } from "react";
|
|
3
3
|
const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
4
4
|
|
|
5
5
|
:root {
|
|
@@ -159,6 +159,9 @@ const Sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
159
159
|
.sa-tf-size-sm .sa-tf-box {
|
|
160
160
|
min-height: 32px;
|
|
161
161
|
}
|
|
162
|
+
.sa-tf-size-sm .sa-tf-box-content {
|
|
163
|
+
padding-block: 6px;
|
|
164
|
+
}
|
|
162
165
|
.sa-tf-size-md .sa-tf-box {
|
|
163
166
|
min-height: 40px;
|
|
164
167
|
}
|
|
@@ -607,12 +610,12 @@ function Dn(n, a) {
|
|
|
607
610
|
return l + 1;
|
|
608
611
|
return n.length;
|
|
609
612
|
}
|
|
610
|
-
const Fn =
|
|
613
|
+
const Fn = xn(
|
|
611
614
|
({ options: n, value: a, setValue: r, isComponentVisible: l, onOptionChange: d }, f) => {
|
|
612
615
|
const [g, V] = I([]), c = L(null), u = () => {
|
|
613
616
|
if (f != null && f.current && c.current) {
|
|
614
|
-
const
|
|
615
|
-
c.current.style.left = `${p.left}px`, c.current.style.width = `${p.width}px`, w >=
|
|
617
|
+
const x = window.innerHeight, p = f == null ? void 0 : f.current.getBoundingClientRect(), m = c.current.getBoundingClientRect(), w = p.bottom + m.height;
|
|
618
|
+
c.current.style.left = `${p.left}px`, c.current.style.width = `${p.width}px`, w >= x - 10 ? c.current.style.top = `${p.top - m.height - 5}px` : c.current.style.top = `${p.top + p.height}px`;
|
|
616
619
|
}
|
|
617
620
|
};
|
|
618
621
|
return O(() => (window.addEventListener("scroll", u), window.addEventListener("resize", u), () => {
|
|
@@ -622,7 +625,7 @@ const Fn = hn(
|
|
|
622
625
|
}, [l]), O(() => {
|
|
623
626
|
V(
|
|
624
627
|
(n == null ? void 0 : n.filter(
|
|
625
|
-
(
|
|
628
|
+
(x) => x.toLowerCase().startsWith(a.toLowerCase())
|
|
626
629
|
)) || []
|
|
627
630
|
);
|
|
628
631
|
}, [a, n]), /* @__PURE__ */ s(
|
|
@@ -640,7 +643,7 @@ const Fn = hn(
|
|
|
640
643
|
zIndex: 5e4
|
|
641
644
|
},
|
|
642
645
|
children: g == null ? void 0 : g.map(
|
|
643
|
-
(
|
|
646
|
+
(x) => Tn(x, a, r, d)
|
|
644
647
|
)
|
|
645
648
|
}
|
|
646
649
|
);
|
|
@@ -724,10 +727,10 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
724
727
|
)
|
|
725
728
|
]
|
|
726
729
|
}
|
|
727
|
-
), Yn =
|
|
730
|
+
), Yn = xn(
|
|
728
731
|
(n, a) => {
|
|
729
732
|
const {
|
|
730
|
-
size: r = "
|
|
733
|
+
size: r = "md",
|
|
731
734
|
variant: l = "outline",
|
|
732
735
|
status: d = "default",
|
|
733
736
|
label: f,
|
|
@@ -735,7 +738,7 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
735
738
|
required: V,
|
|
736
739
|
optional: c,
|
|
737
740
|
description: u,
|
|
738
|
-
helperText:
|
|
741
|
+
helperText: x,
|
|
739
742
|
errorText: p,
|
|
740
743
|
leftIcon: m,
|
|
741
744
|
rightIcon: w,
|
|
@@ -743,7 +746,7 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
743
746
|
rightAddons: R,
|
|
744
747
|
onClickLeftIcon: Q,
|
|
745
748
|
onClickRightIcon: Z,
|
|
746
|
-
fullWidth:
|
|
749
|
+
fullWidth: hn = !1,
|
|
747
750
|
highlightPlaceholder: $,
|
|
748
751
|
currency: S,
|
|
749
752
|
options: E,
|
|
@@ -788,7 +791,7 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
788
791
|
v ? "sa-tf-disabled" : "",
|
|
789
792
|
wn ? "sa-tf-floating" : "",
|
|
790
793
|
f ? "" : "sa-tf-no-label",
|
|
791
|
-
|
|
794
|
+
hn ? "sa-tf-fullwidth" : ""
|
|
792
795
|
].filter(Boolean).join(" "), yn = () => {
|
|
793
796
|
var t;
|
|
794
797
|
return (t = C.current) == null ? void 0 : t.focus();
|
|
@@ -800,12 +803,12 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
800
803
|
return;
|
|
801
804
|
}
|
|
802
805
|
const i = t.target.value;
|
|
803
|
-
let b = i,
|
|
806
|
+
let b = i, h = t.target.selectionStart ?? i.length;
|
|
804
807
|
if (mn === "Backspace") {
|
|
805
808
|
const T = W.replace(/\D/g, ""), In = i.replace(/\D/g, "");
|
|
806
|
-
T.length === In.length &&
|
|
809
|
+
T.length === In.length && h > 0 && (b = i.slice(0, h - 1) + i.slice(h), h -= 1);
|
|
807
810
|
}
|
|
808
|
-
const X = J(b), Cn = b.slice(0,
|
|
811
|
+
const X = J(b), Cn = b.slice(0, h).replace(/\D/g, "").length, Nn = Dn(X, Cn);
|
|
809
812
|
k.current = Nn, y(X), (cn = e.onChange) == null || cn.call(e, {
|
|
810
813
|
...t,
|
|
811
814
|
target: {
|
|
@@ -826,7 +829,7 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
826
829
|
c ? /* @__PURE__ */ s("span", { className: "sa-tf-optional", children: "Optional" }) : null,
|
|
827
830
|
V ? /* @__PURE__ */ s("span", { className: "sa-tf-required", "aria-hidden": "true", children: "*" }) : null
|
|
828
831
|
] }) : null, _ = /* @__PURE__ */ o(Ln, { children: [
|
|
829
|
-
|
|
832
|
+
x ? /* @__PURE__ */ s("p", { className: "sa-tf-helper", children: x }) : null,
|
|
830
833
|
p && d === "error" ? /* @__PURE__ */ s("p", { className: "sa-tf-error", children: p }) : null
|
|
831
834
|
] }), F = (t, i) => /* @__PURE__ */ s(
|
|
832
835
|
"span",
|
|
@@ -862,8 +865,8 @@ const $n = (n) => /* @__PURE__ */ o(
|
|
|
862
865
|
currentTarget: { value: "", name: e.name }
|
|
863
866
|
};
|
|
864
867
|
(b = e.onChange) == null || b.call(e, i), Y == null || Y(), k.current = 0, requestAnimationFrame(() => {
|
|
865
|
-
var
|
|
866
|
-
return (
|
|
868
|
+
var h;
|
|
869
|
+
return (h = C.current) == null ? void 0 : h.focus();
|
|
867
870
|
});
|
|
868
871
|
},
|
|
869
872
|
onMouseDown: (t) => t.preventDefault(),
|
package/dist/input.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(x,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):(x=typeof globalThis<"u"?globalThis:x||self,n(x.Input={},x.jsxRuntime,x.React))})(this,function(x,n,o){"use strict";const pn=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
2
2
|
|
|
3
3
|
:root {
|
|
4
4
|
/* Layer 3 — references Layer 2 semantic tokens */
|
|
@@ -157,6 +157,9 @@
|
|
|
157
157
|
.sa-tf-size-sm .sa-tf-box {
|
|
158
158
|
min-height: 32px;
|
|
159
159
|
}
|
|
160
|
+
.sa-tf-size-sm .sa-tf-box-content {
|
|
161
|
+
padding-block: 6px;
|
|
162
|
+
}
|
|
160
163
|
.sa-tf-size-md .sa-tf-box {
|
|
161
164
|
min-height: 40px;
|
|
162
165
|
}
|
|
@@ -583,4 +586,4 @@
|
|
|
583
586
|
.sa-tf-label-inside.sa-tf-floating.sa-tf-size-xl .sa-tf-box {
|
|
584
587
|
min-height: 80px;
|
|
585
588
|
}
|
|
586
|
-
`,y=t=>t==="lg"||t==="xl"?18: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)"},J=(t,a)=>a?j.disable:j[t]??j.default;function bn(t){return Number(t.replace(/\./g,""))}function O(t){let a=t.replace(/[^\d]/g,"");return a=a.replace(/^0+(?=\d)/,""),a.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function
|
|
589
|
+
`,y=t=>t==="lg"||t==="xl"?18: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)"},J=(t,a)=>a?j.disable:j[t]??j.default;function bn(t){return Number(t.replace(/\./g,""))}function O(t){let a=t.replace(/[^\d]/g,"");return a=a.replace(/^0+(?=\d)/,""),a.replace(/\B(?=(\d{3})+(?!\d))/g,".")}function xn(t,a){if(a<=0)return 0;let i=0;for(let l=0;l<t.length;l++)if(/\d/.test(t[l])&&(i+=1,i===a))return l+1;return t.length}const hn=o.forwardRef(({options:t,value:a,setValue:i,isComponentVisible:l,onOptionChange:d},f)=>{const[v,V]=o.useState([]),c=o.useRef(null),u=()=>{if(f!=null&&f.current&&c.current){const h=window.innerHeight,p=f==null?void 0:f.current.getBoundingClientRect(),m=c.current.getBoundingClientRect(),k=p.bottom+m.height;c.current.style.left=`${p.left}px`,c.current.style.width=`${p.width}px`,k>=h-10?c.current.style.top=`${p.top-m.height-5}px`:c.current.style.top=`${p.top+p.height}px`}};return o.useEffect(()=>(window.addEventListener("scroll",u),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u),window.removeEventListener("resize",u)}),[f,c]),o.useEffect(()=>{u()},[l]),o.useEffect(()=>{V((t==null?void 0:t.filter(h=>h.toLowerCase().startsWith(a.toLowerCase())))||[])},[a,t]),n.jsx("div",{ref:c,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:v==null?void 0:v.map(h=>gn(h,a,i,d))})}),gn=(t,a,i,l)=>{const d=t.toLowerCase().indexOf(a.toLowerCase());return n.jsxs("p",{style:{fontFamily:"Poppins",color:"var(--sa-color-gray-400, #b7b9be)",fontWeight:500,padding:"8px 14px",cursor:"pointer"},onClick:()=>{i(t),l&&l(t)},children:[t.slice(0,d),n.jsx("span",{style:{color:"var(--sa-text-primary, #292a2e)"},children:t.slice(d,d+a.length)}),t.slice(d+a.length)]})};function vn(t){const[a,i]=o.useState(t),l=o.useRef(null),d=f=>{l.current&&!l.current.contains(f.target)&&i(!1)};return o.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:l,isComponentVisible:a,setIsComponentVisible:i}}const Q="sa-input-styles";(t=>{if(!(typeof document>"u")&&!document.getElementById(Q)){const a=document.createElement("style");a.id=Q,a.textContent=t,document.head.appendChild(a)}})(pn);const mn=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"})]}),wn=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"})]}),Z=o.forwardRef((t,a)=>{const{size:i="md",variant:l="outline",status:d="default",label:f,labelPosition:v="outside-top",required:V,optional:c,description:u,helperText:h,errorText:p,leftIcon:m,rightIcon:k,leftAddons:S,rightAddons:L,onClickLeftIcon:R,onClickRightIcon:nn,fullWidth:kn=!1,highlightPlaceholder:$,currency:B,options:E,onOptionChange:Y,clearable:zn=!0,onClear:A,...s}=t,M=s.value!==void 0,[P,z]=o.useState(()=>{const e=s.value!==void 0?String(s.value??""):String(s.defaultValue??"");return B?O(e):e}),[tn,en]=o.useState(!1),[Cn,sn]=o.useState(""),C=o.useRef(null),N=o.useRef(null);o.useImperativeHandle(a,()=>N.current);const an=o.useRef(s.id??`sa-input-${Math.random().toString(36).slice(2,9)}`),{isComponentVisible:rn,ref:W,setIsComponentVisible:Nn}=vn(!1);o.useLayoutEffect(()=>{if(!M)return;const e=s.value===void 0||s.value===null?"":String(s.value),r=B?O(e):e;z(b=>b===r?b:r)},[s.value,B,M]),o.useLayoutEffect(()=>{if(C.current===null)return;const e=N.current,r=C.current;if(C.current=null,!!e)try{e.setSelectionRange(r,r)}catch{}},[P]);const I=P,T=I!==""&&I!==void 0,w=d==="disable"||s.disabled,q=w?"disable":d,H=v==="inside",In=H&&(T||tn),K=["sa-tf",`sa-tf-variant-${l}`,`sa-tf-size-${i}`,`sa-tf-status-${q}`,`sa-tf-label-${v}`,tn?"sa-tf-focused":"",w?"sa-tf-disabled":"",In?"sa-tf-floating":"",f?"":"sa-tf-no-label",kn?"sa-tf-fullwidth":""].filter(Boolean).join(" "),Sn=()=>{var e;return(e=N.current)==null?void 0:e.focus()},Ln=e=>{var cn,un;if(!B){const F=e.target.selectionStart;F!==null&&(C.current=F),z(e.target.value),(cn=s.onChange)==null||cn.call(s,e);return}const r=e.target.value;let b=r,g=e.target.selectionStart??r.length;if(Cn==="Backspace"){const F=P.replace(/\D/g,""),Fn=r.replace(/\D/g,"");F.length===Fn.length&&g>0&&(b=r.slice(0,g-1)+r.slice(g),g-=1)}const G=O(b),Tn=b.slice(0,g).replace(/\D/g,"").length,Dn=xn(G,Tn);C.current=Dn,z(G),(un=s.onChange)==null||un.call(s,{...e,target:{...e.target,value:String(bn(G)),name:e.target.name}}),sn("")},_=e=>f?n.jsxs("div",{className:e,children:[n.jsx("label",{htmlFor:an.current,style:{cursor:w?"not-allowed":"pointer"},children:f}),c?n.jsx("span",{className:"sa-tf-optional",children:"Optional"}):null,V?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,p&&d==="error"?n.jsx("p",{className:"sa-tf-error",children:p}):null]}),D=(e,r)=>n.jsx("span",{className:`sa-tf-icon${r?" sa-tf-icon-clickable":""}`,onClick:r,children:o.cloneElement(e,{width:y(i),height:y(i),color:J(q,w),style:{color:J(q,w)}})}),on=d==="success"?n.jsx("span",{className:"sa-tf-icon sa-tf-success-mark","aria-hidden":"true",children:n.jsx(mn,{width:y(i),height:y(i)})}):null,Bn=e=>{var b;e.stopPropagation(),M||z("");const r={target:{value:"",name:s.name},currentTarget:{value:"",name:s.name}};(b=s.onChange)==null||b.call(s,r),A==null||A(),C.current=0,requestAnimationFrame(()=>{var g;return(g=N.current)==null?void 0:g.focus()})},ln=zn&&!w?n.jsx("button",{type:"button",className:`sa-tf-icon sa-tf-clear${T?"":" sa-tf-clear-hidden"}`,"aria-label":"Clear input","aria-hidden":!T,tabIndex:-1,onClick:Bn,onMouseDown:e=>e.preventDefault(),children:n.jsx(wn,{width:y(i),height:y(i)})}):null,En=!T&&!!s.placeholder&&!!$,dn=n.jsxs("div",{className:"sa-tf-field-wrap",children:[n.jsx("input",{...s,id:an.current,ref:N,className:"sa-tf-input",disabled:w,placeholder:$?"":s.placeholder,value:I,onFocus:e=>{var r;en(!0),Nn(!0),(r=s.onFocus)==null||r.call(s,e)},onBlur:e=>{var r;en(!1),(r=s.onBlur)==null||r.call(s,e)},onKeyDown:e=>{var r;e.key==="Backspace"&&sn(e.key),(r=s.onKeyDown)==null||r.call(s,e)},onChange:Ln}),En?yn(s.placeholder,$):null]}),fn=I&&rn&&(E!=null&&E.length)?n.jsx(hn,{options:E,value:I,setValue:z,ref:W,isComponentVisible:rn,onOptionChange:e=>{Y==null||Y(e),z(e)}}):null,X=H?n.jsxs("div",{className:"sa-tf-box",ref:W,onClick:Sn,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?D(m,R):null,n.jsxs("div",{className:"sa-tf-inside-stack",children:[_("sa-tf-inside-label-row"),n.jsx("div",{className:"sa-tf-inside-row",children:dn})]}),ln,on,k?D(k,nn):null]}),L?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:L}):null,fn]}):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?D(m,R):null,dn,ln,on,k?D(k,nn):null]}),L?n.jsx("div",{className:"sa-tf-addon sa-tf-addon-right",children:L}):null,fn]});return v==="outside-left"?n.jsxs("div",{className:K,children:[n.jsxs("div",{className:"sa-tf-label-col",children:[_("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null]}),n.jsxs("div",{className:"sa-tf-input-col",children:[X,U]})]}):H?n.jsxs("div",{className:K,children:[X,U]}):n.jsxs("div",{className:K,children:[_("sa-tf-label"),u?n.jsx("p",{className:"sa-tf-desc-top",children:u}):null,X,U]})}),yn=(t,a)=>{if(!t)return null;if(!a)return n.jsx("p",{className:"sa-tf-placeholder",children:t});const i=t.toLowerCase().indexOf(a.toLowerCase());return i===-1?n.jsx("p",{className:"sa-tf-placeholder",children:t}):n.jsxs("p",{className:"sa-tf-placeholder",children:[t.slice(0,i),n.jsx("span",{className:"sa-tf-placeholder-highlight",children:t.slice(i,i+a.length)}),t.slice(i+a.length)]})};Z.displayName="Input",x.Input=Z,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starasia/input",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "input component for starasia UI",
|
|
5
5
|
"author": "Rizki Izzul Haq",
|
|
6
6
|
"main": "dist/input.umd.js",
|
|
@@ -12,10 +12,6 @@
|
|
|
12
12
|
"dist/*.map",
|
|
13
13
|
"dist/*.css"
|
|
14
14
|
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"dev": "vite --config vite.config.ts --port 3000",
|
|
17
|
-
"build": "vite build --config vite.config.ts"
|
|
18
|
-
},
|
|
19
15
|
"keywords": [],
|
|
20
16
|
"license": "ISC",
|
|
21
17
|
"type": "module",
|
|
@@ -37,5 +33,9 @@
|
|
|
37
33
|
"react-dom": "^18.2.0",
|
|
38
34
|
"@types/react": "^18.2.55",
|
|
39
35
|
"@types/react-dom": "^18.2.19"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"dev": "vite --config vite.config.ts --port 3000",
|
|
39
|
+
"build": "vite build --config vite.config.ts"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|