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