@kakadu/components 4.3.1 → 4.3.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),K=require("@kuma-ui/core"),se=require("../hooks/use-synchronized-value.js"),ne=require("../icons/icon.js"),oe=require("../icons/chevron-up.js"),ae=require("../utilities/search.js"),re=require("./input.js"),B=require("./text.js"),X=require("./flex.js"),ue=require("./skeleton.js");function Y(){const{value:n,setValue:p}=se.default("isKeyboardNavigating");return e.useMemo(()=>({isKeyboardNavigating:n,setIsKeyboardNavigating:p}),[n,p])}function O(n){return"text"in n?n.text:n.label}const D="kakadu-components-1144794361",T="kakadu-components-2911184744";function ce({isSelected:n,id:p,value:v,label:a,onSelect:h,onHover:j}){const{isKeyboardNavigating:b}=Y(),g=e.useCallback(()=>{h(v)},[h,v]),l=e.useCallback(f=>{b||f.movementX===0&&f.movementY===0||j(v)},[b,j,v]),r=e.useRef(null);return e.useEffect(()=>{const f=r.current;n&&f&&b&&setTimeout(()=>{f.scrollIntoView({behavior:"smooth",block:"nearest"})},0)},[n,b]),i.jsxRuntimeExports.jsx("li",{ref:r,id:p,role:"option","aria-selected":n,tabIndex:-1,className:K.cx(D,"kakadu-components-4130497639",b?"kakadu-components-962373561":"kakadu-components-1109598791"),onClick:g,onMouseMove:l,children:i.jsxRuntimeExports.jsx(B.Span,{className:K.cx(T,typeof a=="string"&&"kakadu-components-154286052"),children:a})})}function ie({isLoading:n,id:p,activeOptionId:v,selectedValue:a,options:h,onSelect:j,onHover:b}){const g=e.useRef(null);return e.useEffect(()=>{const l=g.current;l&&l.scrollIntoView({behavior:"smooth",block:"nearest"})},[]),i.jsxRuntimeExports.jsxs("ul",{ref:g,id:p,role:"listbox","aria-label":"Options",tabIndex:-1,className:"kakadu-components-1951042708",children:[h.length===0?n?null:i.jsxRuntimeExports.jsxs(X.default,{"aria-atomic":!0,as:"li",role:"status","aria-live":"polite",direction:"row",preset:"start",gap:.5,className:D,children:[i.jsxRuntimeExports.jsx(ne.default,{size:15,type:"exclamationTriangle"}),i.jsxRuntimeExports.jsx(B.Span,{className:T,children:"No results."})]}):h.map((l,r)=>i.jsxRuntimeExports.jsx(ce,{...l,id:l.value===a?v:void 0,isSelected:l.value===a,onSelect:j,onHover:b},O(l)+r)),n?i.jsxRuntimeExports.jsx(X.default,{as:"li",alignment:"center",className:D,children:i.jsxRuntimeExports.jsx(B.Span,{className:T,children:i.jsxRuntimeExports.jsx(ue.SkeletonInstance,{width:"100%",height:"1.3em"})})}):null]})}function le({isLoading:n,shouldFilterOptions:p=!0,label:v,options:a,error:h,warning:j,information:b,footnote:g,className:l,onChange:r,onSelect:f,...F}){const S=e.useRef(null),H=e.useId(),P=e.useId(),[w,M]=e.useState(!1),$=e.useCallback(()=>{M(!0)},[]),G=e.useCallback(t=>{var s;(s=S.current)!=null&&s.contains(t.relatedTarget)||M(!1)},[]),[y,u]=e.useState(!1);e.useEffect(()=>{u(w)},[w]);const[A,I]=e.useState(""),{value:k}=F,[m,N]=e.useState(k),[q,J]=e.useState(k),z=e.useRef(q),c=e.useCallback(t=>{J(t),z.current=t},[]);e.useEffect(()=>{N(k),c(k)},[k,c]),e.useEffect(()=>{const t=a.find(s=>s.value===k);t?I(O(t)):k===void 0&&I("")},[k,a]);const Q=e.useCallback(()=>{m&&(I(""),c(void 0))},[m,c]),W=e.useCallback((t,s)=>{I(t),r==null||r(t,s),u(!0),N(void 0)},[r]),Z=e.useCallback(t=>{var s;(s=S.current)!=null&&s.contains(t.target)&&u(!0)},[]),E=e.useCallback(t=>{const s=t==null?void 0:t.value;c(s),t?I(O(t)):(I(""),r==null||r("")),f==null||f(s)},[c,r,f]),ee=e.useCallback(t=>{const s=a.find(x=>x.value===t);E(s),N(t),u(!1)},[a,E]),te=e.useCallback(t=>{c(t)},[c]),C=e.useDeferredValue(A),d=e.useMemo(()=>!p||m?a:ae.default(C,a,O),[p,m,a,C]);e.useEffect(()=>{!m&&C.length>0&&d.length>0&&!d.some(t=>q===t.value)&&c(d[0].value)},[m,C,d,q,c]);const{setIsKeyboardNavigating:V}=Y();return e.useEffect(()=>{if(!w)return;const t=s=>{s.movementX===0&&s.movementY===0||V(!1)};return window.addEventListener("mousemove",t,{capture:!0}),()=>{window.removeEventListener("mousemove",t,{capture:!0})}},[w,V]),e.useEffect(()=>{if(!w)return;const t=s=>{var U;let x;const _=d.length,L=d.findIndex(o=>o.value===z.current),R=()=>{s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation()};switch(s.key){case"Enter":{const o=d[L];o&&(R(),V(!0),u(!1),E(o),N(o.value));break}case"Escape":{if(y)R(),m?c(void 0):E(void 0),u(!1);else if(m)R(),u(!0),E(void 0);else{R(),M(!1);const o=document.activeElement;o instanceof HTMLElement&&((U=S.current)!=null&&U.contains(o))&&o.blur()}return}case"ArrowDown":{x=L+1,u(!0);break}case"ArrowUp":{x=L-1,u(!0),x<0&&(x=_-1);break}case"Home":{u(!0),x=0;break}case"End":{u(!0),x=_-1;break}case"Backspace":{d.some(o=>o.value===m)&&(R(),E(void 0),u(!0));break}}if(x!==void 0&&(R(),V(!0),_>0)){const o=d[x%_];o&&c(o.value)}};return window.addEventListener("keydown",t,{capture:!0}),()=>{window.removeEventListener("keydown",t,{capture:!0})}},[w,d,V,u,E,N,y,m,c]),i.jsxRuntimeExports.jsx(re.default,{...F,ref:S,role:"combobox",autoComplete:"off","aria-controls":H,"aria-expanded":y,"aria-activedescendant":y?P:void 0,label:v,value:A,error:h,warning:j,information:b,footnote:g,attachments:y?i.jsxRuntimeExports.jsx(ie,{isLoading:n,id:H,activeOptionId:P,selectedValue:q,options:d,onSelect:ee,onHover:te}):null,className:K.cx(l,"kakadu-components-879486679"),onMouseDown:Z,onChange:W,onBeforeInput:Q,onFocus:$,onBlur:G,children:i.jsxRuntimeExports.jsx(oe.default,{width:14,height:14,className:"kakadu-components-158931186"})})}exports.default=le;exports.getComboboxOptionString=O;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { j as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { cx as
|
|
1
|
+
import { j as i } from "../jsx-runtime-B4hRZ52C.mjs";
|
|
2
|
+
import { useRef as H, useId as Q, useState as K, useCallback as m, useEffect as h, useDeferredValue as ce, useMemo as Z } from "react";
|
|
3
|
+
import { cx as P } from "@kuma-ui/core";
|
|
4
4
|
import ie from "../hooks/use-synchronized-value.mjs";
|
|
5
5
|
import le from "../icons/icon.mjs";
|
|
6
6
|
import ue from "../icons/chevron-up.mjs";
|
|
7
7
|
import me from "../utilities/search.mjs";
|
|
8
8
|
import de from "./input.mjs";
|
|
9
|
-
import { Span as
|
|
9
|
+
import { Span as R } from "./text.mjs";
|
|
10
10
|
import W from "./flex.mjs";
|
|
11
11
|
import { SkeletonInstance as fe } from "./skeleton.mjs";
|
|
12
12
|
function _() {
|
|
@@ -19,7 +19,7 @@ function _() {
|
|
|
19
19
|
setIsKeyboardNavigating: v
|
|
20
20
|
}), [n, v]);
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function F(n) {
|
|
23
23
|
return "text" in n ? n.text : n.label;
|
|
24
24
|
}
|
|
25
25
|
const z = "kakadu-components-1144794361", U = "kakadu-components-2911184744";
|
|
@@ -27,119 +27,122 @@ function pe({
|
|
|
27
27
|
isSelected: n,
|
|
28
28
|
id: v,
|
|
29
29
|
value: x,
|
|
30
|
-
label:
|
|
31
|
-
onSelect:
|
|
32
|
-
onHover:
|
|
30
|
+
label: o,
|
|
31
|
+
onSelect: w,
|
|
32
|
+
onHover: g
|
|
33
33
|
}) {
|
|
34
34
|
const {
|
|
35
35
|
isKeyboardNavigating: b
|
|
36
|
-
} = _(),
|
|
37
|
-
|
|
38
|
-
}, [
|
|
39
|
-
b || d.movementX === 0 && d.movementY === 0 ||
|
|
40
|
-
}, [b,
|
|
41
|
-
return
|
|
42
|
-
const d =
|
|
36
|
+
} = _(), N = m(() => {
|
|
37
|
+
w(x);
|
|
38
|
+
}, [w, x]), l = m((d) => {
|
|
39
|
+
b || d.movementX === 0 && d.movementY === 0 || g(x);
|
|
40
|
+
}, [b, g, x]), r = H(null);
|
|
41
|
+
return h(() => {
|
|
42
|
+
const d = r.current;
|
|
43
43
|
n && d && b && setTimeout(() => {
|
|
44
44
|
d.scrollIntoView({
|
|
45
45
|
behavior: "smooth",
|
|
46
46
|
block: "nearest"
|
|
47
47
|
});
|
|
48
48
|
}, 0);
|
|
49
|
-
}, [n, b]), /* @__PURE__ */
|
|
49
|
+
}, [n, b]), /* @__PURE__ */ i.jsx("li", { ref: r, id: v, role: "option", "aria-selected": n, tabIndex: -1, className: P(z, "kakadu-components-4130497639", b ? "kakadu-components-962373561" : "kakadu-components-1109598791"), onClick: N, onMouseMove: l, children: /* @__PURE__ */ i.jsx(R, { className: P(U, typeof o == "string" && "kakadu-components-154286052"), children: o }) });
|
|
50
50
|
}
|
|
51
51
|
function ve({
|
|
52
52
|
isLoading: n,
|
|
53
53
|
id: v,
|
|
54
54
|
activeOptionId: x,
|
|
55
|
-
selectedValue:
|
|
56
|
-
options:
|
|
57
|
-
onSelect:
|
|
55
|
+
selectedValue: o,
|
|
56
|
+
options: w,
|
|
57
|
+
onSelect: g,
|
|
58
58
|
onHover: b
|
|
59
59
|
}) {
|
|
60
|
-
const
|
|
61
|
-
return
|
|
62
|
-
const l =
|
|
60
|
+
const N = H(null);
|
|
61
|
+
return h(() => {
|
|
62
|
+
const l = N.current;
|
|
63
63
|
l && l.scrollIntoView({
|
|
64
64
|
behavior: "smooth",
|
|
65
65
|
block: "nearest"
|
|
66
66
|
});
|
|
67
|
-
}, []), /* @__PURE__ */
|
|
68
|
-
|
|
69
|
-
/* @__PURE__ */
|
|
70
|
-
/* @__PURE__ */
|
|
71
|
-
] }) :
|
|
67
|
+
}, []), /* @__PURE__ */ i.jsxs("ul", { ref: N, id: v, role: "listbox", "aria-label": "Options", tabIndex: -1, className: "kakadu-components-1951042708", children: [
|
|
68
|
+
w.length === 0 ? n ? null : /* @__PURE__ */ i.jsxs(W, { "aria-atomic": !0, as: "li", role: "status", "aria-live": "polite", direction: "row", preset: "start", gap: 0.5, className: z, children: [
|
|
69
|
+
/* @__PURE__ */ i.jsx(le, { size: 15, type: "exclamationTriangle" }),
|
|
70
|
+
/* @__PURE__ */ i.jsx(R, { className: U, children: "No results." })
|
|
71
|
+
] }) : w.map((l, r) => /* @__PURE__ */ i.jsx(
|
|
72
72
|
pe,
|
|
73
73
|
{
|
|
74
74
|
...l,
|
|
75
|
-
id: l.value ===
|
|
76
|
-
isSelected: l.value ===
|
|
77
|
-
onSelect:
|
|
75
|
+
id: l.value === o ? x : void 0,
|
|
76
|
+
isSelected: l.value === o,
|
|
77
|
+
onSelect: g,
|
|
78
78
|
onHover: b
|
|
79
79
|
},
|
|
80
|
-
|
|
80
|
+
F(l) + r
|
|
81
81
|
)),
|
|
82
|
-
n ? /* @__PURE__ */
|
|
82
|
+
n ? /* @__PURE__ */ i.jsx(W, { as: "li", alignment: "center", className: z, children: /* @__PURE__ */ i.jsx(R, { className: U, children: /* @__PURE__ */ i.jsx(fe, { width: "100%", height: "1.3em" }) }) }) : null
|
|
83
83
|
] });
|
|
84
84
|
}
|
|
85
85
|
function Oe({
|
|
86
86
|
isLoading: n,
|
|
87
87
|
shouldFilterOptions: v = !0,
|
|
88
88
|
label: x,
|
|
89
|
-
options:
|
|
90
|
-
error:
|
|
91
|
-
warning:
|
|
89
|
+
options: o,
|
|
90
|
+
error: w,
|
|
91
|
+
warning: g,
|
|
92
92
|
information: b,
|
|
93
|
-
footnote:
|
|
93
|
+
footnote: N,
|
|
94
94
|
className: l,
|
|
95
|
-
onChange:
|
|
95
|
+
onChange: r,
|
|
96
96
|
onSelect: d,
|
|
97
97
|
...X
|
|
98
98
|
}) {
|
|
99
|
-
const
|
|
100
|
-
|
|
99
|
+
const M = H(null), Y = Q(), q = Q(), [V, T] = K(!1), $ = m(() => {
|
|
100
|
+
T(!0);
|
|
101
101
|
}, []), ee = m((e) => {
|
|
102
102
|
var t;
|
|
103
|
-
(t =
|
|
104
|
-
}, []), [
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}, [
|
|
108
|
-
const [C,
|
|
109
|
-
value:
|
|
110
|
-
} = X, [f,
|
|
103
|
+
(t = M.current) != null && t.contains(e.relatedTarget) || T(!1);
|
|
104
|
+
}, []), [O, a] = K(!1);
|
|
105
|
+
h(() => {
|
|
106
|
+
a(V);
|
|
107
|
+
}, [V]);
|
|
108
|
+
const [C, j] = K(""), {
|
|
109
|
+
value: k
|
|
110
|
+
} = X, [f, E] = K(k), [S, te] = K(k), G = H(S), c = m((e) => {
|
|
111
111
|
te(e), G.current = e;
|
|
112
112
|
}, []);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}, [
|
|
113
|
+
h(() => {
|
|
114
|
+
E(k), c(k);
|
|
115
|
+
}, [k, c]), h(() => {
|
|
116
|
+
const e = o.find((t) => t.value === k);
|
|
117
|
+
e ? j(F(e)) : k === void 0 && j("");
|
|
118
|
+
}, [k, o]);
|
|
116
119
|
const ne = m(() => {
|
|
117
|
-
f && (
|
|
118
|
-
}, [f,
|
|
119
|
-
|
|
120
|
-
}, [
|
|
120
|
+
f && (j(""), c(void 0));
|
|
121
|
+
}, [f, c]), se = m((e, t) => {
|
|
122
|
+
j(e), r == null || r(e, t), a(!0), E(void 0);
|
|
123
|
+
}, [r]), oe = m((e) => {
|
|
121
124
|
var t;
|
|
122
|
-
(t =
|
|
123
|
-
}, []),
|
|
125
|
+
(t = M.current) != null && t.contains(e.target) && a(!0);
|
|
126
|
+
}, []), I = m((e) => {
|
|
124
127
|
const t = e == null ? void 0 : e.value;
|
|
125
|
-
|
|
126
|
-
}, [
|
|
127
|
-
const t =
|
|
128
|
-
|
|
129
|
-
}, [
|
|
130
|
-
|
|
131
|
-
}, [
|
|
132
|
-
|
|
133
|
-
!f && B.length > 0 && u.length > 0 && !u.some((e) => S === e.value) &&
|
|
134
|
-
}, [f, B, u, S,
|
|
128
|
+
c(t), e ? j(F(e)) : (j(""), r == null || r("")), d == null || d(t);
|
|
129
|
+
}, [c, r, d]), re = m((e) => {
|
|
130
|
+
const t = o.find((p) => p.value === e);
|
|
131
|
+
I(t), E(e), a(!1);
|
|
132
|
+
}, [o, I]), ae = m((e) => {
|
|
133
|
+
c(e);
|
|
134
|
+
}, [c]), B = ce(C), u = Z(() => !v || f ? o : me(B, o, F), [v, f, o, B]);
|
|
135
|
+
h(() => {
|
|
136
|
+
!f && B.length > 0 && u.length > 0 && !u.some((e) => S === e.value) && c(u[0].value);
|
|
137
|
+
}, [f, B, u, S, c]);
|
|
135
138
|
const {
|
|
136
|
-
setIsKeyboardNavigating:
|
|
139
|
+
setIsKeyboardNavigating: L
|
|
137
140
|
} = _();
|
|
138
|
-
return
|
|
139
|
-
if (!
|
|
141
|
+
return h(() => {
|
|
142
|
+
if (!V)
|
|
140
143
|
return;
|
|
141
144
|
const e = (t) => {
|
|
142
|
-
t.movementX === 0 && t.movementY === 0 ||
|
|
145
|
+
t.movementX === 0 && t.movementY === 0 || L(!1);
|
|
143
146
|
};
|
|
144
147
|
return window.addEventListener("mousemove", e, {
|
|
145
148
|
capture: !0
|
|
@@ -148,57 +151,57 @@ function Oe({
|
|
|
148
151
|
capture: !0
|
|
149
152
|
});
|
|
150
153
|
};
|
|
151
|
-
}, [
|
|
152
|
-
if (!
|
|
154
|
+
}, [V, L]), h(() => {
|
|
155
|
+
if (!V)
|
|
153
156
|
return;
|
|
154
157
|
const e = (t) => {
|
|
155
158
|
var J;
|
|
156
159
|
let p;
|
|
157
|
-
const D = u.length,
|
|
160
|
+
const D = u.length, A = u.findIndex((s) => s.value === G.current), y = () => {
|
|
158
161
|
t.preventDefault(), t.stopPropagation(), t.stopImmediatePropagation();
|
|
159
162
|
};
|
|
160
163
|
switch (t.key) {
|
|
161
164
|
case "Enter": {
|
|
162
|
-
const s = u[
|
|
163
|
-
s && (
|
|
165
|
+
const s = u[A];
|
|
166
|
+
s && (y(), L(!0), a(!1), I(s), E(s.value));
|
|
164
167
|
break;
|
|
165
168
|
}
|
|
166
169
|
case "Escape": {
|
|
167
|
-
if (
|
|
168
|
-
|
|
170
|
+
if (O)
|
|
171
|
+
y(), f ? c(void 0) : I(void 0), a(!1);
|
|
169
172
|
else if (f)
|
|
170
|
-
|
|
173
|
+
y(), a(!0), I(void 0);
|
|
171
174
|
else {
|
|
172
|
-
|
|
175
|
+
y(), T(!1);
|
|
173
176
|
const s = document.activeElement;
|
|
174
|
-
s instanceof HTMLElement && ((J =
|
|
177
|
+
s instanceof HTMLElement && ((J = M.current) != null && J.contains(s)) && s.blur();
|
|
175
178
|
}
|
|
176
179
|
return;
|
|
177
180
|
}
|
|
178
181
|
case "ArrowDown": {
|
|
179
|
-
p =
|
|
182
|
+
p = A + 1, a(!0);
|
|
180
183
|
break;
|
|
181
184
|
}
|
|
182
185
|
case "ArrowUp": {
|
|
183
|
-
p =
|
|
186
|
+
p = A - 1, a(!0), p < 0 && (p = D - 1);
|
|
184
187
|
break;
|
|
185
188
|
}
|
|
186
189
|
case "Home": {
|
|
187
|
-
|
|
190
|
+
a(!0), p = 0;
|
|
188
191
|
break;
|
|
189
192
|
}
|
|
190
193
|
case "End": {
|
|
191
|
-
|
|
194
|
+
a(!0), p = D - 1;
|
|
192
195
|
break;
|
|
193
196
|
}
|
|
194
197
|
case "Backspace": {
|
|
195
|
-
u.some((s) => s.value === f) && (
|
|
198
|
+
u.some((s) => s.value === f) && (y(), I(void 0), a(!0));
|
|
196
199
|
break;
|
|
197
200
|
}
|
|
198
201
|
}
|
|
199
|
-
if (p !== void 0 && (
|
|
202
|
+
if (p !== void 0 && (y(), L(!0), D > 0)) {
|
|
200
203
|
const s = u[p % D];
|
|
201
|
-
s &&
|
|
204
|
+
s && c(s.value);
|
|
202
205
|
}
|
|
203
206
|
};
|
|
204
207
|
return window.addEventListener("keydown", e, {
|
|
@@ -208,9 +211,9 @@ function Oe({
|
|
|
208
211
|
capture: !0
|
|
209
212
|
});
|
|
210
213
|
};
|
|
211
|
-
}, [
|
|
214
|
+
}, [V, u, L, a, I, E, O, f, c]), /* @__PURE__ */ i.jsx(de, { ...X, ref: M, role: "combobox", autoComplete: "off", "aria-controls": Y, "aria-expanded": O, "aria-activedescendant": O ? q : void 0, label: x, value: C, error: w, warning: g, information: b, footnote: N, attachments: O ? /* @__PURE__ */ i.jsx(ve, { isLoading: n, id: Y, activeOptionId: q, selectedValue: S, options: u, onSelect: re, onHover: ae }) : null, className: P(l, "kakadu-components-879486679"), onMouseDown: oe, onChange: se, onBeforeInput: ne, onFocus: $, onBlur: ee, children: /* @__PURE__ */ i.jsx(ue, { width: 14, height: 14, className: "kakadu-components-158931186" }) });
|
|
212
215
|
}
|
|
213
216
|
export {
|
|
214
217
|
Oe as default,
|
|
215
|
-
|
|
218
|
+
F as getComboboxOptionString
|
|
216
219
|
};
|