react-animated-select 0.7.7 → 0.8.0
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/base.css +1 -0
- package/dist/chip.cjs +1 -0
- package/dist/chip.css +1 -0
- package/dist/chip.js +94 -0
- package/dist/chipGeometry.cjs +1 -0
- package/dist/chipGeometry.js +64 -0
- package/dist/dropdown.cjs +1 -0
- package/dist/dropdown.js +70 -0
- package/dist/dropdownPosition.cjs +1 -0
- package/dist/dropdownPosition.js +87 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +28 -1
- package/dist/index.js +13 -0
- package/dist/liveRegion.cjs +1 -0
- package/dist/liveRegion.js +42 -0
- package/dist/model.cjs +1 -0
- package/dist/model.js +138 -0
- package/dist/motion.cjs +1 -0
- package/dist/motion.js +120 -0
- package/dist/optionList.cjs +1 -0
- package/dist/optionList.js +105 -0
- package/dist/paging.cjs +1 -0
- package/dist/paging.js +47 -0
- package/dist/select.cjs +1 -0
- package/dist/select.js +165 -0
- package/dist/state.cjs +1 -0
- package/dist/state.js +50 -0
- package/dist/style.css +4 -0
- package/dist/theme.css +1 -0
- package/dist/trigger.cjs +1 -0
- package/dist/trigger.js +94 -0
- package/dist/useChipLayout.cjs +1 -0
- package/dist/useChipLayout.js +78 -0
- package/dist/useSelect.cjs +1 -0
- package/dist/useSelect.js +100 -0
- package/dist/useSelectBehavior.cjs +1 -0
- package/dist/useSelectBehavior.js +109 -0
- package/dist/useSelectModel.cjs +1 -0
- package/dist/useSelectModel.js +59 -0
- package/dist/utils.cjs +1 -0
- package/dist/utils.js +99 -0
- package/index.d.ts +28 -1
- package/package.json +4 -4
- package/dist/index.css +0 -1
- package/dist/index.es.js +0 -1299
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo as F, useRef as L, useLayoutEffect as j, useEffect as U } from "react";
|
|
3
|
+
import { useStableActions as C } from "./state.js";
|
|
4
|
+
import { stopEvent as D } from "./utils.js";
|
|
5
|
+
const Q = { index: -1, fallback: -1, ready: !1 }, S = ({ index: r, fallback: f }) => r === -1 ? f : r, V = 10, z = 500, R = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp", "PageDown", "PageUp", "Home", "End"]), I = (r, f) => F(() => {
|
|
6
|
+
const u = new Set(r.map((n) => n.group).filter(Boolean)), i = (n) => !!n && !n.disabled && !n.loading && (n.groupHeader ? u.has(n.name) : !n.group || f.has(n.group));
|
|
7
|
+
return { reach: i, list: r.flatMap((n, o) => i(n) ? [o] : []) };
|
|
8
|
+
}, [r, f]), Y = (r, f, u, i) => {
|
|
9
|
+
const n = r.length - 1;
|
|
10
|
+
if (n < 0) return -1;
|
|
11
|
+
if (u === "Home") return r[0];
|
|
12
|
+
if (u === "End") return r[n];
|
|
13
|
+
const o = u === "ArrowUp" || u === "PageUp" ? -1 : 1, l = r.indexOf(f);
|
|
14
|
+
if (l === -1) return r[o > 0 ? 0 : n];
|
|
15
|
+
const s = l + o * (u.startsWith("Page") ? V : 1);
|
|
16
|
+
return s >= 0 && s <= n ? r[s] : u.startsWith("Page") || i ? r[s < 0 ? 0 : n] : r[(s + r.length) % r.length];
|
|
17
|
+
}, _ = (r, f, u, i) => {
|
|
18
|
+
const n = [...i].every((c) => c === i[0]), o = n ? i[0] : i, l = f.filter((c) => "original" in r[c]), s = Math.max(l.indexOf(u) + (n ? 1 : 0), 0);
|
|
19
|
+
for (let c = 0; c < l.length; c++) {
|
|
20
|
+
const h = l[(s + c) % l.length];
|
|
21
|
+
if (String(r[h].name).toLowerCase().startsWith(o)) return h;
|
|
22
|
+
}
|
|
23
|
+
return -1;
|
|
24
|
+
};
|
|
25
|
+
function X({ props: r, state: f, setState: u, normalizedOptions: i, expandedGroups: n, selected: o, selectedIDs: l, visibility: s, setVisibility: c, modelActions: h, highlightStore: T }) {
|
|
26
|
+
const { disabled: v, multiple: E, hasMore: k, loadButton: H, icons: x, onFocus: P, onBlur: p, onKeyDown: A } = r, { selectOption: B, clear: W, removeOption: q } = h, { deleting: w } = f, { reach: y, list: g } = I(i, n), d = L({ lastWindowFocusTime: 0, justFocused: !1, focusTimeout: null, query: "", queryTimeout: null }), M = F(() => {
|
|
27
|
+
const e = new Set(E ? l.map((a) => a.id) : o ? [o.id] : []), t = e.size ? i.findIndex((a) => e.has(a.id) && y(a)) : -1;
|
|
28
|
+
return t !== -1 ? t : g.find((a) => !i[a].groupHeader) ?? g[0] ?? -1;
|
|
29
|
+
}, [i, o, l, E, y, g]);
|
|
30
|
+
j(() => {
|
|
31
|
+
const { index: e } = T.get();
|
|
32
|
+
T.set({ fallback: M, index: e !== -1 && y(i[e]) ? e : -1 });
|
|
33
|
+
}), U(() => {
|
|
34
|
+
const e = d.current, t = () => e.lastWindowFocusTime = Date.now();
|
|
35
|
+
return window.addEventListener("focus", t), () => {
|
|
36
|
+
window.removeEventListener("focus", t), clearTimeout(e.focusTimeout), clearTimeout(e.queryTimeout);
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
const b = (e) => T.set({ index: e }), K = (e, t) => {
|
|
40
|
+
const a = d.current;
|
|
41
|
+
clearTimeout(a.queryTimeout), a.queryTimeout = setTimeout(() => a.query = "", z), a.query += e.toLowerCase();
|
|
42
|
+
const m = _(i, g, t, a.query);
|
|
43
|
+
m !== -1 && b(m), s || c(!0);
|
|
44
|
+
};
|
|
45
|
+
return C({
|
|
46
|
+
highlight: b,
|
|
47
|
+
handleBlur: (e) => {
|
|
48
|
+
const t = e.relatedTarget?.closest(".rac-options");
|
|
49
|
+
e.currentTarget.contains(e.relatedTarget) || t || (p?.(e), w && u({ deleting: !1 }), s && c(!1));
|
|
50
|
+
},
|
|
51
|
+
// [DOC: select-behavior]
|
|
52
|
+
handleFocus: (e) => {
|
|
53
|
+
const t = e.currentTarget.contains(e.relatedTarget);
|
|
54
|
+
t || P?.(e), !(t || e.target !== e.currentTarget || s || v || w || document.hidden || Date.now() - d.current.lastWindowFocusTime < 100) && (clearTimeout(d.current.focusTimeout), d.current.focusTimeout = setTimeout(() => d.current.justFocused = !1, 200), d.current.justFocused = !0, c(!0));
|
|
55
|
+
},
|
|
56
|
+
toggleVisibility: (e) => {
|
|
57
|
+
if (w) {
|
|
58
|
+
D(e), u({ deleting: !1 });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
v || d.current.justFocused || c(!s);
|
|
62
|
+
},
|
|
63
|
+
handleKeyDown: (e) => {
|
|
64
|
+
if (A?.(e), e.defaultPrevented || v || e.nativeEvent?.isComposing) return;
|
|
65
|
+
const { key: t } = e;
|
|
66
|
+
if (e.target !== e.currentTarget && (t === "Enter" || t.length === 1)) return;
|
|
67
|
+
const a = S(T.get());
|
|
68
|
+
if (t.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && (t !== " " || d.current.query)) {
|
|
69
|
+
e.preventDefault(), K(t, a);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (R.has(t)) {
|
|
73
|
+
e.preventDefault(), (s || t === "Home" || t === "End") && b(Y(g, a, t, !H && k)), s || c(!0);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
switch (t) {
|
|
77
|
+
case "Enter":
|
|
78
|
+
case " ":
|
|
79
|
+
e.preventDefault(), s ? a !== -1 && i[a] && (b(a), B(i[a], e)) : c(!0);
|
|
80
|
+
break;
|
|
81
|
+
// [DOC: select-behavior]
|
|
82
|
+
case "Escape":
|
|
83
|
+
if (w) u({ deleting: !1 });
|
|
84
|
+
else if (s) c(!1);
|
|
85
|
+
else break;
|
|
86
|
+
D(e);
|
|
87
|
+
break;
|
|
88
|
+
case "Tab":
|
|
89
|
+
s && c(!1);
|
|
90
|
+
break;
|
|
91
|
+
// [DOC: select-behavior]
|
|
92
|
+
case "Backspace":
|
|
93
|
+
case "Delete": {
|
|
94
|
+
const m = l.at(-1);
|
|
95
|
+
if (E && t === "Backspace" && x.remove && m) q(m.id);
|
|
96
|
+
else if (x.clear && (o || m)) W();
|
|
97
|
+
else break;
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
X as default,
|
|
107
|
+
S as effectiveHighlight,
|
|
108
|
+
Q as initialHighlight
|
|
109
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("./model.cjs"),O=require("./state.cjs"),b=require("./utils.cjs"),c=require("react"),I=[];function oe({props:m,jsxOptions:G,state:X,setState:y,ext:q,setVisibility:C,loadMoreOnce:Y}){const{onChange:Z,disabled:S,loading:E,error:w,multiple:n,childrenFirst:A,groupsClosed:D,hasMore:P,loadButton:T,placeholder:_,selectedText:g,texts:i}=m,{disabledOption:k,emptyOption:V,invalidOption:z,emptyGroup:H,loadMore:K,loadingMore:N}=i,{loadPending:j,internalValue:$,toggledGroups:x,picked:B}=X,F=O.useDeepStable(m.options),J=O.useDeepStable(m.value),L=J!==void 0,s=L?J:$,Q=c.useMemo(()=>q.row?.({hasMore:P,loadButton:T,loadPending:j,moreText:K,pendingText:N})??null,[q,P,T,j,K,N]),o=c.useMemo(()=>h.normalizeOptions({options:F,jsxOptions:G,childrenFirst:A,tail:Q,emptyOption:V,invalidOption:z,disabledOption:k,emptyGroup:H}),[F,G,A,Q,V,z,k,H]),ee=c.useMemo(()=>new Set(o.filter(e=>e.groupHeader&&!e.disabled&&D===x.has(e.name)).map(e=>e.name)),[o,x,D]),{selected:r,selectedIDs:d}=c.useMemo(()=>h.resolveSelection(s,o,n,B),[s,o,n,B]),p=o.length>0,te=!S&&p,f=s!=null&&!(Array.isArray(s)&&!s.length)&&!(h.isPlain(s)&&!Object.keys(s).length),le=f&&g?null:r,ne=c.useMemo(()=>f&&g?g:r?r.name:w?i.error:E?i.loading:S?i.disabled:p?_:i.empty,[w,E,S,f,g,r,p,_,i]),R=e=>y(t=>{const l=new Set(t.toggledGroups);return l.has(e)?l.delete(e):l.add(e),{toggledGroups:l}}),v=(e,t,l)=>{y(L?{picked:l}:{internalValue:e,picked:l}),Z?.(e,t)},U=e=>v(e.map(t=>t.original),e.map(t=>t.userId),e.map(t=>t.id)),se=O.useStableActions({toggleGroup:R,selectOption:(e,t)=>{if(e.groupHeader){b.stopEvent(t),e.disabled||R(e.name);return}if(e.disabled||e.loadMore){b.stopEvent(t),e.loadMore&&!e.loading&&Y();return}if(n){b.stopEvent(t);const l=d.some(a=>a.id===e.id);U(l?d.filter(a=>a.id!==e.id):[...d,e]);return}r?.id!==e.id&&v(e.original,e.userId,[e.id]),C(!1)},clear:e=>{b.stopEvent(e),v(n?[]:null,n?[]:null,I)},removeOption:e=>U(d.filter(t=>t.id!==e)),reset:()=>{y({deleting:!1,invalid:!1}),C(!1);const e=n?[]:null,t=m.defaultValue??e,{selected:l,selectedIDs:a}=h.resolveSelection(t,o,n,I),M=n?a:l?[l]:[],W=n?d:r?[r]:[];O.deepEqual(s??e,t)&&M.length===W.length&&M.every((u,re)=>u.id===W[re].id)||v(t,n?M.map(u=>u.userId):l?.userId??null,M.map(u=>u.id))}});return{normalizedOptions:o,expandedGroups:ee,selected:r,selectedIDs:d,hasOptions:p,active:te,hasActualValue:f,title:ne,valueOption:le,actions:se}}exports.NO_PICK=I;exports.default=oe;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { normalizeOptions as oe, resolveSelection as R, isPlain as de } from "./model.js";
|
|
3
|
+
import { useDeepStable as U, useStableActions as ie, deepEqual as ae } from "./state.js";
|
|
4
|
+
import { stopEvent as O } from "./utils.js";
|
|
5
|
+
import { useMemo as c } from "react";
|
|
6
|
+
const W = [];
|
|
7
|
+
function ge({ props: m, jsxOptions: M, state: X, setState: b, ext: I, setVisibility: G, loadMoreOnce: Y }) {
|
|
8
|
+
const { onChange: Z, disabled: y, loading: S, error: w, multiple: n, childrenFirst: A, groupsClosed: C, hasMore: k, loadButton: D, placeholder: T, selectedText: f, texts: d } = m, { disabledOption: V, emptyOption: x, invalidOption: z, emptyGroup: E, loadMore: H, loadingMore: P } = d, { loadPending: q, internalValue: $, toggledGroups: B, picked: F } = X, K = U(m.options), N = U(m.value), _ = N !== void 0, r = _ ? N : $, j = c(() => I.row?.({ hasMore: k, loadButton: D, loadPending: q, moreText: H, pendingText: P }) ?? null, [I, k, D, q, H, P]), o = c(() => oe({
|
|
9
|
+
options: K,
|
|
10
|
+
jsxOptions: M,
|
|
11
|
+
childrenFirst: A,
|
|
12
|
+
tail: j,
|
|
13
|
+
emptyOption: x,
|
|
14
|
+
invalidOption: z,
|
|
15
|
+
disabledOption: V,
|
|
16
|
+
emptyGroup: E
|
|
17
|
+
}), [K, M, A, j, x, z, V, E]), ee = c(() => new Set(
|
|
18
|
+
o.filter((e) => e.groupHeader && !e.disabled && C === B.has(e.name)).map((e) => e.name)
|
|
19
|
+
), [o, B, C]), { selected: s, selectedIDs: i } = c(() => R(r, o, n, F), [r, o, n, F]), g = o.length > 0, le = !y && g, p = r != null && !(Array.isArray(r) && !r.length) && !(de(r) && !Object.keys(r).length), te = p && f ? null : s, ne = c(() => p && f ? f : s ? s.name : w ? d.error : S ? d.loading : y ? d.disabled : g ? T : d.empty, [w, S, y, p, f, s, g, T, d]), J = (e) => b((l) => {
|
|
20
|
+
const t = new Set(l.toggledGroups);
|
|
21
|
+
return t.has(e) ? t.delete(e) : t.add(e), { toggledGroups: t };
|
|
22
|
+
}), h = (e, l, t) => {
|
|
23
|
+
b(_ ? { picked: t } : { internalValue: e, picked: t }), Z?.(e, l);
|
|
24
|
+
}, L = (e) => h(e.map((l) => l.original), e.map((l) => l.userId), e.map((l) => l.id)), re = ie({
|
|
25
|
+
toggleGroup: J,
|
|
26
|
+
selectOption: (e, l) => {
|
|
27
|
+
if (e.groupHeader) {
|
|
28
|
+
O(l), e.disabled || J(e.name);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (e.disabled || e.loadMore) {
|
|
32
|
+
O(l), e.loadMore && !e.loading && Y();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (n) {
|
|
36
|
+
O(l);
|
|
37
|
+
const t = i.some((a) => a.id === e.id);
|
|
38
|
+
L(t ? i.filter((a) => a.id !== e.id) : [...i, e]);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
s?.id !== e.id && h(e.original, e.userId, [e.id]), G(!1);
|
|
42
|
+
},
|
|
43
|
+
clear: (e) => {
|
|
44
|
+
O(e), h(n ? [] : null, n ? [] : null, W);
|
|
45
|
+
},
|
|
46
|
+
removeOption: (e) => L(i.filter((l) => l.id !== e)),
|
|
47
|
+
// [DOC: form-field]
|
|
48
|
+
reset: () => {
|
|
49
|
+
b({ deleting: !1, invalid: !1 }), G(!1);
|
|
50
|
+
const e = n ? [] : null, l = m.defaultValue ?? e, { selected: t, selectedIDs: a } = R(l, o, n, W), v = n ? a : t ? [t] : [], Q = n ? i : s ? [s] : [];
|
|
51
|
+
ae(r ?? e, l) && v.length === Q.length && v.every((u, se) => u.id === Q[se].id) || h(l, n ? v.map((u) => u.userId) : t?.userId ?? null, v.map((u) => u.id));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return { normalizedOptions: o, expandedGroups: ee, selected: s, selectedIDs: i, hasOptions: g, active: le, hasActualValue: p, title: ne, valueOption: te, actions: re };
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
W as NO_PICK,
|
|
58
|
+
ge as default
|
|
59
|
+
};
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),d=require("react"),p={XMark:({className:t="",...e})=>n.jsx("svg",{className:t,viewBox:"0 0 320 512",fill:"currentColor","aria-hidden":"true",height:"1em",width:"1em",...e,children:n.jsx("path",{d:"M310.6 361.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L160 301.3 54.6 406.6c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L114.7 256 9.4 150.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 210.7 265.4 105.4c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3L205.3 256l105.3 105.4z"})}),ArrowUp:({className:t="",...e})=>n.jsx("svg",{className:t,viewBox:"0 0 448 512",fill:"currentColor","aria-hidden":"true",height:"1em",width:"1em",...e,children:n.jsx("path",{d:"M34.9 289.5l175.9-175.8c9.4-9.4 24.6-9.4 33.9 0L420.1 289.5c15.1 15.1 4.4 41-17 41H51.9c-21.4 0-32.1-25.9-17-41z"})}),Checkmark:({className:t="",...e})=>n.jsx("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",height:"1em",width:"1em",...e,children:n.jsx("path",{d:"M20.285 6.708a1 1 0 0 0-1.414-1.416l-9.192 9.192-4.243-4.244a1 1 0 1 0-1.414 1.416l5 5a1 1 0 0 0 1.414 0l9.849-9.948z"})})},j=(t,e)=>{if(!t)return null;const i=(s={})=>({...e,...s,style:{...e?.style,...s?.style}});if(typeof t=="string")return n.jsx("img",{src:t,...i(),className:u("rac-icon",e?.className),alt:""});if(d.isValidElement(t))return d.cloneElement(t,i(t.props));if(typeof t=="function"||typeof t=="object"&&t.$$typeof){const s=t;return n.jsx(s,{...i()})}return null},v=(t,e)=>`${t}-${String(e).replace(/[^A-Za-z0-9-]/gu,i=>`_${i.codePointAt(0).toString(36)}_`)}`,m=t=>t?"":void 0,u=(t,e)=>e?`${t} ${e}`:t,y=(t,e,i)=>t.jsx||(e&&"original"in t?e(t.original,{selected:i,disabled:!!t.disabled}):null),E=n.jsxs("span",{className:"rac-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),C=(()=>{try{return process.env.NODE_ENV!=="production"}catch{return!1}})(),h=new Set,M=(t,e)=>{!C||h.has(t)||(h.add(t),console.warn(`[react-animated-select] ${e}`))},b=t=>{t?.stopPropagation(),t?.preventDefault()},$=(t,e)=>{t?.currentTarget.contains(document.activeElement)&&e.current?.focus()},g="(prefers-reduced-motion: reduce)",f=()=>!!window.matchMedia?.(g).matches,S=t=>{const e=window.matchMedia?.(g);return e?.addEventListener("change",t),()=>e?.removeEventListener("change",t)},D=(t,e,i,s,w,r)=>{if(!t||i===e.value)return;const o=getComputedStyle(t),c=e.anim?o.height:e.root;e.anim?.cancel(),r&&Object.assign(r.style,{height:`${i}px`,boxSizing:"border-box"}),e.root=o.height,r&&Object.assign(r.style,{height:"",boxSizing:""});const x=!e.value||c===e.root||!t.animate||f();if(e.value=i,e.anim=null,x)return;const a={overflow:"hidden",alignItems:"flex-start"},l=e.anim=t.animate([{...a,height:c},{...a,height:e.root}],{duration:s,easing:w});l.onfinish=()=>{e.anim===l&&(e.anim=null)}};exports.dots=E;exports.flag=m;exports.followHeight=D;exports.icons=p;exports.optionContent=y;exports.optionDomId=v;exports.reducedMotion=f;exports.refocus=$;exports.renderIcon=j;exports.stopEvent=b;exports.warnOnce=M;exports.watchMotion=S;exports.withClass=u;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as i, jsxs as f } from "react/jsx-runtime";
|
|
3
|
+
import { isValidElement as p, cloneElement as w } from "react";
|
|
4
|
+
const C = {
|
|
5
|
+
XMark: ({ className: t = "", ...e }) => /* @__PURE__ */ i(
|
|
6
|
+
"svg",
|
|
7
|
+
{
|
|
8
|
+
className: t,
|
|
9
|
+
viewBox: "0 0 320 512",
|
|
10
|
+
fill: "currentColor",
|
|
11
|
+
"aria-hidden": "true",
|
|
12
|
+
height: "1em",
|
|
13
|
+
width: "1em",
|
|
14
|
+
...e,
|
|
15
|
+
children: /* @__PURE__ */ i("path", { d: "M310.6 361.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L160 301.3 54.6 406.6c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L114.7 256 9.4 150.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 210.7 265.4 105.4c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3L205.3 256l105.3 105.4z" })
|
|
16
|
+
}
|
|
17
|
+
),
|
|
18
|
+
ArrowUp: ({ className: t = "", ...e }) => /* @__PURE__ */ i(
|
|
19
|
+
"svg",
|
|
20
|
+
{
|
|
21
|
+
className: t,
|
|
22
|
+
viewBox: "0 0 448 512",
|
|
23
|
+
fill: "currentColor",
|
|
24
|
+
"aria-hidden": "true",
|
|
25
|
+
height: "1em",
|
|
26
|
+
width: "1em",
|
|
27
|
+
...e,
|
|
28
|
+
children: /* @__PURE__ */ i("path", { d: "M34.9 289.5l175.9-175.8c9.4-9.4 24.6-9.4 33.9 0L420.1 289.5c15.1 15.1 4.4 41-17 41H51.9c-21.4 0-32.1-25.9-17-41z" })
|
|
29
|
+
}
|
|
30
|
+
),
|
|
31
|
+
Checkmark: ({ className: t = "", ...e }) => /* @__PURE__ */ i(
|
|
32
|
+
"svg",
|
|
33
|
+
{
|
|
34
|
+
className: t,
|
|
35
|
+
viewBox: "0 0 24 24",
|
|
36
|
+
fill: "currentColor",
|
|
37
|
+
"aria-hidden": "true",
|
|
38
|
+
height: "1em",
|
|
39
|
+
width: "1em",
|
|
40
|
+
...e,
|
|
41
|
+
children: /* @__PURE__ */ i("path", { d: "M20.285 6.708a1 1 0 0 0-1.414-1.416l-9.192 9.192-4.243-4.244a1 1 0 1 0-1.414 1.416l5 5a1 1 0 0 0 1.414 0l9.849-9.948z" })
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
}, $ = (t, e) => {
|
|
45
|
+
if (!t) return null;
|
|
46
|
+
const n = (r = {}) => ({
|
|
47
|
+
...e,
|
|
48
|
+
...r,
|
|
49
|
+
style: {
|
|
50
|
+
...e?.style,
|
|
51
|
+
...r?.style
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return typeof t == "string" ? /* @__PURE__ */ i("img", { src: t, ...n(), className: m("rac-icon", e?.className), alt: "" }) : p(t) ? w(t, n(t.props)) : typeof t == "function" || typeof t == "object" && t.$$typeof ? /* @__PURE__ */ i(t, { ...n() }) : null;
|
|
55
|
+
}, M = (t, e) => `${t}-${String(e).replace(/[^A-Za-z0-9-]/gu, (n) => `_${n.codePointAt(0).toString(36)}_`)}`, b = (t) => t ? "" : void 0, m = (t, e) => e ? `${t} ${e}` : t, L = (t, e, n) => t.jsx || (e && "original" in t ? e(t.original, { selected: n, disabled: !!t.disabled }) : null), j = /* @__PURE__ */ f("span", { className: "rac-dots", "aria-hidden": "true", children: [
|
|
56
|
+
/* @__PURE__ */ i("i", {}),
|
|
57
|
+
/* @__PURE__ */ i("i", {}),
|
|
58
|
+
/* @__PURE__ */ i("i", {})
|
|
59
|
+
] }), v = (() => {
|
|
60
|
+
try {
|
|
61
|
+
return process.env.NODE_ENV !== "production";
|
|
62
|
+
} catch {
|
|
63
|
+
return !1;
|
|
64
|
+
}
|
|
65
|
+
})(), d = /* @__PURE__ */ new Set(), z = (t, e) => {
|
|
66
|
+
!v || d.has(t) || (d.add(t), console.warn(`[react-animated-select] ${e}`));
|
|
67
|
+
}, D = (t) => {
|
|
68
|
+
t?.stopPropagation(), t?.preventDefault();
|
|
69
|
+
}, S = (t, e) => {
|
|
70
|
+
t?.currentTarget.contains(document.activeElement) && e.current?.focus();
|
|
71
|
+
}, h = "(prefers-reduced-motion: reduce)", y = () => !!window.matchMedia?.(h).matches, N = (t) => {
|
|
72
|
+
const e = window.matchMedia?.(h);
|
|
73
|
+
return e?.addEventListener("change", t), () => e?.removeEventListener("change", t);
|
|
74
|
+
}, A = (t, e, n, r, u, s) => {
|
|
75
|
+
if (!t || n === e.value) return;
|
|
76
|
+
const o = getComputedStyle(t), c = e.anim ? o.height : e.root;
|
|
77
|
+
e.anim?.cancel(), s && Object.assign(s.style, { height: `${n}px`, boxSizing: "border-box" }), e.root = o.height, s && Object.assign(s.style, { height: "", boxSizing: "" });
|
|
78
|
+
const g = !e.value || c === e.root || !t.animate || y();
|
|
79
|
+
if (e.value = n, e.anim = null, g) return;
|
|
80
|
+
const a = { overflow: "hidden", alignItems: "flex-start" }, l = e.anim = t.animate([{ ...a, height: c }, { ...a, height: e.root }], { duration: r, easing: u });
|
|
81
|
+
l.onfinish = () => {
|
|
82
|
+
e.anim === l && (e.anim = null);
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export {
|
|
86
|
+
j as dots,
|
|
87
|
+
b as flag,
|
|
88
|
+
A as followHeight,
|
|
89
|
+
C as icons,
|
|
90
|
+
L as optionContent,
|
|
91
|
+
M as optionDomId,
|
|
92
|
+
y as reducedMotion,
|
|
93
|
+
S as refocus,
|
|
94
|
+
$ as renderIcon,
|
|
95
|
+
D as stopEvent,
|
|
96
|
+
z as warnOnce,
|
|
97
|
+
N as watchMotion,
|
|
98
|
+
m as withClass
|
|
99
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {FC, FunctionComponent, ReactNode, CSSProperties, ElementType, Ref, FocusEvent, AriaAttributes} from 'react'
|
|
1
|
+
import {FC, FunctionComponent, ReactNode, CSSProperties, ElementType, Ref, FocusEvent, KeyboardEvent, AriaAttributes} from 'react'
|
|
2
|
+
|
|
3
|
+
/** Live region message: a template with {label} / {n}, or a function for plural forms. */
|
|
4
|
+
export type LiveText = string | ((value: string | number) => string)
|
|
2
5
|
|
|
3
6
|
export interface SelectTexts {
|
|
4
7
|
empty: string
|
|
@@ -13,7 +16,21 @@ export interface SelectTexts {
|
|
|
13
16
|
invalidOption: string
|
|
14
17
|
disabledOption: string
|
|
15
18
|
emptyGroup: string
|
|
19
|
+
/** State word in a group header's accessible name. Default `'expanded'`. */
|
|
20
|
+
groupOpen: string
|
|
21
|
+
/** State word in a group header's accessible name. Default `'collapsed'`. */
|
|
22
|
+
groupClosed: string
|
|
16
23
|
list: string
|
|
24
|
+
/** Validation bubble text of an empty required Select; default: the browser's own. */
|
|
25
|
+
required?: string
|
|
26
|
+
/** Default `'Removed {label}'`. */
|
|
27
|
+
removed?: LiveText
|
|
28
|
+
/** Default `'Selection cleared'`. */
|
|
29
|
+
cleared?: LiveText
|
|
30
|
+
/** Default `'{n} selected'`. */
|
|
31
|
+
selected?: LiveText
|
|
32
|
+
/** Default `'{n} more options loaded'`. */
|
|
33
|
+
loaded?: LiveText
|
|
17
34
|
}
|
|
18
35
|
|
|
19
36
|
export type SelectIcon = ElementType | string | ReactNode | null | false
|
|
@@ -32,9 +49,13 @@ export interface SelectProps extends AriaAttributes {
|
|
|
32
49
|
ref?: Ref<HTMLDivElement>
|
|
33
50
|
children?: ReactNode
|
|
34
51
|
|
|
52
|
+
/** A dictionary's values are the options, keys ignored; a key named name/label/id/value makes it one option, options/group a group. Array items take no className/style (use <Option/>). */
|
|
35
53
|
options?: any[] | Record<string, any>
|
|
54
|
+
/** undefined = uncontrolled; keep one mode, clear a controlled Select with null / [] (a switch warns in dev). */
|
|
36
55
|
value?: any
|
|
56
|
+
/** Initial value of an uncontrolled Select; also the target of form.reset(), in both modes, with or without name. */
|
|
37
57
|
defaultValue?: any
|
|
58
|
+
/** value: an array item as given (an object stays the whole object), an <Option/> as its `value`; a controlled value must have the shape of its source. */
|
|
38
59
|
onChange?: (value: any, ids: any) => void
|
|
39
60
|
multiple?: boolean
|
|
40
61
|
childrenFirst?: boolean
|
|
@@ -46,11 +67,17 @@ export interface SelectProps extends AriaAttributes {
|
|
|
46
67
|
|
|
47
68
|
open?: boolean
|
|
48
69
|
onOpenChange?: (open: boolean) => void
|
|
70
|
+
/** false: no panel, a tag list: role="group" without the combobox ARIA, never opens, no arrow; chip deletion and clear keep working. Default true. */
|
|
71
|
+
popup?: boolean
|
|
49
72
|
onFocus?: (e: FocusEvent<HTMLDivElement>) => void
|
|
50
73
|
onBlur?: (e: FocusEvent<HTMLDivElement>) => void
|
|
74
|
+
/** Runs before the Select handles a key; event.preventDefault() makes the Select skip it. */
|
|
75
|
+
onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void
|
|
51
76
|
|
|
52
77
|
id?: string
|
|
53
78
|
name?: string
|
|
79
|
+
/** Id of the owner <form>, like <select form="id">: submits and resets with it even when placed outside. */
|
|
80
|
+
form?: string
|
|
54
81
|
required?: boolean
|
|
55
82
|
|
|
56
83
|
hasMore?: boolean
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-animated-select",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "l1nway",
|
|
@@ -39,20 +39,20 @@
|
|
|
39
39
|
"prepublishOnly": "npm run build"
|
|
40
40
|
},
|
|
41
41
|
"main": "./dist/index.cjs",
|
|
42
|
-
"module": "./dist/index.
|
|
42
|
+
"module": "./dist/index.js",
|
|
43
43
|
"types": "./index.d.ts",
|
|
44
44
|
"exports": {
|
|
45
45
|
".": {
|
|
46
46
|
"import": {
|
|
47
47
|
"types": "./index.d.ts",
|
|
48
|
-
"default": "./dist/index.
|
|
48
|
+
"default": "./dist/index.js"
|
|
49
49
|
},
|
|
50
50
|
"require": {
|
|
51
51
|
"types": "./dist/index.d.cts",
|
|
52
52
|
"default": "./dist/index.cjs"
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
-
"./style.css": "./dist/
|
|
55
|
+
"./style.css": "./dist/style.css",
|
|
56
56
|
"./package.json": "./package.json"
|
|
57
57
|
},
|
|
58
58
|
"sideEffects": [
|
package/dist/index.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer rac.base,rac.theme;@property --rac-list-max-height{syntax: "<length>"; inherits: true; initial-value: 250px;}@layer rac.base{:root{--rac-row: 2em}.rac-select,.rac-options{--rac-duration-fast: calc(var(--rac-duration) * .5)}@media(prefers-reduced-motion:reduce){.rac-select,.rac-options{--rac-duration: 1ms !important}.rac-dots i{animation:none}}.rac-select{position:relative;display:flex;align-items:center;box-sizing:border-box;min-width:0;max-width:100%;cursor:pointer}.rac-select:not([aria-haspopup]){cursor:default}.rac-select[aria-busy=true]{cursor:progress}.rac-select[aria-disabled=true]{cursor:not-allowed}.rac-select[aria-disabled=true][aria-busy=true]{cursor:wait}.rac-value{flex:1;min-width:0;min-height:var(--rac-row);display:flex;flex-wrap:wrap;align-items:center}.rac-title{max-width:calc(100% - .25px);white-space:nowrap}.rac-title,.rac-chip-text,.rac-chip>.rac-option-jsx{min-width:0;overflow-x:clip}.rac-title,.rac-chip-text{text-overflow:ellipsis}.rac-dots{display:inline-flex;gap:.17em;margin-inline-start:.25em}.rac-dots i{width:.25em;height:.25em;border-radius:50%;background:currentColor;animation:rac-blink 1.4s infinite both}.rac-dots i:nth-child(2){animation-delay:.2s}.rac-dots i:nth-child(3){animation-delay:.4s}.rac-clear,.rac-arrow{display:grid;place-items:center;align-self:center}.rac-clear,.rac-chip-del{padding:0;border:0;background:none;color:inherit;font:inherit;cursor:pointer}.rac-arrow,.rac-group-arrow{transition:rotate var(--rac-duration) var(--rac-ease)}.rac-select:not([data-placement=top],[aria-expanded=true]) .rac-arrow,.rac-select[data-placement=top][aria-expanded=true] .rac-arrow{rotate:180deg}.rac-icon{height:1em}.rac-input{position:absolute;inset:0;box-sizing:border-box;width:100%;height:100%;margin:0;padding:0;border:0;opacity:0;pointer-events:none}.rac-live{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.rac-chip-slot{display:flex;align-items:center;max-width:100%}.rac-chip{position:relative;display:inline-flex;flex-shrink:0;align-items:center;box-sizing:border-box;max-width:inherit;white-space:nowrap;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;touch-action:pan-y}.rac-chip-del{position:absolute;flex-shrink:0;inset-inline-end:0;height:100%;display:grid;align-items:center}.rac-chip-del:disabled{cursor:inherit}.rac-select:is([data-deleting],[data-inline-delete]) .rac-chip-del{position:relative}@media(any-pointer:coarse){.rac-clear{position:relative}.rac-arrow{pointer-events:none}.rac-clear:before,.rac-chip-del:before{content:"";position:absolute;inset:min(0px,50% - 12px)}}.rac-spacer{flex-basis:100%;height:0;margin-inline-end:1px}.rac-options{box-sizing:border-box;z-index:2147483647;overflow:clip}.rac-options{transition:opacity var(--rac-duration) var(--rac-ease),visibility 0s}.rac-options[data-offscreen]{opacity:0;visibility:hidden;transition-delay:0s,var(--rac-duration)}.rac-list{max-height:var(--rac-list-max-height);overflow-x:hidden;overflow-y:auto;scrollbar-gutter:stable;scroll-behavior:smooth}.rac-option{display:flex;justify-content:space-between;align-items:center;overflow-wrap:anywhere;cursor:pointer}.rac-option[aria-disabled=true]{cursor:not-allowed}.rac-option[data-error]{cursor:default}.rac-option[data-loading]{justify-content:start;align-items:baseline;cursor:wait}.rac-check{position:relative;display:flex;justify-content:center;align-items:center}.rac-check[data-default]{width:1em;height:1em;border:1px solid}.rac-checkmark{position:absolute;width:auto;height:1em;opacity:0;scale:0;transition:opacity var(--rac-duration) var(--rac-ease),scale var(--rac-duration) var(--rac-ease)}.rac-option[aria-selected=true] .rac-checkmark{opacity:1;scale:1}.rac-group{display:flex;justify-content:space-between;align-items:center;cursor:pointer}.rac-group[data-disabled]{cursor:not-allowed}.rac-group-arrow{display:grid}.rac-group[data-open]>.rac-group-arrow{rotate:180deg}@keyframes rac-blink{0%{opacity:.2}20%{opacity:1}to{opacity:.2}}}@layer rac.base,rac.theme;@layer rac.theme{:root{--rac-bg: color-mix(in srgb, Canvas 98%, CanvasText 2%);--rac-fg: CanvasText;--rac-danger: #e7000b;--rac-success: #4caf50;--rac-radius: 0px}.rac-select,.rac-options{--rac-tint-1: color-mix(in srgb, var(--rac-fg) 5%, var(--rac-bg));--rac-tint-2: color-mix(in srgb, var(--rac-fg) 10%, var(--rac-bg));--rac-tint-3: color-mix(in srgb, var(--rac-fg) 20%, var(--rac-bg));--rac-muted: color-mix(in srgb, var(--rac-fg) 55%, var(--rac-bg))}.rac-select,.rac-options{border-radius:var(--rac-radius)}.rac-select{padding:0 .5em;border:2px solid var(--rac-bg);background-color:var(--rac-bg);color:var(--rac-fg);transition:background-color var(--rac-duration) var(--rac-ease),border-color var(--rac-duration) var(--rac-ease),opacity var(--rac-duration) var(--rac-ease)}.rac-select[aria-haspopup]:not([aria-disabled=true]):hover{background-color:var(--rac-tint-1)}.rac-select[aria-haspopup]:not([aria-disabled=true],[data-error],[data-invalid]):hover{border-color:var(--rac-tint-1)}.rac-select[aria-disabled=true]{opacity:.75}.rac-select:is([data-error],[data-invalid]){border-color:var(--rac-danger)}.rac-select[aria-busy=true]:after{content:"";position:absolute;inset:0;border-radius:inherit;background:linear-gradient(90deg,transparent,var(--rac-muted),transparent) 0 100% / 40% 2px no-repeat;animation:rac-busy 1.5s ease-in-out infinite;pointer-events:none}@media(prefers-reduced-motion:reduce){.rac-select[aria-busy=true]:after{animation:none;background-size:100% 2px}}:is(.rac-title,.rac-option)[data-bool=true]{color:var(--rac-success)}:is(.rac-title,.rac-option)[data-bool=false]{color:var(--rac-danger)}.rac-chip{min-height:calc(var(--rac-row) - .5em);margin-block:.25em;margin-inline-end:.5em;padding-inline:.25em;border-radius:calc(var(--rac-radius) / 2);line-height:normal;background-color:var(--rac-tint-2);transition:background-color var(--rac-duration-fast) var(--rac-ease)}@media(hover:hover){.rac-chip:hover{background-color:var(--rac-tint-3)}}.rac-select[data-deleting] .rac-chip{background-color:color-mix(in srgb,var(--rac-danger) 15%,var(--rac-bg));animation:rac-shake .3s infinite}@media(prefers-reduced-motion:reduce){.rac-select[data-deleting] .rac-chip{animation:none}}.rac-chip-del{border-start-end-radius:inherit;border-end-end-radius:inherit;background-color:color-mix(in srgb,var(--rac-danger) 30%,var(--rac-bg));transition:color var(--rac-duration) var(--rac-ease),background-color var(--rac-duration) var(--rac-ease)}.rac-chip-del:hover{color:var(--rac-danger)}.rac-select:is([data-deleting],[data-inline-delete]) .rac-chip-del{background-color:transparent}.rac-list{background-color:var(--rac-bg);color:var(--rac-fg);scrollbar-color:var(--rac-tint-2) var(--rac-tint-1);scrollbar-width:thin;scroll-padding-block:.5em}.rac-option{gap:.5em;padding:.5em;transition:background-color var(--rac-duration-fast) var(--rac-ease)}.rac-option[data-highlighted]{background-color:var(--rac-tint-2)}.rac-option[aria-selected=true]{background-color:var(--rac-tint-3)}.rac-option[aria-selected=true][data-highlighted]{background-color:color-mix(in srgb,var(--rac-fg) 30%,var(--rac-bg))}.rac-option[aria-disabled=true]{color:var(--rac-muted)}.rac-option[data-invalid]{color:var(--rac-danger)}.rac-option[data-loading]{gap:0;color:var(--rac-muted)}.rac-option[data-error]{color:var(--rac-danger)}.rac-check{margin-inline-end:.2em}.rac-check[data-default]{border-color:var(--rac-muted)}.rac-group{padding:.5em;font-size:1.25em;font-weight:700;transition:background-color var(--rac-duration-fast) var(--rac-ease)}.rac-group[data-highlighted]{background-color:var(--rac-tint-2)}.rac-group[data-disabled]{color:var(--rac-muted)}.rac-group-items{padding-inline-start:1em}@keyframes rac-busy{0%{background-position-x:-100%}to{background-position-x:200%}}@keyframes rac-shake{0%{transform:rotate(0)}25%{transform:rotate(-1deg)}75%{transform:rotate(1deg)}to{transform:rotate(0)}}}
|