@solibo/solibo-ui 2.2.4 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/dropdown/index.cjs +1 -1
- package/dist/components/dropdown/index.js +192 -153
- package/dist/index.d.ts +13 -1
- package/dist/tokens.json +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('../../assets/index41.css');const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('../../assets/index41.css');const s=require("react/jsx-runtime"),C=require("classix"),r=require("react"),V=require("../button/index.cjs"),$e=require("../../icons-BIdcCH-v.cjs"),fe=require("../../index-7blZaPiA.cjs"),De=require("../list/index.cjs"),Fe=require("../loading/index.cjs"),F=require("../../index-VLDsM9it.cjs");function L(t){return typeof t=="string"||typeof t=="number"?String(t):Array.isArray(t)?t.map(L).join(" "):r.isValidElement(t)?L(t.props.children):""}function Le(t){return r.isValidElement(t)&&t.type==="option"}function Me(t){return r.isValidElement(t)&&t.type==="optgroup"}function Qe(t){return r.isValidElement(t)&&t.type===r.Fragment}function We(t){return r.isValidElement(t)&&t.type===F.Select}function Z(t,c,i=!1){const o=[];return r.Children.forEach(t,n=>{if(Qe(n))o.push(...Z(n.props.children,c,i));else if(Le(n)){const a=L(n.props.children).trim(),h=n.props.value!=null?String(n.props.value):a;o.push({disabled:i||!!n.props.disabled,groupLabel:c,hidden:!!n.props.hidden,isPlaceholder:!!(n.props.hidden&&h===""),label:n.props.children,selected:!!n.props.selected,text:a,value:h})}else Me(n)&&o.push(...Z(n.props.children,n.props.label,i||!!n.props.disabled))}),o}function ze(t){const c=t.trim();if(!c)return null;const o=[.../[*?]/.test(c)?c:`*${c}*`].map(n=>n==="*"?".*":n==="?"?".":n.replace(/[|\\{}()[\]^$+.,]/g,"\\$&")).join("");return new RegExp(`^${o}$`,"i")}function Ge(t,c){const i=ze(c),o=t.filter(n=>!n.hidden&&!n.isPlaceholder);return i?o.filter(n=>i.test([n.groupLabel,n.text,n.value].filter(Boolean).join(" "))):o}function Pe(t,c){return t.find(i=>i.value===c)??t.find(i=>i.isPlaceholder)??t[0]}function Te(t,c,i){var o,n;return c!=null?String(c):i!=null?String(i):((o=t.find(a=>a.selected))==null?void 0:o.value)??((n=t[0])==null?void 0:n.value)??""}function Ae(t){if(We(t)){const{children:c,placeholder:i,...o}=t.props;return{children:s.jsxs(s.Fragment,{children:[i&&s.jsx("option",{hidden:!0,value:"",children:i}),c]}),props:o}}return{children:t.props.children,props:t.props}}const Ke="_combobox_5r227_3",Oe="_dropdown_5r227_20",He="_empty_5r227_25",Je="_group_5r227_26",Ue="_placeholder_5r227_27",Xe="_filter_5r227_35",Ye="_native_5r227_45",Ze="_option_5r227_55",et="_options_5r227_76",tt="_panel_5r227_83",nt="_selected_5r227_108",st="_text_5r227_112",rt="_trigger_5r227_120",lt="_minimal_5r227_157",it="_inline_5r227_217",ot="_label_5r227_249",l={combobox:Ke,"combobox-input":"_combobox-input_5r227_12",dropdown:Oe,empty:He,group:Je,placeholder:Ue,filter:Xe,native:Ye,option:Ze,options:et,panel:tt,selected:nt,text:st,trigger:rt,minimal:lt,inline:it,label:ot,"inline-field":"_inline-field_5r227_255"};function pe(t,c){return{"--icon-svg":$e.iconSVG(t,c)}}const ct=({children:t,className:c,combobox:i=!1,createOption:o,emptyLabel:n="No matches found",errorLabel:a,onRetry:h,retryLabel:me="Retry",label:b,filterOptions:_e=!0,hasNextPage:v=!1,loading:m=!1,loadMoreLabel:be="Load more",onLoadMore:g,onOpenChange:I,onSearchChange:B,searchValue:M,renderOption:Q,searchPlaceholder:W="Filter",selectedItems:ve,variant:j="default",...xe})=>{const z=Ae(t),{defaultValue:ye,onChange:G,value:P,...he}=z.props,u=F.sanitizeSelectProps(he),{className:ge,...je}=u,ee=r.useRef(null),te=r.useRef(null),k=r.useId(),ne=r.useRef(null),x=r.useRef(null),se=r.useRef(null),re=r.useRef(null),T=r.useRef(!1),A=r.useRef(!1),K=r.useRef(g),le=!!g,w=Z(z.children),E=P!=null,O=Te(w,P,ye),[H,J]=r.useState(()=>O),[d,we]=r.useState(!1),[Ee,Re]=r.useState(""),R=M??Ee,N=r.useCallback(e=>{M===void 0&&Re(e),B==null||B(e)},[B,M]),p=r.useCallback(e=>{T.current===e||e&&u.disabled||(T.current=e,we(e),I==null||I(e),e||N(""))},[I,u.disabled,N]),q=E?String(P):H,ie={default:F.resolveColor("--colors-semantic-content-secondary"),white:F.resolveColor("--color-white","white")},oe=j==="minimal"?ie.white:ie.default,$=Pe(w,q),Ne=pe("CaretDown",oe),Se=pe("MagnifyingGlass",oe),U=Ge(w,_e?R:""),y=R.trim(),D=!!(i&&o&&y&&o.isValid(y)),Ce=b&&j==="inline"?fe.formatInlineLabel(b):b,ce=e=>e?(Q==null?void 0:Q({groupLabel:e.groupLabel,isSelected:e.value===q,label:e.label,text:e.text,value:e.value}))??e.label:"Select an option";r.useEffect(()=>{!E&&!w.some(e=>e.value===H)&&J(O)},[O,H,E,w]),r.useEffect(()=>{var e;d&&((e=x.current)==null||e.focus())},[d]),r.useEffect(()=>{if(!d)return;const e=f=>{var _;(_=te.current)!=null&&_.contains(f.target)||p(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[p,d]),r.useEffect(()=>{K.current=g},[g]),r.useEffect(()=>{u.disabled&&p(!1)},[p,u.disabled]);const X=r.useCallback(()=>{!T.current||u.disabled||m||a||!v||!K.current||A.current||(A.current=!0,K.current())},[a,v,m,u.disabled]);r.useEffect(()=>{if(A.current=!1,!d||u.disabled||m||a||!v||!le)return;const e=re.current,f=se.current;if(!e||!f||typeof IntersectionObserver>"u")return;let _=!0;const S=new IntersectionObserver(ke=>{_&&ke.some(qe=>qe.isIntersecting)&&X()},{root:f});return S.observe(e),()=>{_=!1,S.disconnect()}},[d,m,a,v,le,X,U.length,R,u.disabled]);const Ve=e=>{E||J(e.target.value),G==null||G(e)},Y=()=>{var e;p(!1),i||(e=ee.current)==null||e.focus()},ae=()=>{var e;N(""),p(!0),(e=x.current)==null||e.focus()},ue=()=>{!o||!D||(o.onCreate(y),ae())},Ie=e=>{var S;E||J(e);const f=ne.current;if(!f){Y();return}const _=(S=Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype,"value"))==null?void 0:S.set;_==null||_.call(f,e),f.dispatchEvent(new Event("change",{bubbles:!0})),i?ae():Y()},Be=e=>{e.key==="Escape"&&Y(),e.key==="Enter"&&e.target===x.current&&D&&(e.preventDefault(),ue())},de=s.jsxs("div",{className:C(l.dropdown,j==="inline"&&l.inline,j==="minimal"&&l.minimal,c),onKeyDown:Be,ref:te,...xe,"data-component":"dropdown",children:[s.jsx("select",{...je,"aria-hidden":"true",className:C(l.native,ge),onChange:Ve,ref:ne,tabIndex:-1,value:q,children:z.children}),i?s.jsxs("div",{className:l.combobox,onClick:()=>{var e;return(e=x.current)==null?void 0:e.focus()},children:[ve,s.jsx("input",{"aria-autocomplete":"list","aria-expanded":d,"aria-label":u["aria-label"]??b??W,className:l["combobox-input"],disabled:u.disabled,onChange:e=>{N(e.target.value),p(!0)},onClick:()=>p(!0),onFocus:()=>p(!0),placeholder:W||void 0,ref:x,role:"combobox",type:"text",value:R})]}):s.jsx(V.Button,{"aria-expanded":d,"aria-haspopup":"dialog","aria-labelledby":b?`${k} ${k}-value`:void 0,className:C(l.trigger,($==null?void 0:$.isPlaceholder)&&l.placeholder),"data-open":d?"true":void 0,disabled:u.disabled,onClick:()=>p(!d),ref:ee,style:Ne,variant:"simple",children:s.jsx("span",{className:l.text,id:`${k}-value`,children:ce($)})}),d&&s.jsxs("div",{className:l.panel,children:[!i&&s.jsx(fe.Input,{"aria-label":"Filter",className:l.filter,icon:"MagnifyingGlass",onChange:e=>N(e.target.value),placeholder:W,ref:x,style:Se,type:"search",value:R}),s.jsxs(De.List,{"aria-label":"Dropdown","aria-busy":m||void 0,className:l.options,ref:se,children:[U.map(e=>{const f=e.value===q;return s.jsx("li",{"data-component":"dropdown",children:s.jsxs(V.Button,{"aria-label":f?`${e.text}, selected`:e.text,className:C(l.option,f&&l.selected),disabled:e.disabled,onClick:()=>Ie(e.value),variant:"tertiary",children:[s.jsx("span",{className:l.text,children:ce(e)}),e.groupLabel&&s.jsx("small",{className:l.group,children:e.groupLabel})]})},`${e.groupLabel??"root"}-${e.value}`)}),D&&o&&s.jsx("li",{children:s.jsx(V.Button,{"aria-label":L(o.render(y))||y,className:l.option,onClick:ue,variant:"tertiary",children:s.jsx("span",{className:l.text,children:o.render(y)})})}),U.length===0&&!D&&!m&&!a&&!v&&s.jsx("li",{className:l.empty,children:n}),a&&s.jsxs("li",{className:l.empty,children:[s.jsx("span",{role:"alert",children:a}),h&&s.jsx(V.Button,{disabled:m,onClick:h,variant:"tertiary",children:me})]}),m&&s.jsx("li",{"aria-label":"Loading",className:l.empty,role:"status",children:s.jsx(Fe.Loading,{size:"small"})}),v&&g&&!a&&s.jsx("li",{ref:re,children:s.jsx(V.Button,{className:l.option,disabled:m,onClick:X,variant:"tertiary",children:be})})]})]})]});return b?s.jsxs("div",{className:C(l.label,j==="inline"&&l["inline-field"]),"data-component":"dropdown",children:[s.jsx("span",{id:k,children:Ce}),de]}):de};exports.Dropdown=ct;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,76 +1,77 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Button as
|
|
5
|
-
import { i as
|
|
6
|
-
import { f as
|
|
7
|
-
import { List as
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
|
|
1
|
+
import { jsxs as _, Fragment as We, jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import $ from "classix";
|
|
3
|
+
import ze, { Children as Ge, isValidElement as B, useRef as b, useId as Me, useState as te, useCallback as ne, useEffect as w } from "react";
|
|
4
|
+
import { Button as k } from "../button/index.js";
|
|
5
|
+
import { i as Pe } from "../../icons-DVeBguFb.js";
|
|
6
|
+
import { f as qe, I as Ae } from "../../index-Dd20d_9U.js";
|
|
7
|
+
import { List as Ke } from "../list/index.js";
|
|
8
|
+
import { Loading as Te } from "../loading/index.js";
|
|
9
|
+
import { S as He, s as Oe, r as _e } from "../../index-Dx-KtGBg.js";
|
|
10
|
+
import '../../assets/index41.css';function z(t) {
|
|
11
|
+
return typeof t == "string" || typeof t == "number" ? String(t) : Array.isArray(t) ? t.map(z).join(" ") : B(t) ? z(t.props.children) : "";
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
-
return
|
|
13
|
+
function Je(t) {
|
|
14
|
+
return B(t) && t.type === "option";
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
return
|
|
16
|
+
function Ue(t) {
|
|
17
|
+
return B(t) && t.type === "optgroup";
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
19
|
+
function Xe(t) {
|
|
20
|
+
return B(t) && t.type === ze.Fragment;
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
22
|
+
function Ye(t) {
|
|
23
|
+
return B(t) && t.type === He;
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
else if (
|
|
30
|
-
const a =
|
|
31
|
-
|
|
32
|
-
disabled:
|
|
33
|
-
groupLabel:
|
|
25
|
+
function re(t, i, l = !1) {
|
|
26
|
+
const s = [];
|
|
27
|
+
return Ge.forEach(t, (n) => {
|
|
28
|
+
if (Xe(n))
|
|
29
|
+
s.push(...re(n.props.children, i, l));
|
|
30
|
+
else if (Je(n)) {
|
|
31
|
+
const a = z(n.props.children).trim(), x = n.props.value != null ? String(n.props.value) : a;
|
|
32
|
+
s.push({
|
|
33
|
+
disabled: l || !!n.props.disabled,
|
|
34
|
+
groupLabel: i,
|
|
34
35
|
hidden: !!n.props.hidden,
|
|
35
|
-
isPlaceholder: !!(n.props.hidden &&
|
|
36
|
+
isPlaceholder: !!(n.props.hidden && x === ""),
|
|
36
37
|
label: n.props.children,
|
|
37
38
|
selected: !!n.props.selected,
|
|
38
39
|
text: a,
|
|
39
|
-
value:
|
|
40
|
+
value: x
|
|
40
41
|
});
|
|
41
|
-
} else
|
|
42
|
-
}),
|
|
42
|
+
} else Ue(n) && s.push(...re(n.props.children, n.props.label, l || !!n.props.disabled));
|
|
43
|
+
}), s;
|
|
43
44
|
}
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
if (!
|
|
47
|
-
const
|
|
48
|
-
return new RegExp(`^${
|
|
45
|
+
function Ze(t) {
|
|
46
|
+
const i = t.trim();
|
|
47
|
+
if (!i) return null;
|
|
48
|
+
const s = [.../[*?]/.test(i) ? i : `*${i}*`].map((n) => n === "*" ? ".*" : n === "?" ? "." : n.replace(/[|\\{}()[\]^$+.,]/g, "\\$&")).join("");
|
|
49
|
+
return new RegExp(`^${s}$`, "i");
|
|
49
50
|
}
|
|
50
|
-
function
|
|
51
|
-
const
|
|
52
|
-
return
|
|
51
|
+
function et(t, i) {
|
|
52
|
+
const l = Ze(i), s = t.filter((n) => !n.hidden && !n.isPlaceholder);
|
|
53
|
+
return l ? s.filter((n) => l.test([n.groupLabel, n.text, n.value].filter(Boolean).join(" "))) : s;
|
|
53
54
|
}
|
|
54
|
-
function
|
|
55
|
-
return t.find((
|
|
55
|
+
function tt(t, i) {
|
|
56
|
+
return t.find((l) => l.value === i) ?? t.find((l) => l.isPlaceholder) ?? t[0];
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
-
var
|
|
59
|
-
return
|
|
58
|
+
function nt(t, i, l) {
|
|
59
|
+
var s, n;
|
|
60
|
+
return i != null ? String(i) : l != null ? String(l) : ((s = t.find((a) => a.selected)) == null ? void 0 : s.value) ?? ((n = t[0]) == null ? void 0 : n.value) ?? "";
|
|
60
61
|
}
|
|
61
|
-
function
|
|
62
|
-
if (
|
|
62
|
+
function rt(t) {
|
|
63
|
+
if (Ye(t)) {
|
|
63
64
|
const {
|
|
64
|
-
children:
|
|
65
|
-
placeholder:
|
|
66
|
-
...
|
|
65
|
+
children: i,
|
|
66
|
+
placeholder: l,
|
|
67
|
+
...s
|
|
67
68
|
} = t.props;
|
|
68
69
|
return {
|
|
69
|
-
children: /* @__PURE__ */
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
children: /* @__PURE__ */ _(We, { children: [
|
|
71
|
+
l && /* @__PURE__ */ o("option", { hidden: !0, value: "", children: l }),
|
|
72
|
+
i
|
|
72
73
|
] }),
|
|
73
|
-
props:
|
|
74
|
+
props: s
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
return {
|
|
@@ -78,138 +79,176 @@ function De(t) {
|
|
|
78
79
|
props: t.props
|
|
79
80
|
};
|
|
80
81
|
}
|
|
81
|
-
const
|
|
82
|
-
combobox:
|
|
82
|
+
const lt = "_combobox_5r227_3", st = "_dropdown_5r227_20", it = "_empty_5r227_25", ot = "_group_5r227_26", at = "_placeholder_5r227_27", ct = "_filter_5r227_35", ut = "_native_5r227_45", dt = "_option_5r227_55", pt = "_options_5r227_76", ft = "_panel_5r227_83", mt = "_selected_5r227_108", bt = "_text_5r227_112", _t = "_trigger_5r227_120", vt = "_minimal_5r227_157", yt = "_inline_5r227_217", ht = "_label_5r227_249", r = {
|
|
83
|
+
combobox: lt,
|
|
83
84
|
"combobox-input": "_combobox-input_5r227_12",
|
|
84
|
-
dropdown:
|
|
85
|
-
empty:
|
|
86
|
-
group:
|
|
87
|
-
placeholder:
|
|
88
|
-
filter:
|
|
89
|
-
native:
|
|
90
|
-
option:
|
|
91
|
-
options:
|
|
92
|
-
panel:
|
|
93
|
-
selected:
|
|
94
|
-
text:
|
|
95
|
-
trigger:
|
|
96
|
-
minimal:
|
|
97
|
-
inline:
|
|
98
|
-
label:
|
|
85
|
+
dropdown: st,
|
|
86
|
+
empty: it,
|
|
87
|
+
group: ot,
|
|
88
|
+
placeholder: at,
|
|
89
|
+
filter: ct,
|
|
90
|
+
native: ut,
|
|
91
|
+
option: dt,
|
|
92
|
+
options: pt,
|
|
93
|
+
panel: ft,
|
|
94
|
+
selected: mt,
|
|
95
|
+
text: bt,
|
|
96
|
+
trigger: _t,
|
|
97
|
+
minimal: vt,
|
|
98
|
+
inline: yt,
|
|
99
|
+
label: ht,
|
|
99
100
|
"inline-field": "_inline-field_5r227_255"
|
|
100
101
|
};
|
|
101
|
-
function
|
|
102
|
+
function ve(t, i) {
|
|
102
103
|
return {
|
|
103
|
-
"--icon-svg":
|
|
104
|
+
"--icon-svg": Pe(t, i)
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
|
-
const
|
|
107
|
+
const Vt = ({
|
|
107
108
|
children: t,
|
|
108
|
-
className:
|
|
109
|
-
combobox:
|
|
110
|
-
createOption:
|
|
109
|
+
className: i,
|
|
110
|
+
combobox: l = !1,
|
|
111
|
+
createOption: s,
|
|
111
112
|
emptyLabel: n = "No matches found",
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
errorLabel: a,
|
|
114
|
+
onRetry: x,
|
|
115
|
+
retryLabel: ye = "Retry",
|
|
116
|
+
label: v,
|
|
117
|
+
filterOptions: he = !0,
|
|
118
|
+
hasNextPage: y = !1,
|
|
119
|
+
loading: f = !1,
|
|
120
|
+
loadMoreLabel: ge = "Load more",
|
|
121
|
+
onLoadMore: N,
|
|
122
|
+
onOpenChange: D,
|
|
123
|
+
onSearchChange: j,
|
|
124
|
+
searchValue: G,
|
|
125
|
+
renderOption: M,
|
|
126
|
+
searchPlaceholder: P = "Filter",
|
|
127
|
+
selectedItems: we,
|
|
128
|
+
variant: S = "default",
|
|
129
|
+
...xe
|
|
118
130
|
}) => {
|
|
119
|
-
const
|
|
120
|
-
defaultValue:
|
|
121
|
-
onChange:
|
|
122
|
-
value:
|
|
123
|
-
...
|
|
124
|
-
} =
|
|
125
|
-
className:
|
|
126
|
-
...
|
|
127
|
-
} =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
const q = rt(t), {
|
|
132
|
+
defaultValue: Ne,
|
|
133
|
+
onChange: A,
|
|
134
|
+
value: K,
|
|
135
|
+
...Se
|
|
136
|
+
} = q.props, c = Oe(Se), {
|
|
137
|
+
className: Ie,
|
|
138
|
+
...Ee
|
|
139
|
+
} = c, le = b(null), se = b(null), F = Me(), ie = b(null), h = b(null), oe = b(null), ae = b(null), T = b(!1), H = b(!1), O = b(N), ce = !!N, I = re(q.children), E = K != null, J = nt(I, K, Ne), [U, X] = te(() => J), [u, Re] = te(!1), [Ce, Ve] = te(""), R = G ?? Ce, C = ne((e) => {
|
|
140
|
+
G === void 0 && Ve(e), j == null || j(e);
|
|
141
|
+
}, [j, G]), p = ne((e) => {
|
|
142
|
+
T.current === e || e && c.disabled || (T.current = e, Re(e), D == null || D(e), e || C(""));
|
|
143
|
+
}, [D, c.disabled, C]), L = E ? String(K) : U, ue = {
|
|
144
|
+
default: _e("--colors-semantic-content-secondary"),
|
|
145
|
+
white: _e("--color-white", "white")
|
|
146
|
+
}, de = S === "minimal" ? ue.white : ue.default, Q = tt(I, L), $e = ve("CaretDown", de), ke = ve("MagnifyingGlass", de), Y = et(I, he ? R : ""), g = R.trim(), W = !!(l && s && g && s.isValid(g)), Be = v && S === "inline" ? qe(v) : v, pe = (e) => e ? (M == null ? void 0 : M({
|
|
131
147
|
groupLabel: e.groupLabel,
|
|
132
|
-
isSelected: e.value ===
|
|
148
|
+
isSelected: e.value === L,
|
|
133
149
|
label: e.label,
|
|
134
150
|
text: e.text,
|
|
135
151
|
value: e.value
|
|
136
152
|
})) ?? e.label : "Select an option";
|
|
137
|
-
|
|
138
|
-
!
|
|
139
|
-
}, [
|
|
153
|
+
w(() => {
|
|
154
|
+
!E && !I.some((e) => e.value === U) && X(J);
|
|
155
|
+
}, [J, U, E, I]), w(() => {
|
|
140
156
|
var e;
|
|
141
|
-
|
|
142
|
-
|
|
157
|
+
u && ((e = h.current) == null || e.focus());
|
|
158
|
+
}, [u]), w(() => {
|
|
159
|
+
if (!u)
|
|
143
160
|
return;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!c)
|
|
148
|
-
return;
|
|
149
|
-
const e = (u) => {
|
|
150
|
-
var _;
|
|
151
|
-
(_ = K.current) != null && _.contains(u.target) || d(!1);
|
|
161
|
+
const e = (d) => {
|
|
162
|
+
var m;
|
|
163
|
+
(m = se.current) != null && m.contains(d.target) || p(!1);
|
|
152
164
|
};
|
|
153
165
|
return document.addEventListener("mousedown", e), () => {
|
|
154
166
|
document.removeEventListener("mousedown", e);
|
|
155
167
|
};
|
|
156
|
-
}, [
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
168
|
+
}, [p, u]), w(() => {
|
|
169
|
+
O.current = N;
|
|
170
|
+
}, [N]), w(() => {
|
|
171
|
+
c.disabled && p(!1);
|
|
172
|
+
}, [p, c.disabled]);
|
|
173
|
+
const Z = ne(() => {
|
|
174
|
+
!T.current || c.disabled || f || a || !y || !O.current || H.current || (H.current = !0, O.current());
|
|
175
|
+
}, [a, y, f, c.disabled]);
|
|
176
|
+
w(() => {
|
|
177
|
+
if (H.current = !1, !u || c.disabled || f || a || !y || !ce) return;
|
|
178
|
+
const e = ae.current, d = oe.current;
|
|
179
|
+
if (!e || !d || typeof IntersectionObserver > "u") return;
|
|
180
|
+
let m = !0;
|
|
181
|
+
const V = new IntersectionObserver((Le) => {
|
|
182
|
+
m && Le.some((Qe) => Qe.isIntersecting) && Z();
|
|
183
|
+
}, {
|
|
184
|
+
root: d
|
|
185
|
+
});
|
|
186
|
+
return V.observe(e), () => {
|
|
187
|
+
m = !1, V.disconnect();
|
|
188
|
+
};
|
|
189
|
+
}, [u, f, a, y, ce, Z, Y.length, R, c.disabled]);
|
|
190
|
+
const De = (e) => {
|
|
191
|
+
E || X(e.target.value), A == null || A(e);
|
|
192
|
+
}, ee = () => {
|
|
160
193
|
var e;
|
|
161
|
-
|
|
162
|
-
},
|
|
194
|
+
p(!1), l || (e = le.current) == null || e.focus();
|
|
195
|
+
}, fe = () => {
|
|
163
196
|
var e;
|
|
164
|
-
C(""),
|
|
165
|
-
},
|
|
166
|
-
!
|
|
167
|
-
},
|
|
168
|
-
var
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
if (!
|
|
172
|
-
|
|
197
|
+
C(""), p(!0), (e = h.current) == null || e.focus();
|
|
198
|
+
}, me = () => {
|
|
199
|
+
!s || !W || (s.onCreate(g), fe());
|
|
200
|
+
}, je = (e) => {
|
|
201
|
+
var V;
|
|
202
|
+
E || X(e);
|
|
203
|
+
const d = ie.current;
|
|
204
|
+
if (!d) {
|
|
205
|
+
ee();
|
|
173
206
|
return;
|
|
174
207
|
}
|
|
175
|
-
const
|
|
176
|
-
|
|
208
|
+
const m = (V = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, "value")) == null ? void 0 : V.set;
|
|
209
|
+
m == null || m.call(d, e), d.dispatchEvent(new Event("change", {
|
|
177
210
|
bubbles: !0
|
|
178
|
-
})),
|
|
179
|
-
},
|
|
180
|
-
e.key === "Escape" &&
|
|
181
|
-
},
|
|
182
|
-
/* @__PURE__ */
|
|
183
|
-
|
|
211
|
+
})), l ? fe() : ee();
|
|
212
|
+
}, Fe = (e) => {
|
|
213
|
+
e.key === "Escape" && ee(), e.key === "Enter" && e.target === h.current && W && (e.preventDefault(), me());
|
|
214
|
+
}, be = /* @__PURE__ */ _("div", { className: $(r.dropdown, S === "inline" && r.inline, S === "minimal" && r.minimal, i), onKeyDown: Fe, ref: se, ...xe, "data-component": "dropdown", children: [
|
|
215
|
+
/* @__PURE__ */ o("select", { ...Ee, "aria-hidden": "true", className: $(r.native, Ie), onChange: De, ref: ie, tabIndex: -1, value: L, children: q.children }),
|
|
216
|
+
l ? /* @__PURE__ */ _("div", { className: r.combobox, onClick: () => {
|
|
184
217
|
var e;
|
|
185
|
-
return (e =
|
|
218
|
+
return (e = h.current) == null ? void 0 : e.focus();
|
|
186
219
|
}, children: [
|
|
187
|
-
|
|
188
|
-
/* @__PURE__ */
|
|
189
|
-
C(e.target.value),
|
|
190
|
-
}, onClick: () =>
|
|
191
|
-
] }) : /* @__PURE__ */
|
|
192
|
-
|
|
193
|
-
!
|
|
194
|
-
/* @__PURE__ */
|
|
195
|
-
|
|
196
|
-
const
|
|
197
|
-
return /* @__PURE__ */
|
|
198
|
-
/* @__PURE__ */
|
|
199
|
-
e.groupLabel && /* @__PURE__ */
|
|
220
|
+
we,
|
|
221
|
+
/* @__PURE__ */ o("input", { "aria-autocomplete": "list", "aria-expanded": u, "aria-label": c["aria-label"] ?? v ?? P, className: r["combobox-input"], disabled: c.disabled, onChange: (e) => {
|
|
222
|
+
C(e.target.value), p(!0);
|
|
223
|
+
}, onClick: () => p(!0), onFocus: () => p(!0), placeholder: P || void 0, ref: h, role: "combobox", type: "text", value: R })
|
|
224
|
+
] }) : /* @__PURE__ */ o(k, { "aria-expanded": u, "aria-haspopup": "dialog", "aria-labelledby": v ? `${F} ${F}-value` : void 0, className: $(r.trigger, (Q == null ? void 0 : Q.isPlaceholder) && r.placeholder), "data-open": u ? "true" : void 0, disabled: c.disabled, onClick: () => p(!u), ref: le, style: $e, variant: "simple", children: /* @__PURE__ */ o("span", { className: r.text, id: `${F}-value`, children: pe(Q) }) }),
|
|
225
|
+
u && /* @__PURE__ */ _("div", { className: r.panel, children: [
|
|
226
|
+
!l && /* @__PURE__ */ o(Ae, { "aria-label": "Filter", className: r.filter, icon: "MagnifyingGlass", onChange: (e) => C(e.target.value), placeholder: P, ref: h, style: ke, type: "search", value: R }),
|
|
227
|
+
/* @__PURE__ */ _(Ke, { "aria-label": "Dropdown", "aria-busy": f || void 0, className: r.options, ref: oe, children: [
|
|
228
|
+
Y.map((e) => {
|
|
229
|
+
const d = e.value === L;
|
|
230
|
+
return /* @__PURE__ */ o("li", { "data-component": "dropdown", children: /* @__PURE__ */ _(k, { "aria-label": d ? `${e.text}, selected` : e.text, className: $(r.option, d && r.selected), disabled: e.disabled, onClick: () => je(e.value), variant: "tertiary", children: [
|
|
231
|
+
/* @__PURE__ */ o("span", { className: r.text, children: pe(e) }),
|
|
232
|
+
e.groupLabel && /* @__PURE__ */ o("small", { className: r.group, children: e.groupLabel })
|
|
200
233
|
] }) }, `${e.groupLabel ?? "root"}-${e.value}`);
|
|
201
234
|
}),
|
|
202
|
-
|
|
203
|
-
|
|
235
|
+
W && s && /* @__PURE__ */ o("li", { children: /* @__PURE__ */ o(k, { "aria-label": z(s.render(g)) || g, className: r.option, onClick: me, variant: "tertiary", children: /* @__PURE__ */ o("span", { className: r.text, children: s.render(g) }) }) }),
|
|
236
|
+
Y.length === 0 && !W && !f && !a && !y && /* @__PURE__ */ o("li", { className: r.empty, children: n }),
|
|
237
|
+
a && /* @__PURE__ */ _("li", { className: r.empty, children: [
|
|
238
|
+
/* @__PURE__ */ o("span", { role: "alert", children: a }),
|
|
239
|
+
x && /* @__PURE__ */ o(k, { disabled: f, onClick: x, variant: "tertiary", children: ye })
|
|
240
|
+
] }),
|
|
241
|
+
f && /* @__PURE__ */ o("li", { "aria-label": "Loading", className: r.empty, role: "status", children: /* @__PURE__ */ o(Te, { size: "small" }) }),
|
|
242
|
+
y && N && !a && /* @__PURE__ */ o("li", { ref: ae, children: /* @__PURE__ */ o(k, { className: r.option, disabled: f, onClick: Z, variant: "tertiary", children: ge }) })
|
|
204
243
|
] })
|
|
205
244
|
] })
|
|
206
245
|
] });
|
|
207
|
-
return
|
|
208
|
-
/* @__PURE__ */
|
|
209
|
-
|
|
210
|
-
] }) :
|
|
246
|
+
return v ? /* @__PURE__ */ _("div", { className: $(r.label, S === "inline" && r["inline-field"]), "data-component": "dropdown", children: [
|
|
247
|
+
/* @__PURE__ */ o("span", { id: F, children: Be }),
|
|
248
|
+
be
|
|
249
|
+
] }) : be;
|
|
211
250
|
};
|
|
212
251
|
export {
|
|
213
|
-
|
|
252
|
+
Vt as Dropdown
|
|
214
253
|
};
|
|
215
254
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -243,7 +243,7 @@ export declare const Divider: ({ className, ...props }: DividerProps) => JSX.Ele
|
|
|
243
243
|
|
|
244
244
|
export declare type DividerProps = React.ComponentPropsWithoutRef<'hr'>;
|
|
245
245
|
|
|
246
|
-
export declare const Dropdown: ({ children: selectElement, className, combobox, createOption, emptyLabel, label, renderOption, searchPlaceholder, selectedItems, variant, ...props }: DropdownProps) => JSX.Element;
|
|
246
|
+
export declare const Dropdown: ({ children: selectElement, className, combobox, createOption, emptyLabel, errorLabel, onRetry, retryLabel, label, filterOptions, hasNextPage, loading, loadMoreLabel, onLoadMore, onOpenChange, onSearchChange, searchValue, renderOption, searchPlaceholder, selectedItems, variant, ...props }: DropdownProps) => JSX.Element;
|
|
247
247
|
|
|
248
248
|
export declare type DropdownCreateOption = {
|
|
249
249
|
isValid: (value: string) => boolean;
|
|
@@ -267,7 +267,19 @@ declare type DropdownProps = Omit<default_2.ComponentPropsWithoutRef<'div'>, 'ch
|
|
|
267
267
|
combobox?: boolean;
|
|
268
268
|
createOption?: DropdownCreateOption;
|
|
269
269
|
emptyLabel?: string;
|
|
270
|
+
errorLabel?: string;
|
|
271
|
+
onRetry?: () => void;
|
|
272
|
+
retryLabel?: string;
|
|
270
273
|
label?: string;
|
|
274
|
+
/** Disable local matching when the supplied options are already server-filtered. */
|
|
275
|
+
filterOptions?: boolean;
|
|
276
|
+
hasNextPage?: boolean;
|
|
277
|
+
loading?: boolean;
|
|
278
|
+
loadMoreLabel?: string;
|
|
279
|
+
onLoadMore?: () => void;
|
|
280
|
+
onOpenChange?: (open: boolean) => void;
|
|
281
|
+
onSearchChange?: (value: string) => void;
|
|
282
|
+
searchValue?: string;
|
|
271
283
|
renderOption?: (option: DropdownRenderOption) => default_2.ReactNode;
|
|
272
284
|
searchPlaceholder?: string;
|
|
273
285
|
selectedItems?: default_2.ReactNode;
|
package/dist/tokens.json
CHANGED