@solibo/solibo-ui 0.4.12 → 0.5.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.
Files changed (191) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/index.css +1 -1
  3. package/dist/assets/index10.css +1 -1
  4. package/dist/assets/index11.css +1 -1
  5. package/dist/assets/index12.css +1 -1
  6. package/dist/assets/index13.css +1 -1
  7. package/dist/assets/index14.css +1 -1
  8. package/dist/assets/index15.css +1 -1
  9. package/dist/assets/index16.css +1 -1
  10. package/dist/assets/index17.css +1 -1
  11. package/dist/assets/index18.css +1 -1
  12. package/dist/assets/index19.css +1 -1
  13. package/dist/assets/index2.css +1 -1
  14. package/dist/assets/index20.css +1 -1
  15. package/dist/assets/index21.css +1 -1
  16. package/dist/assets/index22.css +1 -1
  17. package/dist/assets/index23.css +1 -1
  18. package/dist/assets/index24.css +1 -1
  19. package/dist/assets/index25.css +1 -1
  20. package/dist/assets/index26.css +1 -1
  21. package/dist/assets/index27.css +1 -1
  22. package/dist/assets/index29.css +1 -1
  23. package/dist/assets/index3.css +1 -1
  24. package/dist/assets/index31.css +1 -1
  25. package/dist/assets/index32.css +1 -1
  26. package/dist/assets/index33.css +1 -1
  27. package/dist/assets/index34.css +1 -1
  28. package/dist/assets/index35.css +1 -1
  29. package/dist/assets/index36.css +1 -1
  30. package/dist/assets/index37.css +1 -1
  31. package/dist/assets/index38.css +1 -1
  32. package/dist/assets/index39.css +1 -1
  33. package/dist/assets/index40.css +1 -1
  34. package/dist/assets/index41.css +1 -1
  35. package/dist/assets/index42.css +1 -1
  36. package/dist/assets/index43.css +1 -1
  37. package/dist/assets/index44.css +1 -1
  38. package/dist/assets/index5.css +1 -1
  39. package/dist/assets/index6.css +1 -1
  40. package/dist/assets/index7.css +0 -1
  41. package/dist/assets/index8.css +1 -0
  42. package/dist/assets/index9.css +1 -1
  43. package/dist/assets/styles.css +1 -1
  44. package/dist/components/_avatar/index.cjs +1 -1
  45. package/dist/components/_avatar/index.cjs.map +1 -1
  46. package/dist/components/_avatar/index.js +9 -9
  47. package/dist/components/_avatar/index.js.map +1 -1
  48. package/dist/components/_card/index.cjs +1 -1
  49. package/dist/components/_card/index.js +12 -12
  50. package/dist/components/_collapsible/index.cjs +1 -1
  51. package/dist/components/_collapsible/index.js +1 -1
  52. package/dist/components/_croppable/index.cjs +1 -1
  53. package/dist/components/_croppable/index.js +175 -175
  54. package/dist/components/_dropdown/index.cjs +1 -1
  55. package/dist/components/_dropdown/index.cjs.map +1 -1
  56. package/dist/components/_dropdown/index.js +87 -87
  57. package/dist/components/_dropdown/index.js.map +1 -1
  58. package/dist/components/_dropzone/index.cjs +1 -1
  59. package/dist/components/_dropzone/index.js +34 -34
  60. package/dist/components/_editor/index.cjs +16 -16
  61. package/dist/components/_editor/index.cjs.map +1 -1
  62. package/dist/components/_editor/index.js +19 -19
  63. package/dist/components/_editor/index.js.map +1 -1
  64. package/dist/components/_messages/index.cjs +1 -1
  65. package/dist/components/_messages/index.cjs.map +1 -1
  66. package/dist/components/_messages/index.js +15 -15
  67. package/dist/components/_messages/index.js.map +1 -1
  68. package/dist/components/_portal/index.cjs +1 -1
  69. package/dist/components/_portal/index.cjs.map +1 -1
  70. package/dist/components/_portal/index.js +17 -16
  71. package/dist/components/_portal/index.js.map +1 -1
  72. package/dist/components/_sortable/index.cjs +1 -1
  73. package/dist/components/_sortable/index.cjs.map +1 -1
  74. package/dist/components/_sortable/index.js +21 -21
  75. package/dist/components/_sortable/index.js.map +1 -1
  76. package/dist/components/_widget/index.cjs +1 -1
  77. package/dist/components/_widget/index.js +3 -3
  78. package/dist/components/app-link/index.cjs +1 -1
  79. package/dist/components/app-link/index.cjs.map +1 -1
  80. package/dist/components/app-link/index.js +9 -9
  81. package/dist/components/app-link/index.js.map +1 -1
  82. package/dist/components/aside/index.cjs +1 -1
  83. package/dist/components/aside/index.js +6 -6
  84. package/dist/components/badge/index.cjs +1 -1
  85. package/dist/components/badge/index.cjs.map +1 -1
  86. package/dist/components/badge/index.js +19 -18
  87. package/dist/components/badge/index.js.map +1 -1
  88. package/dist/components/banner/index.cjs +1 -1
  89. package/dist/components/banner/index.js +9 -9
  90. package/dist/components/branding/index.cjs +1 -1
  91. package/dist/components/branding/index.js +12 -12
  92. package/dist/components/button/index.cjs +1 -1
  93. package/dist/components/button/index.js +12 -12
  94. package/dist/components/checkbox/index.cjs +1 -1
  95. package/dist/components/checkbox/index.js +7 -7
  96. package/dist/components/controls/index.cjs +1 -1
  97. package/dist/components/controls/index.cjs.map +1 -1
  98. package/dist/components/controls/index.js +21 -10
  99. package/dist/components/controls/index.js.map +1 -1
  100. package/dist/components/dialog/index.cjs +1 -1
  101. package/dist/components/dialog/index.js +3 -3
  102. package/dist/components/figure/index.cjs +1 -1
  103. package/dist/components/figure/index.cjs.map +1 -1
  104. package/dist/components/figure/index.js +11 -11
  105. package/dist/components/figure/index.js.map +1 -1
  106. package/dist/components/file/index.cjs +1 -1
  107. package/dist/components/file/index.cjs.map +1 -1
  108. package/dist/components/file/index.js +14 -13
  109. package/dist/components/file/index.js.map +1 -1
  110. package/dist/components/footer/index.cjs +1 -1
  111. package/dist/components/footer/index.js +3 -3
  112. package/dist/components/form/index.cjs +1 -1
  113. package/dist/components/form/index.js +11 -11
  114. package/dist/components/graph/index.cjs +1 -1
  115. package/dist/components/graph/index.cjs.map +1 -1
  116. package/dist/components/graph/index.js +31 -31
  117. package/dist/components/graph/index.js.map +1 -1
  118. package/dist/components/group/index.cjs +1 -1
  119. package/dist/components/group/index.js +1 -1
  120. package/dist/components/header/index.cjs +1 -1
  121. package/dist/components/header/index.js +3 -3
  122. package/dist/components/icon/index.cjs +1 -1
  123. package/dist/components/icon/index.cjs.map +1 -1
  124. package/dist/components/icon/index.js +26 -26
  125. package/dist/components/icon/index.js.map +1 -1
  126. package/dist/components/image/index.cjs +1 -1
  127. package/dist/components/image/index.js +9 -9
  128. package/dist/components/input/index.cjs +1 -1
  129. package/dist/components/input/index.cjs.map +1 -1
  130. package/dist/components/input/index.js +34 -33
  131. package/dist/components/input/index.js.map +1 -1
  132. package/dist/components/link/index.cjs +1 -1
  133. package/dist/components/link/index.js +11 -11
  134. package/dist/components/list/index.cjs +1 -1
  135. package/dist/components/list/index.js +7 -7
  136. package/dist/components/loading/index.cjs +1 -1
  137. package/dist/components/loading/index.js +13 -13
  138. package/dist/components/message/index.cjs +1 -1
  139. package/dist/components/message/index.js +7 -7
  140. package/dist/components/nav/index.cjs +1 -1
  141. package/dist/components/nav/index.js +23 -23
  142. package/dist/components/object/index.cjs +1 -1
  143. package/dist/components/object/index.cjs.map +1 -1
  144. package/dist/components/object/index.js +1 -1
  145. package/dist/components/object/index.js.map +1 -1
  146. package/dist/components/select/index.cjs +1 -1
  147. package/dist/components/select/index.js +1 -1
  148. package/dist/components/table/index.cjs +1 -1
  149. package/dist/components/table/index.cjs.map +1 -1
  150. package/dist/components/table/index.js +22 -22
  151. package/dist/components/table/index.js.map +1 -1
  152. package/dist/components/textarea/index.cjs +1 -1
  153. package/dist/components/textarea/index.cjs.map +1 -1
  154. package/dist/components/textarea/index.js +23 -23
  155. package/dist/components/textarea/index.js.map +1 -1
  156. package/dist/components/toast/index.cjs +1 -1
  157. package/dist/components/toast/index.cjs.map +1 -1
  158. package/dist/components/toast/index.js +23 -24
  159. package/dist/components/toast/index.js.map +1 -1
  160. package/dist/components/toggle/index.cjs +1 -1
  161. package/dist/components/toggle/index.js +1 -1
  162. package/dist/components/toolbar/index.cjs +1 -1
  163. package/dist/components/toolbar/index.js +9 -9
  164. package/dist/index-CiEbbnD6.js +42 -0
  165. package/dist/index-CiEbbnD6.js.map +1 -0
  166. package/dist/index-ClrKYsAQ.cjs +2 -0
  167. package/dist/index-ClrKYsAQ.cjs.map +1 -0
  168. package/dist/index.cjs +1 -1
  169. package/dist/index.d.ts +20 -23
  170. package/dist/index.js +40 -42
  171. package/dist/index.js.map +1 -1
  172. package/dist/styles.module-BOTEBJ0C.js +9 -0
  173. package/dist/styles.module-BOTEBJ0C.js.map +1 -0
  174. package/dist/styles.module-BPvMQa_x.cjs +2 -0
  175. package/dist/styles.module-BPvMQa_x.cjs.map +1 -0
  176. package/dist/tokens.css +44 -12
  177. package/dist/tokens.json +541 -68
  178. package/package.json +1 -1
  179. package/dist/assets/index45.css +0 -1
  180. package/dist/components/layout/index.cjs +0 -2
  181. package/dist/components/layout/index.cjs.map +0 -1
  182. package/dist/components/layout/index.js +0 -18
  183. package/dist/components/layout/index.js.map +0 -1
  184. package/dist/index-BNaQZHo6.js +0 -40
  185. package/dist/index-BNaQZHo6.js.map +0 -1
  186. package/dist/index-Bh5n72jH.cjs +0 -2
  187. package/dist/index-Bh5n72jH.cjs.map +0 -1
  188. package/dist/styles.module-DZXAP_eP.js +0 -8
  189. package/dist/styles.module-DZXAP_eP.js.map +0 -1
  190. package/dist/styles.module-Vt6mmlsz.cjs +0 -2
  191. package/dist/styles.module-Vt6mmlsz.cjs.map +0 -1
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('../../assets/index22.css');const i=require("react/jsx-runtime"),E=require("../../classix-5H4IWnMA.cjs"),o=require("react"),W=require("../button/index.cjs"),U=require("../../icons-C_cX1FYp.cjs"),X=require("../input/index.cjs"),Y=require("../../styles.module-Vt6mmlsz.cjs"),Z=require("../list/index.cjs"),k=require("../../index-Bh5n72jH.cjs"),M=require("../../utils-DBzf7CFq.cjs"),ee="_dropdown_ruf4w_1",te="_empty_ruf4w_4",ne="_group_ruf4w_5",re="_placeholder_ruf4w_6",se="_filter_ruf4w_14",oe="_native_ruf4w_25",le="_option_ruf4w_35",ie="_options_ruf4w_57",ce="_panel_ruf4w_81",ae="_selected_ruf4w_102",ue="_text_ruf4w_106",pe="_trigger_ruf4w_114",de="_minimal_ruf4w_130",c={dropdown:ee,empty:te,group:ne,placeholder:re,filter:se,native:oe,option:le,options:ie,panel:ce,selected:ae,text:ue,trigger:pe,minimal:de};function Q(e,r){return{"--icon-svg":U.iconSVG(e).replace("currentColor",r)}}function N(e){return typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(N).join(" "):o.isValidElement(e)?N(e.props.children):""}function fe(e){return o.isValidElement(e)&&e.type==="option"}function me(e){return o.isValidElement(e)&&e.type==="optgroup"}function he(e){return o.isValidElement(e)&&e.type===o.Fragment}function _e(e){return o.isValidElement(e)&&e.type===k.Select}function V(e,r,s=!1){const l=[];return o.Children.forEach(e,t=>{if(he(t)){l.push(...V(t.props.children,r,s));return}if(fe(t)){const p=N(t.props.children).trim(),d=t.props.value!=null?String(t.props.value):p;l.push({disabled:s||!!t.props.disabled,groupLabel:r,hidden:!!t.props.hidden,isPlaceholder:!!(t.props.hidden&&d===""),label:t.props.children,selected:!!t.props.selected,text:p,value:d});return}me(t)&&l.push(...V(t.props.children,t.props.label,s||!!t.props.disabled))}),l}function ge(e){const r=e.trim();if(!r)return null;const l=[.../[*?]/.test(r)?r:`*${r}*`].map(t=>t==="*"?".*":t==="?"?".":t.replace(/[|\\{}()[\]^$+.,]/g,"\\$&")).join("");return new RegExp(`^${l}$`,"i")}function we(e,r){const s=ge(r),l=e.filter(t=>!t.hidden&&!t.isPlaceholder);return s?l.filter(t=>s.test([t.groupLabel,t.text,t.value].filter(Boolean).join(" "))):l}function ve(e,r){return e.find(s=>s.value===r)??e.find(s=>s.isPlaceholder)??e[0]}function xe(e,r,s){var t;if(r!=null)return String(r);if(s!=null)return String(s);const l=e.find(p=>p.selected);return l?l.value:((t=e[0])==null?void 0:t.value)??""}function ye(e){if(_e(e)){const{children:r,placeholder:s,...l}=e.props;return{children:i.jsxs(i.Fragment,{children:[s&&i.jsx("option",{hidden:!0,value:"",children:s}),r]}),props:l}}return{children:e.props.children,props:e.props}}const be=({children:e,className:r,emptyLabel:s="No matches found",searchPlaceholder:l="Filter",variant:t="default",...p})=>{const d=ye(e),{defaultValue:z,onChange:g,value:w,...T}=d.props,q=k.sanitizeSelectProps(T),C=o.useRef(null),R=o.useRef(null),O=o.useRef(null),P=o.useRef(null),h=V(d.children),_=w!=null,v=xe(h,w,z),[x,y]=o.useState(()=>v),[u,b]=o.useState(!1),[B,$]=o.useState(""),S=_?String(w):x,I={default:M.resolveColor("--color-icon"),white:M.resolveColor("--color-white","white")},L=t==="minimal"?I.white:I.default,f=ve(h,S),A=Q("chevron",L),G=Q("search",L),D=we(h,B);o.useEffect(()=>{!_&&!h.some(n=>n.value===x)&&y(v)},[v,x,_,h]),o.useEffect(()=>{var n;if(!u){$("");return}(n=P.current)==null||n.focus()},[u]),o.useEffect(()=>{if(!u)return;const n=a=>{var m;(m=R.current)!=null&&m.contains(a.target)||b(!1)};return document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n)}},[u]);const K=n=>{_||y(n.target.value),g==null||g(n)},j=()=>{var n;b(!1),(n=C.current)==null||n.focus()},H=n=>{var F;_||y(n);const a=O.current;if(!a){j();return}const m=(F=Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype,"value"))==null?void 0:F.set;m==null||m.call(a,n),a.dispatchEvent(new Event("change",{bubbles:!0})),j()},J=n=>{n.key==="Escape"&&j()};return i.jsxs("div",{className:E.t(c.dropdown,t==="minimal"&&c.minimal,r),onKeyDown:J,ref:R,...p,"data-component":"dropdown",children:[i.jsx("select",{...q,"aria-hidden":"true",className:c.native,onChange:K,ref:O,tabIndex:-1,value:S,children:d.children}),i.jsx(W.Button,{"aria-expanded":u,"aria-haspopup":"dialog",className:E.t(t==="default"&&Y.inputStyles.input,c.trigger,(f==null?void 0:f.isPlaceholder)&&c.placeholder),"data-open":u?"true":void 0,disabled:q.disabled,onClick:()=>b(n=>!n),ref:C,style:A,variant:"minimal",children:i.jsx("span",{className:c.text,children:(f==null?void 0:f.label)??"Select an option"})}),u&&i.jsxs("div",{className:c.panel,children:[i.jsx(X.Input,{"aria-label":"Filter",className:c.filter,icon:"search",onChange:n=>$(n.target.value),placeholder:l,ref:P,style:G,type:"search",value:B}),i.jsx(Z.List,{"aria-label":"Dropdown",className:c.options,children:D.length>0?D.map(n=>{const a=n.value===S;return i.jsx("li",{"data-component":"dropdown",children:i.jsxs(W.Button,{"aria-label":a?`${n.text}, selected`:n.text,className:E.t(c.option,a&&c.selected),disabled:n.disabled,onClick:()=>H(n.value),variant:"minimal",children:[i.jsx("span",{className:c.text,children:n.label}),n.groupLabel&&i.jsx("small",{className:c.group,children:n.groupLabel})]})},`${n.groupLabel??"root"}-${n.value}`)}):i.jsx("li",{className:c.empty,children:s})})]})]})};exports.Dropdown=be;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('../../assets/index22.css');const i=require("react/jsx-runtime"),E=require("../../classix-5H4IWnMA.cjs"),o=require("react"),W=require("../button/index.cjs"),U=require("../../icons-C_cX1FYp.cjs"),X=require("../input/index.cjs"),Y=require("../../styles.module-BPvMQa_x.cjs"),Z=require("../list/index.cjs"),k=require("../../index-ClrKYsAQ.cjs"),M=require("../../utils-DBzf7CFq.cjs"),ee="_dropdown_1dsxx_1",te="_empty_1dsxx_4",ne="_group_1dsxx_5",re="_placeholder_1dsxx_6",se="_filter_1dsxx_14",oe="_native_1dsxx_25",le="_option_1dsxx_35",ie="_options_1dsxx_57",ce="_panel_1dsxx_81",ae="_selected_1dsxx_104",ue="_text_1dsxx_108",de="_trigger_1dsxx_117",pe="_minimal_1dsxx_133",c={dropdown:ee,empty:te,group:ne,placeholder:re,filter:se,native:oe,option:le,options:ie,panel:ce,selected:ae,text:ue,trigger:de,minimal:pe};function Q(e,r){return{"--icon-svg":U.iconSVG(e).replace("currentColor",r)}}function N(e){return typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(N).join(" "):o.isValidElement(e)?N(e.props.children):""}function fe(e){return o.isValidElement(e)&&e.type==="option"}function me(e){return o.isValidElement(e)&&e.type==="optgroup"}function xe(e){return o.isValidElement(e)&&e.type===o.Fragment}function he(e){return o.isValidElement(e)&&e.type===k.Select}function V(e,r,s=!1){const l=[];return o.Children.forEach(e,t=>{if(xe(t)){l.push(...V(t.props.children,r,s));return}if(fe(t)){const d=N(t.props.children).trim(),p=t.props.value!=null?String(t.props.value):d;l.push({disabled:s||!!t.props.disabled,groupLabel:r,hidden:!!t.props.hidden,isPlaceholder:!!(t.props.hidden&&p===""),label:t.props.children,selected:!!t.props.selected,text:d,value:p});return}me(t)&&l.push(...V(t.props.children,t.props.label,s||!!t.props.disabled))}),l}function _e(e){const r=e.trim();if(!r)return null;const l=[.../[*?]/.test(r)?r:`*${r}*`].map(t=>t==="*"?".*":t==="?"?".":t.replace(/[|\\{}()[\]^$+.,]/g,"\\$&")).join("");return new RegExp(`^${l}$`,"i")}function ge(e,r){const s=_e(r),l=e.filter(t=>!t.hidden&&!t.isPlaceholder);return s?l.filter(t=>s.test([t.groupLabel,t.text,t.value].filter(Boolean).join(" "))):l}function ve(e,r){return e.find(s=>s.value===r)??e.find(s=>s.isPlaceholder)??e[0]}function ye(e,r,s){var t;if(r!=null)return String(r);if(s!=null)return String(s);const l=e.find(d=>d.selected);return l?l.value:((t=e[0])==null?void 0:t.value)??""}function be(e){if(he(e)){const{children:r,placeholder:s,...l}=e.props;return{children:i.jsxs(i.Fragment,{children:[s&&i.jsx("option",{hidden:!0,value:"",children:s}),r]}),props:l}}return{children:e.props.children,props:e.props}}const we=({children:e,className:r,emptyLabel:s="No matches found",searchPlaceholder:l="Filter",variant:t="default",...d})=>{const p=be(e),{defaultValue:z,onChange:_,value:g,...T}=p.props,q=k.sanitizeSelectProps(T),C=o.useRef(null),R=o.useRef(null),O=o.useRef(null),P=o.useRef(null),x=V(p.children),h=g!=null,v=ye(x,g,z),[y,b]=o.useState(()=>v),[u,w]=o.useState(!1),[B,$]=o.useState(""),S=h?String(g):y,I={default:M.resolveColor("--colors-semantic-content-secondary"),white:M.resolveColor("--color-white","white")},L=t==="minimal"?I.white:I.default,f=ve(x,S),A=Q("chevron",L),G=Q("search",L),D=ge(x,B);o.useEffect(()=>{!h&&!x.some(n=>n.value===y)&&b(v)},[v,y,h,x]),o.useEffect(()=>{var n;if(!u){$("");return}(n=P.current)==null||n.focus()},[u]),o.useEffect(()=>{if(!u)return;const n=a=>{var m;(m=R.current)!=null&&m.contains(a.target)||w(!1)};return document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n)}},[u]);const K=n=>{h||b(n.target.value),_==null||_(n)},j=()=>{var n;w(!1),(n=C.current)==null||n.focus()},H=n=>{var F;h||b(n);const a=O.current;if(!a){j();return}const m=(F=Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype,"value"))==null?void 0:F.set;m==null||m.call(a,n),a.dispatchEvent(new Event("change",{bubbles:!0})),j()},J=n=>{n.key==="Escape"&&j()};return i.jsxs("div",{className:E.t(c.dropdown,t==="minimal"&&c.minimal,r),onKeyDown:J,ref:R,...d,"data-component":"dropdown",children:[i.jsx("select",{...q,"aria-hidden":"true",className:c.native,onChange:K,ref:O,tabIndex:-1,value:S,children:p.children}),i.jsx(W.Button,{"aria-expanded":u,"aria-haspopup":"dialog",className:E.t(t==="default"&&Y.inputStyles.input,c.trigger,(f==null?void 0:f.isPlaceholder)&&c.placeholder),"data-open":u?"true":void 0,disabled:q.disabled,onClick:()=>w(n=>!n),ref:C,style:A,variant:"minimal",children:i.jsx("span",{className:c.text,children:(f==null?void 0:f.label)??"Select an option"})}),u&&i.jsxs("div",{className:c.panel,children:[i.jsx(X.Input,{"aria-label":"Filter",className:c.filter,icon:"search",onChange:n=>$(n.target.value),placeholder:l,ref:P,style:G,type:"search",value:B}),i.jsx(Z.List,{"aria-label":"Dropdown",className:c.options,children:D.length>0?D.map(n=>{const a=n.value===S;return i.jsx("li",{"data-component":"dropdown",children:i.jsxs(W.Button,{"aria-label":a?`${n.text}, selected`:n.text,className:E.t(c.option,a&&c.selected),disabled:n.disabled,onClick:()=>H(n.value),variant:"minimal",children:[i.jsx("span",{className:c.text,children:n.label}),n.groupLabel&&i.jsx("small",{className:c.group,children:n.groupLabel})]})},`${n.groupLabel??"root"}-${n.value}`)}):i.jsx("li",{className:c.empty,children:s})})]})]})};exports.Dropdown=we;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../src/components/_dropdown/index.tsx"],"sourcesContent":["import cx from 'classix';\nimport React, { Children, isValidElement, useEffect, useRef, useState } from 'react';\n\nimport { Button } from '@/components/button';\nimport { type IconName, iconSVG } from '@/components/icon/icons';\nimport { Input } from '@/components/input';\nimport inputStyles from '@/components/input/styles.module.css';\nimport { List } from '@/components/list';\nimport { Select, type SelectProps } from '@/components/select';\nimport { sanitizeSelectProps } from '@/components/select/sanitizeSelectProps';\nimport { resolveColor } from '@/utils';\n\nimport styles from './styles.module.css';\n\ntype NativeSelectProps = Omit<React.ComponentPropsWithoutRef<'select'>, 'children' | 'multiple'> & {\n children: React.ReactNode;\n multiple?: false;\n};\n\ntype NativeSelectElement = React.ReactElement<NativeSelectProps, 'select'>;\ntype WrappedSelectElement = React.ReactElement<SelectProps, typeof Select>;\ntype DropdownSelectElement = NativeSelectElement | WrappedSelectElement;\n\ntype DropdownOption = {\n disabled: boolean;\n groupLabel?: string;\n hidden: boolean;\n isPlaceholder: boolean;\n label: React.ReactNode;\n selected: boolean;\n text: string;\n value: string;\n};\n\nexport type DropdownProps = Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> & {\n children: DropdownSelectElement;\n emptyLabel?: string;\n searchPlaceholder?: string;\n variant?: 'default' | 'minimal';\n};\n\ntype withVars = React.CSSProperties & {\n '--icon-svg'?: string;\n};\n\nfunction getIconWithVars(icon: IconName, color: string): withVars {\n return {\n '--icon-svg': iconSVG(icon).replace('currentColor', color),\n };\n}\n\nfunction getNodeText(node: React.ReactNode): string {\n if (typeof node === 'string' || typeof node === 'number') {\n return String(node);\n }\n\n if (Array.isArray(node)) {\n return node.map(getNodeText).join(' ');\n }\n\n if (isValidElement<{ children?: React.ReactNode }>(node)) {\n return getNodeText(node.props.children);\n }\n\n return '';\n}\n\nfunction isOptionElement(\n node: React.ReactNode\n): node is React.ReactElement<React.ComponentPropsWithoutRef<'option'>, 'option'> {\n return isValidElement(node) && node.type === 'option';\n}\n\nfunction isOptGroupElement(\n node: React.ReactNode\n): node is React.ReactElement<React.ComponentPropsWithoutRef<'optgroup'>, 'optgroup'> {\n return isValidElement(node) && node.type === 'optgroup';\n}\n\nfunction isFragmentElement(\n node: React.ReactNode\n): node is React.ReactElement<{ children?: React.ReactNode }, typeof React.Fragment> {\n return isValidElement(node) && node.type === React.Fragment;\n}\n\nfunction isWrappedSelectElement(node: React.ReactNode): node is WrappedSelectElement {\n return isValidElement(node) && node.type === Select;\n}\n\nfunction extractOptions(\n children: React.ReactNode,\n groupLabel?: string,\n groupDisabled = false\n): DropdownOption[] {\n const options: DropdownOption[] = [];\n\n Children.forEach(children, (child) => {\n if (isFragmentElement(child)) {\n options.push(...extractOptions(child.props.children, groupLabel, groupDisabled));\n return;\n }\n\n if (isOptionElement(child)) {\n const text = getNodeText(child.props.children).trim();\n const value = child.props.value != null ? String(child.props.value) : text;\n\n options.push({\n disabled: groupDisabled || Boolean(child.props.disabled),\n groupLabel,\n hidden: Boolean(child.props.hidden),\n isPlaceholder: Boolean(child.props.hidden && value === ''),\n label: child.props.children,\n selected: Boolean(child.props.selected),\n text,\n value,\n });\n\n return;\n }\n\n if (isOptGroupElement(child)) {\n options.push(\n ...extractOptions(\n child.props.children,\n child.props.label,\n groupDisabled || Boolean(child.props.disabled)\n )\n );\n }\n });\n\n return options;\n}\n\nfunction buildWildcardMatcher(query: string) {\n const trimmedQuery = query.trim();\n\n if (!trimmedQuery) {\n return null;\n }\n\n const wildcardQuery = /[*?]/.test(trimmedQuery) ? trimmedQuery : `*${trimmedQuery}*`;\n const expression = [...wildcardQuery]\n .map((character) => {\n if (character === '*') {\n return '.*';\n }\n\n if (character === '?') {\n return '.';\n }\n\n return character.replace(/[|\\\\{}()[\\]^$+.,]/g, '\\\\$&');\n })\n .join('');\n\n return new RegExp(`^${expression}$`, 'i');\n}\n\nfunction filterOptions(options: DropdownOption[], query: string) {\n const matcher = buildWildcardMatcher(query);\n const selectableOptions = options.filter((option) => !option.hidden && !option.isPlaceholder);\n\n if (!matcher) {\n return selectableOptions;\n }\n\n return selectableOptions.filter((option) =>\n matcher.test([option.groupLabel, option.text, option.value].filter(Boolean).join(' '))\n );\n}\n\nfunction getDisplayOption(options: DropdownOption[], selectedValue: string) {\n return (\n options.find((option) => option.value === selectedValue) ??\n options.find((option) => option.isPlaceholder) ??\n options[0]\n );\n}\n\nfunction getInitialValue(\n options: DropdownOption[],\n value?: NativeSelectProps['value'],\n defaultValue?: NativeSelectProps['defaultValue']\n) {\n if (value != null) {\n return String(value);\n }\n\n if (defaultValue != null) {\n return String(defaultValue);\n }\n\n const selectedOption = options.find((option) => option.selected);\n\n if (selectedOption) {\n return selectedOption.value;\n }\n\n return options[0]?.value ?? '';\n}\n\nfunction normalizeSelectElement(selectElement: DropdownSelectElement) {\n if (isWrappedSelectElement(selectElement)) {\n const { children, placeholder, ...props } = selectElement.props;\n\n return {\n children: (\n <>\n {placeholder && (\n <option\n hidden\n value=''\n >\n {placeholder}\n </option>\n )}\n {children}\n </>\n ),\n props,\n };\n }\n\n return {\n children: selectElement.props.children,\n props: selectElement.props,\n };\n}\n\nexport const Dropdown = ({\n children: selectElement,\n className,\n emptyLabel = 'No matches found',\n searchPlaceholder = 'Filter',\n variant = 'default',\n ...props\n}: DropdownProps) => {\n const normalizedSelect = normalizeSelectElement(selectElement);\n const { defaultValue, onChange, value, ...restSelectProps } = normalizedSelect.props;\n const selectProps = sanitizeSelectProps(restSelectProps);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const nativeSelectRef = useRef<HTMLSelectElement>(null);\n const searchRef = useRef<HTMLInputElement>(null);\n const options = extractOptions(normalizedSelect.children);\n const isControlled = value != null;\n const initialValue = getInitialValue(options, value, defaultValue);\n const [internalValue, setInternalValue] = useState(() => initialValue);\n const [isOpen, setIsOpen] = useState(false);\n const [query, setQuery] = useState('');\n const selectedValue = isControlled ? String(value) : internalValue;\n const iconColors = {\n default: resolveColor('--color-icon'),\n white: resolveColor('--color-white', 'white'),\n };\n const dropdownIconColor = variant === 'minimal' ? iconColors.white : iconColors.default;\n const displayOption = getDisplayOption(options, selectedValue);\n const triggerWithVars = getIconWithVars('chevron', dropdownIconColor);\n const filterWithVars = getIconWithVars('search', dropdownIconColor);\n const filteredOptions = filterOptions(options, query);\n\n useEffect(() => {\n if (!isControlled && !options.some((option) => option.value === internalValue)) {\n setInternalValue(initialValue);\n }\n }, [initialValue, internalValue, isControlled, options]);\n\n useEffect(() => {\n if (!isOpen) {\n setQuery('');\n return;\n }\n\n searchRef.current?.focus();\n }, [isOpen]);\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n\n const handlePointerDown = (event: MouseEvent) => {\n if (!containerRef.current?.contains(event.target as Node)) {\n setIsOpen(false);\n }\n };\n\n document.addEventListener('mousedown', handlePointerDown);\n\n return () => {\n document.removeEventListener('mousedown', handlePointerDown);\n };\n }, [isOpen]);\n\n const handleNativeChange = (event: React.ChangeEvent<HTMLSelectElement>) => {\n if (!isControlled) {\n setInternalValue(event.target.value);\n }\n\n onChange?.(event);\n };\n\n const closeMenu = () => {\n setIsOpen(false);\n buttonRef.current?.focus();\n };\n\n const commitValue = (nextValue: string) => {\n if (!isControlled) {\n setInternalValue(nextValue);\n }\n\n const nativeSelect = nativeSelectRef.current;\n\n if (!nativeSelect) {\n closeMenu();\n return;\n }\n\n const valueSetter = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, 'value')?.set;\n\n valueSetter?.call(nativeSelect, nextValue);\n nativeSelect.dispatchEvent(new Event('change', { bubbles: true }));\n closeMenu();\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Escape') {\n closeMenu();\n }\n };\n\n return (\n <div\n className={cx(styles.dropdown, variant === 'minimal' && styles.minimal, className)}\n onKeyDown={handleKeyDown}\n ref={containerRef}\n {...props}\n >\n <select\n {...selectProps}\n aria-hidden='true'\n className={styles.native}\n onChange={handleNativeChange}\n ref={nativeSelectRef}\n tabIndex={-1}\n value={selectedValue}\n >\n {normalizedSelect.children}\n </select>\n <Button\n aria-expanded={isOpen}\n aria-haspopup='dialog'\n className={cx(\n variant === 'default' && inputStyles.input,\n styles.trigger,\n displayOption?.isPlaceholder && styles.placeholder\n )}\n data-open={isOpen ? 'true' : undefined}\n disabled={selectProps.disabled}\n onClick={() => setIsOpen((currentValue) => !currentValue)}\n ref={buttonRef}\n style={triggerWithVars}\n variant='minimal'\n >\n <span className={styles.text}>{displayOption?.label ?? 'Select an option'}</span>\n </Button>\n {isOpen && (\n <div className={styles.panel}>\n <Input\n aria-label='Filter'\n className={styles.filter}\n icon='search'\n onChange={(event) => setQuery(event.target.value)}\n placeholder={searchPlaceholder}\n ref={searchRef}\n style={filterWithVars}\n type='search'\n value={query}\n />\n <List\n aria-label='Dropdown'\n className={styles.options}\n >\n {filteredOptions.length > 0 ? (\n filteredOptions.map((option) => {\n const isSelected = option.value === selectedValue;\n\n return (\n <li key={`${option.groupLabel ?? 'root'}-${option.value}`}>\n <Button\n aria-label={isSelected ? `${option.text}, selected` : option.text}\n className={cx(styles.option, isSelected && styles.selected)}\n disabled={option.disabled}\n onClick={() => commitValue(option.value)}\n variant='minimal'\n >\n <span className={styles.text}>{option.label}</span>\n {option.groupLabel && (\n <small className={styles.group}>{option.groupLabel}</small>\n )}\n </Button>\n </li>\n );\n })\n ) : (\n <li className={styles.empty}>{emptyLabel}</li>\n )}\n </List>\n </div>\n )}\n </div>\n );\n};\n"],"names":["getIconWithVars","icon","color","iconSVG","replace","getNodeText","node","String","Array","isArray","map","join","isValidElement","props","children","isOptionElement","type","isOptGroupElement","isFragmentElement","React","Fragment","isWrappedSelectElement","Select","extractOptions","groupLabel","groupDisabled","options","Children","forEach","child","push","text","trim","value","disabled","Boolean","hidden","isPlaceholder","label","selected","buildWildcardMatcher","query","trimmedQuery","expression","test","character","RegExp","filterOptions","matcher","selectableOptions","filter","option","getDisplayOption","selectedValue","find","getInitialValue","defaultValue","selectedOption","normalizeSelectElement","selectElement","placeholder","jsxs","Dropdown","className","emptyLabel","searchPlaceholder","variant","normalizedSelect","onChange","restSelectProps","selectProps","sanitizeSelectProps","buttonRef","useRef","containerRef","nativeSelectRef","searchRef","isControlled","initialValue","internalValue","setInternalValue","useState","isOpen","setIsOpen","setQuery","iconColors","default","resolveColor","white","dropdownIconColor","displayOption","triggerWithVars","filterWithVars","filteredOptions","useEffect","some","current","focus","handlePointerDown","event","contains","target","document","addEventListener","removeEventListener","handleNativeChange","closeMenu","commitValue","nextValue","nativeSelect","valueSetter","Object","getOwnPropertyDescriptor","HTMLSelectElement","prototype","set","call","dispatchEvent","Event","bubbles","handleKeyDown","key","cx","styles","dropdown","minimal","jsx","native","Button","inputStyles","input","trigger","undefined","currentValue","panel","Input","List","length","isSelected","group","empty"],"mappings":"k2BA6CA,SAASA,EAAgBC,EAAgBC,EAAyB,CAChE,MAAO,CACL,aAAcC,EAAAA,QAAQF,CAAI,EAAEG,QAAQ,eAAgBF,CAAK,CAAA,CAE7D,CAEA,SAASG,EAAYC,EAA+B,CAClD,OAAI,OAAOA,GAAS,UAAY,OAAOA,GAAS,SACvCC,OAAOD,CAAI,EAGhBE,MAAMC,QAAQH,CAAI,EACbA,EAAKI,IAAIL,CAAW,EAAEM,KAAK,GAAG,EAGnCC,EAAAA,eAA+CN,CAAI,EAC9CD,EAAYC,EAAKO,MAAMC,QAAQ,EAGjC,EACT,CAEA,SAASC,GACPT,EACgF,CAChF,OAAOM,EAAAA,eAAeN,CAAI,GAAKA,EAAKU,OAAS,QAC/C,CAEA,SAASC,GACPX,EACoF,CACpF,OAAOM,EAAAA,eAAeN,CAAI,GAAKA,EAAKU,OAAS,UAC/C,CAEA,SAASE,GACPZ,EACmF,CACnF,OAAOM,EAAAA,eAAeN,CAAI,GAAKA,E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OpB,IAAI,aAAeoB,EAAOpB,KAC7D,UAAW2F,EAAAA,EAAGC,EAAOxE,OAAQuF,GAAcf,EAAOpF,QAAQ,EAC1D,SAAUY,EAAOjB,SACjB,QAAS,IAAMyE,EAAYxD,EAAOlB,KAAK,EACvC,QAAQ,UAER,SAAA,CAAA6F,MAAC,OAAA,CAAK,UAAWH,EAAO5F,KAAOoB,WAAOb,MAAM,EAC3Ca,EAAO3B,YACNsG,MAAC,QAAA,CAAM,UAAWH,EAAOgB,MAAQxF,WAAO3B,UAAAA,CAAW,CAAA,EAEvD,CAAA,EAZO,GAAG2B,EAAO3B,YAAc,MAAM,IAAI2B,EAAOlB,KAAK,EAavD,CAEJ,CAAC,EAED6F,MAAC,KAAA,CAAG,UAAWH,EAAOiB,MAAQ5E,WAAW,CAAA,CAE7C,CAAA,CAAA,CACF,CAAA,EAEJ,CAEJ"}
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/components/_dropdown/index.tsx"],"sourcesContent":["import cx from 'classix';\nimport React, { Children, isValidElement, useEffect, useRef, useState } from 'react';\n\nimport { Button } from '@/components/button';\nimport { type IconName, iconSVG } from '@/components/icon/icons';\nimport { Input } from '@/components/input';\nimport inputStyles from '@/components/input/styles.module.css';\nimport { List } from '@/components/list';\nimport { Select, type SelectProps } from '@/components/select';\nimport { sanitizeSelectProps } from '@/components/select/sanitizeSelectProps';\nimport { resolveColor } from '@/utils';\n\nimport styles from './styles.module.css';\n\ntype NativeSelectProps = Omit<React.ComponentPropsWithoutRef<'select'>, 'children' | 'multiple'> & {\n children: React.ReactNode;\n multiple?: false;\n};\n\ntype NativeSelectElement = React.ReactElement<NativeSelectProps, 'select'>;\ntype WrappedSelectElement = React.ReactElement<SelectProps, typeof Select>;\ntype DropdownSelectElement = NativeSelectElement | WrappedSelectElement;\n\ntype DropdownOption = {\n disabled: boolean;\n groupLabel?: string;\n hidden: boolean;\n isPlaceholder: boolean;\n label: React.ReactNode;\n selected: boolean;\n text: string;\n value: string;\n};\n\nexport type DropdownProps = Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> & {\n children: DropdownSelectElement;\n emptyLabel?: string;\n searchPlaceholder?: string;\n variant?: 'default' | 'minimal';\n};\n\ntype withVars = React.CSSProperties & {\n '--icon-svg'?: string;\n};\n\nfunction getIconWithVars(icon: IconName, color: string): withVars {\n return {\n '--icon-svg': iconSVG(icon).replace('currentColor', color),\n };\n}\n\nfunction getNodeText(node: React.ReactNode): string {\n if (typeof node === 'string' || typeof node === 'number') {\n return String(node);\n }\n\n if (Array.isArray(node)) {\n return node.map(getNodeText).join(' ');\n }\n\n if (isValidElement<{ children?: React.ReactNode }>(node)) {\n return getNodeText(node.props.children);\n }\n\n return '';\n}\n\nfunction isOptionElement(\n node: React.ReactNode\n): node is React.ReactElement<React.ComponentPropsWithoutRef<'option'>, 'option'> {\n return isValidElement(node) && node.type === 'option';\n}\n\nfunction isOptGroupElement(\n node: React.ReactNode\n): node is React.ReactElement<React.ComponentPropsWithoutRef<'optgroup'>, 'optgroup'> {\n return isValidElement(node) && node.type === 'optgroup';\n}\n\nfunction isFragmentElement(\n node: React.ReactNode\n): node is React.ReactElement<{ children?: React.ReactNode }, typeof React.Fragment> {\n return isValidElement(node) && node.type === React.Fragment;\n}\n\nfunction isWrappedSelectElement(node: React.ReactNode): node is WrappedSelectElement {\n return isValidElement(node) && node.type === Select;\n}\n\nfunction extractOptions(\n children: React.ReactNode,\n groupLabel?: string,\n groupDisabled = false\n): DropdownOption[] {\n const options: DropdownOption[] = [];\n\n Children.forEach(children, (child) => {\n if (isFragmentElement(child)) {\n options.push(...extractOptions(child.props.children, groupLabel, groupDisabled));\n return;\n }\n\n if (isOptionElement(child)) {\n const text = getNodeText(child.props.children).trim();\n const value = child.props.value != null ? String(child.props.value) : text;\n\n options.push({\n disabled: groupDisabled || Boolean(child.props.disabled),\n groupLabel,\n hidden: Boolean(child.props.hidden),\n isPlaceholder: Boolean(child.props.hidden && value === ''),\n label: child.props.children,\n selected: Boolean(child.props.selected),\n text,\n value,\n });\n\n return;\n }\n\n if (isOptGroupElement(child)) {\n options.push(\n ...extractOptions(\n child.props.children,\n child.props.label,\n groupDisabled || Boolean(child.props.disabled)\n )\n );\n }\n });\n\n return options;\n}\n\nfunction buildWildcardMatcher(query: string) {\n const trimmedQuery = query.trim();\n\n if (!trimmedQuery) {\n return null;\n }\n\n const wildcardQuery = /[*?]/.test(trimmedQuery) ? trimmedQuery : `*${trimmedQuery}*`;\n const expression = [...wildcardQuery]\n .map((character) => {\n if (character === '*') {\n return '.*';\n }\n\n if (character === '?') {\n return '.';\n }\n\n return character.replace(/[|\\\\{}()[\\]^$+.,]/g, '\\\\$&');\n })\n .join('');\n\n return new RegExp(`^${expression}$`, 'i');\n}\n\nfunction filterOptions(options: DropdownOption[], query: string) {\n const matcher = buildWildcardMatcher(query);\n const selectableOptions = options.filter((option) => !option.hidden && !option.isPlaceholder);\n\n if (!matcher) {\n return selectableOptions;\n }\n\n return selectableOptions.filter((option) =>\n matcher.test([option.groupLabel, option.text, option.value].filter(Boolean).join(' '))\n );\n}\n\nfunction getDisplayOption(options: DropdownOption[], selectedValue: string) {\n return (\n options.find((option) => option.value === selectedValue) ??\n options.find((option) => option.isPlaceholder) ??\n options[0]\n );\n}\n\nfunction getInitialValue(\n options: DropdownOption[],\n value?: NativeSelectProps['value'],\n defaultValue?: NativeSelectProps['defaultValue']\n) {\n if (value != null) {\n return String(value);\n }\n\n if (defaultValue != null) {\n return String(defaultValue);\n }\n\n const selectedOption = options.find((option) => option.selected);\n\n if (selectedOption) {\n return selectedOption.value;\n }\n\n return options[0]?.value ?? '';\n}\n\nfunction normalizeSelectElement(selectElement: DropdownSelectElement) {\n if (isWrappedSelectElement(selectElement)) {\n const { children, placeholder, ...props } = selectElement.props;\n\n return {\n children: (\n <>\n {placeholder && (\n <option\n hidden\n value=''\n >\n {placeholder}\n </option>\n )}\n {children}\n </>\n ),\n props,\n };\n }\n\n return {\n children: selectElement.props.children,\n props: selectElement.props,\n };\n}\n\nexport const Dropdown = ({\n children: selectElement,\n className,\n emptyLabel = 'No matches found',\n searchPlaceholder = 'Filter',\n variant = 'default',\n ...props\n}: DropdownProps) => {\n const normalizedSelect = normalizeSelectElement(selectElement);\n const { defaultValue, onChange, value, ...restSelectProps } = normalizedSelect.props;\n const selectProps = sanitizeSelectProps(restSelectProps);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const nativeSelectRef = useRef<HTMLSelectElement>(null);\n const searchRef = useRef<HTMLInputElement>(null);\n const options = extractOptions(normalizedSelect.children);\n const isControlled = value != null;\n const initialValue = getInitialValue(options, value, defaultValue);\n const [internalValue, setInternalValue] = useState(() => initialValue);\n const [isOpen, setIsOpen] = useState(false);\n const [query, setQuery] = useState('');\n const selectedValue = isControlled ? String(value) : internalValue;\n const iconColors = {\n default: resolveColor('--colors-semantic-content-secondary'),\n white: resolveColor('--color-white', 'white'),\n };\n const dropdownIconColor = variant === 'minimal' ? iconColors.white : iconColors.default;\n const displayOption = getDisplayOption(options, selectedValue);\n const triggerWithVars = getIconWithVars('chevron', dropdownIconColor);\n const filterWithVars = getIconWithVars('search', dropdownIconColor);\n const filteredOptions = filterOptions(options, query);\n\n useEffect(() => {\n if (!isControlled && !options.some((option) => option.value === internalValue)) {\n setInternalValue(initialValue);\n }\n }, [initialValue, internalValue, isControlled, options]);\n\n useEffect(() => {\n if (!isOpen) {\n setQuery('');\n return;\n }\n\n searchRef.current?.focus();\n }, [isOpen]);\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n\n const handlePointerDown = (event: MouseEvent) => {\n if (!containerRef.current?.contains(event.target as Node)) {\n setIsOpen(false);\n }\n };\n\n document.addEventListener('mousedown', handlePointerDown);\n\n return () => {\n document.removeEventListener('mousedown', handlePointerDown);\n };\n }, [isOpen]);\n\n const handleNativeChange = (event: React.ChangeEvent<HTMLSelectElement>) => {\n if (!isControlled) {\n setInternalValue(event.target.value);\n }\n\n onChange?.(event);\n };\n\n const closeMenu = () => {\n setIsOpen(false);\n buttonRef.current?.focus();\n };\n\n const commitValue = (nextValue: string) => {\n if (!isControlled) {\n setInternalValue(nextValue);\n }\n\n const nativeSelect = nativeSelectRef.current;\n\n if (!nativeSelect) {\n closeMenu();\n return;\n }\n\n const valueSetter = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, 'value')?.set;\n\n valueSetter?.call(nativeSelect, nextValue);\n nativeSelect.dispatchEvent(new Event('change', { bubbles: true }));\n closeMenu();\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Escape') {\n closeMenu();\n }\n };\n\n return (\n <div\n className={cx(styles.dropdown, variant === 'minimal' && styles.minimal, className)}\n onKeyDown={handleKeyDown}\n ref={containerRef}\n {...props}\n >\n <select\n {...selectProps}\n aria-hidden='true'\n className={styles.native}\n onChange={handleNativeChange}\n ref={nativeSelectRef}\n tabIndex={-1}\n value={selectedValue}\n >\n {normalizedSelect.children}\n </select>\n <Button\n aria-expanded={isOpen}\n aria-haspopup='dialog'\n className={cx(\n variant === 'default' && inputStyles.input,\n styles.trigger,\n displayOption?.isPlaceholder && styles.placeholder\n )}\n data-open={isOpen ? 'true' : undefined}\n disabled={selectProps.disabled}\n onClick={() => setIsOpen((currentValue) => !currentValue)}\n ref={buttonRef}\n style={triggerWithVars}\n variant='minimal'\n >\n <span className={styles.text}>{displayOption?.label ?? 'Select an option'}</span>\n </Button>\n {isOpen && (\n <div className={styles.panel}>\n <Input\n aria-label='Filter'\n className={styles.filter}\n icon='search'\n onChange={(event) => setQuery(event.target.value)}\n placeholder={searchPlaceholder}\n ref={searchRef}\n style={filterWithVars}\n type='search'\n value={query}\n />\n <List\n aria-label='Dropdown'\n className={styles.options}\n >\n {filteredOptions.length > 0 ? (\n filteredOptions.map((option) => {\n const isSelected = option.value === selectedValue;\n\n return (\n <li key={`${option.groupLabel ?? 'root'}-${option.value}`}>\n <Button\n aria-label={isSelected ? `${option.text}, selected` : option.text}\n className={cx(styles.option, isSelected && styles.selected)}\n disabled={option.disabled}\n onClick={() => commitValue(option.value)}\n variant='minimal'\n >\n <span className={styles.text}>{option.label}</span>\n {option.groupLabel && (\n <small className={styles.group}>{option.groupLabel}</small>\n )}\n </Button>\n </li>\n );\n })\n ) : (\n <li className={styles.empty}>{emptyLabel}</li>\n )}\n </List>\n </div>\n )}\n </div>\n );\n};\n"],"names":["getIconWithVars","icon","color","iconSVG","replace","getNodeText","node","String","Array","isArray","map","join","isValidElement","props","children","isOptionElement","type","isOptGroupElement","isFragmentElement","React","Fragment","isWrappedSelectElement","Select","extractOptions","groupLabel","groupDisabled","options","Children","forEach","child","push","text","trim","value","disabled","Boolean","hidden","isPlaceholder","label","selected","buildWildcardMatcher","query","trimmedQuery","expression","test","character","RegExp","filterOptions","matcher","selectableOptions","filter","option","getDisplayOption","selectedValue","find","getInitialValue","defaultValue","selectedOption","normalizeSelectElement","selectElement","placeholder","jsxs","Dropdown","className","emptyLabel","searchPlaceholder","variant","normalizedSelect","onChange","restSelectProps","selectProps","sanitizeSelectProps","buttonRef","useRef","containerRef","nativeSelectRef","searchRef","isControlled","initialValue","internalValue","setInternalValue","useState","isOpen","setIsOpen","setQuery","iconColors","default","resolveColor","white","dropdownIconColor","displayOption","triggerWithVars","filterWithVars","filteredOptions","useEffect","some","current","focus","handlePointerDown","event","contains","target","document","addEventListener","removeEventListener","handleNativeChange","closeMenu","commitValue","nextValue","nativeSelect","valueSetter","Object","getOwnPropertyDescriptor","HTMLSelectElement","prototype","set","call","dispatchEvent","Event","bubbles","handleKeyDown","key","cx","styles","dropdown","minimal","jsx","native","Button","inputStyles","input","trigger","undefined","currentValue","panel","Input","List","length","isSelected","group","empty"],"mappings":"k2BA6CA,SAASA,EAAgBC,EAAgBC,EAAyB,CAChE,MAAO,CACL,aAAcC,EAAAA,QAAQF,CAAI,EAAEG,QAAQ,eAAgBF,CAAK,CAAA,CAE7D,CAEA,SAASG,EAAYC,EAA+B,CAClD,OA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AA,MAAA,CACC,aAAW,SACX,UAAWZ,EAAOzE,OAClB,KAAK,SACL,SAAWiD,GAAUf,EAASe,EAAME,OAAOpE,KAAK,EAChD,YAAagC,EACb,IAAKW,EACL,MAAOgB,EACP,KAAK,SACL,MAAOnD,CAAAA,CAAM,EAEfqF,EAAAA,IAACU,EAAAA,KAAA,CACC,aAAW,WACX,UAAWb,EAAOjG,QAEjBmE,SAAAA,EAAgB4C,OAAS,EACxB5C,EAAgBnF,IAAKyC,GAAW,CAC9B,MAAMuF,EAAavF,EAAOlB,QAAUoB,EAEpC,OACEyE,EAAAA,IAAC,KAAA,CAAyD,iBAAA,WACxD,gBAACE,EAAAA,OAAA,CACC,aAAYU,EAAa,GAAGvF,EAAOpB,IAAI,aAAeoB,EAAOpB,KAC7D,UAAW2F,EAAAA,EAAGC,EAAOxE,OAAQuF,GAAcf,EAAOpF,QAAQ,EAC1D,SAAUY,EAAOjB,SACjB,QAAS,IAAMyE,EAAYxD,EAAOlB,KAAK,EACvC,QAAQ,UAER,SAAA,CAAA6F,MAAC,OAAA,CAAK,UAAWH,EAAO5F,KAAOoB,WAAOb,MAAM,EAC3Ca,EAAO3B,YACNsG,MAAC,QAAA,CAAM,UAAWH,EAAOgB,MAAQxF,WAAO3B,UAAAA,CAAW,CAAA,EAEvD,CAAA,EAZO,GAAG2B,EAAO3B,YAAc,MAAM,IAAI2B,EAAOlB,KAAK,EAavD,CAEJ,CAAC,EAED6F,MAAC,KAAA,CAAG,UAAWH,EAAOiB,MAAQ5E,WAAW,CAAA,CAE7C,CAAA,CAAA,CACF,CAAA,EAEJ,CAEJ"}
@@ -1,108 +1,108 @@
1
- import { jsxs as w, jsx as i, Fragment as Z } from "react/jsx-runtime";
1
+ import { jsxs as _, jsx as i, Fragment as Z } from "react/jsx-runtime";
2
2
  import { t as V } from "../../classix-DG18itHa.js";
