@starasia/dropdown 6.1.2 → 6.1.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.
@@ -105,20 +105,20 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
105
105
  }
106
106
 
107
107
  /* --- Standard variant (default) --- */
108
- .sa-input-dropdown-container.standard {
108
+ .sa-input-dropdown-container.sa-input-dropdown-standard {
109
109
  background-color: var(--sa-dropdown-bg-neutral);
110
110
  border: 1px solid transparent;
111
111
  border-radius: var(--borderRadius);
112
112
  }
113
- .sa-input-dropdown-container.standard.active {
113
+ .sa-input-dropdown-container.sa-input-dropdown-standard.active {
114
114
  border: 1px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
115
115
  box-shadow: var(--sa-dropdown-ring-active);
116
116
  }
117
- .sa-input-dropdown-container.standard.error {
117
+ .sa-input-dropdown-container.sa-input-dropdown-standard.error {
118
118
  background-color: var(--sa-dropdown-bg-error);
119
119
  border-color: var(--sa-dropdown-border-error-subtle);
120
120
  }
121
- .sa-input-dropdown-container.standard.disable {
121
+ .sa-input-dropdown-container.sa-input-dropdown-standard.disable {
122
122
  background-color: var(--sa-dropdown-bg-disabled);
123
123
  border-color: transparent;
124
124
  cursor: not-allowed;
@@ -127,21 +127,21 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
127
127
  }
128
128
 
129
129
  /* --- Outline variant --- */
130
- .sa-input-dropdown-container.outline {
130
+ .sa-input-dropdown-container.sa-input-dropdown-outline {
131
131
  background-color: transparent;
132
132
  border: 1px solid var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
133
133
  border-radius: var(--borderRadius);
134
134
  outline: none;
135
135
  }
136
- .sa-input-dropdown-container.outline.active {
136
+ .sa-input-dropdown-container.sa-input-dropdown-outline.active {
137
137
  border: 1.2px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
138
138
  box-shadow: none;
139
139
  }
140
- .sa-input-dropdown-container.outline.error {
140
+ .sa-input-dropdown-container.sa-input-dropdown-outline.error {
141
141
  background-color: transparent;
142
142
  border: 1px solid var(--sa-dropdown-border-error-subtle);
143
143
  }
144
- .sa-input-dropdown-container.outline.disable {
144
+ .sa-input-dropdown-container.sa-input-dropdown-outline.disable {
145
145
  background-color: var(--sa-dropdown-bg-disabled);
146
146
  border-color: var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
147
147
  cursor: not-allowed;
@@ -150,20 +150,20 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
150
150
  }
151
151
 
152
152
  /* --- Flushed variant --- */
153
- .sa-input-dropdown-container.flushed {
153
+ .sa-input-dropdown-container.sa-input-dropdown-flushed {
154
154
  background-color: transparent;
155
155
  border: none;
156
156
  border-bottom: 1px solid var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
157
157
  border-radius: 0;
158
158
  }
159
- .sa-input-dropdown-container.flushed.active {
159
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.active {
160
160
  border-bottom: 1.2px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
161
161
  box-shadow: none;
162
162
  }
163
- .sa-input-dropdown-container.flushed.error {
163
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.error {
164
164
  border-bottom: 1px solid var(--sa-dropdown-border-error-subtle);
165
165
  }
166
- .sa-input-dropdown-container.flushed.disable {
166
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.disable {
167
167
  cursor: not-allowed;
168
168
  pointer-events: none;
169
169
  opacity: 0.6;
@@ -223,8 +223,8 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
223
223
  color: var(--sa-dropdown-placeholder);
224
224
  font-weight: 400;
225
225
  }
226
- .sa-input-dropdown-container.outline .sa-input-dropdown-placeholder,
227
- .sa-input-dropdown-container.flushed .sa-input-dropdown-placeholder {
226
+ .sa-input-dropdown-container.sa-input-dropdown-outline .sa-input-dropdown-placeholder,
227
+ .sa-input-dropdown-container.sa-input-dropdown-flushed .sa-input-dropdown-placeholder {
228
228
  color: var(--sa-dropdown-placeholder-subtle);
229
229
  }
230
230
 
@@ -252,8 +252,8 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
252
252
  .sa-input-dropdown-trigger-input::placeholder {
253
253
  color: var(--sa-dropdown-placeholder);
254
254
  }
255
- .sa-input-dropdown-container.outline .sa-input-dropdown-trigger-input::placeholder,
256
- .sa-input-dropdown-container.flushed .sa-input-dropdown-trigger-input::placeholder {
255
+ .sa-input-dropdown-container.sa-input-dropdown-outline .sa-input-dropdown-trigger-input::placeholder,
256
+ .sa-input-dropdown-container.sa-input-dropdown-flushed .sa-input-dropdown-trigger-input::placeholder {
257
257
  color: var(--sa-dropdown-placeholder-subtle);
258
258
  }
259
259
  .sa-input-dropdown-container.disable .sa-input-dropdown-trigger-input {
@@ -660,9 +660,9 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
660
660
  searchValue: y,
661
661
  highlightedIndex: N,
662
662
  listboxId: M,
663
- footer: T,
663
+ footer: $,
664
664
  groupLabel: C,
665
- onSelectAll: $,
665
+ onSelectAll: T,
666
666
  emptyState: X
667
667
  }, Y) => {
668
668
  const O = K([]), q = y !== void 0, [Z, Q] = S(""), d = q ? y : Z, H = !t || t.length === 0;
@@ -719,12 +719,12 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
719
719
  ] }) : "No data available") }),
720
720
  C && !H && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
721
721
  /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: C }),
722
- k && $ && /* @__PURE__ */ n(
722
+ k && T && /* @__PURE__ */ n(
723
723
  "button",
724
724
  {
725
725
  className: "sa-input-dropdown-section-select-all",
726
726
  onClick: (a) => {
727
- a.stopPropagation(), $();
727
+ a.stopPropagation(), T();
728
728
  },
729
729
  children: "Select all"
730
730
  }
@@ -783,7 +783,7 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
783
783
  ]
784
784
  }
785
785
  ),
786
- T && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: T })
786
+ $ && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: $ })
787
787
  ]
