@bug-on/md3-react 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +20 -12
- package/CHANGELOG.md +24 -0
- package/dist/index.css +178 -0
- package/dist/index.d.mts +65 -6
- package/dist/index.d.ts +65 -6
- package/dist/index.js +796 -487
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +742 -436
- package/dist/index.mjs.map +1 -1
- package/dist/plugin.d.mts +1 -0
- package/dist/plugin.d.ts +1 -0
- package/dist/plugin.js +13 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugin.mjs +3 -0
- package/dist/plugin.mjs.map +1 -0
- package/package.json +8 -2
- package/scripts/copy-assets.js +36 -3
- package/src/index.ts +9 -1
- package/src/lib/theme-utils.ts +19 -4
- package/src/plugin.ts +12 -0
- package/src/ui/button.test.tsx +19 -10
- package/src/ui/button.tsx +2 -6
- package/src/ui/navigation-bar.test.tsx +111 -0
- package/src/ui/navigation-bar.tsx +448 -0
- package/src/ui/navigation-rail.test.tsx +5 -4
- package/src/ui/navigation-rail.tsx +28 -26
- package/src/ui/scroll-area.tsx +4 -0
- package/src/ui/shared/constants.ts +13 -0
- package/src/ui/theme-provider/index.tsx +32 -7
- package/tsup.config.ts +3 -3
- package/test_output.txt +0 -164
- package/test_output_v2.txt +0 -5
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { cva } from "class-variance-authority";
|
|
4
|
+
import { AnimatePresence, domMax, LazyMotion, m, type Transition } from "motion/react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
import { Icon } from "./icon";
|
|
8
|
+
import { Ripple, useRippleState } from "./ripple";
|
|
9
|
+
import { SPRING_TRANSITION_EXPRESSIVE } from "./shared/constants";
|
|
10
|
+
import { TouchTarget } from "./shared/touch-target";
|
|
11
|
+
|
|
12
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
13
|
+
// Types
|
|
14
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Layout styling for navigation bar items.
|
|
18
|
+
* - vertical: Icon above label (default for mobile)
|
|
19
|
+
* - horizontal: Icon beside label (forced)
|
|
20
|
+
*/
|
|
21
|
+
export type NavigationBarItemLayout = "vertical" | "horizontal";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Visual variant of the Navigation Bar.
|
|
25
|
+
* - flexible: Default MD3 behavior (h-16), becomes horizontal on desktop.
|
|
26
|
+
* - baseline: Taller MD3 behavior (h-20), always vertical.
|
|
27
|
+
* - xr: Floating orbiter variant for spatial interfaces (detached from bottom).
|
|
28
|
+
*/
|
|
29
|
+
export type NavigationBarVariant = "flexible" | "baseline" | "xr";
|
|
30
|
+
|
|
31
|
+
export interface NavigationBarItemProps {
|
|
32
|
+
selected: boolean;
|
|
33
|
+
icon: React.ReactNode;
|
|
34
|
+
label: React.ReactNode;
|
|
35
|
+
onClick?: () => void;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
badge?: React.ReactNode;
|
|
38
|
+
"aria-label"?: string;
|
|
39
|
+
className?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface NavigationBarProps {
|
|
43
|
+
/** Visual variant of the Navigation Bar */
|
|
44
|
+
variant?: NavigationBarVariant;
|
|
45
|
+
/** Forces a specific item layout (horizontal/vertical) */
|
|
46
|
+
itemLayout?: NavigationBarItemLayout;
|
|
47
|
+
/** Whether the bar should hide when scrolling down */
|
|
48
|
+
hideOnScroll?: boolean;
|
|
49
|
+
/** Whether the bar should have an elevation shadow */
|
|
50
|
+
elevated?: boolean;
|
|
51
|
+
/** Whether the bar is fixed to the viewport (default) or absolute */
|
|
52
|
+
fixed?: boolean;
|
|
53
|
+
/** Container ref to track scrolling for hideOnScroll */
|
|
54
|
+
scrollContainerRef?: React.RefObject<HTMLElement | null>;
|
|
55
|
+
/** Transition for the active indicator pill */
|
|
56
|
+
activeIndicatorTransition?: Transition;
|
|
57
|
+
/** Navigation items */
|
|
58
|
+
children: React.ReactNode;
|
|
59
|
+
/** Optional additional classes */
|
|
60
|
+
className?: string;
|
|
61
|
+
/** Optional inline styles */
|
|
62
|
+
style?: React.CSSProperties;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
66
|
+
// Context
|
|
67
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
68
|
+
|
|
69
|
+
const NavigationBarContext = React.createContext<{
|
|
70
|
+
variant: NavigationBarVariant;
|
|
71
|
+
itemLayout?: NavigationBarItemLayout;
|
|
72
|
+
activeIndicatorTransition?: Transition;
|
|
73
|
+
}>({ variant: "flexible" });
|
|
74
|
+
|
|
75
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
76
|
+
// Helpers
|
|
77
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
78
|
+
|
|
79
|
+
function cloneIconWithFill(
|
|
80
|
+
icon: React.ReactNode,
|
|
81
|
+
selected: boolean,
|
|
82
|
+
): React.ReactNode {
|
|
83
|
+
if (!React.isValidElement(icon)) return icon;
|
|
84
|
+
if ((icon.type as unknown) === Icon) {
|
|
85
|
+
return React.cloneElement(
|
|
86
|
+
icon as React.ReactElement<{ fill?: 0 | 1; animateFill?: boolean }>,
|
|
87
|
+
{ fill: selected ? 1 : 0, animateFill: true },
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return icon;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
94
|
+
// NavigationBarItem Sub-components
|
|
95
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
96
|
+
|
|
97
|
+
function ActivePill() {
|
|
98
|
+
const { activeIndicatorTransition } = React.useContext(NavigationBarContext);
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<m.div
|
|
102
|
+
className="absolute inset-0 bg-m3-secondary-container pointer-events-none"
|
|
103
|
+
style={{
|
|
104
|
+
borderRadius: 9999,
|
|
105
|
+
zIndex: 0,
|
|
106
|
+
}}
|
|
107
|
+
initial={{ opacity: 0, scale: 0.5 }}
|
|
108
|
+
animate={{ opacity: 1, scale: 1 }}
|
|
109
|
+
exit={{ opacity: 0, scale: 0.5 }}
|
|
110
|
+
transition={activeIndicatorTransition || SPRING_TRANSITION_EXPRESSIVE}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function HoverStateLayer() {
|
|
116
|
+
return (
|
|
117
|
+
<div className="absolute inset-0 rounded-full bg-m3-on-surface opacity-0 group-hover:opacity-[0.08] group-focus-visible:opacity-[0.10] active:opacity-[0.10] transition-opacity duration-200 pointer-events-none z-0" />
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
interface RippleLayerProps {
|
|
122
|
+
ripples: ReturnType<typeof useRippleState>["ripples"];
|
|
123
|
+
onRippleDone: ReturnType<typeof useRippleState>["removeRipple"];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function RippleLayer({ ripples, onRippleDone }: RippleLayerProps) {
|
|
127
|
+
return (
|
|
128
|
+
<div className="absolute inset-0 rounded-full overflow-hidden pointer-events-none z-0">
|
|
129
|
+
<Ripple ripples={ripples} onRippleDone={onRippleDone} />
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
interface IconContainerProps {
|
|
135
|
+
selected: boolean;
|
|
136
|
+
badge?: React.ReactNode;
|
|
137
|
+
children: React.ReactNode;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function IconContainer({ selected, badge, children }: IconContainerProps) {
|
|
141
|
+
return (
|
|
142
|
+
<div
|
|
143
|
+
aria-hidden="true"
|
|
144
|
+
className={cn(
|
|
145
|
+
"relative flex items-center justify-center size-6 transition-colors duration-200 shrink-0",
|
|
146
|
+
selected
|
|
147
|
+
? "text-m3-on-secondary-container"
|
|
148
|
+
: "text-m3-on-surface-variant",
|
|
149
|
+
)}
|
|
150
|
+
>
|
|
151
|
+
{children}
|
|
152
|
+
{badge && (
|
|
153
|
+
<span className="absolute -top-1 -right-1 flex min-w-3 h-3 items-center justify-center rounded-full bg-m3-error px-1 text-[10px] font-medium leading-none tracking-normal text-m3-on-error ring-[1.5px] ring-m3-surface">
|
|
154
|
+
{badge}
|
|
155
|
+
</span>
|
|
156
|
+
)}
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
162
|
+
// NavigationBarItem
|
|
163
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
164
|
+
|
|
165
|
+
const NavigationBarItemComponent = React.forwardRef<
|
|
166
|
+
HTMLButtonElement,
|
|
167
|
+
NavigationBarItemProps
|
|
168
|
+
>(
|
|
169
|
+
(
|
|
170
|
+
{
|
|
171
|
+
selected,
|
|
172
|
+
icon,
|
|
173
|
+
label,
|
|
174
|
+
onClick,
|
|
175
|
+
disabled = false,
|
|
176
|
+
badge,
|
|
177
|
+
className,
|
|
178
|
+
"aria-label": ariaLabelProp,
|
|
179
|
+
},
|
|
180
|
+
ref,
|
|
181
|
+
) => {
|
|
182
|
+
const { variant, itemLayout } = React.useContext(NavigationBarContext);
|
|
183
|
+
|
|
184
|
+
const isForcedHorizontal = itemLayout === "horizontal";
|
|
185
|
+
const isResponsiveHorizontal =
|
|
186
|
+
(variant === "flexible" || variant === "xr") && itemLayout === undefined;
|
|
187
|
+
|
|
188
|
+
const { ripples, onPointerDown, removeRipple } = useRippleState({
|
|
189
|
+
disabled,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const handleClick = React.useCallback(
|
|
193
|
+
(e: React.MouseEvent<HTMLButtonElement>) => {
|
|
194
|
+
if (disabled) {
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (selected) {
|
|
199
|
+
if (typeof window !== "undefined" && window.scrollY > 0) {
|
|
200
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
onClick?.();
|
|
205
|
+
},
|
|
206
|
+
[disabled, selected, onClick],
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const filledIcon = cloneIconWithFill(icon, selected);
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<m.button
|
|
213
|
+
ref={ref}
|
|
214
|
+
type="button"
|
|
215
|
+
role="menuitem"
|
|
216
|
+
aria-current={selected ? "page" : undefined}
|
|
217
|
+
aria-disabled={disabled ? true : undefined}
|
|
218
|
+
aria-label={
|
|
219
|
+
ariaLabelProp || (typeof label === "string" ? label : undefined)
|
|
220
|
+
}
|
|
221
|
+
onClick={handleClick}
|
|
222
|
+
onPointerDown={onPointerDown}
|
|
223
|
+
className={cn(
|
|
224
|
+
"group relative flex flex-1 cursor-pointer transition-colors duration-200 outline-none select-none h-full",
|
|
225
|
+
variant === "xr"
|
|
226
|
+
? "items-center justify-center max-[599px]:min-w-28 max-[599px]:max-w-28 max-[599px]:items-start max-[599px]:pt-3 max-[599px]:pb-4"
|
|
227
|
+
: "items-center justify-center",
|
|
228
|
+
disabled && "pointer-events-none opacity-[0.38]",
|
|
229
|
+
className,
|
|
230
|
+
)}
|
|
231
|
+
>
|
|
232
|
+
<div
|
|
233
|
+
className={cn(
|
|
234
|
+
"relative flex items-center justify-center flex-col gap-y-1 w-full",
|
|
235
|
+
isResponsiveHorizontal &&
|
|
236
|
+
"min-[600px]:flex-row min-[600px]:gap-y-0 min-[600px]:gap-x-1 min-[600px]:h-10 min-[600px]:px-4 min-[600px]:rounded-full min-[600px]:w-auto min-[600px]:max-w-42",
|
|
237
|
+
isForcedHorizontal &&
|
|
238
|
+
"flex-row gap-y-0 gap-x-1 h-10 px-4 rounded-full w-auto max-w-42",
|
|
239
|
+
)}
|
|
240
|
+
>
|
|
241
|
+
{/* Horizontal active indicator — covers icon + label */}
|
|
242
|
+
<div
|
|
243
|
+
className={cn(
|
|
244
|
+
"absolute inset-0 z-0 hidden",
|
|
245
|
+
isResponsiveHorizontal && "min-[600px]:block",
|
|
246
|
+
isForcedHorizontal && "block!",
|
|
247
|
+
)}
|
|
248
|
+
>
|
|
249
|
+
<AnimatePresence initial={false}>
|
|
250
|
+
{selected && <ActivePill />}
|
|
251
|
+
</AnimatePresence>
|
|
252
|
+
<HoverStateLayer />
|
|
253
|
+
<RippleLayer ripples={ripples} onRippleDone={removeRipple} />
|
|
254
|
+
</div>
|
|
255
|
+
|
|
256
|
+
{/* Icon pill — background visible only in vertical layout */}
|
|
257
|
+
<div
|
|
258
|
+
className={cn(
|
|
259
|
+
"relative flex items-center justify-center shrink-0 z-10",
|
|
260
|
+
"h-8 w-16 mx-auto rounded-full",
|
|
261
|
+
isResponsiveHorizontal &&
|
|
262
|
+
"min-[600px]:size-6 min-[600px]:w-auto min-[600px]:h-auto",
|
|
263
|
+
isForcedHorizontal && "size-6 w-auto h-auto",
|
|
264
|
+
)}
|
|
265
|
+
>
|
|
266
|
+
<div
|
|
267
|
+
className={cn(
|
|
268
|
+
"absolute inset-0 z-0",
|
|
269
|
+
isResponsiveHorizontal && "min-[600px]:hidden",
|
|
270
|
+
isForcedHorizontal && "hidden",
|
|
271
|
+
)}
|
|
272
|
+
>
|
|
273
|
+
<AnimatePresence initial={false}>
|
|
274
|
+
{selected && <ActivePill />}
|
|
275
|
+
</AnimatePresence>
|
|
276
|
+
<HoverStateLayer />
|
|
277
|
+
<RippleLayer ripples={ripples} onRippleDone={removeRipple} />
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
<div className="relative z-10 flex size-6 items-center justify-center text-current">
|
|
281
|
+
<IconContainer selected={selected} badge={badge}>
|
|
282
|
+
{filledIcon}
|
|
283
|
+
</IconContainer>
|
|
284
|
+
</div>
|
|
285
|
+
</div>
|
|
286
|
+
|
|
287
|
+
<AnimatePresence mode="popLayout">
|
|
288
|
+
<span
|
|
289
|
+
key="nav-label"
|
|
290
|
+
className={cn(
|
|
291
|
+
"z-10 transition-all duration-200 truncate px-1",
|
|
292
|
+
selected ? "text-m3-on-surface" : "text-m3-on-surface-variant",
|
|
293
|
+
"font-medium text-[12px] leading-4 tracking-[0.5px]",
|
|
294
|
+
)}
|
|
295
|
+
>
|
|
296
|
+
{label}
|
|
297
|
+
</span>
|
|
298
|
+
</AnimatePresence>
|
|
299
|
+
</div>
|
|
300
|
+
<TouchTarget />
|
|
301
|
+
</m.button>
|
|
302
|
+
);
|
|
303
|
+
},
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
NavigationBarItemComponent.displayName = "NavigationBarItem";
|
|
307
|
+
export const NavigationBarItem = React.memo(NavigationBarItemComponent);
|
|
308
|
+
|
|
309
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
310
|
+
// NavigationBar Container
|
|
311
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
312
|
+
|
|
313
|
+
const navContainerVariants = cva(
|
|
314
|
+
"flex items-center justify-center select-none transition-transform duration-300 z-50",
|
|
315
|
+
{
|
|
316
|
+
variants: {
|
|
317
|
+
variant: {
|
|
318
|
+
flexible: "bottom-0 left-0 right-0 w-full h-16 pb-safe",
|
|
319
|
+
baseline: "bottom-0 left-0 right-0 w-full h-20 pb-safe",
|
|
320
|
+
xr: "bottom-6 left-1/2 -translate-x-1/2 w-auto max-w-fit h-20 min-[600px]:h-16 rounded-[48px] px-2",
|
|
321
|
+
},
|
|
322
|
+
position: {
|
|
323
|
+
fixed: "fixed",
|
|
324
|
+
absolute: "absolute",
|
|
325
|
+
},
|
|
326
|
+
elevated: {
|
|
327
|
+
true: "shadow-[0_-1px_3px_rgba(0,0,0,0.1)]",
|
|
328
|
+
false: "shadow-none",
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
defaultVariants: {
|
|
332
|
+
variant: "flexible",
|
|
333
|
+
position: "fixed",
|
|
334
|
+
elevated: false,
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
export const NavigationBarComponent = React.forwardRef<
|
|
340
|
+
HTMLElement,
|
|
341
|
+
NavigationBarProps
|
|
342
|
+
>(
|
|
343
|
+
(
|
|
344
|
+
{
|
|
345
|
+
variant = "flexible",
|
|
346
|
+
itemLayout,
|
|
347
|
+
hideOnScroll = false,
|
|
348
|
+
elevated = false,
|
|
349
|
+
fixed = true,
|
|
350
|
+
scrollContainerRef,
|
|
351
|
+
activeIndicatorTransition,
|
|
352
|
+
children,
|
|
353
|
+
className,
|
|
354
|
+
style,
|
|
355
|
+
},
|
|
356
|
+
ref,
|
|
357
|
+
) => {
|
|
358
|
+
const [isVisible, setIsVisible] = React.useState(true);
|
|
359
|
+
const lastScrollY = React.useRef(
|
|
360
|
+
typeof window !== "undefined" ? window.scrollY : 0,
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
React.useEffect(() => {
|
|
364
|
+
if (typeof window === "undefined" || !hideOnScroll) {
|
|
365
|
+
setIsVisible(true);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Do not hide if screen reader or reduced motion is active
|
|
370
|
+
const prefersReducedMotion = window.matchMedia(
|
|
371
|
+
"(prefers-reduced-motion: reduce)",
|
|
372
|
+
).matches;
|
|
373
|
+
if (prefersReducedMotion) {
|
|
374
|
+
setIsVisible(true);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
let ticking = false;
|
|
379
|
+
|
|
380
|
+
const handleScroll = () => {
|
|
381
|
+
if (ticking) return;
|
|
382
|
+
ticking = true;
|
|
383
|
+
window.requestAnimationFrame(() => {
|
|
384
|
+
const currentScrollY = scrollContainerRef?.current
|
|
385
|
+
? scrollContainerRef.current.scrollTop
|
|
386
|
+
: window.scrollY;
|
|
387
|
+
|
|
388
|
+
if (currentScrollY <= 0 || currentScrollY < lastScrollY.current) {
|
|
389
|
+
setIsVisible(true);
|
|
390
|
+
} else if (currentScrollY > lastScrollY.current) {
|
|
391
|
+
setIsVisible(false);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
lastScrollY.current = currentScrollY;
|
|
395
|
+
ticking = false;
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
const target = scrollContainerRef?.current || window;
|
|
400
|
+
|
|
401
|
+
target.addEventListener("scroll", handleScroll, { passive: true });
|
|
402
|
+
return () => target.removeEventListener("scroll", handleScroll);
|
|
403
|
+
}, [hideOnScroll, scrollContainerRef]);
|
|
404
|
+
|
|
405
|
+
const navBaseClasses = cn(
|
|
406
|
+
navContainerVariants({
|
|
407
|
+
variant,
|
|
408
|
+
elevated,
|
|
409
|
+
position: fixed ? "fixed" : "absolute",
|
|
410
|
+
}),
|
|
411
|
+
variant === "xr"
|
|
412
|
+
? "bg-m3-surface border border-white/5 shadow-xl"
|
|
413
|
+
: "bg-m3-surface-container",
|
|
414
|
+
className,
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
return (
|
|
418
|
+
<LazyMotion features={domMax} strict>
|
|
419
|
+
<NavigationBarContext.Provider value={{ variant, itemLayout, activeIndicatorTransition }}>
|
|
420
|
+
<m.nav
|
|
421
|
+
ref={ref}
|
|
422
|
+
role="navigation"
|
|
423
|
+
aria-label="Main navigation"
|
|
424
|
+
className={navBaseClasses}
|
|
425
|
+
style={style}
|
|
426
|
+
initial={false}
|
|
427
|
+
animate={{ y: isVisible ? "0%" : "100%" }}
|
|
428
|
+
transition={{ type: "tween", duration: 0.3, ease: "easeInOut" }}
|
|
429
|
+
>
|
|
430
|
+
<div
|
|
431
|
+
role="menubar"
|
|
432
|
+
aria-orientation="horizontal"
|
|
433
|
+
className={cn(
|
|
434
|
+
"flex w-full h-full mx-auto",
|
|
435
|
+
variant === "xr" ? "gap-0 min-[600px]:gap-1.5" : "max-w-7xl gap-1.5",
|
|
436
|
+
)}
|
|
437
|
+
>
|
|
438
|
+
{children}
|
|
439
|
+
</div>
|
|
440
|
+
</m.nav>
|
|
441
|
+
</NavigationBarContext.Provider>
|
|
442
|
+
</LazyMotion>
|
|
443
|
+
);
|
|
444
|
+
},
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
NavigationBarComponent.displayName = "NavigationBar";
|
|
448
|
+
export const NavigationBar = React.memo(NavigationBarComponent);
|
|
@@ -373,9 +373,9 @@ describe("NavigationRail & NavigationRailItem", () => {
|
|
|
373
373
|
expect(nav).toHaveClass("w-20"); // narrow width
|
|
374
374
|
});
|
|
375
375
|
|
|
376
|
-
it("applies xr (spatial) styling when xr
|
|
376
|
+
it("applies xr (spatial) styling when variant='xr'", () => {
|
|
377
377
|
render(
|
|
378
|
-
<NavigationRail xr>
|
|
378
|
+
<NavigationRail variant="xr">
|
|
379
379
|
<NavigationRailItem selected icon={<svg />} label="Home" />
|
|
380
380
|
</NavigationRail>,
|
|
381
381
|
);
|
|
@@ -383,10 +383,11 @@ describe("NavigationRail & NavigationRailItem", () => {
|
|
|
383
383
|
expect(nav).toHaveClass("py-5", "rounded-[48px]", "bg-m3-surface");
|
|
384
384
|
});
|
|
385
385
|
|
|
386
|
-
it("renders spatial wrapper structurally when
|
|
386
|
+
it("renders spatial wrapper structurally when fabPlacement='spatialized'", () => {
|
|
387
387
|
render(
|
|
388
388
|
<NavigationRail
|
|
389
|
-
|
|
389
|
+
variant="xr"
|
|
390
|
+
fabPlacement="spatialized"
|
|
390
391
|
fab={
|
|
391
392
|
<button type="button" data-testid="rail-fab">
|
|
392
393
|
FAB
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { cva } from "class-variance-authority";
|
|
2
|
-
import { AnimatePresence, domMax, LazyMotion, m } from "motion/react";
|
|
2
|
+
import { AnimatePresence, domMax, LazyMotion, m, type Transition } from "motion/react";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
5
5
|
import { cn } from "../lib/utils";
|
|
6
6
|
import { Icon } from "./icon";
|
|
7
7
|
import { Ripple, useRippleState } from "./ripple";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
SPRING_TRANSITION,
|
|
10
|
+
SPRING_TRANSITION_EXPRESSIVE,
|
|
11
|
+
} from "./shared/constants";
|
|
9
12
|
import { TouchTarget } from "./shared/touch-target";
|
|
10
13
|
|
|
11
14
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
12
15
|
// Types & Constants
|
|
13
16
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
14
17
|
|
|
15
|
-
export type NavigationRailVariant = "collapsed" | "expanded" | "modal";
|
|
18
|
+
export type NavigationRailVariant = "collapsed" | "expanded" | "modal" | "xr";
|
|
16
19
|
export type NavigationRailLabelVisibility = "labeled" | "auto" | "unlabeled";
|
|
17
20
|
|
|
18
21
|
export interface NavigationRailItemProps {
|
|
@@ -31,11 +34,12 @@ export interface NavigationRailProps {
|
|
|
31
34
|
labelVisibility?: NavigationRailLabelVisibility;
|
|
32
35
|
header?: React.ReactNode;
|
|
33
36
|
fab?: React.ReactNode;
|
|
37
|
+
fabPlacement?: "contained" | "spatialized";
|
|
34
38
|
footer?: React.ReactNode;
|
|
35
39
|
narrow?: boolean;
|
|
36
40
|
open?: boolean;
|
|
37
|
-
xr?: boolean | "contained" | "spatialized";
|
|
38
41
|
onClose?: () => void;
|
|
42
|
+
activeIndicatorTransition?: Transition;
|
|
39
43
|
children: React.ReactNode;
|
|
40
44
|
className?: string;
|
|
41
45
|
style?: React.CSSProperties;
|
|
@@ -44,8 +48,8 @@ export interface NavigationRailProps {
|
|
|
44
48
|
const NavigationRailContext = React.createContext<{
|
|
45
49
|
variant: NavigationRailVariant;
|
|
46
50
|
labelVisibility: NavigationRailLabelVisibility;
|
|
47
|
-
|
|
48
|
-
}>({ variant: "collapsed", labelVisibility: "labeled"
|
|
51
|
+
activeIndicatorTransition?: Transition;
|
|
52
|
+
}>({ variant: "collapsed", labelVisibility: "labeled" });
|
|
49
53
|
|
|
50
54
|
const MD3_MODAL_TRANSITION = {
|
|
51
55
|
type: "tween",
|
|
@@ -62,19 +66,16 @@ const railContainerVariants = cva(
|
|
|
62
66
|
{
|
|
63
67
|
variants: {
|
|
64
68
|
variant: {
|
|
65
|
-
collapsed: "items-center",
|
|
66
|
-
expanded: "items-start",
|
|
69
|
+
collapsed: "items-center h-full pt-11 pb-4 shadow-none bg-m3-surface rounded-none",
|
|
70
|
+
expanded: "items-start h-full pt-11 pb-4 shadow-none bg-m3-surface rounded-none",
|
|
67
71
|
modal:
|
|
68
|
-
"bg-m3-surface shadow-lg rounded-r-[var(--m3-shape-corner-large)]",
|
|
72
|
+
"bg-m3-surface shadow-lg rounded-r-[var(--m3-shape-corner-large)] h-full pt-11 pb-4",
|
|
73
|
+
xr: "h-fit py-5 rounded-[48px] shadow-xl bg-m3-surface border border-white/5",
|
|
69
74
|
},
|
|
70
75
|
narrow: {
|
|
71
76
|
true: "w-20",
|
|
72
77
|
false: "w-24",
|
|
73
78
|
},
|
|
74
|
-
xr: {
|
|
75
|
-
true: "h-fit py-5 rounded-[48px] shadow-xl bg-m3-surface border border-white/5",
|
|
76
|
-
false: "h-full pt-11 pb-4 shadow-none bg-m3-surface rounded-none",
|
|
77
|
-
},
|
|
78
79
|
},
|
|
79
80
|
compoundVariants: [
|
|
80
81
|
{ variant: "expanded", className: "min-w-[13.75rem] max-w-[22.5rem]" },
|
|
@@ -83,7 +84,6 @@ const railContainerVariants = cva(
|
|
|
83
84
|
defaultVariants: {
|
|
84
85
|
variant: "collapsed",
|
|
85
86
|
narrow: false,
|
|
86
|
-
xr: false,
|
|
87
87
|
},
|
|
88
88
|
},
|
|
89
89
|
);
|
|
@@ -133,15 +133,17 @@ interface ActivePillProps {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
function ActivePill({ layoutId, disableInitial = false }: ActivePillProps) {
|
|
136
|
+
const { activeIndicatorTransition } = React.useContext(NavigationRailContext);
|
|
137
|
+
|
|
136
138
|
return (
|
|
137
139
|
<m.div
|
|
138
140
|
layoutId={layoutId}
|
|
139
141
|
className="absolute inset-0 bg-m3-secondary-container pointer-events-none"
|
|
140
|
-
style={{ borderRadius: 9999, zIndex: 0 }}
|
|
141
|
-
initial={disableInitial ? false : { opacity: 0 }}
|
|
142
|
-
animate={{ opacity: 1 }}
|
|
143
|
-
exit={{ opacity: 0 }}
|
|
144
|
-
transition={
|
|
142
|
+
style={{ borderRadius: 9999, zIndex: 0, originX: 0.5, originY: 0.5 }}
|
|
143
|
+
initial={disableInitial ? false : { opacity: 0, scale: 0.5 }}
|
|
144
|
+
animate={{ opacity: 1, scale: 1 }}
|
|
145
|
+
exit={{ opacity: 0, scale: 0.5, transition: { duration: 0.15 } }}
|
|
146
|
+
transition={activeIndicatorTransition || SPRING_TRANSITION_EXPRESSIVE}
|
|
145
147
|
/>
|
|
146
148
|
);
|
|
147
149
|
}
|
|
@@ -428,11 +430,12 @@ const NavigationRailComponent = React.forwardRef<
|
|
|
428
430
|
labelVisibility = "labeled",
|
|
429
431
|
header,
|
|
430
432
|
fab,
|
|
433
|
+
fabPlacement = "contained",
|
|
431
434
|
footer,
|
|
432
435
|
narrow = false,
|
|
433
436
|
open = false,
|
|
434
|
-
xr = false,
|
|
435
437
|
onClose,
|
|
438
|
+
activeIndicatorTransition,
|
|
436
439
|
children,
|
|
437
440
|
className,
|
|
438
441
|
style,
|
|
@@ -440,9 +443,8 @@ const NavigationRailComponent = React.forwardRef<
|
|
|
440
443
|
ref,
|
|
441
444
|
) => {
|
|
442
445
|
const isModal = variant === "modal";
|
|
443
|
-
const isXr =
|
|
444
|
-
const
|
|
445
|
-
const isSpatial = isXr && xrMode === "spatialized";
|
|
446
|
+
const isXr = variant === "xr";
|
|
447
|
+
const isSpatial = isXr && fabPlacement === "spatialized";
|
|
446
448
|
const applyAnimation = !isXr || !isSpatial;
|
|
447
449
|
|
|
448
450
|
const navRef = React.useRef<HTMLElement>(null);
|
|
@@ -458,13 +460,13 @@ const NavigationRailComponent = React.forwardRef<
|
|
|
458
460
|
);
|
|
459
461
|
|
|
460
462
|
const navBaseClasses = cn(
|
|
461
|
-
railContainerVariants({ variant, narrow
|
|
463
|
+
railContainerVariants({ variant, narrow }),
|
|
462
464
|
);
|
|
463
465
|
const modalPositioning = isModal ? "fixed left-0 top-0 z-[100]" : "";
|
|
464
466
|
|
|
465
467
|
const navHeaderSpacing = (() => {
|
|
466
468
|
if (!isXr) return "mb-6 min-h-10";
|
|
467
|
-
if (
|
|
469
|
+
if (fabPlacement === "contained") return fab ? "mb-10" : "mb-5";
|
|
468
470
|
return "mb-5";
|
|
469
471
|
})();
|
|
470
472
|
|
|
@@ -561,7 +563,7 @@ const NavigationRailComponent = React.forwardRef<
|
|
|
561
563
|
|
|
562
564
|
const finalNavElement = isSpatial ? spatialWrapper : navElement;
|
|
563
565
|
|
|
564
|
-
const contextValue = { variant, labelVisibility,
|
|
566
|
+
const contextValue = { variant, labelVisibility, activeIndicatorTransition };
|
|
565
567
|
|
|
566
568
|
if (isModal) {
|
|
567
569
|
if (typeof document === "undefined") return null;
|
package/src/ui/scroll-area.tsx
CHANGED
|
@@ -32,6 +32,8 @@ export interface ScrollAreaProps
|
|
|
32
32
|
scrollHideDelay?: number;
|
|
33
33
|
/** Extra classes applied to the inner viewport element. */
|
|
34
34
|
viewportClassName?: string;
|
|
35
|
+
/** Ref to the scrolling viewport element. */
|
|
36
|
+
viewportRef?: React.Ref<HTMLDivElement>;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
// ─── Root ─────────────────────────────────────────────────────────────────────
|
|
@@ -47,6 +49,7 @@ const ScrollArea = React.forwardRef<
|
|
|
47
49
|
type = "hover",
|
|
48
50
|
orientation = "vertical",
|
|
49
51
|
scrollHideDelay = 600,
|
|
52
|
+
viewportRef,
|
|
50
53
|
...props
|
|
51
54
|
},
|
|
52
55
|
ref,
|
|
@@ -62,6 +65,7 @@ const ScrollArea = React.forwardRef<
|
|
|
62
65
|
{...props}
|
|
63
66
|
>
|
|
64
67
|
<RadixScrollArea.Viewport
|
|
68
|
+
ref={viewportRef}
|
|
65
69
|
className={cn(
|
|
66
70
|
"h-full w-full flex-1 min-h-0 min-w-0 rounded-[inherit]",
|
|
67
71
|
"outline-none focus-visible:ring-2 focus-visible:ring-m3-primary focus-visible:ring-offset-1",
|
|
@@ -48,6 +48,19 @@ export const SPRING_TRANSITION: Transition = {
|
|
|
48
48
|
duration: 0.3,
|
|
49
49
|
} as const;
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* MD3 Expressive spring — active indicator expand/collapse.
|
|
53
|
+
* Higher bounce for the "pop" effect per MD3 Expressive spec.
|
|
54
|
+
*
|
|
55
|
+
* - Duration: 400ms
|
|
56
|
+
* - Bounce: 0.35 (spring overshoot → lò xo)
|
|
57
|
+
*/
|
|
58
|
+
export const SPRING_TRANSITION_EXPRESSIVE: Transition = {
|
|
59
|
+
type: "spring",
|
|
60
|
+
bounce: 0.45,
|
|
61
|
+
duration: 0.4,
|
|
62
|
+
} as const;
|
|
63
|
+
|
|
51
64
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
52
65
|
// Icon Span Motion Variants
|
|
53
66
|
// Used for icon/loading indicator swap animation inside FAB and IconButton.
|