3
- import ee, { useRef as _, useState as O, useEffect as P, Children as te, isValidElement as g } from "react";
3
+ import ee, { useRef as g, useState as O, useEffect as P, Children as te, isValidElement as x } from "react";
4
4
  import { Button as A } from "../button/index.js";
5
- import { i as re } from "../../icons-DfmpRbxE.js";
6
- import { Input as ne } from "../input/index.js";
7
- import { i as oe } from "../../styles.module-DZXAP_eP.js";
8
- import { List as le } from "../list/index.js";
9
- import { s as se, S as ie } from "../../index-BNaQZHo6.js";
5
+ import { i as ne } from "../../icons-DfmpRbxE.js";
6
+ import { Input as re } from "../input/index.js";
7
+ import { i as oe } from "../../styles.module-BOTEBJ0C.js";
8
+ import { List as se } from "../list/index.js";
9
+ import { s as le, S as ie } from "../../index-CiEbbnD6.js";
10
10
  import { r as G } from "../../utils--n2yqjCy.js";
11
- import '../../assets/index22.css';const ae = "_dropdown_ruf4w_1", ce = "_empty_ruf4w_4", ue = "_group_ruf4w_5", pe = "_placeholder_ruf4w_6", de = "_filter_ruf4w_14", fe = "_native_ruf4w_25", me = "_option_ruf4w_35", he = "_options_ruf4w_57", ge = "_panel_ruf4w_81", _e = "_selected_ruf4w_102", we = "_text_ruf4w_106", ve = "_trigger_ruf4w_114", ye = "_minimal_ruf4w_130", s = {
11
+ import '../../assets/index22.css';const ae = "_dropdown_1dsxx_1", ce = "_empty_1dsxx_4", pe = "_group_1dsxx_5", ue = "_placeholder_1dsxx_6", de = "_filter_1dsxx_14", fe = "_native_1dsxx_25", me = "_option_1dsxx_35", he = "_options_1dsxx_57", xe = "_panel_1dsxx_81", ge = "_selected_1dsxx_104", _e = "_text_1dsxx_108", ve = "_trigger_1dsxx_117", ye = "_minimal_1dsxx_133", l = {
12
12
  dropdown: ae,
13
13
  empty: ce,
14
- group: ue,
15
- placeholder: pe,
14
+ group: pe,
15
+ placeholder: ue,
16
16
  filter: de,
17
17
  native: fe,
18
18
  option: me,
19
19
  options: he,
20
- panel: ge,
21
- selected: _e,
22
- text: we,
20
+ panel: xe,
21
+ selected: ge,
22
+ text: _e,
23
23
  trigger: ve,
24
24
  minimal: ye
25
25
  };
26
- function K(e, n) {
26
+ function K(e, r) {
27
27
  return {
28
- "--icon-svg": re(e).replace("currentColor", n)
28
+ "--icon-svg": ne(e).replace("currentColor", r)
29
29
  };
30
30
  }
31
31
  function $(e) {
32
- return typeof e == "string" || typeof e == "number" ? String(e) : Array.isArray(e) ? e.map($).join(" ") : g(e) ? $(e.props.children) : "";
32
+ return typeof e == "string" || typeof e == "number" ? String(e) : Array.isArray(e) ? e.map($).join(" ") : x(e) ? $(e.props.children) : "";
33
33
  }
34
34
  function be(e) {
35
- return g(e) && e.type === "option";
35
+ return x(e) && e.type === "option";
36
36
  }
37
- function Se(e) {
38
- return g(e) && e.type === "optgroup";
37
+ function we(e) {
38
+ return x(e) && e.type === "optgroup";
39
39
  }
40
- function xe(e) {
41
- return g(e) && e.type === ee.Fragment;
40
+ function Se(e) {
41
+ return x(e) && e.type === ee.Fragment;
42
42
  }
43
43
  function Ne(e) {
44
- return g(e) && e.type === ie;
44
+ return x(e) && e.type === ie;
45
45
  }
46
- function B(e, n, o = !1) {
47
- const l = [];
46
+ function B(e, r, o = !1) {
47
+ const s = [];
48
48
  return te.forEach(e, (t) => {
49
- if (xe(t)) {
50
- l.push(...B(t.props.children, n, o));
49
+ if (Se(t)) {
50
+ s.push(...B(t.props.children, r, o));
51
51
  return;
52
52
  }
53
53
  if (be(t)) {
54
- const u = $(t.props.children).trim(), p = t.props.value != null ? String(t.props.value) : u;
55
- l.push({
54
+ const p = $(t.props.children).trim(), u = t.props.value != null ? String(t.props.value) : p;
55
+ s.push({
56
56
  disabled: o || !!t.props.disabled,
57
- groupLabel: n,
57
+ groupLabel: r,
58
58
  hidden: !!t.props.hidden,
59
- isPlaceholder: !!(t.props.hidden && p === ""),
59
+ isPlaceholder: !!(t.props.hidden && u === ""),
60
60
  label: t.props.children,
61
61
  selected: !!t.props.selected,
62
- text: u,
63
- value: p
62
+ text: p,
63
+ value: u
64
64
  });
65
65
  return;
66
66
  }
67
- Se(t) && l.push(...B(t.props.children, t.props.label, o || !!t.props.disabled));
68
- }), l;
67
+ we(t) && s.push(...B(t.props.children, t.props.label, o || !!t.props.disabled));
68
+ }), s;
69
69
  }
70
70
  function Ee(e) {
71
- const n = e.trim();
72
- if (!n)
71
+ const r = e.trim();
72
+ if (!r)
73
73
  return null;
74
- const l = [.../[*?]/.test(n) ? n : `*${n}*`].map((t) => t === "*" ? ".*" : t === "?" ? "." : t.replace(/[|\\{}()[\]^$+.,]/g, "\\$&")).join("");
75
- return new RegExp(`^${l}$`, "i");
74
+ const s = [.../[*?]/.test(r) ? r : `*${r}*`].map((t) => t === "*" ? ".*" : t === "?" ? "." : t.replace(/[|\\{}()[\]^$+.,]/g, "\\$&")).join("");
75
+ return new RegExp(`^${s}$`, "i");
76
76
  }
77
- function Ce(e, n) {
78
- const o = Ee(n), l = e.filter((t) => !t.hidden && !t.isPlaceholder);
79
- return o ? l.filter((t) => o.test([t.groupLabel, t.text, t.value].filter(Boolean).join(" "))) : l;
77
+ function Ce(e, r) {
78
+ const o = Ee(r), s = e.filter((t) => !t.hidden && !t.isPlaceholder);
79
+ return o ? s.filter((t) => o.test([t.groupLabel, t.text, t.value].filter(Boolean).join(" "))) : s;
80
80
  }
81
- function Ve(e, n) {
82
- return e.find((o) => o.value === n) ?? e.find((o) => o.isPlaceholder) ?? e[0];
81
+ function Ve(e, r) {
82
+ return e.find((o) => o.value === r) ?? e.find((o) => o.isPlaceholder) ?? e[0];
83
83
  }
84
- function Oe(e, n, o) {
84
+ function Oe(e, r, o) {
85
85
  var t;
86
- if (n != null)
87
- return String(n);
86
+ if (r != null)
87
+ return String(r);
88
88
  if (o != null)
89
89
  return String(o);
90
- const l = e.find((u) => u.selected);
91
- return l ? l.value : ((t = e[0]) == null ? void 0 : t.value) ?? "";
90
+ const s = e.find((p) => p.selected);
91
+ return s ? s.value : ((t = e[0]) == null ? void 0 : t.value) ?? "";
92
92
  }
93
93
  function Pe(e) {
94
94
  if (Ne(e)) {
95
95
  const {
96
- children: n,
96
+ children: r,
97
97
  placeholder: o,
98
- ...l
98
+ ...s
99
99
  } = e.props;
100
100
  return {
101
- children: /* @__PURE__ */ w(Z, { children: [
101
+ children: /* @__PURE__ */ _(Z, { children: [
102
102
  o && /* @__PURE__ */ i("option", { hidden: !0, value: "", children: o }),
103
- n
103
+ r
104
104
  ] }),
105
- props: l
105
+ props: s
106
106
  };
107
107
  }
108
108
  return {
@@ -112,73 +112,73 @@ function Pe(e) {
112
112
  }
113
113
  const ke = ({
114
114
  children: e,
115
- className: n,
115
+ className: r,
116
116
  emptyLabel: o = "No matches found",
117
- searchPlaceholder: l = "Filter",
117
+ searchPlaceholder: s = "Filter",
118
118
  variant: t = "default",
119
- ...u
119
+ ...p
120
120
  }) => {
121
- const p = Pe(e), {
121
+ const u = Pe(e), {
122
122
  defaultValue: T,
123
123
  onChange: v,
124
124
  value: y,
125
125
  ...q
126
- } = p.props, I = se(q), L = _(null), R = _(null), j = _(null), D = _(null), m = B(p.children), h = y != null, b = Oe(m, y, T), [S, x] = O(() => b), [c, N] = O(!1), [F, W] = O(""), E = h ? String(y) : S, Q = {
127
- default: G("--color-icon"),
126
+ } = u.props, I = le(q), L = g(null), R = g(null), j = g(null), D = g(null), m = B(u.children), h = y != null, b = Oe(m, y, T), [w, S] = O(() => b), [c, N] = O(!1), [F, W] = O(""), E = h ? String(y) : w, Q = {
127
+ default: G("--colors-semantic-content-secondary"),
128
128
  white: G("--color-white", "white")
129
129
  }, k = t === "minimal" ? Q.white : Q.default, d = Ve(m, E), H = K("chevron", k), J = K("search", k), z = Ce(m, F);
130
130
  P(() => {
131
- !h && !m.some((r) => r.value === S) && x(b);
132
- }, [b, S, h, m]), P(() => {
133
- var r;
131
+ !h && !m.some((n) => n.value === w) && S(b);
132
+ }, [b, w, h, m]), P(() => {
133
+ var n;
134
134
  if (!c) {
135
135
  W("");
136
136
  return;
137
137
  }
138
- (r = D.current) == null || r.focus();
138
+ (n = D.current) == null || n.focus();
139
139
  }, [c]), P(() => {
140
140
  if (!c)
141
141
  return;
142
- const r = (a) => {
142
+ const n = (a) => {
143
143
  var f;
144
144
  (f = R.current) != null && f.contains(a.target) || N(!1);
145
145
  };
146
- return document.addEventListener("mousedown", r), () => {
147
- document.removeEventListener("mousedown", r);
146
+ return document.addEventListener("mousedown", n), () => {
147
+ document.removeEventListener("mousedown", n);
148
148
  };
149
149
  }, [c]);
150
- const U = (r) => {
151
- h || x(r.target.value), v == null || v(r);
150
+ const U = (n) => {
151
+ h || S(n.target.value), v == null || v(n);
152
152
  }, C = () => {
153
- var r;
154
- N(!1), (r = L.current) == null || r.focus();
155
- }, X = (r) => {
153
+ var n;
154
+ N(!1), (n = L.current) == null || n.focus();
155
+ }, X = (n) => {
156
156
  var M;
157
- h || x(r);
157
+ h || S(n);
158
158
  const a = j.current;
159
159
  if (!a) {
160
160
  C();
161
161
  return;
162
162
  }
163
163
  const f = (M = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, "value")) == null ? void 0 : M.set;
164
- f == null || f.call(a, r), a.dispatchEvent(new Event("change", {
164
+ f == null || f.call(a, n), a.dispatchEvent(new Event("change", {
165
165
  bubbles: !0
166
166
  })), C();
167
- }, Y = (r) => {
168
- r.key === "Escape" && C();
167
+ }, Y = (n) => {
168
+ n.key === "Escape" && C();
169
169
  };
170
- return /* @__PURE__ */ w("div", { className: V(s.dropdown, t === "minimal" && s.minimal, n), onKeyDown: Y, ref: R, ...u, "data-component": "dropdown", children: [
171
- /* @__PURE__ */ i("select", { ...I, "aria-hidden": "true", className: s.native, onChange: U, ref: j, tabIndex: -1, value: E, children: p.children }),
172
- /* @__PURE__ */ i(A, { "aria-expanded": c, "aria-haspopup": "dialog", className: V(t === "default" && oe.input, s.trigger, (d == null ? void 0 : d.isPlaceholder) && s.placeholder), "data-open": c ? "true" : void 0, disabled: I.disabled, onClick: () => N((r) => !r), ref: L, style: H, variant: "minimal", children: /* @__PURE__ */ i("span", { className: s.text, children: (d == null ? void 0 : d.label) ?? "Select an option" }) }),
173
- c && /* @__PURE__ */ w("div", { className: s.panel, children: [
174
- /* @__PURE__ */ i(ne, { "aria-label": "Filter", className: s.filter, icon: "search", onChange: (r) => W(r.target.value), placeholder: l, ref: D, style: J, type: "search", value: F }),
175
- /* @__PURE__ */ i(le, { "aria-label": "Dropdown", className: s.options, children: z.length > 0 ? z.map((r) => {
176
- const a = r.value === E;
177
- return /* @__PURE__ */ i("li", { "data-component": "dropdown", children: /* @__PURE__ */ w(A, { "aria-label": a ? `${r.text}, selected` : r.text, className: V(s.option, a && s.selected), disabled: r.disabled, onClick: () => X(r.value), variant: "minimal", children: [
178
- /* @__PURE__ */ i("span", { className: s.text, children: r.label }),
179
- r.groupLabel && /* @__PURE__ */ i("small", { className: s.group, children: r.groupLabel })
180
- ] }) }, `${r.groupLabel ?? "root"}-${r.value}`);
181
- }) : /* @__PURE__ */ i("li", { className: s.empty, children: o }) })
170
+ return /* @__PURE__ */ _("div", { className: V(l.dropdown, t === "minimal" && l.minimal, r), onKeyDown: Y, ref: R, ...p, "data-component": "dropdown", children: [
171
+ /* @__PURE__ */ i("select", { ...I, "aria-hidden": "true", className: l.native, onChange: U, ref: j, tabIndex: -1, value: E, children: u.children }),
172
+ /* @__PURE__ */ i(A, { "aria-expanded": c, "aria-haspopup": "dialog", className: V(t === "default" && oe.input, l.trigger, (d == null ? void 0 : d.isPlaceholder) && l.placeholder), "data-open": c ? "true" : void 0, disabled: I.disabled, onClick: () => N((n) => !n), ref: L, style: H, variant: "minimal", children: /* @__PURE__ */ i("span", { className: l.text, children: (d == null ? void 0 : d.label) ?? "Select an option" }) }),
173
+ c && /* @__PURE__ */ _("div", { className: l.panel, children: [
174
+ /* @__PURE__ */ i(re, { "aria-label": "Filter", className: l.filter, icon: "search", onChange: (n) => W(n.target.value), placeholder: s, ref: D, style: J, type: "search", value: F }),
175
+ /* @__PURE__ */ i(se, { "aria-label": "Dropdown", className: l.options, children: z.length > 0 ? z.map((n) => {
176
+ const a = n.value === E;
177
+ return /* @__PURE__ */ i("li", { "data-component": "dropdown", children: /* @__PURE__ */ _(A, { "aria-label": a ? `${n.text}, selected` : n.text, className: V(l.option, a && l.selected), disabled: n.disabled, onClick: () => X(n.value), variant: "minimal", children: [
178
+ /* @__PURE__ */ i("span", { className: l.text, children: n.label }),
179
+ n.groupLabel && /* @__PURE__ */ i("small", { className: l.group, children: n.groupLabel })
180
+ ] }) }, `${n.groupLabel ?? "root"}-${n.value}`);
181
+ }) : /* @__PURE__ */ i("li", { className: l.empty, children: o }) })
182
182
  ] })
183
183
  ] });
184
184
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/_dropdown/index.tsx"],"sourcesContent":["import cx from 'classix';\nimport React, { Children, isValidElement, useEffect, useRef, useState } from 'react';\n\nimport { Button } from '@/components/button';\nimport { type IconName, iconSVG } from '@/components/icon/icons';\nimport { Input } from '@/components/input';\nimport inputStyles from '@/components/input/styles.module.css';\nimport { List } from '@/components/list';\nimport { Select, type SelectProps } from '@/components/select';\nimport { sanitizeSelectProps } from '@/components/select/sanitizeSelectProps';\nimport { resolveColor } from '@/utils';\n\nimport styles from './styles.module.css';\n\ntype NativeSelectProps = Omit<React.ComponentPropsWithoutRef<'select'>, 'children' | 'multiple'> & {\n children: React.ReactNode;\n multiple?: false;\n};\n\ntype NativeSelectElement = React.ReactElement<NativeSelectProps, 'select'>;\ntype WrappedSelectElement = React.ReactElement<SelectProps, typeof Select>;\ntype DropdownSelectElement = NativeSelectElement | WrappedSelectElement;\n\ntype DropdownOption = {\n disabled: boolean;\n groupLabel?: string;\n hidden: boolean;\n isPlaceholder: boolean;\n label: React.ReactNode;\n selected: boolean;\n text: string;\n value: string;\n};\n\nexport type DropdownProps = Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> & {\n children: DropdownSelectElement;\n emptyLabel?: string;\n searchPlaceholder?: string;\n variant?: 'default' | 'minimal';\n};\n\ntype withVars = React.CSSProperties & {\n '--icon-svg'?: string;\n};\n\nfunction getIconWithVars(icon: IconName, color: string): withVars {\n return {\n '--icon-svg': iconSVG(icon).replace('currentColor', color),\n };\n}\n\nfunction getNodeText(node: React.ReactNode): string {\n if (typeof node === 'string' || typeof node === 'number') {\n return String(node);\n }\n\n if (Array.isArray(node)) {\n return node.map(getNodeText).join(' ');\n }\n\n if (isValidElement<{ children?: React.ReactNode }>(node)) {\n return getNodeText(node.props.children);\n }\n\n return '';\n}\n\nfunction isOptionElement(\n node: React.ReactNode\n): node is React.ReactElement<React.ComponentPropsWithoutRef<'option'>, 'option'> {\n return isValidElement(node) && node.type === 'option';\n}\n\nfunction isOptGroupElement(\n node: React.ReactNode\n): node is React.ReactElement<React.ComponentPropsWithoutRef<'optgroup'>, 'optgroup'> {\n return isValidElement(node) && node.type === 'optgroup';\n}\n\nfunction isFragmentElement(\n node: React.ReactNode\n): node is React.ReactElement<{ children?: React.ReactNode }, typeof React.Fragment> {\n return isValidElement(node) && node.type === React.Fragment;\n}\n\nfunction isWrappedSelectElement(node: React.ReactNode): node is WrappedSelectElement {\n return isValidElement(node) && node.type === Select;\n}\n\nfunction extractOptions(\n children: React.ReactNode,\n groupLabel?: string,\n groupDisabled = false\n): DropdownOption[] {\n const options: DropdownOption[] = [];\n\n Children.forEach(children, (child) => {\n if (isFragmentElement(child)) {\n options.push(...extractOptions(child.props.children, groupLabel, groupDisabled));\n return;\n }\n\n if (isOptionElement(child)) {\n const text = getNodeText(child.props.children).trim();\n const value = child.props.value != null ? String(child.props.value) : text;\n\n options.push({\n disabled: groupDisabled || Boolean(child.props.disabled),\n groupLabel,\n hidden: Boolean(child.props.hidden),\n isPlaceholder: Boolean(child.props.hidden && value === ''),\n label: child.props.children,\n selected: Boolean(child.props.selected),\n text,\n value,\n });\n\n return;\n }\n\n if (isOptGroupElement(child)) {\n options.push(\n ...extractOptions(\n child.props.children,\n child.props.label,\n groupDisabled || Boolean(child.props.disabled)\n )\n );\n }\n });\n\n return options;\n}\n\nfunction buildWildcardMatcher(query: string) {\n const trimmedQuery = query.trim();\n\n if (!trimmedQuery) {\n return null;\n }\n\n const wildcardQuery = /[*?]/.test(trimmedQuery) ? trimmedQuery : `*${trimmedQuery}*`;\n const expression = [...wildcardQuery]\n .map((character) => {\n if (character === '*') {\n return '.*';\n }\n\n if (character === '?') {\n return '.';\n }\n\n return character.replace(/[|\\\\{}()[\\]^$+.,]/g, '\\\\$&');\n })\n .join('');\n\n return new RegExp(`^${expression}$`, 'i');\n}\n\nfunction filterOptions(options: DropdownOption[], query: string) {\n const matcher = buildWildcardMatcher(query);\n const selectableOptions = options.filter((option) => !option.hidden && !option.isPlaceholder);\n\n if (!matcher) {\n return selectableOptions;\n }\n\n return selectableOptions.filter((option) =>\n matcher.test([option.groupLabel, option.text, option.value].filter(Boolean).join(' '))\n );\n}\n\nfunction getDisplayOption(options: DropdownOption[], selectedValue: string) {\n return (\n options.find((option) => option.value === selectedValue) ??\n options.find((option) => option.isPlaceholder) ??\n options[0]\n );\n}\n\nfunction getInitialValue(\n options: DropdownOption[],\n value?: NativeSelectProps['value'],\n defaultValue?: NativeSelectProps['defaultValue']\n) {\n if (value != null) {\n return String(value);\n }\n\n if (defaultValue != null) {\n return String(defaultValue);\n }\n\n const selectedOption = options.find((option) => option.selected);\n\n if (selectedOption) {\n return selectedOption.value;\n }\n\n return options[0]?.value ?? '';\n}\n\nfunction normalizeSelectElement(selectElement: DropdownSelectElement) {\n if (isWrappedSelectElement(selectElement)) {\n const { children, placeholder, ...props } = selectElement.props;\n\n return {\n children: (\n <>\n {placeholder && (\n <option\n hidden\n value=''\n >\n {placeholder}\n </option>\n )}\n {children}\n </>\n ),\n props,\n };\n }\n\n return {\n children: selectElement.props.children,\n props: selectElement.props,\n };\n}\n\nexport const Dropdown = ({\n children: selectElement,\n className,\n emptyLabel = 'No matches found',\n searchPlaceholder = 'Filter',\n variant = 'default',\n ...props\n}: DropdownProps) => {\n const normalizedSelect = normalizeSelectElement(selectElement);\n const { defaultValue, onChange, value, ...restSelectProps } = normalizedSelect.props;\n const selectProps = sanitizeSelectProps(restSelectProps);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const nativeSelectRef = useRef<HTMLSelectElement>(null);\n const searchRef = useRef<HTMLInputElement>(null);\n const options = extractOptions(normalizedSelect.children);\n const isControlled = value != null;\n const initialValue = getInitialValue(options, value, defaultValue);\n const [internalValue, setInternalValue] = useState(() => initialValue);\n const [isOpen, setIsOpen] = useState(false);\n const [query, setQuery] = useState('');\n const selectedValue = isControlled ? String(value) : internalValue;\n const iconColors = {\n default: resolveColor('--color-icon'),\n white: resolveColor('--color-white', 'white'),\n };\n const dropdownIconColor = variant === 'minimal' ? iconColors.white : iconColors.default;\n const displayOption = getDisplayOption(options, selectedValue);\n const triggerWithVars = getIconWithVars('chevron', dropdownIconColor);\n const filterWithVars = getIconWithVars('search', dropdownIconColor);\n const filteredOptions = filterOptions(options, query);\n\n useEffect(() => {\n if (!isControlled && !options.some((option) => option.value === internalValue)) {\n setInternalValue(initialValue);\n }\n }, [initialValue, internalValue, isControlled, options]);\n\n useEffect(() => {\n if (!isOpen) {\n setQuery('');\n return;\n }\n\n searchRef.current?.focus();\n }, [isOpen]);\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n\n const handlePointerDown = (event: MouseEvent) => {\n if (!containerRef.current?.contains(event.target as Node)) {\n setIsOpen(false);\n }\n };\n\n document.addEventListener('mousedown', handlePointerDown);\n\n return () => {\n document.removeEventListener('mousedown', handlePointerDown);\n };\n }, [isOpen]);\n\n const handleNativeChange = (event: React.ChangeEvent<HTMLSelectElement>) => {\n if (!isControlled) {\n setInternalValue(event.target.value);\n }\n\n onChange?.(event);\n };\n\n const closeMenu = () => {\n setIsOpen(false);\n buttonRef.current?.focus();\n };\n\n const commitValue = (nextValue: string) => {\n if (!isControlled) {\n setInternalValue(nextValue);\n }\n\n const nativeSelect = nativeSelectRef.current;\n\n if (!nativeSelect) {\n closeMenu();\n return;\n }\n\n const valueSetter = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, 'value')?.set;\n\n valueSetter?.call(nativeSelect, nextValue);\n nativeSelect.dispatchEvent(new Event('change', { bubbles: true }));\n closeMenu();\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Escape') {\n closeMenu();\n }\n };\n\n return (\n <div\n className={cx(styles.dropdown, variant === 'minimal' && styles.minimal, className)}\n onKeyDown={handleKeyDown}\n ref={containerRef}\n {...props}\n >\n <select\n {...selectProps}\n aria-hidden='true'\n className={styles.native}\n onChange={handleNativeChange}\n ref={nativeSelectRef}\n tabIndex={-1}\n value={selectedValue}\n >\n {normalizedSelect.children}\n </select>\n <Button\n aria-expanded={isOpen}\n aria-haspopup='dialog'\n className={cx(\n variant === 'default' && inputStyles.input,\n styles.trigger,\n displayOption?.isPlaceholder && styles.placeholder\n )}\n data-open={isOpen ? 'true' : undefined}\n disabled={selectProps.disabled}\n onClick={() => setIsOpen((currentValue) => !currentValue)}\n ref={buttonRef}\n style={triggerWithVars}\n variant='minimal'\n >\n <span className={styles.text}>{displayOption?.label ?? 'Select an option'}</span>\n </Button>\n {isOpen && (\n <div className={styles.panel}>\n <Input\n aria-label='Filter'\n className={styles.filter}\n icon='search'\n onChange={(event) => setQuery(event.target.value)}\n placeholder={searchPlaceholder}\n ref={searchRef}\n style={filterWithVars}\n type='search'\n value={query}\n />\n <List\n aria-label='Dropdown'\n className={styles.options}\n >\n {filteredOptions.length > 0 ? (\n filteredOptions.map((option) => {\n const isSelected = option.value === selectedValue;\n\n return (\n <li key={`${option.groupLabel ?? 'root'}-${option.value}`}>\n <Button\n aria-label={isSelected ? `${option.text}, selected` : option.text}\n className={cx(styles.option, isSelected && styles.selected)}\n disabled={option.disabled}\n onClick={() => commitValue(option.value)}\n variant='minimal'\n >\n <span className={styles.text}>{option.label}</span>\n {option.groupLabel && (\n <small className={styles.group}>{option.groupLabel}</small>\n )}\n </Button>\n </li>\n );\n })\n ) : (\n <li className={styles.empty}>{emptyLabel}</li>\n )}\n </List>\n </div>\n )}\n </div>\n );\n};\n"],"names":["getIconWithVars","icon","color","iconSVG","replace","getNodeText","node","String","Array","isArray","map","join","isValidElement","props","children","isOptionElement","type","isOptGroupElement","isFragmentElement","React","Fragment","isWrappedSelectElement","Select","extractOptions","groupLabel","groupDisabled","options","Children","forEach","child","push","text","trim","value","disabled","Boolean","hidden","isPlaceholder","label","selected","buildWildcardMatcher","query","trimmedQuery","expression","test","character","RegExp","filterOptions","matcher","selectableOptions","filter","option","getDisplayOption","selectedValue","find","getInitialValue","defaultValue","selectedOption","normalizeSelectElement","selectElement","placeholder","jsxs","Dropdown","className","emptyLabel","searchPlaceholder","variant","normalizedSelect","onChange","restSelectProps","selectProps","sanitizeSelectProps","buttonRef","useRef","containerRef","nativeSelectRef","searchRef","isControlled","initialValue","internalValue","setInternalValue","useState","isOpen","setIsOpen","setQuery","iconColors","default","resolveColor","white","dropdownIconColor","displayOption","triggerWithVars","filterWithVars","filteredOptions","useEffect","some","current","focus","handlePointerDown","event","contains","target","document","addEventListener","removeEventListener","handleNativeChange","closeMenu","commitValue","nextValue","nativeSelect","valueSetter","Object","getOwnPropertyDescriptor","HTMLSelectElement","prototype","set","call","dispatchEvent","Event","bubbles","handleKeyDown","key","cx","styles","dropdown","minimal","jsx","native","Button","inputStyles","input","trigger","undefined","currentValue","panel","Input","List","length","isSelected","group","empty"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAASA,EAAgBC,GAAgBC,GAAyB;AAChE,SAAO;AAAA,IACL,cAAcC,GAAQF,CAAI,EAAEG,QAAQ,gBAAgBF,CAAK;AAAA,EAAA;AAE7D;AAEA,SAASG,EAAYC,GAA+B;AAClD,SAAI,OAAOA,KAAS,YAAY,OAAOA,KAAS,WACvCC,OAAOD,CAAI,IAGhBE,MAAMC,QAAQH,CAAI,IACbA,EAAKI,IAAIL,CAAW,EAAEM,KAAK,GAAG,IAGnCC,EAA+CN,CAAI,IAC9CD,EAAYC,EAAKO,MAAMC,QAAQ,IAGjC;AACT;AAEA,SAAS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;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/_dropdown/index.tsx"],"sourcesContent":["import cx from 'classix';\nimport React, { Children, isValidElement, useEffect, useRef, useState } from 'react';\n\nimport { Button } from '@/components/button';\nimport { type IconName, iconSVG } from '@/components/icon/icons';\nimport { Input } from '@/components/input';\nimport inputStyles from '@/components/input/styles.module.css';\nimport { List } from '@/components/list';\nimport { Select, type SelectProps } from '@/components/select';\nimport { sanitizeSelectProps } from '@/components/select/sanitizeSelectProps';\nimport { resolveColor } from '@/utils';\n\nimport styles from './styles.module.css';\n\ntype NativeSelectProps = Omit<React.ComponentPropsWithoutRef<'select'>, 'children' | 'multiple'> & {\n children: React.ReactNode;\n multiple?: false;\n};\n\ntype NativeSelectElement = React.ReactElement<NativeSelectProps, 'select'>;\ntype WrappedSelectElement = React.ReactElement<SelectProps, typeof Select>;\ntype DropdownSelectElement = NativeSelectElement | WrappedSelectElement;\n\ntype DropdownOption = {\n disabled: boolean;\n groupLabel?: string;\n hidden: boolean;\n isPlaceholder: boolean;\n label: React.ReactNode;\n selected: boolean;\n text: string;\n value: string;\n};\n\nexport type DropdownProps = Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> & {\n children: DropdownSelectElement;\n emptyLabel?: string;\n searchPlaceholder?: string;\n variant?: 'default' | 'minimal';\n};\n\ntype withVars = React.CSSProperties & {\n '--icon-svg'?: string;\n};\n\nfunction getIconWithVars(icon: IconName, color: string): withVars {\n return {\n '--icon-svg': iconSVG(icon).replace('currentColor', color),\n };\n}\n\nfunction getNodeText(node: React.ReactNode): string {\n if (typeof node === 'string' || typeof node === 'number') {\n return String(node);\n }\n\n if (Array.isArray(node)) {\n return node.map(getNodeText).join(' ');\n }\n\n if (isValidElement<{ children?: React.ReactNode }>(node)) {\n return getNodeText(node.props.children);\n }\n\n return '';\n}\n\nfunction isOptionElement(\n node: React.ReactNode\n): node is React.ReactElement<React.ComponentPropsWithoutRef<'option'>, 'option'> {\n return isValidElement(node) && node.type === 'option';\n}\n\nfunction isOptGroupElement(\n node: React.ReactNode\n): node is React.ReactElement<React.ComponentPropsWithoutRef<'optgroup'>, 'optgroup'> {\n return isValidElement(node) && node.type === 'optgroup';\n}\n\nfunction isFragmentElement(\n node: React.ReactNode\n): node is React.ReactElement<{ children?: React.ReactNode }, typeof React.Fragment> {\n return isValidElement(node) && node.type === React.Fragment;\n}\n\nfunction isWrappedSelectElement(node: React.ReactNode): node is WrappedSelectElement {\n return isValidElement(node) && node.type === Select;\n}\n\nfunction extractOptions(\n children: React.ReactNode,\n groupLabel?: string,\n groupDisabled = false\n): DropdownOption[] {\n const options: DropdownOption[] = [];\n\n Children.forEach(children, (child) => {\n if (isFragmentElement(child)) {\n options.push(...extractOptions(child.props.children, groupLabel, groupDisabled));\n return;\n }\n\n if (isOptionElement(child)) {\n const text = getNodeText(child.props.children).trim();\n const value = child.props.value != null ? String(child.props.value) : text;\n\n options.push({\n disabled: groupDisabled || Boolean(child.props.disabled),\n groupLabel,\n hidden: Boolean(child.props.hidden),\n isPlaceholder: Boolean(child.props.hidden && value === ''),\n label: child.props.children,\n selected: Boolean(child.props.selected),\n text,\n value,\n });\n\n return;\n }\n\n if (isOptGroupElement(child)) {\n options.push(\n ...extractOptions(\n child.props.children,\n child.props.label,\n groupDisabled || Boolean(child.props.disabled)\n )\n );\n }\n });\n\n return options;\n}\n\nfunction buildWildcardMatcher(query: string) {\n const trimmedQuery = query.trim();\n\n if (!trimmedQuery) {\n return null;\n }\n\n const wildcardQuery = /[*?]/.test(trimmedQuery) ? trimmedQuery : `*${trimmedQuery}*`;\n const expression = [...wildcardQuery]\n .map((character) => {\n if (character === '*') {\n return '.*';\n }\n\n if (character === '?') {\n return '.';\n }\n\n return character.replace(/[|\\\\{}()[\\]^$+.,]/g, '\\\\$&');\n })\n .join('');\n\n return new RegExp(`^${expression}$`, 'i');\n}\n\nfunction filterOptions(options: DropdownOption[], query: string) {\n const matcher = buildWildcardMatcher(query);\n const selectableOptions = options.filter((option) => !option.hidden && !option.isPlaceholder);\n\n if (!matcher) {\n return selectableOptions;\n }\n\n return selectableOptions.filter((option) =>\n matcher.test([option.groupLabel, option.text, option.value].filter(Boolean).join(' '))\n );\n}\n\nfunction getDisplayOption(options: DropdownOption[], selectedValue: string) {\n return (\n options.find((option) => option.value === selectedValue) ??\n options.find((option) => option.isPlaceholder) ??\n options[0]\n );\n}\n\nfunction getInitialValue(\n options: DropdownOption[],\n value?: NativeSelectProps['value'],\n defaultValue?: NativeSelectProps['defaultValue']\n) {\n if (value != null) {\n return String(value);\n }\n\n if (defaultValue != null) {\n return String(defaultValue);\n }\n\n const selectedOption = options.find((option) => option.selected);\n\n if (selectedOption) {\n return selectedOption.value;\n }\n\n return options[0]?.value ?? '';\n}\n\nfunction normalizeSelectElement(selectElement: DropdownSelectElement) {\n if (isWrappedSelectElement(selectElement)) {\n const { children, placeholder, ...props } = selectElement.props;\n\n return {\n children: (\n <>\n {placeholder && (\n <option\n hidden\n value=''\n >\n {placeholder}\n </option>\n )}\n {children}\n </>\n ),\n props,\n };\n }\n\n return {\n children: selectElement.props.children,\n props: selectElement.props,\n };\n}\n\nexport const Dropdown = ({\n children: selectElement,\n className,\n emptyLabel = 'No matches found',\n searchPlaceholder = 'Filter',\n variant = 'default',\n ...props\n}: DropdownProps) => {\n const normalizedSelect = normalizeSelectElement(selectElement);\n const { defaultValue, onChange, value, ...restSelectProps } = normalizedSelect.props;\n const selectProps = sanitizeSelectProps(restSelectProps);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const nativeSelectRef = useRef<HTMLSelectElement>(null);\n const searchRef = useRef<HTMLInputElement>(null);\n const options = extractOptions(normalizedSelect.children);\n const isControlled = value != null;\n const initialValue = getInitialValue(options, value, defaultValue);\n const [internalValue, setInternalValue] = useState(() => initialValue);\n const [isOpen, setIsOpen] = useState(false);\n const [query, setQuery] = useState('');\n const selectedValue = isControlled ? String(value) : internalValue;\n const iconColors = {\n default: resolveColor('--colors-semantic-content-secondary'),\n white: resolveColor('--color-white', 'white'),\n };\n const dropdownIconColor = variant === 'minimal' ? iconColors.white : iconColors.default;\n const displayOption = getDisplayOption(options, selectedValue);\n const triggerWithVars = getIconWithVars('chevron', dropdownIconColor);\n const filterWithVars = getIconWithVars('search', dropdownIconColor);\n const filteredOptions = filterOptions(options, query);\n\n useEffect(() => {\n if (!isControlled && !options.some((option) => option.value === internalValue)) {\n setInternalValue(initialValue);\n }\n }, [initialValue, internalValue, isControlled, options]);\n\n useEffect(() => {\n if (!isOpen) {\n setQuery('');\n return;\n }\n\n searchRef.current?.focus();\n }, [isOpen]);\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n\n const handlePointerDown = (event: MouseEvent) => {\n if (!containerRef.current?.contains(event.target as Node)) {\n setIsOpen(false);\n }\n };\n\n document.addEventListener('mousedown', handlePointerDown);\n\n return () => {\n document.removeEventListener('mousedown', handlePointerDown);\n };\n }, [isOpen]);\n\n const handleNativeChange = (event: React.ChangeEvent<HTMLSelectElement>) => {\n if (!isControlled) {\n setInternalValue(event.target.value);\n }\n\n onChange?.(event);\n };\n\n const closeMenu = () => {\n setIsOpen(false);\n buttonRef.current?.focus();\n };\n\n const commitValue = (nextValue: string) => {\n if (!isControlled) {\n setInternalValue(nextValue);\n }\n\n const nativeSelect = nativeSelectRef.current;\n\n if (!nativeSelect) {\n closeMenu();\n return;\n }\n\n const valueSetter = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, 'value')?.set;\n\n valueSetter?.call(nativeSelect, nextValue);\n nativeSelect.dispatchEvent(new Event('change', { bubbles: true }));\n closeMenu();\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Escape') {\n closeMenu();\n }\n };\n\n return (\n <div\n className={cx(styles.dropdown, variant === 'minimal' && styles.minimal, className)}\n onKeyDown={handleKeyDown}\n ref={containerRef}\n {...props}\n >\n <select\n {...selectProps}\n aria-hidden='true'\n className={styles.native}\n onChange={handleNativeChange}\n ref={nativeSelectRef}\n tabIndex={-1}\n value={selectedValue}\n >\n {normalizedSelect.children}\n </select>\n <Button\n aria-expanded={isOpen}\n aria-haspopup='dialog'\n className={cx(\n variant === 'default' && inputStyles.input,\n styles.trigger,\n displayOption?.isPlaceholder && styles.placeholder\n )}\n data-open={isOpen ? 'true' : undefined}\n disabled={selectProps.disabled}\n onClick={() => setIsOpen((currentValue) => !currentValue)}\n ref={buttonRef}\n style={triggerWithVars}\n variant='minimal'\n >\n <span className={styles.text}>{displayOption?.label ?? 'Select an option'}</span>\n </Button>\n {isOpen && (\n <div className={styles.panel}>\n <Input\n aria-label='Filter'\n className={styles.filter}\n icon='search'\n onChange={(event) => setQuery(event.target.value)}\n placeholder={searchPlaceholder}\n ref={searchRef}\n style={filterWithVars}\n type='search'\n value={query}\n />\n <List\n aria-label='Dropdown'\n className={styles.options}\n >\n {filteredOptions.length > 0 ? (\n filteredOptions.map((option) => {\n const isSelected = option.value === selectedValue;\n\n return (\n <li key={`${option.groupLabel ?? 'root'}-${option.value}`}>\n <Button\n aria-label={isSelected ? `${option.text}, selected` : option.text}\n className={cx(styles.option, isSelected && styles.selected)}\n disabled={option.disabled}\n onClick={() => commitValue(option.value)}\n variant='minimal'\n >\n <span className={styles.text}>{option.label}</span>\n {option.groupLabel && (\n <small className={styles.group}>{option.groupLabel}</small>\n )}\n </Button>\n </li>\n );\n })\n ) : (\n <li className={styles.empty}>{emptyLabel}</li>\n )}\n </List>\n </div>\n )}\n </div>\n );\n};\n"],"names":["getIconWithVars","icon","color","iconSVG","replace","getNodeText","node","String","Array","isArray","map","join","isValidElement","props","children","isOptionElement","type","isOptGroupElement","isFragmentElement","React","Fragment","isWrappedSelectElement","Select","extractOptions","groupLabel","groupDisabled","options","Children","forEach","child","push","text","trim","value","disabled","Boolean","hidden","isPlaceholder","label","selected","buildWildcardMatcher","query","trimmedQuery","expression","test","character","RegExp","filterOptions","matcher","selectableOptions","filter","option","getDisplayOption","selectedValue","find","getInitialValue","defaultValue","selectedOption","normalizeSelectElement","selectElement","placeholder","jsxs","Dropdown","className","emptyLabel","searchPlaceholder","variant","normalizedSelect","onChange","restSelectProps","selectProps","sanitizeSelectProps","buttonRef","useRef","containerRef","nativeSelectRef","searchRef","isControlled","initialValue","internalValue","setInternalValue","useState","isOpen","setIsOpen","setQuery","iconColors","default","resolveColor","white","dropdownIconColor","displayOption","triggerWithVars","filterWithVars","filteredOptions","useEffect","some","current","focus","handlePointerDown","event","contains","target","document","addEventListener","removeEventListener","handleNativeChange","closeMenu","commitValue","nextValue","nativeSelect","valueSetter","Object","getOwnPropertyDescriptor","HTMLSelectElement","prototype","set","call","dispatchEvent","Event","bubbles","handleKeyDown","key","cx","styles","dropdown","minimal","jsx","native","Button","inputStyles","input","trigger","undefined","currentValue","panel","Input","List","length","isSelected","group","empty"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAASA,EAAgBC,GAAgBC,GAAyB;AAChE,SAAO;AAAA,IACL,cAAcC,GAAQF,CAAI,EAAEG,QAAQ,gBAAgBF,CAAK;AAAA,EAAA;AAE7D;AAEA,SAASG,EAAYC,GAA+B;AAClD,SAAI,OAAOA,KAAS,YAAY,OAAOA,KAAS,WACvCC,OAAOD,CAAI,IAGhBE,MAAMC,QAAQH,CAAI,IACbA,EAAKI,IAAIL,CAAW,EAAEM,KAAK,GAAG,IAGnCC,EAA+CN,CAAI,IAC9CD,EAAYC,EAAKO,MAAMC,QAAQ,IAGjC;AACT;AAEA,SAASC,GACPT,GACgF;AAChF,SAAOM,EAAeN,CAAI,KAAKA,EAAKU,SAAS;AAC/C;AAEA,SAASC,GACPX,GACoF;AACpF,SAAOM,EAAeN,CAAI,KAAKA,EAAKU,SAAS;AAC/C;AAEA,SAASE,GACPZ,GACmF;AACnF,SAAOM,EAAeN,CAAI,KAAKA,EAAKU,SAASG,GAAMC;AACrD;AAEA,SAASC,GAAuBf,GAAqD;AACnF,SAAOM,EAAeN,CAAI,KAAKA,EAAK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aAAagC,GACb,KAAKW,GACL,OAAOgB,GACP,MAAK,UACL,OAAOnD,EAAAA,CAAM;AAAA,MAEf,gBAAAqF,EAACU,IAAA,EACC,cAAW,YACX,WAAWb,EAAOjG,SAEjBmE,UAAAA,EAAgB4C,SAAS,IACxB5C,EAAgBnF,IAAKyC,CAAAA,MAAW;AAC9B,cAAMuF,IAAavF,EAAOlB,UAAUoB;AAEpC,eACE,gBAAAyE,EAAC,MAAA,EAAyD,kBAAA,YACxD,4BAACE,GAAA,EACC,cAAYU,IAAa,GAAGvF,EAAOpB,IAAI,eAAeoB,EAAOpB,MAC7D,WAAW2F,EAAGC,EAAOxE,QAAQuF,KAAcf,EAAOpF,QAAQ,GAC1D,UAAUY,EAAOjB,UACjB,SAAS,MAAMyE,EAAYxD,EAAOlB,KAAK,GACvC,SAAQ,WAER,UAAA;AAAA,UAAA,gBAAA6F,EAAC,QAAA,EAAK,WAAWH,EAAO5F,MAAOoB,YAAOb,OAAM;AAAA,UAC3Ca,EAAO3B,cACN,gBAAAsG,EAAC,SAAA,EAAM,WAAWH,EAAOgB,OAAQxF,YAAO3B,WAAAA,CAAW;AAAA,QAAA,GAEvD,EAAA,GAZO,GAAG2B,EAAO3B,cAAc,MAAM,IAAI2B,EAAOlB,KAAK,EAavD;AAAA,MAEJ,CAAC,IAED,gBAAA6F,EAAC,MAAA,EAAG,WAAWH,EAAOiB,OAAQ5E,aAAW,EAAA,CAE7C;AAAA,IAAA,EAAA,CACF;AAAA,EAAA,GAEJ;AAEJ;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('../../assets/index23.css');const i=require("react/jsx-runtime"),h=require("../../classix-5H4IWnMA.cjs"),x=require("react"),q=require("../button/index.cjs"),I=require("../icon/index.cjs"),R="_dropzone_1xbnl_1",T="_dragging_1xbnl_18",S="_minimal_1xbnl_22",g={dropzone:R,dragging:T,minimal:S},k=({accepts:z,label:F="Select files",maxFileSize:m,multiple:d=!1,onChange:n,onValidation:a,variant:p="default",...D})=>{const f=x.useRef(null),[y,o]=x.useState(!1),c=e=>{e.preventDefault(),e.stopPropagation()},_=e=>{const t=f.current;if(!t)return;const s=new DataTransfer;for(const r of e)s.items.add(r);t.files=s.files,n==null||n({target:t,currentTarget:t})},v=e=>{const{validFiles:t,emptyFiles:s,oversizedFiles:r}=e.reduce((u,l)=>(l.size===0?u.emptyFiles.push(l):m&&l.size>m?u.oversizedFiles.push(l):u.validFiles.push(l),u),{validFiles:[],emptyFiles:[],oversizedFiles:[]});return(s.length>0||r.length>0)&&(a==null||a(s,r)),t},b=e=>{c(e),o(!1);const t=Array.from(e.dataTransfer.files??[]),s=v(t);if(s.length===0)return;const r=d?s:s.slice(0,1);_(r)},j=e=>{const t=Array.from(e.target.files??[]),s=v(t);if(s.length===t.length){n==null||n(e);return}const r=d?s:s.slice(0,1);_(r)};return i.jsx("div",{className:h.t(g.dropzone,g[p],y&&g.dragging),onDragEnter:e=>{c(e),o(!0)},onDragOver:e=>{c(e),o(!0)},onDragLeave:e=>{c(e),o(!1)},onDrop:b,...D,"data-component":"dropzone",children:i.jsxs("label",{children:[i.jsx("input",{accept:z,hidden:!0,multiple:d,onChange:j,ref:f,type:"file"}),i.jsx(I.Icon,{name:"upload",size:p==="minimal"?"medium":"large"}),i.jsx("br",{}),p!=="minimal"&&i.jsx(q.Button,{onClick:()=>{var e;return(e=f.current)==null?void 0:e.click()},type:"button",children:F})]})})};exports.Dropzone=k;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('../../assets/index23.css');const i=require("react/jsx-runtime"),b=require("../../classix-5H4IWnMA.cjs"),z=require("react"),q=require("../button/index.cjs"),I=require("../icon/index.cjs"),R="_dropzone_1rpsf_1",T="_dragging_1rpsf_19",S="_minimal_1rpsf_23",g={dropzone:R,dragging:T,minimal:S},k=({accepts:F,label:D="Select files",maxFileSize:m,multiple:d=!1,onChange:n,onValidation:a,variant:p="default",...y})=>{const f=z.useRef(null),[x,l]=z.useState(!1),c=e=>{e.preventDefault(),e.stopPropagation()},_=e=>{const t=f.current;if(!t)return;const s=new DataTransfer;for(const r of e)s.items.add(r);t.files=s.files,n==null||n({target:t,currentTarget:t})},v=e=>{const{validFiles:t,emptyFiles:s,oversizedFiles:r}=e.reduce((u,o)=>(o.size===0?u.emptyFiles.push(o):m&&o.size>m?u.oversizedFiles.push(o):u.validFiles.push(o),u),{validFiles:[],emptyFiles:[],oversizedFiles:[]});return(s.length>0||r.length>0)&&(a==null||a(s,r)),t},j=e=>{c(e),l(!1);const t=Array.from(e.dataTransfer.files??[]),s=v(t);if(s.length===0)return;const r=d?s:s.slice(0,1);_(r)},h=e=>{const t=Array.from(e.target.files??[]),s=v(t);if(s.length===t.length){n==null||n(e);return}const r=d?s:s.slice(0,1);_(r)};return i.jsx("div",{className:b.t(g.dropzone,g[p],x&&g.dragging),onDragEnter:e=>{c(e),l(!0)},onDragOver:e=>{c(e),l(!0)},onDragLeave:e=>{c(e),l(!1)},onDrop:j,...y,"data-component":"dropzone",children:i.jsxs("label",{children:[i.jsx("input",{accept:F,hidden:!0,multiple:d,onChange:h,ref:f,type:"file"}),i.jsx(I.Icon,{name:"upload",size:p==="minimal"?"medium":"large"}),i.jsx("br",{}),p!=="minimal"&&i.jsx(q.Button,{onClick:()=>{var e;return(e=f.current)==null?void 0:e.click()},type:"button",children:D})]})})};exports.Dropzone=k;
2
2
  //# sourceMappingURL=index.cjs.map