asheeui 0.6.12 → 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/autocomplete/Autocomplete.js +3 -3
- 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 +1 -1
- package/dist/components/date-picker/DatePicker.d.ts.map +1 -1
- package/dist/components/date-picker/DatePicker.js +167 -156
- 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/multi-select/MultiSelect.js +3 -3
- package/dist/components/select/Select.d.ts.map +1 -1
- package/dist/components/select/Select.js +107 -105
- package/dist/components/select-menu/SelectMenu.d.ts +6 -9
- package/dist/components/select-menu/SelectMenu.d.ts.map +1 -1
- package/dist/components/select-menu/SelectMenu.js +116 -107
- 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 -20
- package/dist/components/select-menu/use-select-floating.d.ts.map +1 -1
- package/dist/components/select-menu/use-select-floating.js +35 -28
- package/dist/theme/controller.d.ts.map +1 -1
- package/dist/theme/controller.js +14 -16
- package/package.json +1 -1
|
@@ -1,189 +1,198 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as l, jsxs as
|
|
3
|
-
import { FloatingFocusManager as
|
|
4
|
-
import { useState as
|
|
5
|
-
import { CheckIcon as
|
|
6
|
-
import { SearchIcon as
|
|
7
|
-
import { useAsheeConfig as
|
|
8
|
-
import { resolveCascade as
|
|
9
|
-
import { Button as
|
|
10
|
-
import { Input as
|
|
11
|
-
import { FALLBACK_SELECT_MENU_CONFIG as
|
|
12
|
-
import { cn as
|
|
13
|
-
const
|
|
14
|
-
filteredOptions:
|
|
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";
|
|
11
|
+
import { FALLBACK_SELECT_MENU_CONFIG as d } from "./select-menu-config.js";
|
|
12
|
+
import { cn as dt } from "../../utils/cn.js";
|
|
13
|
+
const ct = P(function({
|
|
14
|
+
filteredOptions: v,
|
|
15
15
|
selectedValues: w,
|
|
16
|
-
onSelectMenuOption:
|
|
16
|
+
onSelectMenuOption: x,
|
|
17
17
|
renderOption: b,
|
|
18
|
-
itemVariant:
|
|
18
|
+
itemVariant: I,
|
|
19
19
|
itemColor: i,
|
|
20
|
-
activeItemVariant:
|
|
21
|
-
activeItemColor:
|
|
20
|
+
activeItemVariant: f,
|
|
21
|
+
activeItemColor: N,
|
|
22
22
|
radius: s,
|
|
23
|
-
size:
|
|
23
|
+
size: S
|
|
24
24
|
}) {
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
const
|
|
28
|
-
return b ? b(
|
|
29
|
-
|
|
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
30
|
{
|
|
31
|
-
variant:
|
|
32
|
-
color:
|
|
31
|
+
variant: c ? f : I,
|
|
32
|
+
color: c ? N : i,
|
|
33
33
|
radius: s,
|
|
34
|
-
size:
|
|
35
|
-
isDisabled:
|
|
36
|
-
onClick: () =>
|
|
34
|
+
size: S,
|
|
35
|
+
isDisabled: o.disabled,
|
|
36
|
+
onClick: () => x(o),
|
|
37
37
|
className: "w-full justify-between font-normal text-left transition-colors truncate",
|
|
38
38
|
children: [
|
|
39
|
-
/* @__PURE__ */ l("span", { children:
|
|
40
|
-
|
|
39
|
+
/* @__PURE__ */ l("span", { children: o.label }),
|
|
40
|
+
c && /* @__PURE__ */ l(tt, { className: "w-3.5 h-3.5 shrink-0 ml-2" })
|
|
41
41
|
]
|
|
42
42
|
},
|
|
43
|
-
String(
|
|
43
|
+
String(o.value)
|
|
44
44
|
);
|
|
45
45
|
}) });
|
|
46
|
-
}),
|
|
47
|
-
isOpen:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
getFloatingProps:
|
|
46
|
+
}), it = ({
|
|
47
|
+
isOpen: y,
|
|
48
|
+
floatingStyles: v,
|
|
49
|
+
context: w,
|
|
50
|
+
getFloatingProps: x,
|
|
51
51
|
setFloatingRef: b,
|
|
52
|
-
isPositioned:
|
|
52
|
+
isPositioned: I = !0,
|
|
53
53
|
options: i = [],
|
|
54
|
-
selectedValues:
|
|
55
|
-
onSelectMenuOption:
|
|
54
|
+
selectedValues: f = [],
|
|
55
|
+
onSelectMenuOption: N,
|
|
56
56
|
isSearch: s = !0,
|
|
57
|
-
searchPlaceholder:
|
|
58
|
-
searchInputName:
|
|
59
|
-
searchQuery:
|
|
60
|
-
onSearchChange:
|
|
61
|
-
belowList:
|
|
57
|
+
searchPlaceholder: S = "Search...",
|
|
58
|
+
searchInputName: V = "select-menu-search",
|
|
59
|
+
searchQuery: o,
|
|
60
|
+
onSearchChange: c,
|
|
61
|
+
belowList: k,
|
|
62
62
|
menuConfig: e,
|
|
63
63
|
menuProps: t = {},
|
|
64
|
-
renderOption:
|
|
65
|
-
initialFocus:
|
|
66
|
-
returnFocus:
|
|
64
|
+
renderOption: E,
|
|
65
|
+
initialFocus: Q,
|
|
66
|
+
returnFocus: R
|
|
67
67
|
}) => {
|
|
68
|
-
const h =
|
|
69
|
-
|
|
70
|
-
},
|
|
68
|
+
const h = lt(), [j, K] = p(""), n = o ?? j, _ = (r) => {
|
|
69
|
+
c ? c(r) : K(r);
|
|
70
|
+
}, z = a(
|
|
71
71
|
t == null ? void 0 : t.lockScroll,
|
|
72
72
|
e == null ? void 0 : e.lockScroll,
|
|
73
73
|
void 0,
|
|
74
|
-
|
|
75
|
-
), B =
|
|
74
|
+
d.lockScroll
|
|
75
|
+
), B = a(
|
|
76
76
|
t == null ? void 0 : t.portal,
|
|
77
77
|
e == null ? void 0 : e.portal,
|
|
78
78
|
void 0,
|
|
79
|
-
|
|
80
|
-
), O =
|
|
79
|
+
d.portal
|
|
80
|
+
), O = a(
|
|
81
81
|
t == null ? void 0 : t.portalTarget,
|
|
82
82
|
e == null ? void 0 : e.portalTarget,
|
|
83
83
|
void 0,
|
|
84
84
|
typeof document < "u" ? document.body : null
|
|
85
85
|
);
|
|
86
|
-
|
|
87
|
-
if (!
|
|
88
|
-
const
|
|
89
|
-
return document.body.style.
|
|
90
|
-
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);
|
|
91
91
|
};
|
|
92
|
-
}, [
|
|
93
|
-
const
|
|
94
|
-
(
|
|
95
|
-
), [i, s,
|
|
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(
|
|
96
96
|
t == null ? void 0 : t.itemVariant,
|
|
97
97
|
e == null ? void 0 : e.itemVariant,
|
|
98
98
|
void 0,
|
|
99
|
-
|
|
100
|
-
), L =
|
|
99
|
+
d.itemVariant
|
|
100
|
+
), L = a(
|
|
101
101
|
t == null ? void 0 : t.itemColor,
|
|
102
102
|
e == null ? void 0 : e.itemColor,
|
|
103
103
|
h.defaultColor,
|
|
104
|
-
|
|
105
|
-
),
|
|
104
|
+
d.itemColor
|
|
105
|
+
), G = a(
|
|
106
106
|
t == null ? void 0 : t.activeItemVariant,
|
|
107
107
|
e == null ? void 0 : e.activeItemVariant,
|
|
108
108
|
h.defaultVariant,
|
|
109
|
-
|
|
110
|
-
),
|
|
109
|
+
d.activeItemVariant
|
|
110
|
+
), U = a(
|
|
111
111
|
t == null ? void 0 : t.activeItemColor,
|
|
112
112
|
e == null ? void 0 : e.activeItemColor,
|
|
113
113
|
h.defaultColor,
|
|
114
|
-
|
|
115
|
-
),
|
|
114
|
+
d.activeItemColor
|
|
115
|
+
), F = ot(
|
|
116
116
|
t == null ? void 0 : t.radius,
|
|
117
117
|
e == null ? void 0 : e.radius,
|
|
118
118
|
h.defaultRadius,
|
|
119
|
-
|
|
120
|
-
),
|
|
119
|
+
d.radius
|
|
120
|
+
), M = a(
|
|
121
121
|
t == null ? void 0 : t.size,
|
|
122
122
|
e == null ? void 0 : e.size,
|
|
123
123
|
void 0,
|
|
124
|
-
|
|
124
|
+
d.size
|
|
125
125
|
);
|
|
126
|
-
if (!
|
|
127
|
-
const
|
|
128
|
-
|
|
126
|
+
if (!y) return null;
|
|
127
|
+
const T = /* @__PURE__ */ l(
|
|
128
|
+
u,
|
|
129
129
|
{
|
|
130
|
-
context:
|
|
130
|
+
context: w,
|
|
131
131
|
modal: !1,
|
|
132
|
-
initialFocus:
|
|
133
|
-
returnFocus:
|
|
134
|
-
children: /* @__PURE__ */
|
|
132
|
+
initialFocus: Q,
|
|
133
|
+
returnFocus: R,
|
|
134
|
+
children: /* @__PURE__ */ A(
|
|
135
135
|
"div",
|
|
136
136
|
{
|
|
137
137
|
ref: b,
|
|
138
|
-
style: { ...
|
|
139
|
-
className:
|
|
138
|
+
style: { ...v },
|
|
139
|
+
className: dt(
|
|
140
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
|
-
|
|
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",
|
|
142
151
|
t == null ? void 0 : t.className
|
|
143
152
|
),
|
|
144
|
-
...
|
|
153
|
+
...x(),
|
|
145
154
|
children: [
|
|
146
155
|
s && /* @__PURE__ */ l("div", { className: "w-full p-1 mb-1 sticky top-0 z-10 border-b border-border", children: /* @__PURE__ */ l(
|
|
147
|
-
|
|
156
|
+
at,
|
|
148
157
|
{
|
|
149
|
-
name:
|
|
158
|
+
name: V,
|
|
150
159
|
type: "text",
|
|
151
160
|
variant: "bordered",
|
|
152
|
-
radius:
|
|
161
|
+
radius: F,
|
|
153
162
|
color: L,
|
|
154
|
-
size:
|
|
155
|
-
value:
|
|
156
|
-
onChange: (
|
|
157
|
-
startContent: /* @__PURE__ */ l(
|
|
158
|
-
placeholder:
|
|
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,
|
|
159
168
|
autoFocus: !0,
|
|
160
169
|
className: "w-full pl-8 h-8 text-xs bg-secondary/30 border-none focus-visible:ring-0"
|
|
161
170
|
}
|
|
162
171
|
) }),
|
|
163
172
|
/* @__PURE__ */ l(
|
|
164
|
-
|
|
173
|
+
ct,
|
|
165
174
|
{
|
|
166
|
-
filteredOptions:
|
|
167
|
-
selectedValues:
|
|
168
|
-
onSelectMenuOption:
|
|
169
|
-
renderOption:
|
|
170
|
-
itemVariant:
|
|
175
|
+
filteredOptions: Y,
|
|
176
|
+
selectedValues: f,
|
|
177
|
+
onSelectMenuOption: N,
|
|
178
|
+
renderOption: E,
|
|
179
|
+
itemVariant: D,
|
|
171
180
|
itemColor: L,
|
|
172
|
-
activeItemVariant:
|
|
173
|
-
activeItemColor:
|
|
174
|
-
radius:
|
|
175
|
-
size:
|
|
181
|
+
activeItemVariant: G,
|
|
182
|
+
activeItemColor: U,
|
|
183
|
+
radius: F,
|
|
184
|
+
size: M
|
|
176
185
|
}
|
|
177
186
|
),
|
|
178
|
-
|
|
187
|
+
k && /* @__PURE__ */ l("div", { className: "border-t border-border pt-1 mt-1", children: k })
|
|
179
188
|
]
|
|
180
189
|
}
|
|
181
190
|
)
|
|
182
191
|
}
|
|
183
192
|
);
|
|
184
|
-
return B ? /* @__PURE__ */ l(
|
|
193
|
+
return B ? /* @__PURE__ */ l(m, { root: O, children: T }) : T;
|
|
185
194
|
};
|
|
186
|
-
|
|
195
|
+
it.displayName = "SelectMenu";
|
|
187
196
|
export {
|
|
188
|
-
|
|
197
|
+
it as SelectMenu
|
|
189
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,17 +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
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
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.
|
|
62
86
|
*
|
|
63
87
|
* @param props - Configuration options for the floating element.
|
|
64
88
|
* @param props.isOpen - Whether the floating element is open.
|
|
@@ -68,22 +92,24 @@ export interface UseSelectFloatingProps {
|
|
|
68
92
|
* @param props.offsetDistance - Distance from reference in pixels. Defaults to 4.
|
|
69
93
|
* @param props.padding - Viewport padding for shift middleware. Defaults to 8.
|
|
70
94
|
* @param props.matchReferenceWidth - Whether to match reference width. Defaults to true.
|
|
71
|
-
* @
|
|
72
|
-
*
|
|
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.
|
|
73
98
|
*
|
|
74
99
|
* @example
|
|
75
100
|
* ```tsx
|
|
76
|
-
* const { refs, floatingStyles,
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
101
|
+
* const { refs, context, floatingStyles, getReferenceProps, getFloatingProps } =
|
|
102
|
+
* useSelectFloating({
|
|
103
|
+
* isOpen,
|
|
104
|
+
* onOpenChange: setIsOpen,
|
|
105
|
+
* disabled: props.disabled,
|
|
106
|
+
* });
|
|
81
107
|
*
|
|
82
108
|
* return (
|
|
83
109
|
* <>
|
|
84
|
-
* <button ref={refs.setReference}>Toggle</button>
|
|
110
|
+
* <button ref={refs.setReference} {...getReferenceProps()}>Toggle</button>
|
|
85
111
|
* {isOpen && (
|
|
86
|
-
* <div ref={refs.setFloating} style={floatingStyles}>
|
|
112
|
+
* <div ref={refs.setFloating} style={floatingStyles} {...getFloatingProps()}>
|
|
87
113
|
* Content
|
|
88
114
|
* </div>
|
|
89
115
|
* )}
|
|
@@ -94,5 +120,5 @@ export interface UseSelectFloatingProps {
|
|
|
94
120
|
* @see useFloating - The underlying Floating UI hook.
|
|
95
121
|
* @see Select - The select component that uses this hook.
|
|
96
122
|
*/
|
|
97
|
-
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>;
|
|
98
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,43 +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",
|
|
17
|
-
|
|
18
|
-
// default) is sufficient to keep a fixed-strategy floating element
|
|
19
|
-
// aligned during scroll, and far cheaper than polling every animation
|
|
20
|
-
// frame. animationFrame:true doesn't fix scroll lag on its own — the
|
|
21
|
-
// actual cost was re-rendering the option list on every tick; see
|
|
22
|
-
// SelectMenuOptionsList in SelectMenu.tsx.
|
|
23
|
-
whileElementsMounted: p,
|
|
18
|
+
whileElementsMounted: y,
|
|
24
19
|
middleware: [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
apply({ availableHeight:
|
|
30
|
-
Object.assign(
|
|
31
|
-
maxHeight: `${
|
|
32
|
-
...
|
|
33
|
-
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`
|
|
34
29
|
}
|
|
35
30
|
});
|
|
36
31
|
}
|
|
37
32
|
})
|
|
38
33
|
]
|
|
39
|
-
})
|
|
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
|
+
};
|
|
40
47
|
}
|
|
41
48
|
export {
|
|
42
|
-
|
|
49
|
+
O as useSelectFloating
|
|
43
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/theme/controller.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,QAAQ,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAa/C;;GAEG;AACH,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAE3B;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,YAAY,EAAE,cAAc,CAAC;IAE7B;;;;OAIG;IACH,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,cAAM,eAAe;IACnB;;;OAGG;IACH,OAAO,CAAC,SAAS,CAA2B;IAE5C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAsB;IAEtC;;;OAGG;IACH,OAAO,CAAC,YAAY,CAA2B;IAE/C;;;OAGG;IACH,OAAO,CAAC,eAAe,CAAyB;IAEhD;;OAEG;IACH,OAAO,CAAC,SAAS,CAAuB;IAExC;;;OAGG;IACH,OAAO,CAAC,UAAU,CAA+B;;IASjD;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,gBAAgB,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/theme/controller.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,QAAQ,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAa/C;;GAEG;AACH,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAE3B;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,YAAY,EAAE,cAAc,CAAC;IAE7B;;;;OAIG;IACH,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,cAAM,eAAe;IACnB;;;OAGG;IACH,OAAO,CAAC,SAAS,CAA2B;IAE5C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAsB;IAEtC;;;OAGG;IACH,OAAO,CAAC,YAAY,CAA2B;IAE/C;;;OAGG;IACH,OAAO,CAAC,eAAe,CAAyB;IAEhD;;OAEG;IACH,OAAO,CAAC,SAAS,CAAuB;IAExC;;;OAGG;IACH,OAAO,CAAC,UAAU,CAA+B;;IASjD;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,gBAAgB,GAAG,IAAI;IAkC3D;;;;;;OAMG;IACH,UAAU,UAAW,cAAc,KAAG,IAAI,CAExC;IAEF;;;OAGG;IACH,YAAY,QAAO,cAAc,CAAmB;IAEpD;;;;;OAKG;IACH,gBAAgB,QAAO,SAAS,CAAkB;IAElD;;;;OAIG;IACH,QAAQ,cAAe,cAAc,KAAG,IAAI,CAS1C;IAEF;;;;;OAKG;IACH,SAAS,aAAc,QAAQ,KAAG,CAAC,MAAM,IAAI,CAAC,CAG5C;IAEF;;;OAGG;IACH,kBAAkB,QAAO,SAAS,MAAM,EAAE,CAAyB;IAEnE;;;;;OAKG;IACH,WAAW,QAAO,IAAI,CAWpB;IAEF;;;;OAIG;IACH,OAAO,CAAC,kBAAkB,CAMxB;IAEF;;;;;OAKG;IACH,OAAO,CAAC,QAAQ;IAKhB;;;;;;;OAOG;IACH,OAAO,CAAC,OAAO;IAOf;;;;;OAKG;IACH,OAAO,CAAC,OAAO;IAKf;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;CA+BvB;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,iBAAwB,CAAC"}
|
package/dist/theme/controller.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
var r = Object.defineProperty;
|
|
3
|
-
var
|
|
4
|
-
var s = (n, e, t) =>
|
|
5
|
-
const
|
|
3
|
+
var d = (n, e, t) => e in n ? r(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
4
|
+
var s = (n, e, t) => d(n, typeof e != "symbol" ? e + "" : e, t);
|
|
5
|
+
const o = "ashee-theme", c = "(prefers-color-scheme: dark)", h = "theme-";
|
|
6
6
|
class m {
|
|
7
7
|
constructor() {
|
|
8
8
|
/**
|
|
@@ -63,7 +63,7 @@ class m {
|
|
|
63
63
|
*/
|
|
64
64
|
s(this, "setTheme", (e) => {
|
|
65
65
|
const t = this.sanitize(e);
|
|
66
|
-
this.selection = t, typeof window < "u" && window.localStorage.setItem(
|
|
66
|
+
this.selection = t, typeof window < "u" && window.localStorage.setItem(o, t), this.applySelection(), this.listeners.forEach((i) => {
|
|
67
67
|
i();
|
|
68
68
|
});
|
|
69
69
|
});
|
|
@@ -101,7 +101,7 @@ class m {
|
|
|
101
101
|
e();
|
|
102
102
|
}));
|
|
103
103
|
});
|
|
104
|
-
typeof window > "u" || (this.mediaQuery = window.matchMedia(
|
|
104
|
+
typeof window > "u" || (this.mediaQuery = window.matchMedia(c), this.mediaQuery.addEventListener("change", this.handleSystemChange));
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* Seeds the controller with the resolved theme config and applies the theme.
|
|
@@ -112,20 +112,18 @@ class m {
|
|
|
112
112
|
* - Never writes to storage (only `setTheme` persists user intent).
|
|
113
113
|
*/
|
|
114
114
|
configure({ defaultTheme: e, themes: t }) {
|
|
115
|
-
if (
|
|
115
|
+
if (this.defaultTheme = e, this.availableThemes = t, typeof window > "u") {
|
|
116
116
|
console.log(
|
|
117
117
|
"[Theme] Running in non-browser environment, skipping localStorage operations."
|
|
118
118
|
);
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
-
const i = window.localStorage.getItem(
|
|
122
|
-
console.log(
|
|
123
|
-
const l = i !== null && this.isValid(i);
|
|
124
|
-
console.log("[Theme] Is stored theme valid?", l), l || i !== null && (console.log(
|
|
121
|
+
const i = window.localStorage.getItem(o), l = i !== null && this.isValid(i);
|
|
122
|
+
l || i !== null && (console.log(
|
|
125
123
|
"[Theme] Invalid stored theme, removing from localStorage."
|
|
126
|
-
), window.localStorage.removeItem(
|
|
127
|
-
|
|
128
|
-
})
|
|
124
|
+
), window.localStorage.removeItem(o)), this.selection = l ? i : e, this.applySelection(), this.listeners.forEach((a) => {
|
|
125
|
+
a();
|
|
126
|
+
});
|
|
129
127
|
}
|
|
130
128
|
/**
|
|
131
129
|
* Validates a theme selection and returns a valid fallback if necessary.
|
|
@@ -169,13 +167,13 @@ class m {
|
|
|
169
167
|
let t = this.resolve(e);
|
|
170
168
|
if (this.availableThemes.length > 0 && !this.availableThemes.includes(t) && (t = this.availableThemes.includes(this.defaultTheme) ? this.defaultTheme : this.availableThemes[0]), this.resolved = t, typeof document > "u") return;
|
|
171
169
|
const i = document.documentElement, l = `${h}${t}`;
|
|
172
|
-
for (const
|
|
173
|
-
|
|
170
|
+
for (const a of Array.from(i.classList))
|
|
171
|
+
a.startsWith(h) && i.classList.remove(a);
|
|
174
172
|
i.classList.add(l);
|
|
175
173
|
}
|
|
176
174
|
}
|
|
177
175
|
const f = new m();
|
|
178
176
|
export {
|
|
179
|
-
|
|
177
|
+
o as THEME_STORAGE_KEY,
|
|
180
178
|
f as themeController
|
|
181
179
|
};
|