asheeui 0.6.10 → 0.6.13
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/components/accordion/Accordion.js +7 -7
- package/dist/components/autocomplete/Autocomplete.d.ts +5 -5
- package/dist/components/autocomplete/Autocomplete.d.ts.map +1 -1
- package/dist/components/autocomplete/Autocomplete.js +42 -41
- package/dist/components/carousel/Carousel.js +43 -43
- package/dist/components/chip/Chip.js +8 -8
- package/dist/components/date-picker/Calendar.d.ts +6 -1
- package/dist/components/date-picker/Calendar.d.ts.map +1 -1
- package/dist/components/date-picker/Calendar.js +30 -30
- package/dist/components/date-picker/DatePicker.d.ts +7 -6
- package/dist/components/date-picker/DatePicker.d.ts.map +1 -1
- package/dist/components/date-picker/DatePicker.js +166 -155
- package/dist/components/date-picker/date-picker-config.d.ts +12 -1
- package/dist/components/date-picker/date-picker-config.d.ts.map +1 -1
- package/dist/components/marquee/Marquee.js +22 -22
- package/dist/components/multi-select/MultiSelect.d.ts +5 -5
- package/dist/components/multi-select/MultiSelect.d.ts.map +1 -1
- package/dist/components/multi-select/MultiSelect.js +45 -44
- package/dist/components/select/Select.d.ts +5 -5
- package/dist/components/select/Select.d.ts.map +1 -1
- package/dist/components/select/Select.js +117 -114
- package/dist/components/select-menu/SelectMenu.d.ts +20 -11
- package/dist/components/select-menu/SelectMenu.d.ts.map +1 -1
- package/dist/components/select-menu/SelectMenu.js +146 -109
- package/dist/components/select-menu/select-menu-config.d.ts +8 -4
- package/dist/components/select-menu/select-menu-config.d.ts.map +1 -1
- package/dist/components/select-menu/select-menu-config.js +1 -1
- package/dist/components/select-menu/use-select-floating.d.ts +46 -17
- package/dist/components/select-menu/use-select-floating.d.ts.map +1 -1
- package/dist/components/select-menu/use-select-floating.js +36 -22
- package/dist/components/toast/ToastItem.js +30 -30
- package/dist/components/toast/ToastProvider.d.ts +5 -5
- package/dist/components/toast/ToastProvider.d.ts.map +1 -1
- package/dist/components/toast/ToastProvider.js +66 -66
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/theme/controller.d.ts.map +1 -1
- package/dist/theme/controller.js +14 -16
- package/package.json +3 -20
|
@@ -1,161 +1,198 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { FloatingFocusManager as
|
|
4
|
-
import { useState as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { Input as P } from "../input/Input.js";
|
|
2
|
+
import { jsx as l, jsxs as A, Fragment as Z } from "react/jsx-runtime";
|
|
3
|
+
import { FloatingFocusManager as u, FloatingPortal as m } from "@floating-ui/react";
|
|
4
|
+
import { useState as p, useEffect as g, useMemo as C, memo as P } from "react";
|
|
5
|
+
import { CheckIcon as tt } from "../../icons/CheckIcon.js";
|
|
6
|
+
import { SearchIcon as et } from "../../icons/SearchIcon.js";
|
|
7
|
+
import { useAsheeConfig as lt } from "../../libs/context.js";
|
|
8
|
+
import { resolveCascade as a, resolveRadiusKey as ot } from "../../utils/resolve-token.js";
|
|
9
|
+
import { Button as rt } from "../button/Button.js";
|
|
10
|
+
import { Input as at } from "../input/Input.js";
|
|
12
11
|
import { FALLBACK_SELECT_MENU_CONFIG as d } from "./select-menu-config.js";
|
|
13
|
-
import { cn as
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
12
|
+
import { cn as dt } from "../../utils/cn.js";
|
|
13
|
+
const ct = P(function({
|
|
14
|
+
filteredOptions: v,
|
|
15
|
+
selectedValues: w,
|
|
16
|
+
onSelectMenuOption: x,
|
|
17
|
+
renderOption: b,
|
|
18
|
+
itemVariant: I,
|
|
19
|
+
itemColor: i,
|
|
20
|
+
activeItemVariant: f,
|
|
21
|
+
activeItemColor: N,
|
|
22
|
+
radius: s,
|
|
23
|
+
size: S
|
|
24
|
+
}) {
|
|
25
|
+
const V = (o) => w.includes(o);
|
|
26
|
+
return v.length === 0 ? /* @__PURE__ */ l("div", { className: "px-3 py-4 text-xs text-foreground/70 text-center", children: "No options found" }) : /* @__PURE__ */ l(Z, { children: v.map((o) => {
|
|
27
|
+
const c = V(o.value);
|
|
28
|
+
return b ? b(o, c) : /* @__PURE__ */ A(
|
|
29
|
+
rt,
|
|
30
|
+
{
|
|
31
|
+
variant: c ? f : I,
|
|
32
|
+
color: c ? N : i,
|
|
33
|
+
radius: s,
|
|
34
|
+
size: S,
|
|
35
|
+
isDisabled: o.disabled,
|
|
36
|
+
onClick: () => x(o),
|
|
37
|
+
className: "w-full justify-between font-normal text-left transition-colors truncate",
|
|
38
|
+
children: [
|
|
39
|
+
/* @__PURE__ */ l("span", { children: o.label }),
|
|
40
|
+
c && /* @__PURE__ */ l(tt, { className: "w-3.5 h-3.5 shrink-0 ml-2" })
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
String(o.value)
|
|
44
|
+
);
|
|
45
|
+
}) });
|
|
46
|
+
}), it = ({
|
|
47
|
+
isOpen: y,
|
|
48
|
+
floatingStyles: v,
|
|
49
|
+
context: w,
|
|
50
|
+
getFloatingProps: x,
|
|
51
|
+
setFloatingRef: b,
|
|
52
|
+
isPositioned: I = !0,
|
|
53
|
+
options: i = [],
|
|
54
|
+
selectedValues: f = [],
|
|
55
|
+
onSelectMenuOption: N,
|
|
56
|
+
isSearch: s = !0,
|
|
57
|
+
searchPlaceholder: S = "Search...",
|
|
58
|
+
searchInputName: V = "select-menu-search",
|
|
59
|
+
searchQuery: o,
|
|
60
|
+
onSearchChange: c,
|
|
61
|
+
belowList: k,
|
|
62
|
+
menuConfig: e,
|
|
30
63
|
menuProps: t = {},
|
|
31
|
-
renderOption:
|
|
32
|
-
initialFocus:
|
|
33
|
-
returnFocus:
|
|
64
|
+
renderOption: E,
|
|
65
|
+
initialFocus: Q,
|
|
66
|
+
returnFocus: R
|
|
34
67
|
}) => {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
},
|
|
68
|
+
const h = lt(), [j, K] = p(""), n = o ?? j, _ = (r) => {
|
|
69
|
+
c ? c(r) : K(r);
|
|
70
|
+
}, z = a(
|
|
38
71
|
t == null ? void 0 : t.lockScroll,
|
|
39
|
-
|
|
72
|
+
e == null ? void 0 : e.lockScroll,
|
|
40
73
|
void 0,
|
|
41
74
|
d.lockScroll
|
|
42
|
-
),
|
|
75
|
+
), B = a(
|
|
43
76
|
t == null ? void 0 : t.portal,
|
|
44
|
-
|
|
77
|
+
e == null ? void 0 : e.portal,
|
|
45
78
|
void 0,
|
|
46
79
|
d.portal
|
|
47
|
-
),
|
|
80
|
+
), O = a(
|
|
48
81
|
t == null ? void 0 : t.portalTarget,
|
|
49
|
-
|
|
82
|
+
e == null ? void 0 : e.portalTarget,
|
|
50
83
|
void 0,
|
|
51
84
|
typeof document < "u" ? document.body : null
|
|
52
85
|
);
|
|
53
|
-
|
|
54
|
-
if (!
|
|
55
|
-
const
|
|
56
|
-
return document.body.style.
|
|
57
|
-
document.body.style.
|
|
86
|
+
g(() => {
|
|
87
|
+
if (!y || !z) return;
|
|
88
|
+
const r = window.scrollY, W = document.body.style.position, $ = document.body.style.top, q = document.body.style.left, H = document.body.style.right, J = document.body.style.width, X = document.body.style.overflow;
|
|
89
|
+
return document.body.style.position = "fixed", document.body.style.top = `-${r}px`, document.body.style.left = "0", document.body.style.right = "0", document.body.style.width = "100%", document.body.style.overflow = "hidden", () => {
|
|
90
|
+
document.body.style.position = W, document.body.style.top = $, document.body.style.left = q, document.body.style.right = H, document.body.style.width = J, document.body.style.overflow = X, window.scrollTo(0, r);
|
|
58
91
|
};
|
|
59
|
-
}, [
|
|
60
|
-
const
|
|
61
|
-
(
|
|
62
|
-
), [
|
|
92
|
+
}, [y, z]);
|
|
93
|
+
const Y = C(() => !s || !n.trim() ? i : i.filter(
|
|
94
|
+
(r) => r.label.toLowerCase().includes(n.toLowerCase())
|
|
95
|
+
), [i, s, n]), D = a(
|
|
63
96
|
t == null ? void 0 : t.itemVariant,
|
|
64
|
-
|
|
97
|
+
e == null ? void 0 : e.itemVariant,
|
|
65
98
|
void 0,
|
|
66
99
|
d.itemVariant
|
|
67
|
-
),
|
|
100
|
+
), L = a(
|
|
68
101
|
t == null ? void 0 : t.itemColor,
|
|
69
|
-
|
|
70
|
-
|
|
102
|
+
e == null ? void 0 : e.itemColor,
|
|
103
|
+
h.defaultColor,
|
|
71
104
|
d.itemColor
|
|
72
|
-
),
|
|
105
|
+
), G = a(
|
|
73
106
|
t == null ? void 0 : t.activeItemVariant,
|
|
74
|
-
|
|
75
|
-
|
|
107
|
+
e == null ? void 0 : e.activeItemVariant,
|
|
108
|
+
h.defaultVariant,
|
|
76
109
|
d.activeItemVariant
|
|
77
|
-
),
|
|
110
|
+
), U = a(
|
|
78
111
|
t == null ? void 0 : t.activeItemColor,
|
|
79
|
-
|
|
80
|
-
|
|
112
|
+
e == null ? void 0 : e.activeItemColor,
|
|
113
|
+
h.defaultColor,
|
|
81
114
|
d.activeItemColor
|
|
82
|
-
),
|
|
115
|
+
), F = ot(
|
|
83
116
|
t == null ? void 0 : t.radius,
|
|
84
|
-
|
|
85
|
-
|
|
117
|
+
e == null ? void 0 : e.radius,
|
|
118
|
+
h.defaultRadius,
|
|
86
119
|
d.radius
|
|
87
|
-
),
|
|
120
|
+
), M = a(
|
|
88
121
|
t == null ? void 0 : t.size,
|
|
89
|
-
|
|
122
|
+
e == null ? void 0 : e.size,
|
|
90
123
|
void 0,
|
|
91
124
|
d.size
|
|
92
125
|
);
|
|
93
|
-
if (!
|
|
94
|
-
const
|
|
95
|
-
|
|
126
|
+
if (!y) return null;
|
|
127
|
+
const T = /* @__PURE__ */ l(
|
|
128
|
+
u,
|
|
96
129
|
{
|
|
97
|
-
context:
|
|
130
|
+
context: w,
|
|
98
131
|
modal: !1,
|
|
99
|
-
initialFocus:
|
|
100
|
-
returnFocus:
|
|
101
|
-
children: /* @__PURE__ */
|
|
132
|
+
initialFocus: Q,
|
|
133
|
+
returnFocus: R,
|
|
134
|
+
children: /* @__PURE__ */ A(
|
|
102
135
|
"div",
|
|
103
136
|
{
|
|
104
|
-
ref:
|
|
105
|
-
style: { ...
|
|
106
|
-
className:
|
|
107
|
-
"z-
|
|
108
|
-
|
|
137
|
+
ref: b,
|
|
138
|
+
style: { ...v },
|
|
139
|
+
className: dt(
|
|
140
|
+
"z-30 w-full outline-none max-h-60 shadow-xl bg-background border border-border p-1 flex flex-col gap-0.5 overflow-y-auto scrollable-hidden",
|
|
141
|
+
// Explicitly disable transitions on the floating element. Floating UI
|
|
142
|
+
// positions this node via a `transform` written on every scroll tick
|
|
143
|
+
// (through floatingStyles). If any transition — global, inherited, or
|
|
144
|
+
// otherwise — applies to `transform` on this element, the browser eases
|
|
145
|
+
// toward each new position instead of snapping to it, which compounds
|
|
146
|
+
// under rapid scroll ticks into a visible spring/bounce effect that
|
|
147
|
+
// worsens with scroll speed. transition-none guarantees position
|
|
148
|
+
// updates apply instantly.
|
|
149
|
+
"transition-none",
|
|
150
|
+
I ? "animate-in fade-in-0 zoom-in-95 slide-in-from-top-1 duration-150 ease-out" : "invisible opacity-0 pointer-events-none",
|
|
109
151
|
t == null ? void 0 : t.className
|
|
110
152
|
),
|
|
111
|
-
...
|
|
153
|
+
...x(),
|
|
112
154
|
children: [
|
|
113
|
-
|
|
114
|
-
|
|
155
|
+
s && /* @__PURE__ */ l("div", { className: "w-full p-1 mb-1 sticky top-0 z-10 border-b border-border", children: /* @__PURE__ */ l(
|
|
156
|
+
at,
|
|
115
157
|
{
|
|
116
|
-
name:
|
|
158
|
+
name: V,
|
|
117
159
|
type: "text",
|
|
118
160
|
variant: "bordered",
|
|
119
|
-
radius:
|
|
120
|
-
color:
|
|
121
|
-
size:
|
|
122
|
-
value:
|
|
123
|
-
onChange: (
|
|
124
|
-
startContent: /* @__PURE__ */
|
|
125
|
-
placeholder:
|
|
161
|
+
radius: F,
|
|
162
|
+
color: L,
|
|
163
|
+
size: M,
|
|
164
|
+
value: n,
|
|
165
|
+
onChange: (r) => _(r.target.value),
|
|
166
|
+
startContent: /* @__PURE__ */ l(et, { className: "w-3.5 h-3.5 text-foreground/70" }),
|
|
167
|
+
placeholder: S,
|
|
126
168
|
autoFocus: !0,
|
|
127
169
|
className: "w-full pl-8 h-8 text-xs bg-secondary/30 border-none focus-visible:ring-0"
|
|
128
170
|
}
|
|
129
171
|
) }),
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
},
|
|
147
|
-
String(e.value)
|
|
148
|
-
);
|
|
149
|
-
}),
|
|
150
|
-
h && /* @__PURE__ */ a("div", { className: "border-t border-border pt-1 mt-1", children: h })
|
|
172
|
+
/* @__PURE__ */ l(
|
|
173
|
+
ct,
|
|
174
|
+
{
|
|
175
|
+
filteredOptions: Y,
|
|
176
|
+
selectedValues: f,
|
|
177
|
+
onSelectMenuOption: N,
|
|
178
|
+
renderOption: E,
|
|
179
|
+
itemVariant: D,
|
|
180
|
+
itemColor: L,
|
|
181
|
+
activeItemVariant: G,
|
|
182
|
+
activeItemColor: U,
|
|
183
|
+
radius: F,
|
|
184
|
+
size: M
|
|
185
|
+
}
|
|
186
|
+
),
|
|
187
|
+
k && /* @__PURE__ */ l("div", { className: "border-t border-border pt-1 mt-1", children: k })
|
|
151
188
|
]
|
|
152
189
|
}
|
|
153
190
|
)
|
|
154
191
|
}
|
|
155
192
|
);
|
|
156
|
-
return
|
|
193
|
+
return B ? /* @__PURE__ */ l(m, { root: O, children: T }) : T;
|
|
157
194
|
};
|
|
158
|
-
|
|
195
|
+
it.displayName = "SelectMenu";
|
|
159
196
|
export {
|
|
160
|
-
|
|
197
|
+
it as SelectMenu
|
|
161
198
|
};
|
|
@@ -74,18 +74,22 @@ export interface MenuConfig {
|
|
|
74
74
|
activeItemColor?: Color;
|
|
75
75
|
/**
|
|
76
76
|
* Whether to lock body scroll when the dropdown is open.
|
|
77
|
-
* When true, the page behind the dropdown cannot scroll
|
|
78
|
-
*
|
|
77
|
+
* When true, the page behind the dropdown cannot scroll, using
|
|
78
|
+
* scroll-position-compensated `position: fixed` on `<body>` so the
|
|
79
|
+
* page doesn't jump. This prevents the page from scrolling while
|
|
80
|
+
* interacting with the dropdown.
|
|
79
81
|
*
|
|
80
|
-
* @default
|
|
82
|
+
* @default true
|
|
81
83
|
*/
|
|
82
84
|
lockScroll?: boolean;
|
|
83
85
|
/**
|
|
84
|
-
* Whether to render the menu
|
|
86
|
+
* Whether to render the menu through Floating UI's `FloatingPortal`.
|
|
85
87
|
* When true, the menu is rendered at the document body level.
|
|
86
88
|
* Defaults to true. This is typically controlled by the parent
|
|
87
89
|
* component (Select, MultiSelect, Autocomplete) via their own
|
|
88
90
|
* config or props.
|
|
91
|
+
*
|
|
92
|
+
* @see FloatingPortal - https://floating-ui.com/docs/FloatingPortal
|
|
89
93
|
*/
|
|
90
94
|
portal?: boolean;
|
|
91
95
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-menu-config.d.ts","sourceRoot":"","sources":["../../../src/components/select-menu/select-menu-config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAEvB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC;IAElB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC;IAExB
|
|
1
|
+
{"version":3,"file":"select-menu-config.d.ts","sourceRoot":"","sources":["../../../src/components/select-menu/select-menu-config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAEvB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC;IAElB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC;IAExB;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CACnC;AAED;;;;GAIG;AACH,eAAO,MAAM,2BAA2B;YACtB,MAAM;UACR,IAAI;iBACM,OAAO;eACP,KAAK;uBACC,OAAO;qBACP,KAAK;;;CAGpC,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Placement,
|
|
1
|
+
import { UseInteractionsReturn, Placement, useFloating } from '@floating-ui/react';
|
|
2
2
|
/**
|
|
3
3
|
* Configuration options for the useSelectFloating hook.
|
|
4
|
-
* Controls the floating element's behavior, positioning, and
|
|
4
|
+
* Controls the floating element's behavior, positioning, size, and
|
|
5
|
+
* interaction wiring (click-to-open, dismiss, and ARIA role).
|
|
5
6
|
*/
|
|
6
7
|
export interface UseSelectFloatingProps {
|
|
7
8
|
/**
|
|
@@ -16,7 +17,8 @@ export interface UseSelectFloatingProps {
|
|
|
16
17
|
onOpenChange: (open: boolean) => void;
|
|
17
18
|
/**
|
|
18
19
|
* Whether the floating element is disabled.
|
|
19
|
-
* When true, the floating element does not open
|
|
20
|
+
* When true, the floating element does not open and click interaction
|
|
21
|
+
* is disabled.
|
|
20
22
|
*
|
|
21
23
|
* @default false
|
|
22
24
|
*/
|
|
@@ -48,15 +50,39 @@ export interface UseSelectFloatingProps {
|
|
|
48
50
|
* @default true
|
|
49
51
|
*/
|
|
50
52
|
matchReferenceWidth?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* ARIA role applied to the floating element via useRole.
|
|
55
|
+
* "listbox" fits Select/MultiSelect/Autocomplete; a component like
|
|
56
|
+
* DatePicker reusing this hook can pass "dialog" instead.
|
|
57
|
+
*
|
|
58
|
+
* @default "listbox"
|
|
59
|
+
*/
|
|
60
|
+
role?: "listbox" | "menu" | "dialog" | "tooltip" | "grid" | "tree";
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Return value of useSelectFloating. Combines Floating UI's positioning
|
|
64
|
+
* context with the resolved interaction prop-getters, so consumers don't
|
|
65
|
+
* need to wire useClick/useDismiss/useRole/useInteractions themselves.
|
|
66
|
+
*/
|
|
67
|
+
export interface UseSelectFloatingReturn<T extends HTMLElement> {
|
|
68
|
+
refs: ReturnType<typeof useFloating<T>>["refs"];
|
|
69
|
+
context: ReturnType<typeof useFloating<T>>["context"];
|
|
70
|
+
floatingStyles: React.CSSProperties;
|
|
71
|
+
isPositioned: boolean;
|
|
72
|
+
getReferenceProps: UseInteractionsReturn["getReferenceProps"];
|
|
73
|
+
getFloatingProps: UseInteractionsReturn["getFloatingProps"];
|
|
51
74
|
}
|
|
52
75
|
/**
|
|
53
|
-
* Shared Floating UI positioning hook for dropdowns and
|
|
54
|
-
* Generic `T` allows passing `HTMLButtonElement`, `HTMLInputElement`,
|
|
76
|
+
* Shared Floating UI positioning and interaction hook for dropdowns and
|
|
77
|
+
* menus. Generic `T` allows passing `HTMLButtonElement`, `HTMLInputElement`,
|
|
78
|
+
* etc.
|
|
55
79
|
*
|
|
56
80
|
* This hook configures Floating UI with sensible defaults for dropdown
|
|
57
|
-
* components
|
|
58
|
-
*
|
|
59
|
-
*
|
|
81
|
+
* components: viewport edge detection via flip and shift middleware,
|
|
82
|
+
* optional width matching of the reference element, and the standard
|
|
83
|
+
* click-to-open / dismiss / ARIA role interaction set via useInteractions.
|
|
84
|
+
* Consumers get back ready-to-spread `getReferenceProps`/`getFloatingProps`
|
|
85
|
+
* instead of wiring useClick/useDismiss/useRole themselves.
|
|
60
86
|
*
|
|
61
87
|
* @param props - Configuration options for the floating element.
|
|
62
88
|
* @param props.isOpen - Whether the floating element is open.
|
|
@@ -66,21 +92,24 @@ export interface UseSelectFloatingProps {
|
|
|
66
92
|
* @param props.offsetDistance - Distance from reference in pixels. Defaults to 4.
|
|
67
93
|
* @param props.padding - Viewport padding for shift middleware. Defaults to 8.
|
|
68
94
|
* @param props.matchReferenceWidth - Whether to match reference width. Defaults to true.
|
|
69
|
-
* @
|
|
95
|
+
* @param props.role - ARIA role for the floating element. Defaults to "listbox".
|
|
96
|
+
* @returns Floating UI refs/context/styles plus `isPositioned` and the
|
|
97
|
+
* resolved `getReferenceProps`/`getFloatingProps` prop-getters.
|
|
70
98
|
*
|
|
71
99
|
* @example
|
|
72
100
|
* ```tsx
|
|
73
|
-
* const { refs, floatingStyles,
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
101
|
+
* const { refs, context, floatingStyles, getReferenceProps, getFloatingProps } =
|
|
102
|
+
* useSelectFloating({
|
|
103
|
+
* isOpen,
|
|
104
|
+
* onOpenChange: setIsOpen,
|
|
105
|
+
* disabled: props.disabled,
|
|
106
|
+
* });
|
|
78
107
|
*
|
|
79
108
|
* return (
|
|
80
109
|
* <>
|
|
81
|
-
* <button ref={refs.setReference}>Toggle</button>
|
|
110
|
+
* <button ref={refs.setReference} {...getReferenceProps()}>Toggle</button>
|
|
82
111
|
* {isOpen && (
|
|
83
|
-
* <div ref={refs.setFloating} style={floatingStyles}>
|
|
112
|
+
* <div ref={refs.setFloating} style={floatingStyles} {...getFloatingProps()}>
|
|
84
113
|
* Content
|
|
85
114
|
* </div>
|
|
86
115
|
* )}
|
|
@@ -91,5 +120,5 @@ export interface UseSelectFloatingProps {
|
|
|
91
120
|
* @see useFloating - The underlying Floating UI hook.
|
|
92
121
|
* @see Select - The select component that uses this hook.
|
|
93
122
|
*/
|
|
94
|
-
export declare function useSelectFloating<T extends HTMLElement = HTMLElement>({ isOpen, onOpenChange, disabled, placement, offsetDistance, padding, matchReferenceWidth, }: UseSelectFloatingProps):
|
|
123
|
+
export declare function useSelectFloating<T extends HTMLElement = HTMLElement>({ isOpen, onOpenChange, disabled, placement, offsetDistance, padding, matchReferenceWidth, role, }: UseSelectFloatingProps): UseSelectFloatingReturn<T>;
|
|
95
124
|
//# sourceMappingURL=use-select-floating.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-select-floating.d.ts","sourceRoot":"","sources":["../../../src/components/select-menu/use-select-floating.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-select-floating.d.ts","sourceRoot":"","sources":["../../../src/components/select-menu/use-select-floating.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAIL,KAAK,SAAS,EAKd,WAAW,EAGZ,MAAM,oBAAoB,CAAC;AAE5B;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAEtC;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;CACpE;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,WAAW;IAC5D,IAAI,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAChD,OAAO,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACtD,cAAc,EAAE,KAAK,CAAC,aAAa,CAAC;IACpC,YAAY,EAAE,OAAO,CAAC;IACtB,iBAAiB,EAAE,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;IAC9D,gBAAgB,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;CAC7D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,EACrE,MAAM,EACN,YAAY,EACZ,QAAgB,EAChB,SAA0B,EAC1B,cAAkB,EAClB,OAAW,EACX,mBAA0B,EAC1B,IAAgB,GACjB,EAAE,sBAAsB,GAAG,uBAAuB,CAAC,CAAC,CAAC,CA2CrD"}
|
|
@@ -1,36 +1,50 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useFloating as
|
|
3
|
-
function
|
|
4
|
-
isOpen:
|
|
5
|
-
onOpenChange:
|
|
2
|
+
import { useFloating as h, autoUpdate as y, offset as w, flip as P, shift as b, size as C, useClick as F, useDismiss as R, useRole as S, useInteractions as k } from "@floating-ui/react";
|
|
3
|
+
function O({
|
|
4
|
+
isOpen: n,
|
|
5
|
+
onOpenChange: l,
|
|
6
6
|
disabled: o = !1,
|
|
7
7
|
placement: a = "bottom-start",
|
|
8
|
-
offsetDistance:
|
|
9
|
-
padding:
|
|
10
|
-
matchReferenceWidth:
|
|
8
|
+
offsetDistance: c = 4,
|
|
9
|
+
padding: r = 8,
|
|
10
|
+
matchReferenceWidth: f = !0,
|
|
11
|
+
role: g = "listbox"
|
|
11
12
|
}) {
|
|
12
|
-
|
|
13
|
-
open:
|
|
14
|
-
onOpenChange: (
|
|
13
|
+
const e = h({
|
|
14
|
+
open: n,
|
|
15
|
+
onOpenChange: (s) => !o && l(s),
|
|
15
16
|
placement: a,
|
|
16
|
-
|
|
17
|
+
strategy: "fixed",
|
|
18
|
+
whileElementsMounted: y,
|
|
17
19
|
middleware: [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
apply({ availableHeight:
|
|
23
|
-
Object.assign(
|
|
24
|
-
maxHeight: `${
|
|
25
|
-
...
|
|
26
|
-
width: `${
|
|
20
|
+
w(c),
|
|
21
|
+
P(),
|
|
22
|
+
b({ padding: r }),
|
|
23
|
+
C({
|
|
24
|
+
apply({ availableHeight: s, elements: i }) {
|
|
25
|
+
Object.assign(i.floating.style, {
|
|
26
|
+
maxHeight: `${s}px`,
|
|
27
|
+
...f && {
|
|
28
|
+
width: `${i.reference.getBoundingClientRect().width}px`
|
|
27
29
|
}
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
})
|
|
31
33
|
]
|
|
32
|
-
})
|
|
34
|
+
}), { context: t } = e, u = F(t, { enabled: !o }), p = R(t), d = S(t, { role: g }), { getReferenceProps: m, getFloatingProps: x } = k([
|
|
35
|
+
u,
|
|
36
|
+
p,
|
|
37
|
+
d
|
|
38
|
+
]);
|
|
39
|
+
return {
|
|
40
|
+
refs: e.refs,
|
|
41
|
+
context: t,
|
|
42
|
+
floatingStyles: e.floatingStyles,
|
|
43
|
+
isPositioned: e.isPositioned,
|
|
44
|
+
getReferenceProps: m,
|
|
45
|
+
getFloatingProps: x
|
|
46
|
+
};
|
|
33
47
|
}
|
|
34
48
|
export {
|
|
35
|
-
|
|
49
|
+
O as useSelectFloating
|
|
36
50
|
};
|