788
788
  }
789
789
  ) : null });
@@ -817,9 +817,9 @@ const Pn = ({
817
817
  onSearch: y,
818
818
  error: N,
819
819
  onBlur: M,
820
- onFocus: T,
820
+ onFocus: $,
821
821
  disable: C,
822
- searchValue: $,
822
+ searchValue: T,
823
823
  variant: X = "outline",
824
824
  footer: Y,
825
825
  groupLabel: O,
@@ -998,7 +998,9 @@ const Pn = ({
998
998
  {
999
999
  className: [
1000
1000
  "sa-input-dropdown-container",
1001
- X,
1001
+ // namespaced: kelas variant polos ("outline"/"standard"/"flushed")
1002
+ // bentrok dgn utility Tailwind/shadcn (mis. `.outline`) → outline gelap.
1003
+ `sa-input-dropdown-${X}`,
1002
1004
  `sa-input-dropdown-size-${c}`,
1003
1005
  d ? "trigger-input" : "",
1004
1006
  w ? "active" : "",
@@ -1015,7 +1017,7 @@ const Pn = ({
1015
1017
  onKeyDown: d ? void 0 : wn,
1016
1018
  tabIndex: d ? void 0 : 0,
1017
1019
  onBlur: d ? void 0 : M,
1018
- onFocus: d ? void 0 : T,
1020
+ onFocus: d ? void 0 : $,
1019
1021
  children: [
1020
1022
  /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
1021
1023
  F ? sn.cloneElement(F, {
@@ -1040,7 +1042,7 @@ const Pn = ({
1040
1042
  onSearch: y,
1041
1043
  ref: v,
1042
1044
  multiSelect: s,
1043
- searchValue: d ? cn : $,
1045
+ searchValue: d ? cn : T,
1044
1046
  highlightedIndex: f,
1045
1047
  footer: Y,
1046
1048
  groupLabel: O,
@@ -1,4 +1,4 @@
1
- (function(g,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):(g=typeof globalThis<"u"?globalThis:g||self,n(g.Dropdown={},g.jsxRuntime,g.React))})(this,function(g,n,s){"use strict";const fn=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
1
+ (function(g,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):(g=typeof globalThis<"u"?globalThis:g||self,n(g.Dropdown={},g.jsxRuntime,g.React))})(this,function(g,n,s){"use strict";const un=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
2
2
  starasia, components, utilities). CSS app/Tailwind utility selalu bisa
3
3
  menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
4
4
  @layer starasia.components {
@@ -103,20 +103,20 @@
103
103
  }
104
104
 
105
105
  /* --- Standard variant (default) --- */
106
- .sa-input-dropdown-container.standard {
106
+ .sa-input-dropdown-container.sa-input-dropdown-standard {
107
107
  background-color: var(--sa-dropdown-bg-neutral);
108
108
  border: 1px solid transparent;
109
109
  border-radius: var(--borderRadius);
110
110
  }
111
- .sa-input-dropdown-container.standard.active {
111
+ .sa-input-dropdown-container.sa-input-dropdown-standard.active {
112
112
  border: 1px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
113
113
  box-shadow: var(--sa-dropdown-ring-active);
114
114
  }
115
- .sa-input-dropdown-container.standard.error {
115
+ .sa-input-dropdown-container.sa-input-dropdown-standard.error {
116
116
  background-color: var(--sa-dropdown-bg-error);
117
117
  border-color: var(--sa-dropdown-border-error-subtle);
118
118
  }
119
- .sa-input-dropdown-container.standard.disable {
119
+ .sa-input-dropdown-container.sa-input-dropdown-standard.disable {
120
120
  background-color: var(--sa-dropdown-bg-disabled);
121
121
  border-color: transparent;
122
122
  cursor: not-allowed;
@@ -125,21 +125,21 @@
125
125
  }
126
126
 
127
127
  /* --- Outline variant --- */
128
- .sa-input-dropdown-container.outline {
128
+ .sa-input-dropdown-container.sa-input-dropdown-outline {
129
129
  background-color: transparent;
130
130
  border: 1px solid var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
131
131
  border-radius: var(--borderRadius);
132
132
  outline: none;
133
133
  }
134
- .sa-input-dropdown-container.outline.active {
134
+ .sa-input-dropdown-container.sa-input-dropdown-outline.active {
135
135
  border: 1.2px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
136
136
  box-shadow: none;
137
137
  }
138
- .sa-input-dropdown-container.outline.error {
138
+ .sa-input-dropdown-container.sa-input-dropdown-outline.error {
139
139
  background-color: transparent;
140
140
  border: 1px solid var(--sa-dropdown-border-error-subtle);
141
141
  }
142
- .sa-input-dropdown-container.outline.disable {
142
+ .sa-input-dropdown-container.sa-input-dropdown-outline.disable {
143
143
  background-color: var(--sa-dropdown-bg-disabled);
144
144
  border-color: var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
145
145
  cursor: not-allowed;
@@ -148,20 +148,20 @@
148
148
  }
149
149
 
150
150
  /* --- Flushed variant --- */
151
- .sa-input-dropdown-container.flushed {
151
+ .sa-input-dropdown-container.sa-input-dropdown-flushed {
152
152
  background-color: transparent;
153
153
  border: none;
154
154
  border-bottom: 1px solid var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
155
155
  border-radius: 0;
156
156
  }
157
- .sa-input-dropdown-container.flushed.active {
157
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.active {
158
158
  border-bottom: 1.2px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
159
159
  box-shadow: none;
160
160
  }
161
- .sa-input-dropdown-container.flushed.error {
161
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.error {
162
162
  border-bottom: 1px solid var(--sa-dropdown-border-error-subtle);
163
163
  }
164
- .sa-input-dropdown-container.flushed.disable {
164
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.disable {
165
165
  cursor: not-allowed;
166
166
  pointer-events: none;
167
167
  opacity: 0.6;
@@ -221,8 +221,8 @@
221
221
  color: var(--sa-dropdown-placeholder);
222
222
  font-weight: 400;
223
223
  }
224
- .sa-input-dropdown-container.outline .sa-input-dropdown-placeholder,
225
- .sa-input-dropdown-container.flushed .sa-input-dropdown-placeholder {
224
+ .sa-input-dropdown-container.sa-input-dropdown-outline .sa-input-dropdown-placeholder,
225
+ .sa-input-dropdown-container.sa-input-dropdown-flushed .sa-input-dropdown-placeholder {
226
226
  color: var(--sa-dropdown-placeholder-subtle);
227
227
  }
228
228
 
@@ -250,8 +250,8 @@
250
250
  .sa-input-dropdown-trigger-input::placeholder {
251
251
  color: var(--sa-dropdown-placeholder);
252
252
  }
253
- .sa-input-dropdown-container.outline .sa-input-dropdown-trigger-input::placeholder,
254
- .sa-input-dropdown-container.flushed .sa-input-dropdown-trigger-input::placeholder {
253
+ .sa-input-dropdown-container.sa-input-dropdown-outline .sa-input-dropdown-trigger-input::placeholder,
254
+ .sa-input-dropdown-container.sa-input-dropdown-flushed .sa-input-dropdown-trigger-input::placeholder {
255
255
  color: var(--sa-dropdown-placeholder-subtle);
256
256
  }
257
257
  .sa-input-dropdown-container.disable .sa-input-dropdown-trigger-input {
@@ -584,4 +584,4 @@
584
584
  }
585
585
 
586
586
  } /* @layer starasia.components */
587
- `;function hn(o){const[d,t]=s.useState(o),p=s.useRef(null),c=i=>{p.current&&!p.current.contains(i.target)&&t(!1)};return s.useEffect(()=>(document.addEventListener("click",c,!0),()=>{document.removeEventListener("click",c,!0)}),[]),{ref:p,isComponentVisible:d,setIsComponentVisible:t}}const un=({...o})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...o,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),bn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),vn=s.forwardRef(({positionDropdown:o,dropdownLists:d,isComponentVisible:t,searchAble:p,hideSearch:c,onSearch:i,value:A,handleChangeValue:T,multiSelect:y,searchValue:k,highlightedIndex:N,listboxId:M,footer:W,groupLabel:E,onSelectAll:$,emptyState:K},X)=>{const O=s.useRef([]),q=k!==void 0,[Y,Z]=s.useState(""),l=q?k:Y,H=!d||d.length===0;s.useEffect(()=>{var a;N>=0&&O.current[N]&&((a=O.current[N])==null||a.scrollIntoView({block:"nearest"}))},[N]);const Q=p&&!c?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(un,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{q||Z(a.target.value),i&&i(a.target.value)},value:l,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:X,children:[Q,n.jsxs("div",{className:`sa-input-dropdown-item-container ${y?"multi":""}`,role:"listbox",id:M,"aria-multiselectable":y||void 0,children:[H&&n.jsx("div",{className:"sa-input-dropdown-empty",children:K??(l?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",l,"”"]})]}):"No data available")}),E&&!H&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:E}),y&&$&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),$()},children:"Select all"})]}),d==null?void 0:d.map((a,m)=>{const C=!!(A!=null&&A.find(S=>S.value===a.value)),_=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",_?"has-description":"",C?"active":"",m===N?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),id:M?`${M}-opt-${m}`:void 0,role:"option","aria-selected":C,"aria-disabled":a.disable||void 0,ref:S=>{O.current[m]=S},onClick:()=>T(a.label,a.value),children:[y&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:C&&n.jsx(bn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:s.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},m)})]}),W&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:W})]}):null})}),xn=({children:o,handleChangePosition:d,enabled:t=!0})=>(s.useEffect(()=>{if(t)return window.addEventListener("scroll",d,!0),()=>{window.removeEventListener("scroll",d,!0)}},[t,d]),n.jsx("div",{children:o})),rn="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(rn)){const d=document.createElement("style");d.id=rn,d.textContent=o,document.head.appendChild(d)}})(fn);const gn=({dropdownLists:o,onChange:d,defaultValue:t,value:p,size:c="sm",multiSelect:i,searchAble:A,iconLeft:T,placeholder:y,onSearch:k,error:N,onBlur:M,onFocus:W,disable:E,searchValue:$,variant:K="outline",footer:X,groupLabel:O,onSelectAll:q,emptyState:Y,fullWidth:Z=!0,triggerInput:l=!1,clearOnSelect:H=!1,hideChevronIcon:Q=!1,clearable:a=!1,onClear:m,label:C,labelPosition:_="outside-top",required:S,optional:dn,description:D,helperText:j,errorText:h})=>{const V=["sa-select-field",`sa-select-field-size-${c}`,Z?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),z=p!==void 0,R=s.useRef(),Nn=N||!!h,[w,L]=s.useState(z?p||[]:t||[]),[En,tn]=s.useState(""),[u,nn]=s.useState(-1),G=s.useId(),ln=u>=0?`${G}-opt-${u}`:void 0,[pn,U]=s.useState(()=>{var e,r;return!i&&(p!=null&&p.length||t!=null&&t.length)?((e=p==null?void 0:p[0])==null?void 0:e.label)??((r=t==null?void 0:t[0])==null?void 0:r.label)??"":""}),v=s.useRef(null),{isComponentVisible:f,ref:en,setIsComponentVisible:B}=hn(!1),I=o!==void 0,cn=w.length>0,Cn=e=>{e.stopPropagation();const r=[];z||L(r),d(r),l&&U(""),m==null||m()},zn=()=>{I&&B(e=>!e)},J=(e,r)=>{if(i){if(w==null?void 0:w.find(x=>x.value===r)){const x=w.filter(jn=>jn.value!==r);z||L(x),d(x)}else{const x=[...w,{label:e,value:r}];z||L(x),d(x)}l&&U("")}else{const b=[{label:e,value:r}];z||L(b),d(b),l&&U(H?"":e),B(!1)}};s.useEffect(()=>{z&&L(p||[])},[p]),s.useEffect(()=>{z||JSON.stringify(R.current)===JSON.stringify(t)||(R.current=t,L(R.current||[]))},[t]);const Bn=()=>w.length?i?w==null?void 0:w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(sn,{onClick:b=>{b.stopPropagation(),J(e.label,e.value)}})]},r)):n.jsx("p",{style:{minWidth:"max-content"},children:w==null?void 0:w[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:y}),F=()=>{if(en.current&&v.current){const e=window.innerHeight,r=en.current.getBoundingClientRect(),b=v.current.getBoundingClientRect(),x=r.bottom+b.height;v.current.style.left=`${r.left}px`,v.current.style.width=`${r.width}px`,x>=e-10?(v.current.style.top=`${r.top-b.height-5}px`,tn("top")):(v.current.style.top=`${r.top+r.height+4}px`,tn("bottom"))}};s.useEffect(()=>(window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F)}),[]),s.useEffect(()=>{F()},[f]),s.useEffect(()=>{if(!f||!v.current)return;const e=new ResizeObserver(()=>{F()});return e.observe(v.current),()=>e.disconnect()},[f]),s.useEffect(()=>{f||nn(-1)},[f]);const wn=e=>{if(I){if(!f){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),B(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=an(o,u,1);r!==-1&&nn(r);break}case"ArrowUp":{e.preventDefault();const r=an(o,u,-1);r!==-1&&nn(r);break}case"Enter":{e.preventDefault(),u>=0&&o[u]&&!o[u].disable&&J(o[u].label,o[u].value);break}case"Escape":B(!1);break}}},P=c==="lg"||c==="xl"?20:c==="xs"?14:16,Sn=a&&!E?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${cn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!cn,tabIndex:-1,onClick:Cn,onMouseDown:e=>e.preventDefault(),children:n.jsx(mn,{width:P,height:P})}):null,Dn=l?n.jsxs(n.Fragment,{children:[i&&w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(sn,{onClick:b=>{b.stopPropagation(),J(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",role:"combobox","aria-expanded":f,"aria-haspopup":"listbox","aria-controls":G,"aria-activedescendant":ln,"aria-autocomplete":"list",value:pn,onChange:e=>{const r=e.target.value;U(r),k==null||k(r),!f&&I&&B(!0)},onFocus:()=>{!E&&I&&B(!0)},onBlur:()=>{i||setTimeout(()=>B(!1),150)},onKeyDown:wn,placeholder:w.length===0||i?y:void 0,disabled:E})]}):null,on=n.jsx(xn,{handleChangePosition:F,enabled:f,children:n.jsxs("div",{className:["sa-input-dropdown-container",K,`sa-input-dropdown-size-${c}`,l?"trigger-input":"",f?"active":"",Nn?"error":"",E?"disable":""].filter(Boolean).join(" "),ref:en,role:l?void 0:"combobox","aria-haspopup":l?void 0:"listbox","aria-expanded":l?void 0:f,"aria-controls":l?void 0:G,"aria-activedescendant":l?void 0:ln,onClick:l?void 0:zn,onKeyDown:l?void 0:wn,tabIndex:l?void 0:0,onBlur:l?void 0:M,onFocus:l?void 0:W,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[T?s.cloneElement(T,{width:P,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:l?Dn:Bn()}),Sn,!Q&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:f?n.jsx(kn,{width:P}):n.jsx(yn,{width:P})})]}),I&&n.jsx(vn,{dropdownLists:o,handleChangeValue:J,isComponentVisible:f,listboxId:G,positionDropdown:En,searchAble:!!A,hideSearch:l,value:w,onSearch:k,ref:v,multiSelect:i,searchValue:l?pn:$,highlightedIndex:u,footer:X,groupLabel:O,onSelectAll:q,emptyState:Y})]})});return C?_==="outside-left"?n.jsxs("div",{className:`${V} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),S&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[on,j&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:j}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})]}):n.jsxs("div",{className:V,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),S&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),on,j&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:j}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]}):n.jsxs("div",{className:V,children:[D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),on,j&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:j}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},an=(o,d,t)=>{const p=o.length;let c=d+t;for(;c>=0&&c<p;){if(!o[c].disable)return c;c+=t}if(t===1){for(let i=0;i<p;i++)if(!o[i].disable)return i}else for(let i=p-1;i>=0;i--)if(!o[i].disable)return i;return-1},mn=o=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o,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"})]}),sn=o=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",style:{flexShrink:0,cursor:"pointer"},...o,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),yn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),kn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 10L8 6L12 10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});g.Dropdown=gn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
587
+ `;function fn(o){const[d,t]=s.useState(o),p=s.useRef(null),c=i=>{p.current&&!p.current.contains(i.target)&&t(!1)};return s.useEffect(()=>(document.addEventListener("click",c,!0),()=>{document.removeEventListener("click",c,!0)}),[]),{ref:p,isComponentVisible:d,setIsComponentVisible:t}}const hn=({...o})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...o,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),bn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),vn=s.forwardRef(({positionDropdown:o,dropdownLists:d,isComponentVisible:t,searchAble:p,hideSearch:c,onSearch:i,value:A,handleChangeValue:T,multiSelect:y,searchValue:k,highlightedIndex:N,listboxId:M,footer:W,groupLabel:E,onSelectAll:$,emptyState:K},X)=>{const O=s.useRef([]),q=k!==void 0,[Y,Z]=s.useState(""),l=q?k:Y,H=!d||d.length===0;s.useEffect(()=>{var a;N>=0&&O.current[N]&&((a=O.current[N])==null||a.scrollIntoView({block:"nearest"}))},[N]);const Q=p&&!c?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(hn,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{q||Z(a.target.value),i&&i(a.target.value)},value:l,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:X,children:[Q,n.jsxs("div",{className:`sa-input-dropdown-item-container ${y?"multi":""}`,role:"listbox",id:M,"aria-multiselectable":y||void 0,children:[H&&n.jsx("div",{className:"sa-input-dropdown-empty",children:K??(l?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",l,"”"]})]}):"No data available")}),E&&!H&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:E}),y&&$&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),$()},children:"Select all"})]}),d==null?void 0:d.map((a,m)=>{const C=!!(A!=null&&A.find(S=>S.value===a.value)),_=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",_?"has-description":"",C?"active":"",m===N?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),id:M?`${M}-opt-${m}`:void 0,role:"option","aria-selected":C,"aria-disabled":a.disable||void 0,ref:S=>{O.current[m]=S},onClick:()=>T(a.label,a.value),children:[y&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:C&&n.jsx(bn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:s.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},m)})]}),W&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:W})]}):null})}),xn=({children:o,handleChangePosition:d,enabled:t=!0})=>(s.useEffect(()=>{if(t)return window.addEventListener("scroll",d,!0),()=>{window.removeEventListener("scroll",d,!0)}},[t,d]),n.jsx("div",{children:o})),rn="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(rn)){const d=document.createElement("style");d.id=rn,d.textContent=o,document.head.appendChild(d)}})(un);const gn=({dropdownLists:o,onChange:d,defaultValue:t,value:p,size:c="sm",multiSelect:i,searchAble:A,iconLeft:T,placeholder:y,onSearch:k,error:N,onBlur:M,onFocus:W,disable:E,searchValue:$,variant:K="outline",footer:X,groupLabel:O,onSelectAll:q,emptyState:Y,fullWidth:Z=!0,triggerInput:l=!1,clearOnSelect:H=!1,hideChevronIcon:Q=!1,clearable:a=!1,onClear:m,label:C,labelPosition:_="outside-top",required:S,optional:dn,description:D,helperText:j,errorText:f})=>{const V=["sa-select-field",`sa-select-field-size-${c}`,Z?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),z=p!==void 0,R=s.useRef(),Nn=N||!!f,[w,L]=s.useState(z?p||[]:t||[]),[En,tn]=s.useState(""),[h,nn]=s.useState(-1),G=s.useId(),ln=h>=0?`${G}-opt-${h}`:void 0,[pn,U]=s.useState(()=>{var e,r;return!i&&(p!=null&&p.length||t!=null&&t.length)?((e=p==null?void 0:p[0])==null?void 0:e.label)??((r=t==null?void 0:t[0])==null?void 0:r.label)??"":""}),v=s.useRef(null),{isComponentVisible:u,ref:en,setIsComponentVisible:B}=fn(!1),I=o!==void 0,cn=w.length>0,Cn=e=>{e.stopPropagation();const r=[];z||L(r),d(r),l&&U(""),m==null||m()},zn=()=>{I&&B(e=>!e)},J=(e,r)=>{if(i){if(w==null?void 0:w.find(x=>x.value===r)){const x=w.filter(jn=>jn.value!==r);z||L(x),d(x)}else{const x=[...w,{label:e,value:r}];z||L(x),d(x)}l&&U("")}else{const b=[{label:e,value:r}];z||L(b),d(b),l&&U(H?"":e),B(!1)}};s.useEffect(()=>{z&&L(p||[])},[p]),s.useEffect(()=>{z||JSON.stringify(R.current)===JSON.stringify(t)||(R.current=t,L(R.current||[]))},[t]);const Bn=()=>w.length?i?w==null?void 0:w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(sn,{onClick:b=>{b.stopPropagation(),J(e.label,e.value)}})]},r)):n.jsx("p",{style:{minWidth:"max-content"},children:w==null?void 0:w[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:y}),F=()=>{if(en.current&&v.current){const e=window.innerHeight,r=en.current.getBoundingClientRect(),b=v.current.getBoundingClientRect(),x=r.bottom+b.height;v.current.style.left=`${r.left}px`,v.current.style.width=`${r.width}px`,x>=e-10?(v.current.style.top=`${r.top-b.height-5}px`,tn("top")):(v.current.style.top=`${r.top+r.height+4}px`,tn("bottom"))}};s.useEffect(()=>(window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F)}),[]),s.useEffect(()=>{F()},[u]),s.useEffect(()=>{if(!u||!v.current)return;const e=new ResizeObserver(()=>{F()});return e.observe(v.current),()=>e.disconnect()},[u]),s.useEffect(()=>{u||nn(-1)},[u]);const wn=e=>{if(I){if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),B(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=an(o,h,1);r!==-1&&nn(r);break}case"ArrowUp":{e.preventDefault();const r=an(o,h,-1);r!==-1&&nn(r);break}case"Enter":{e.preventDefault(),h>=0&&o[h]&&!o[h].disable&&J(o[h].label,o[h].value);break}case"Escape":B(!1);break}}},P=c==="lg"||c==="xl"?20:c==="xs"?14:16,Sn=a&&!E?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${cn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!cn,tabIndex:-1,onClick:Cn,onMouseDown:e=>e.preventDefault(),children:n.jsx(mn,{width:P,height:P})}):null,Dn=l?n.jsxs(n.Fragment,{children:[i&&w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(sn,{onClick:b=>{b.stopPropagation(),J(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",role:"combobox","aria-expanded":u,"aria-haspopup":"listbox","aria-controls":G,"aria-activedescendant":ln,"aria-autocomplete":"list",value:pn,onChange:e=>{const r=e.target.value;U(r),k==null||k(r),!u&&I&&B(!0)},onFocus:()=>{!E&&I&&B(!0)},onBlur:()=>{i||setTimeout(()=>B(!1),150)},onKeyDown:wn,placeholder:w.length===0||i?y:void 0,disabled:E})]}):null,on=n.jsx(xn,{handleChangePosition:F,enabled:u,children:n.jsxs("div",{className:["sa-input-dropdown-container",`sa-input-dropdown-${K}`,`sa-input-dropdown-size-${c}`,l?"trigger-input":"",u?"active":"",Nn?"error":"",E?"disable":""].filter(Boolean).join(" "),ref:en,role:l?void 0:"combobox","aria-haspopup":l?void 0:"listbox","aria-expanded":l?void 0:u,"aria-controls":l?void 0:G,"aria-activedescendant":l?void 0:ln,onClick:l?void 0:zn,onKeyDown:l?void 0:wn,tabIndex:l?void 0:0,onBlur:l?void 0:M,onFocus:l?void 0:W,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[T?s.cloneElement(T,{width:P,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:l?Dn:Bn()}),Sn,!Q&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:u?n.jsx(kn,{width:P}):n.jsx(yn,{width:P})})]}),I&&n.jsx(vn,{dropdownLists:o,handleChangeValue:J,isComponentVisible:u,listboxId:G,positionDropdown:En,searchAble:!!A,hideSearch:l,value:w,onSearch:k,ref:v,multiSelect:i,searchValue:l?pn:$,highlightedIndex:h,footer:X,groupLabel:O,onSelectAll:q,emptyState:Y})]})});return C?_==="outside-left"?n.jsxs("div",{className:`${V} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),S&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[on,j&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:j}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})]}):n.jsxs("div",{className:V,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),S&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),on,j&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:j}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]}):n.jsxs("div",{className:V,children:[D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),on,j&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:j}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})},an=(o,d,t)=>{const p=o.length;let c=d+t;for(;c>=0&&c<p;){if(!o[c].disable)return c;c+=t}if(t===1){for(let i=0;i<p;i++)if(!o[i].disable)return i}else for(let i=p-1;i>=0;i--)if(!o[i].disable)return i;return-1},mn=o=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o,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"})]}),sn=o=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",style:{flexShrink:0,cursor:"pointer"},...o,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),yn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),kn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 10L8 6L12 10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});g.Dropdown=gn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "6.1.2",
3
+ "version": "6.1.3",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",