react-animated-select 0.7.5 → 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 -1096
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[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{min-width:0;overflow-x:clip;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[data-placement=bottom]:not([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-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}.rac-spacer{flex-basis:100%;height:0;margin-inline-end:1px}.rac-options{box-sizing:border-box;z-index:2147483647}.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-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{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:not([aria-disabled=true]):hover{background-color:var(--rac-tint-1)}.rac-select:not([aria-disabled=true],[data-error]):hover{border-color:var(--rac-tint-1)}.rac-select[aria-disabled=true]{opacity:.75}.rac-select[data-error]{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;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{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)}}}
|