@kakadu/components 4.0.0 → 4.0.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.
- package/build/components/combobox.d.ts +25 -0
- package/build/components/combobox.js +1 -0
- package/build/components/combobox.mjs +324 -0
- package/build/components/input.d.ts +11 -18
- package/build/components/input.js +2 -2
- package/build/components/input.mjs +124 -147
- package/build/components/modal.js +1 -1
- package/build/components/modal.mjs +1 -1
- package/build/components/popover-menu.js +1 -1
- package/build/components/popover-menu.mjs +98 -106
- package/build/components/popover.js +1 -1
- package/build/components/popover.mjs +1 -1
- package/build/components/select.d.ts +12 -0
- package/build/components/select.js +1 -0
- package/build/components/select.mjs +36 -0
- package/build/components/theme-setter.d.ts +1 -1
- package/build/components.css +1 -1
- package/build/{focus-trap-react-CcpTuiJi.js → focus-trap-react-CkKg4ubd.js} +5 -5
- package/build/{focus-trap-react-DYXrtbDH.mjs → focus-trap-react-DATIi_Ob.mjs} +34 -29
- package/build/hooks/use-synchronized-value.d.ts +4 -0
- package/build/icons/icon.d.ts +2 -1
- package/build/icons/icon.js +1 -1
- package/build/icons/icon.mjs +90 -89
- package/build/index.d.ts +4 -0
- package/build/index.js +1 -1
- package/build/index.mjs +233 -227
- package/build/use-synchronized-value-D0_rS5Wp.js +1 -0
- package/build/use-synchronized-value-XnIpeq1s.mjs +28 -0
- package/package.json +3 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ChangeEvent, type HTMLProps, type ReactNode } from 'react';
|
|
2
|
+
import { type InputType, type InputLabelControllerProperties } from './input';
|
|
3
|
+
export type ComboboxOption<Type = string> = {
|
|
4
|
+
readonly value: Type;
|
|
5
|
+
} & ({
|
|
6
|
+
readonly label: string;
|
|
7
|
+
} | {
|
|
8
|
+
readonly text: string;
|
|
9
|
+
readonly label: ReactNode;
|
|
10
|
+
});
|
|
11
|
+
export declare function getComboboxOptionString<Type = string>(option: ComboboxOption<Type>): string;
|
|
12
|
+
export type ComboboxOptionsItemProperties<Type = string> = ComboboxOption<Type> & {
|
|
13
|
+
readonly id?: string;
|
|
14
|
+
readonly isSelected?: boolean;
|
|
15
|
+
readonly onSelect: (value: Type) => void;
|
|
16
|
+
readonly onHover: (value: Type) => void;
|
|
17
|
+
};
|
|
18
|
+
export type ComboboxProperties<Type = string> = Omit<InputLabelControllerProperties & HTMLProps<HTMLInputElement>, 'onChange' | 'onSelect' | 'value'> & {
|
|
19
|
+
readonly isLoading?: boolean;
|
|
20
|
+
readonly value?: Type;
|
|
21
|
+
readonly options: Array<ComboboxOption<Type>>;
|
|
22
|
+
readonly onChange?: (value: string, event?: ChangeEvent<InputType>) => void;
|
|
23
|
+
readonly onSelect?: (value?: Type) => void;
|
|
24
|
+
};
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const j=require("../jsx-runtime-BB_1_6y_.js"),o=require("react"),B=require("../focus-trap-react-CkKg4ubd.js"),U=require("@kuma-ui/core"),oe=require("../use-synchronized-value-D0_rS5Wp.js"),re=require("../icons/icon.js"),ae=require("./input.js"),L=require("./text.js"),X=require("./flex.js"),ce=require("./skeleton.js");var F={exports:{}};const M=new Uint32Array(65536),ie=(t,i)=>{const r=t.length,p=i.length,l=1<<r-1;let u=-1,d=0,x=r,n=r;for(;n--;)M[t.charCodeAt(n)]|=1<<n;for(n=0;n<p;n++){let m=M[i.charCodeAt(n)];const h=m|d;m|=(m&u)+u^u,d|=~(m|u),u&=m,d&l&&x++,u&l&&x--,d=d<<1|1,u=u<<1|~(h|d),d&=h}for(n=r;n--;)M[t.charCodeAt(n)]=0;return x},le=(t,i)=>{const r=i.length,p=t.length,l=[],u=[],d=Math.ceil(r/32),x=Math.ceil(p/32);for(let e=0;e<d;e++)u[e]=-1,l[e]=0;let n=0;for(;n<x-1;n++){let e=0,f=-1;const b=n*32,g=Math.min(32,p)+b;for(let s=b;s<g;s++)M[t.charCodeAt(s)]|=1<<s;for(let s=0;s<r;s++){const v=M[i.charCodeAt(s)],k=u[s/32|0]>>>s&1,w=l[s/32|0]>>>s&1,N=v|e,E=((v|w)&f)+f^f|v|w;let O=e|~(E|f),A=f&E;O>>>31^k&&(u[s/32|0]^=1<<s),A>>>31^w&&(l[s/32|0]^=1<<s),O=O<<1|k,A=A<<1|w,f=A|~(N|O),e=O&N}for(let s=b;s<g;s++)M[t.charCodeAt(s)]=0}let m=0,h=-1;const R=n*32,C=Math.min(32,p-R)+R;for(let e=R;e<C;e++)M[t.charCodeAt(e)]|=1<<e;let q=p;for(let e=0;e<r;e++){const f=M[i.charCodeAt(e)],b=u[e/32|0]>>>e&1,g=l[e/32|0]>>>e&1,s=f|m,v=((f|g)&h)+h^h|f|g;let k=m|~(v|h),w=h&v;q+=k>>>p-1&1,q-=w>>>p-1&1,k>>>31^b&&(u[e/32|0]^=1<<e),w>>>31^g&&(l[e/32|0]^=1<<e),k=k<<1|b,w=w<<1|g,h=w|~(s|k),m=k&s}for(let e=R;e<C;e++)M[t.charCodeAt(e)]=0;return q},G=(t,i)=>{if(t.length<i.length){const r=i;i=t,t=r}return i.length===0?t.length:t.length<=32?ie(t,i):le(t,i)},ue=(t,i)=>{let r=1/0,p=0;for(let l=0;l<i.length;l++){const u=G(t,i[l]);u<r&&(r=u,p=l)}return i[p]},fe=Object.freeze(Object.defineProperty({__proto__:null,closest:ue,distance:G},Symbol.toStringTag,{value:"Module"})),de=B.getAugmentedNamespace(fe);var Y;function me(){return Y||(Y=1,(function(t,i){(function(){var r;try{r=typeof Intl<"u"&&typeof Intl.Collator<"u"?Intl.Collator("generic",{sensitivity:"base"}):null}catch{console.log("Collator could not be initialized and wouldn't be used")}var p=de,l=[],u=[],d={get:function(x,n,m){var h=m&&r&&m.useCollator;if(h){var R=x.length,C=n.length;if(R===0)return C;if(C===0)return R;var q,e,f,b,g;for(f=0;f<C;++f)l[f]=f,u[f]=n.charCodeAt(f);l[C]=C;var s;for(f=0;f<R;++f){for(e=f+1,b=0;b<C;++b)q=e,s=r.compare(x.charAt(f),String.fromCharCode(u[b]))===0,e=l[b]+(s?0:1),g=q+1,e>g&&(e=g),g=l[b+1]+1,e>g&&(e=g),l[b]=q;l[b]=e}return e}return p.distance(x,n)}};t!==null&&t.exports===i?t.exports=d:typeof self<"u"&&typeof self.postMessage=="function"&&typeof self.importScripts=="function"?self.Levenshtein=d:typeof window<"u"&&window!==null&&(window.Levenshtein=d)})()})(F,F.exports)),F.exports}var pe=me();const he=B.getDefaultExportFromCjs(pe);function J(){const{value:t,setValue:i}=oe.useSynchronizedValue("isKeyboardNavigating");return o.useMemo(()=>({isKeyboardNavigating:t,setIsKeyboardNavigating:i}),[t,i])}function P(t){return"text"in t?t.text:t.label}const K="kakadu-components-1144794361",$="kakadu-components-2911184744";function ve({isSelected:t,id:i,value:r,label:p,onSelect:l,onHover:u}){const{isKeyboardNavigating:d}=J(),x=o.useCallback(()=>{l(r)},[l,r]),n=o.useCallback(h=>{d||h.movementX===0&&h.movementY===0||u(r)},[d,u,r]),m=o.useRef(null);return o.useEffect(()=>{const h=m.current;t&&h&&d&&setTimeout(()=>{h.scrollIntoView({behavior:"smooth",block:"nearest"})},0)},[t,d]),j.jsxRuntimeExports.jsx("li",{ref:m,id:i,role:"option","aria-selected":t,tabIndex:-1,className:U.cx(K,"kakadu-components-4130497639",d?"kakadu-components-962373561":"kakadu-components-1109598791"),onClick:x,onMouseMove:n,children:j.jsxRuntimeExports.jsx(L.Span,{className:U.cx($,typeof p=="string"&&"kakadu-components-154286052"),children:p})})}function xe({isLoading:t,id:i,activeOptionId:r,selectedValue:p,options:l,onSelect:u,onHover:d}){const x=o.useRef(null);return o.useEffect(()=>{const n=x.current;n&&n.scrollIntoView({behavior:"smooth",block:"nearest"})},[]),j.jsxRuntimeExports.jsxs("ul",{ref:x,id:i,role:"listbox","aria-label":"Options",className:"kakadu-components-1951042708",children:[l.length===0?t?null:j.jsxRuntimeExports.jsxs(X.default,{"aria-atomic":!0,as:"li",role:"status","aria-live":"polite",direction:"row",preset:"start",gap:.5,className:K,children:[j.jsxRuntimeExports.jsx(re.default,{size:15,type:"exclamationTriangle"}),j.jsxRuntimeExports.jsx(L.Span,{className:$,children:"No results."})]}):l.map((n,m)=>j.jsxRuntimeExports.jsx(ve,{...n,id:n.value===p?r:void 0,isSelected:n.value===p,onSelect:u,onHover:d},P(n)+m)),t?j.jsxRuntimeExports.jsx(X.default,{as:"li",alignment:"center",className:K,children:j.jsxRuntimeExports.jsx(L.Span,{className:$,children:j.jsxRuntimeExports.jsx(ce.SkeletonInstance,{width:"100%",height:"1.3em"})})}):null]})}function be({isLoading:t,label:i,options:r,error:p,warning:l,information:u,footnote:d,className:x,onChange:n,onSelect:m,...h}){const R=o.useRef(null),C=o.useId(),q=o.useId(),[e,f]=o.useState(!1),b=o.useCallback(()=>{f(!0)},[]),g=o.useCallback(a=>{var c;(c=R.current)!=null&&c.contains(a.relatedTarget)||f(!1)},[]),[s,v]=o.useState(!1);o.useEffect(()=>{v(e)},[e]);const[k,w]=o.useState(""),{value:N}=h,[E,O]=o.useState(N),[A,Q]=o.useState(N),H=o.useRef(A),I=o.useCallback(a=>{Q(a),H.current=a},[]);o.useEffect(()=>{O(N),I(N)},[N,I]);const W=o.useCallback(()=>{E&&(w(""),I(void 0))},[E,I]),Z=o.useCallback((a,c)=>{w(a),n==null||n(a,c),v(!0),O(void 0)},[n]),ee=o.useCallback(a=>{var c;(c=R.current)!=null&&c.contains(a.target)&&v(!0)},[]),D=o.useCallback(a=>{const c=a==null?void 0:a.value;I(c),a?w(P(a)):(w(""),n==null||n("")),m==null||m(c)},[I,n,m]),te=o.useCallback(a=>{const c=r.find(y=>y.value===a);D(c),O(a),v(!1)},[r,D]),ne=o.useCallback(a=>{I(a)},[I]),S=o.useMemo(()=>E||k.length===0?r:r.filter(a=>{const y=P(a).toLowerCase(),_=k.toLowerCase();return!!(y.includes(_)||_.includes(y)||he.get(y,_,{useCollator:!0})<=2)}),[E,r,k]);o.useEffect(()=>{!E&&k.length>0&&S.length>0&&!S.some(a=>A===a.value)&&I(S[0].value)},[E,k,S,A,I]);const{setIsKeyboardNavigating:T}=J();o.useEffect(()=>{if(!e)return;const a=c=>{c.movementX===0&&c.movementY===0||T(!1)};return window.addEventListener("mousemove",a,{capture:!0}),()=>{window.removeEventListener("mousemove",a,{capture:!0})}},[e,T]),o.useEffect(()=>{if(!e)return;const a=c=>{let y;const _=S.length,z=S.findIndex(V=>V.value===H.current);switch(c.key){case"Enter":{const V=S[z];V&&(c.preventDefault(),c.stopPropagation(),c.stopImmediatePropagation(),T(!0),v(!1),D(V),O(V.value));break}case"Escape":{s?(E?I(void 0):D(void 0),v(!1)):E?(v(!0),D(void 0)):(f(!1),c.target instanceof HTMLInputElement&&c.target.blur());return}case"ArrowDown":{y=z+1,v(!0);break}case"ArrowUp":{y=z-1,v(!0),y<0&&(y=_-1);break}case"Home":{v(!0),y=0;break}case"End":{v(!0),y=_-1;break}case"Backspace":{S.some(V=>V.value===E)&&(c.preventDefault(),c.stopPropagation(),c.stopImmediatePropagation(),D(void 0),v(!0));break}}if(y!==void 0&&(c.preventDefault(),c.stopPropagation(),c.stopImmediatePropagation(),T(!0),_>0)){const V=S[y%_];V&&I(V.value)}};return window.addEventListener("keydown",a,{capture:!0}),()=>{window.removeEventListener("keydown",a,{capture:!0})}},[e,S,T,v,D,O,s,E,I]);const se=o.useMemo(()=>({clickOutsideDeactivates:!0,returnFocusOnDeactivate:!1,escapeDeactivates:!1}),[]);return j.jsxRuntimeExports.jsx(B.focusTrapReactExports.FocusTrap,{active:s,focusTrapOptions:se,children:j.jsxRuntimeExports.jsx(ae.default,{...h,ref:R,role:"combobox",autoComplete:"off","aria-controls":C,"aria-expanded":s,"aria-activedescendant":s?q:void 0,label:i,value:k,error:p,warning:l,information:u,footnote:d,attachments:s?j.jsxRuntimeExports.jsx(xe,{isLoading:t,id:C,activeOptionId:q,selectedValue:A,options:S,onSelect:te,onHover:ne}):null,className:x,onMouseDown:ee,onChange:Z,onBeforeInput:W,onFocus:b,onBlur:g})})}exports.default=be;exports.getComboboxOptionString=P;
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { j as O } from "../jsx-runtime-B4hRZ52C.mjs";
|
|
2
|
+
import { useRef as K, useId as G, useState as P, useCallback as E, useEffect as q, useMemo as B } from "react";
|
|
3
|
+
import { g as ce, a as le, f as ue } from "../focus-trap-react-DATIi_Ob.mjs";
|
|
4
|
+
import { cx as J } from "@kuma-ui/core";
|
|
5
|
+
import { u as fe } from "../use-synchronized-value-XnIpeq1s.mjs";
|
|
6
|
+
import de from "../icons/icon.mjs";
|
|
7
|
+
import me from "./input.mjs";
|
|
8
|
+
import { Span as H } from "./text.mjs";
|
|
9
|
+
import Q from "./flex.mjs";
|
|
10
|
+
import { SkeletonInstance as pe } from "./skeleton.mjs";
|
|
11
|
+
var z = { exports: {} };
|
|
12
|
+
const F = new Uint32Array(65536), he = (t, i) => {
|
|
13
|
+
const r = t.length, m = i.length, c = 1 << r - 1;
|
|
14
|
+
let l = -1, f = 0, v = r, n = r;
|
|
15
|
+
for (; n--; )
|
|
16
|
+
F[t.charCodeAt(n)] |= 1 << n;
|
|
17
|
+
for (n = 0; n < m; n++) {
|
|
18
|
+
let d = F[i.charCodeAt(n)];
|
|
19
|
+
const p = d | f;
|
|
20
|
+
d |= (d & l) + l ^ l, f |= ~(d | l), l &= d, f & c && v++, l & c && v--, f = f << 1 | 1, l = l << 1 | ~(p | f), f &= p;
|
|
21
|
+
}
|
|
22
|
+
for (n = r; n--; )
|
|
23
|
+
F[t.charCodeAt(n)] = 0;
|
|
24
|
+
return v;
|
|
25
|
+
}, ve = (t, i) => {
|
|
26
|
+
const r = i.length, m = t.length, c = [], l = [], f = Math.ceil(r / 32), v = Math.ceil(m / 32);
|
|
27
|
+
for (let e = 0; e < f; e++)
|
|
28
|
+
l[e] = -1, c[e] = 0;
|
|
29
|
+
let n = 0;
|
|
30
|
+
for (; n < v - 1; n++) {
|
|
31
|
+
let e = 0, u = -1;
|
|
32
|
+
const g = n * 32, x = Math.min(32, m) + g;
|
|
33
|
+
for (let o = g; o < x; o++)
|
|
34
|
+
F[t.charCodeAt(o)] |= 1 << o;
|
|
35
|
+
for (let o = 0; o < r; o++) {
|
|
36
|
+
const h = F[i.charCodeAt(o)], b = l[o / 32 | 0] >>> o & 1, w = c[o / 32 | 0] >>> o & 1, S = h | e, I = ((h | w) & u) + u ^ u | h | w;
|
|
37
|
+
let N = e | ~(I | u), D = u & I;
|
|
38
|
+
N >>> 31 ^ b && (l[o / 32 | 0] ^= 1 << o), D >>> 31 ^ w && (c[o / 32 | 0] ^= 1 << o), N = N << 1 | b, D = D << 1 | w, u = D | ~(S | N), e = N & S;
|
|
39
|
+
}
|
|
40
|
+
for (let o = g; o < x; o++)
|
|
41
|
+
F[t.charCodeAt(o)] = 0;
|
|
42
|
+
}
|
|
43
|
+
let d = 0, p = -1;
|
|
44
|
+
const A = n * 32, V = Math.min(32, m - A) + A;
|
|
45
|
+
for (let e = A; e < V; e++)
|
|
46
|
+
F[t.charCodeAt(e)] |= 1 << e;
|
|
47
|
+
let M = m;
|
|
48
|
+
for (let e = 0; e < r; e++) {
|
|
49
|
+
const u = F[i.charCodeAt(e)], g = l[e / 32 | 0] >>> e & 1, x = c[e / 32 | 0] >>> e & 1, o = u | d, h = ((u | x) & p) + p ^ p | u | x;
|
|
50
|
+
let b = d | ~(h | p), w = p & h;
|
|
51
|
+
M += b >>> m - 1 & 1, M -= w >>> m - 1 & 1, b >>> 31 ^ g && (l[e / 32 | 0] ^= 1 << e), w >>> 31 ^ x && (c[e / 32 | 0] ^= 1 << e), b = b << 1 | g, w = w << 1 | x, p = w | ~(o | b), d = b & o;
|
|
52
|
+
}
|
|
53
|
+
for (let e = A; e < V; e++)
|
|
54
|
+
F[t.charCodeAt(e)] = 0;
|
|
55
|
+
return M;
|
|
56
|
+
}, Z = (t, i) => {
|
|
57
|
+
if (t.length < i.length) {
|
|
58
|
+
const r = i;
|
|
59
|
+
i = t, t = r;
|
|
60
|
+
}
|
|
61
|
+
return i.length === 0 ? t.length : t.length <= 32 ? he(t, i) : ve(t, i);
|
|
62
|
+
}, ge = (t, i) => {
|
|
63
|
+
let r = 1 / 0, m = 0;
|
|
64
|
+
for (let c = 0; c < i.length; c++) {
|
|
65
|
+
const l = Z(t, i[c]);
|
|
66
|
+
l < r && (r = l, m = c);
|
|
67
|
+
}
|
|
68
|
+
return i[m];
|
|
69
|
+
}, xe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
70
|
+
__proto__: null,
|
|
71
|
+
closest: ge,
|
|
72
|
+
distance: Z
|
|
73
|
+
}, Symbol.toStringTag, { value: "Module" })), be = /* @__PURE__ */ ce(xe);
|
|
74
|
+
var W;
|
|
75
|
+
function we() {
|
|
76
|
+
return W || (W = 1, (function(t, i) {
|
|
77
|
+
(function() {
|
|
78
|
+
var r;
|
|
79
|
+
try {
|
|
80
|
+
r = typeof Intl < "u" && typeof Intl.Collator < "u" ? Intl.Collator("generic", { sensitivity: "base" }) : null;
|
|
81
|
+
} catch {
|
|
82
|
+
console.log("Collator could not be initialized and wouldn't be used");
|
|
83
|
+
}
|
|
84
|
+
var m = be, c = [], l = [], f = {
|
|
85
|
+
/**
|
|
86
|
+
* Calculate levenshtein distance of the two strings.
|
|
87
|
+
*
|
|
88
|
+
* @param str1 String the first string.
|
|
89
|
+
* @param str2 String the second string.
|
|
90
|
+
* @param [options] Additional options.
|
|
91
|
+
* @param [options.useCollator] Use `Intl.Collator` for locale-sensitive string comparison.
|
|
92
|
+
* @return Integer the levenshtein distance (0 and above).
|
|
93
|
+
*/
|
|
94
|
+
get: function(v, n, d) {
|
|
95
|
+
var p = d && r && d.useCollator;
|
|
96
|
+
if (p) {
|
|
97
|
+
var A = v.length, V = n.length;
|
|
98
|
+
if (A === 0) return V;
|
|
99
|
+
if (V === 0) return A;
|
|
100
|
+
var M, e, u, g, x;
|
|
101
|
+
for (u = 0; u < V; ++u)
|
|
102
|
+
c[u] = u, l[u] = n.charCodeAt(u);
|
|
103
|
+
c[V] = V;
|
|
104
|
+
var o;
|
|
105
|
+
for (u = 0; u < A; ++u) {
|
|
106
|
+
for (e = u + 1, g = 0; g < V; ++g)
|
|
107
|
+
M = e, o = r.compare(v.charAt(u), String.fromCharCode(l[g])) === 0, e = c[g] + (o ? 0 : 1), x = M + 1, e > x && (e = x), x = c[g + 1] + 1, e > x && (e = x), c[g] = M;
|
|
108
|
+
c[g] = e;
|
|
109
|
+
}
|
|
110
|
+
return e;
|
|
111
|
+
}
|
|
112
|
+
return m.distance(v, n);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
t !== null && t.exports === i ? t.exports = f : typeof self < "u" && typeof self.postMessage == "function" && typeof self.importScripts == "function" ? self.Levenshtein = f : typeof window < "u" && window !== null && (window.Levenshtein = f);
|
|
116
|
+
})();
|
|
117
|
+
})(z, z.exports)), z.exports;
|
|
118
|
+
}
|
|
119
|
+
var ke = we();
|
|
120
|
+
const Ie = /* @__PURE__ */ le(ke);
|
|
121
|
+
function ee() {
|
|
122
|
+
const {
|
|
123
|
+
value: t,
|
|
124
|
+
setValue: i
|
|
125
|
+
} = fe("isKeyboardNavigating");
|
|
126
|
+
return B(() => ({
|
|
127
|
+
isKeyboardNavigating: t,
|
|
128
|
+
setIsKeyboardNavigating: i
|
|
129
|
+
}), [t, i]);
|
|
130
|
+
}
|
|
131
|
+
function $(t) {
|
|
132
|
+
return "text" in t ? t.text : t.label;
|
|
133
|
+
}
|
|
134
|
+
const U = "kakadu-components-1144794361", X = "kakadu-components-2911184744";
|
|
135
|
+
function ye({
|
|
136
|
+
isSelected: t,
|
|
137
|
+
id: i,
|
|
138
|
+
value: r,
|
|
139
|
+
label: m,
|
|
140
|
+
onSelect: c,
|
|
141
|
+
onHover: l
|
|
142
|
+
}) {
|
|
143
|
+
const {
|
|
144
|
+
isKeyboardNavigating: f
|
|
145
|
+
} = ee(), v = E(() => {
|
|
146
|
+
c(r);
|
|
147
|
+
}, [c, r]), n = E((p) => {
|
|
148
|
+
f || p.movementX === 0 && p.movementY === 0 || l(r);
|
|
149
|
+
}, [f, l, r]), d = K(null);
|
|
150
|
+
return q(() => {
|
|
151
|
+
const p = d.current;
|
|
152
|
+
t && p && f && setTimeout(() => {
|
|
153
|
+
p.scrollIntoView({
|
|
154
|
+
behavior: "smooth",
|
|
155
|
+
block: "nearest"
|
|
156
|
+
});
|
|
157
|
+
}, 0);
|
|
158
|
+
}, [t, f]), /* @__PURE__ */ O.jsx("li", { ref: d, id: i, role: "option", "aria-selected": t, tabIndex: -1, className: J(U, "kakadu-components-4130497639", f ? "kakadu-components-962373561" : "kakadu-components-1109598791"), onClick: v, onMouseMove: n, children: /* @__PURE__ */ O.jsx(H, { className: J(X, typeof m == "string" && "kakadu-components-154286052"), children: m }) });
|
|
159
|
+
}
|
|
160
|
+
function Oe({
|
|
161
|
+
isLoading: t,
|
|
162
|
+
id: i,
|
|
163
|
+
activeOptionId: r,
|
|
164
|
+
selectedValue: m,
|
|
165
|
+
options: c,
|
|
166
|
+
onSelect: l,
|
|
167
|
+
onHover: f
|
|
168
|
+
}) {
|
|
169
|
+
const v = K(null);
|
|
170
|
+
return q(() => {
|
|
171
|
+
const n = v.current;
|
|
172
|
+
n && n.scrollIntoView({
|
|
173
|
+
behavior: "smooth",
|
|
174
|
+
block: "nearest"
|
|
175
|
+
});
|
|
176
|
+
}, []), /* @__PURE__ */ O.jsxs("ul", { ref: v, id: i, role: "listbox", "aria-label": "Options", className: "kakadu-components-1951042708", children: [
|
|
177
|
+
c.length === 0 ? t ? null : /* @__PURE__ */ O.jsxs(Q, { "aria-atomic": !0, as: "li", role: "status", "aria-live": "polite", direction: "row", preset: "start", gap: 0.5, className: U, children: [
|
|
178
|
+
/* @__PURE__ */ O.jsx(de, { size: 15, type: "exclamationTriangle" }),
|
|
179
|
+
/* @__PURE__ */ O.jsx(H, { className: X, children: "No results." })
|
|
180
|
+
] }) : c.map((n, d) => /* @__PURE__ */ O.jsx(
|
|
181
|
+
ye,
|
|
182
|
+
{
|
|
183
|
+
...n,
|
|
184
|
+
id: n.value === m ? r : void 0,
|
|
185
|
+
isSelected: n.value === m,
|
|
186
|
+
onSelect: l,
|
|
187
|
+
onHover: f
|
|
188
|
+
},
|
|
189
|
+
$(n) + d
|
|
190
|
+
)),
|
|
191
|
+
t ? /* @__PURE__ */ O.jsx(Q, { as: "li", alignment: "center", className: U, children: /* @__PURE__ */ O.jsx(H, { className: X, children: /* @__PURE__ */ O.jsx(pe, { width: "100%", height: "1.3em" }) }) }) : null
|
|
192
|
+
] });
|
|
193
|
+
}
|
|
194
|
+
function Te({
|
|
195
|
+
isLoading: t,
|
|
196
|
+
label: i,
|
|
197
|
+
options: r,
|
|
198
|
+
error: m,
|
|
199
|
+
warning: c,
|
|
200
|
+
information: l,
|
|
201
|
+
footnote: f,
|
|
202
|
+
className: v,
|
|
203
|
+
onChange: n,
|
|
204
|
+
onSelect: d,
|
|
205
|
+
...p
|
|
206
|
+
}) {
|
|
207
|
+
const A = K(null), V = G(), M = G(), [e, u] = P(!1), g = E(() => {
|
|
208
|
+
u(!0);
|
|
209
|
+
}, []), x = E((s) => {
|
|
210
|
+
var a;
|
|
211
|
+
(a = A.current) != null && a.contains(s.relatedTarget) || u(!1);
|
|
212
|
+
}, []), [o, h] = P(!1);
|
|
213
|
+
q(() => {
|
|
214
|
+
h(e);
|
|
215
|
+
}, [e]);
|
|
216
|
+
const [b, w] = P(""), {
|
|
217
|
+
value: S
|
|
218
|
+
} = p, [I, N] = P(S), [D, te] = P(S), Y = K(D), y = E((s) => {
|
|
219
|
+
te(s), Y.current = s;
|
|
220
|
+
}, []);
|
|
221
|
+
q(() => {
|
|
222
|
+
N(S), y(S);
|
|
223
|
+
}, [S, y]);
|
|
224
|
+
const ne = E(() => {
|
|
225
|
+
I && (w(""), y(void 0));
|
|
226
|
+
}, [I, y]), oe = E((s, a) => {
|
|
227
|
+
w(s), n == null || n(s, a), h(!0), N(void 0);
|
|
228
|
+
}, [n]), re = E((s) => {
|
|
229
|
+
var a;
|
|
230
|
+
(a = A.current) != null && a.contains(s.target) && h(!0);
|
|
231
|
+
}, []), _ = E((s) => {
|
|
232
|
+
const a = s == null ? void 0 : s.value;
|
|
233
|
+
y(a), s ? w($(s)) : (w(""), n == null || n("")), d == null || d(a);
|
|
234
|
+
}, [y, n, d]), se = E((s) => {
|
|
235
|
+
const a = r.find((k) => k.value === s);
|
|
236
|
+
_(a), N(s), h(!1);
|
|
237
|
+
}, [r, _]), ae = E((s) => {
|
|
238
|
+
y(s);
|
|
239
|
+
}, [y]), j = B(() => I || b.length === 0 ? r : r.filter((s) => {
|
|
240
|
+
const k = $(s).toLowerCase(), T = b.toLowerCase();
|
|
241
|
+
return !!(k.includes(T) || T.includes(k) || Ie.get(k, T, {
|
|
242
|
+
useCollator: !0
|
|
243
|
+
}) <= 2);
|
|
244
|
+
}), [I, r, b]);
|
|
245
|
+
q(() => {
|
|
246
|
+
!I && b.length > 0 && j.length > 0 && !j.some((s) => D === s.value) && y(j[0].value);
|
|
247
|
+
}, [I, b, j, D, y]);
|
|
248
|
+
const {
|
|
249
|
+
setIsKeyboardNavigating: L
|
|
250
|
+
} = ee();
|
|
251
|
+
q(() => {
|
|
252
|
+
if (!e)
|
|
253
|
+
return;
|
|
254
|
+
const s = (a) => {
|
|
255
|
+
a.movementX === 0 && a.movementY === 0 || L(!1);
|
|
256
|
+
};
|
|
257
|
+
return window.addEventListener("mousemove", s, {
|
|
258
|
+
capture: !0
|
|
259
|
+
}), () => {
|
|
260
|
+
window.removeEventListener("mousemove", s, {
|
|
261
|
+
capture: !0
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
}, [e, L]), q(() => {
|
|
265
|
+
if (!e)
|
|
266
|
+
return;
|
|
267
|
+
const s = (a) => {
|
|
268
|
+
let k;
|
|
269
|
+
const T = j.length, R = j.findIndex((C) => C.value === Y.current);
|
|
270
|
+
switch (a.key) {
|
|
271
|
+
case "Enter": {
|
|
272
|
+
const C = j[R];
|
|
273
|
+
C && (a.preventDefault(), a.stopPropagation(), a.stopImmediatePropagation(), L(!0), h(!1), _(C), N(C.value));
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case "Escape": {
|
|
277
|
+
o ? (I ? y(void 0) : _(void 0), h(!1)) : I ? (h(!0), _(void 0)) : (u(!1), a.target instanceof HTMLInputElement && a.target.blur());
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
case "ArrowDown": {
|
|
281
|
+
k = R + 1, h(!0);
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case "ArrowUp": {
|
|
285
|
+
k = R - 1, h(!0), k < 0 && (k = T - 1);
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case "Home": {
|
|
289
|
+
h(!0), k = 0;
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case "End": {
|
|
293
|
+
h(!0), k = T - 1;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
case "Backspace": {
|
|
297
|
+
j.some((C) => C.value === I) && (a.preventDefault(), a.stopPropagation(), a.stopImmediatePropagation(), _(void 0), h(!0));
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (k !== void 0 && (a.preventDefault(), a.stopPropagation(), a.stopImmediatePropagation(), L(!0), T > 0)) {
|
|
302
|
+
const C = j[k % T];
|
|
303
|
+
C && y(C.value);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
return window.addEventListener("keydown", s, {
|
|
307
|
+
capture: !0
|
|
308
|
+
}), () => {
|
|
309
|
+
window.removeEventListener("keydown", s, {
|
|
310
|
+
capture: !0
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
}, [e, j, L, h, _, N, o, I, y]);
|
|
314
|
+
const ie = B(() => ({
|
|
315
|
+
clickOutsideDeactivates: !0,
|
|
316
|
+
returnFocusOnDeactivate: !1,
|
|
317
|
+
escapeDeactivates: !1
|
|
318
|
+
}), []);
|
|
319
|
+
return /* @__PURE__ */ O.jsx(ue.FocusTrap, { active: o, focusTrapOptions: ie, children: /* @__PURE__ */ O.jsx(me, { ...p, ref: A, role: "combobox", autoComplete: "off", "aria-controls": V, "aria-expanded": o, "aria-activedescendant": o ? M : void 0, label: i, value: b, error: m, warning: c, information: l, footnote: f, attachments: o ? /* @__PURE__ */ O.jsx(Oe, { isLoading: t, id: V, activeOptionId: M, selectedValue: D, options: j, onSelect: se, onHover: ae }) : null, className: v, onMouseDown: re, onChange: oe, onBeforeInput: ne, onFocus: g, onBlur: x }) });
|
|
320
|
+
}
|
|
321
|
+
export {
|
|
322
|
+
Te as default,
|
|
323
|
+
$ as getComboboxOptionString
|
|
324
|
+
};
|
|
@@ -1,45 +1,38 @@
|
|
|
1
1
|
import { type ChangeEvent, type HTMLProps, type ReactNode } from 'react';
|
|
2
2
|
import { type IconType } from '../icons/icon';
|
|
3
|
+
export declare const inputStyles: string;
|
|
3
4
|
export declare const errorParagraph: string;
|
|
4
|
-
type
|
|
5
|
-
type
|
|
5
|
+
type InputLabelMessageType = Error | ReactNode | string;
|
|
6
|
+
type InputLabelMessageProperties<Key extends string> = ({
|
|
6
7
|
readonly [Property in Key]?: undefined;
|
|
7
8
|
} & {
|
|
8
9
|
readonly [Property in `${Key}Id`]?: undefined;
|
|
9
10
|
}) | ({
|
|
10
|
-
readonly [Property in Key]:
|
|
11
|
+
readonly [Property in Key]: InputLabelMessageType;
|
|
11
12
|
} & {
|
|
12
13
|
readonly [Property in `${Key}Id`]: string;
|
|
13
14
|
});
|
|
14
|
-
type
|
|
15
|
+
type InputLabelProperties = HTMLProps<HTMLLabelElement> & InputLabelMessageProperties<'error'> & InputLabelMessageProperties<'warning'> & InputLabelMessageProperties<'information'> & {
|
|
15
16
|
readonly label: string;
|
|
16
17
|
readonly footnote?: ReactNode;
|
|
17
18
|
readonly attachments?: ReactNode;
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
-
export type
|
|
21
|
-
|
|
22
|
-
readonly label: ReactNode | string;
|
|
23
|
-
readonly disabled?: boolean;
|
|
24
|
-
};
|
|
25
|
-
export type SelectProperties<Type extends string = string> = Omit<ControllerProperties & HTMLProps<HTMLSelectElement>, 'onChange'> & {
|
|
26
|
-
readonly options: Array<SelectOption<Type>>;
|
|
27
|
-
readonly onChange?: (value: Type, event: ChangeEvent<HTMLSelectElement>) => void;
|
|
28
|
-
};
|
|
29
|
-
export declare function Select<Type extends string = string>({ label, options, error, warning, information, footnote, className, onChange, ...properties }: SelectProperties<Type>): import("react/jsx-runtime").JSX.Element;
|
|
30
|
-
type InputType = HTMLInputElement | HTMLTextAreaElement;
|
|
20
|
+
export declare function InputLabel({ label, error, errorId, warning, warningId, information, informationId, footnote, attachments, className, children, ...properties }: InputLabelProperties): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export type InputLabelControllerProperties = Omit<InputLabelProperties, 'errorId' | 'warningId' | 'attachments' | 'onClick' | 'onMouseDown' | 'onMouseUp' | 'onChange' | 'onFocus' | 'onBlur' | 'onInput' | 'onBeforeInput'>;
|
|
22
|
+
export type InputType = HTMLInputElement | HTMLTextAreaElement;
|
|
31
23
|
export type InputAction = {
|
|
32
24
|
icon: IconType;
|
|
33
25
|
label: string;
|
|
34
26
|
onClick: () => void;
|
|
35
27
|
};
|
|
36
|
-
export type InputProperties = Omit<
|
|
28
|
+
export type InputProperties = Omit<InputLabelControllerProperties & Omit<HTMLProps<InputType>, 'ref'>, 'onChange'> & {
|
|
37
29
|
readonly suggestion?: string;
|
|
30
|
+
readonly attachments?: ReactNode;
|
|
38
31
|
readonly actions?: InputAction[];
|
|
39
32
|
readonly hasCopyButton?: boolean;
|
|
40
33
|
readonly hasClearButton?: boolean;
|
|
41
34
|
readonly isMultiline?: boolean;
|
|
42
35
|
readonly onChange?: (value: string, event: ChangeEvent<InputType>) => void;
|
|
43
36
|
};
|
|
44
|
-
export default function Input({ type, label, error, warning, information, footnote, suggestion, actions, hasCopyButton, hasClearButton, isMultiline, onChange, className, ...properties }: InputProperties): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export default function Input({ ref, type, label, error, warning, information, footnote, suggestion, attachments, actions, hasCopyButton, hasClearButton, isMultiline, onChange, className, ...properties }: InputProperties): import("react/jsx-runtime").JSX.Element;
|
|
45
38
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../jsx-runtime-BB_1_6y_.js"),t=require("react"),r=require("@kuma-ui/core"),
|
|
2
|
-
`):[],[
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../jsx-runtime-BB_1_6y_.js"),t=require("react"),r=require("@kuma-ui/core"),K=require("../utilities/copy-to-clipboard.js"),L=require("../theme.js"),pe=require("../icons/sparkle.js"),me=require("./button-tooltip.js"),B=require("./text-button.js"),p=require("./text.js"),de=require("./collapsible.js"),Q=require("./click-ripples.js"),X=require("./hover-gradient.js"),je=require("./notification.js"),ke="kakadu-components-922159086",fe="kakadu-components-25448712",N="kakadu-components-1923392328",M="kakadu-components-4056037255",Y=r.cx(M,"kakadu-components-3245407458"),he=r.cx(M,"kakadu-components-1117160492"),Ee=r.cx(M,"kakadu-components-2261792866");function Re({as:m,className:c,...d}){return e.jsxRuntimeExports.jsx(p.Span,{as:m??"span",...d,className:r.cx("kakadu-components-520991867",c)})}function Z({label:m,error:c,errorId:d,warning:l,warningId:E,information:i,informationId:v,footnote:a,attachments:S,className:j,children:k,...f}){const R=!!c,u=!!l,x=!!i,h=!!a;return e.jsxRuntimeExports.jsx("label",{...f,className:r.cx(ke,j),children:e.jsxRuntimeExports.jsxs("div",{className:"kakadu-components-3146929190",children:[e.jsxRuntimeExports.jsx(p.Span,{className:r.cx(L.overflowProtectionStyles,fe),children:e.jsxRuntimeExports.jsx("span",{children:m})}),e.jsxRuntimeExports.jsxs("span",{className:"kakadu-components-3298764637",children:[k,h?e.jsxRuntimeExports.jsx(Re,{className:"kakadu-components-613632806",children:a}):null,S]}),R||u||x?e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2927674627",children:R?e.jsxRuntimeExports.jsx(p.Paragraph,{id:d,className:Y,children:c instanceof Error?c.message:c}):u?e.jsxRuntimeExports.jsx(p.Paragraph,{id:E,className:he,children:l instanceof Error?l.message:l}):x?e.jsxRuntimeExports.jsx(p.Paragraph,{id:v,className:Ee,children:i instanceof Error?i.message:i}):null}):null]})})}const be=40,w="kakadu-components-4233741488";function ge({ref:m,type:c,label:d,error:l,warning:E,information:i,footnote:v,suggestion:a,attachments:S,actions:j=[],hasCopyButton:k,hasClearButton:f,isMultiline:R,onChange:u,className:x,...h}){const T=t.useRef(null),$=t.useRef(null),C=t.useRef(null),H=je.useCreateNotification(),q=t.useId(),A=`${q}-error`,F=`${q}-warning`,V=`${q}-information`,{value:b,disabled:ee}=h,[te,O]=t.useState(""),o=b??te,[se,ne]=t.useState(),ae=c==="textarea"||!!R;t.useLayoutEffect(()=>{typeof o=="string"&&C.current&&ne(C.current.scrollHeight)},[o]);const I=t.useMemo(()=>typeof o=="string"?`${o} `.split(`
|
|
2
|
+
`):[],[o]),oe=t.useMemo(()=>I.length,[I]),g=!!l,P=!g&&!!E,_=!!i,W=g?A:P?F:_?V:void 0;t.useEffect(()=>{O(typeof b=="string"?b:"")},[b]);const z=t.useCallback(s=>{const{value:n}=s.target;O(n),u==null||u(n,s)},[u]),re=t.useCallback(()=>{typeof o=="string"&&(K.default(o),H({type:"success",children:"Copied to clipboard."}))},[o,H]),y=t.useCallback(s=>{var U;const n=$.current??T.current??void 0;if(n){const J=(U=Object.getOwnPropertyDescriptor(n instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLInputElement.prototype,"value"))==null?void 0:U.set;if(J){J.call(n,s);const xe=new Event("input",{bubbles:!0});n.dispatchEvent(xe),n.focus();return}}throw new Error("Unable to set value.")},[]),ce=t.useCallback(()=>{y("")},[y]),[le,ie]=t.useState(""),D=!!a&&le!==a,ue=t.useCallback(()=>{if(a){try{y(a)}catch{K.default(a)}ie(a)}},[a,y]),G=t.useMemo(()=>j.length,[j]);return e.jsxRuntimeExports.jsxs(Z,{ref:m,label:d,error:l,errorId:A,warning:E,warningId:F,information:i,informationId:V,footnote:v,attachments:e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(de.default,{isCollapsed:!D,children:D?e.jsxRuntimeExports.jsxs("button",{type:"button",className:r.cx(L.buttonResetStyles,L.overflowProtectionStyles,"kakadu-components-4141839293"),onClick:ue,children:[e.jsxRuntimeExports.jsx(me.default,{label:"Apply suggestion"}),e.jsxRuntimeExports.jsx(pe.default,{width:13,height:13,className:"kakadu-components-1417828741"}),e.jsxRuntimeExports.jsx(p.Span,{className:"kakadu-components-1384720019",children:a}),e.jsxRuntimeExports.jsx(Q.default,{className:"kakadu-components-2744733744"}),e.jsxRuntimeExports.jsx(X.default,{})]}):null}),S]}),style:{"--button-padding":`calc(${be*((k?1:0)+(f?1:0)+G)}px + 6px)`},children:[e.jsxRuntimeExports.jsxs("div",{className:"kakadu-components-3146929190",children:[ae?e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("span",{ref:C,"aria-hidden":!0,className:r.cx(N,x,"kakadu-components-2033521835"),children:[I.map((s,n)=>e.jsxRuntimeExports.jsxs("span",{children:[s,oe>1?e.jsxRuntimeExports.jsx("br",{}):null]},n))," "]}),e.jsxRuntimeExports.jsx("textarea",{...h,ref:$,rows:1,"aria-invalid":g,"data-warning":P,"data-information":_,"aria-describedby":W,value:o,className:r.cx(N,x,"kakadu-components-2119524139"),style:{minHeight:se},onChange:z})]}):e.jsxRuntimeExports.jsx("input",{...h,ref:T,type:c??"text",value:o,"aria-invalid":g,"data-warning":P,"data-information":_,"aria-describedby":W,className:r.cx(N,x),onChange:z}),ee?null:e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(Q.default,{className:"kakadu-components-616311160"}),e.jsxRuntimeExports.jsx(X.default,{className:"kakadu-components-1962999040"})]})]}),k||f||G>0?e.jsxRuntimeExports.jsxs("div",{className:"kakadu-components-131986363",children:[j.map((s,n)=>e.jsxRuntimeExports.jsx(B.default,{iconLeft:s.icon,label:s.label,tooltip:s.label,className:w,onClick:s.onClick},s.label+n)),k?e.jsxRuntimeExports.jsx(B.default,{iconLeft:"copy",label:"Copy",tooltip:"Copy",className:w,onClick:re}):null,f?e.jsxRuntimeExports.jsx(B.default,{iconLeft:"times",label:"Clear",tooltip:"Clear",className:w,onClick:ce}):null]}):null]})}exports.InputLabel=Z;exports.default=ge;exports.errorParagraph=Y;exports.inputStyles=N;
|