Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Reclaim vertical space in the dashboard chrome (#14408)

Damian Legawiecfb7c39f02bce
diff --git a/packages/dashboard-core/src/components/nav-main.tsx b/packages/dashboard-core/src/components/nav-main.tsx
index c7b7121f45..2dfa4fe409 100644
--- a/packages/dashboard-core/src/components/nav-main.tsx
+++ b/packages/dashboard-core/src/components/nav-main.tsx
@@ -14,7 +14,7 @@ import {
} from '@spree/dashboard-ui'
import { Link, useRouterState } from '@tanstack/react-router'
import type { LucideIcon } from 'lucide-react'
-import { type ComponentType, useState } from 'react'
+import { type ComponentType, useCallback, useEffect, useRef, useState } from 'react'
import type { SubjectName } from '../lib/permissions'
export type NavItem = {
@@ -47,27 +47,122 @@ export function NavIcon({ icon: Icon, isActive }: { icon: NavItem['icon']; isAct
)
}
-function CollapsedDropdown({ item, children }: { item: NavItem; children: React.ReactNode }) {
- const [open, setOpen] = useState(false)
+/** Grace period between leaving the trigger/menu and the menu closing. */
+const HOVER_CLOSE_DELAY_MS = 150
+
+/**
+ * Which collapsed-nav menu is open, shared across the whole rail.
+ *
+ * One value rather than per-item state, so the menus are mutually exclusive by
+ * construction: hovering a neighbour replaces the open key instantly instead of
+ * leaving the previous menu on screen for the close delay, which read as two
+ * panels flickering over each other.
+ */
+interface HoverMenuController {
+ openKey: string | null
+ /** Opens `key` immediately, replacing whatever was open. */
+ open: (key: string) => void
+ /** Schedules a close, but only if `key` is still the open one. */
+ closeSoon: (key: string) => void
+ /** Closes right away — for explicit dismissals (Escape, selecting an item). */
+ closeNow: () => void
+ /** Cancels a pending close (pointer came back). */
+ cancelClose: () => void
+}
+
+function useHoverMenuController(): HoverMenuController {
+ const [openKey, setOpenKey] = useState<string | null>(null)
+ const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
+
+ const cancelClose = useCallback(() => {
+ if (closeTimer.current) {
+ clearTimeout(closeTimer.current)
+ closeTimer.current = null
+ }
+ }, [])
+
+ const open = useCallback(
+ (key: string) => {
+ cancelClose()
+ setOpenKey(key)
+ },
+ [cancelClose],
+ )
+
+ const closeSoon = useCallback(
+ (key: string) => {
+ cancelClose()
+ closeTimer.current = setTimeout(() => {
+ // Guarded so a late timer from the menu the pointer just left can't
+ // close the one it has since moved to.
+ setOpenKey((current) => (current === key ? null : current))
+ }, HOVER_CLOSE_DELAY_MS)
+ },
+ [cancelClose],
+ )
+
+ const closeNow = useCallback(() => {
+ cancelClose()
+ setOpenKey(null)
+ }, [cancelClose])
+
+ useEffect(
+ () => () => {
+ if (closeTimer.current) clearTimeout(closeTimer.current)
+ },
+ [],
+ )
+
+ return { openKey, open, closeSoon, closeNow, cancelClose }
+}
+
+function CollapsedDropdown({
+ item,
+ controller,
+ children,
+}: {
+ item: NavItem
+ controller: HoverMenuController
+ children: React.ReactNode
+}) {
+ const key = item.title
+ const open = controller.openKey === key
+ const openNow = () => controller.open(key)
+ const closeSoon = () => controller.closeSoon(key)
return (
- <DropdownMenu open={open} onOpenChange={setOpen}>
+ <DropdownMenu
+ open={open}
+ // Base UI's own open/close signals (Escape, outside click, selecting an
+ // item) are explicit dismissals, so they close immediately — the grace
+ // period exists only for the pointer leaving on its way somewhere.
+ onOpenChange={(next) => {
+ if (next) controller.open(key)
+ else controller.closeNow()
+ }}
+ >
{/* `nativeButton={false}` because the trigger renders a `<div>` wrapping
a `SidebarMenuButton` (whose inner element is a `<Link>` → `<a>`),
not a `<button>`. The wrapper exists to attach `onMouseLeave` for
the hover-out close, so we can't drop it; instead we tell Base UI
we're rendering a non-button trigger and let it apply menu role +
keyboard semantics. */}
- <DropdownMenuTrigger asChild nativeButton={false} onMouseEnter={() => setOpen(true)}>
+ <DropdownMenuTrigger asChild nativeButton={false} onMouseEnter={openNow}>
{/* biome-ignore lint/a11y/noStaticElementInteractions: hover trigger for collapsed nav */}
- <div onMouseLeave={() => setOpen(false)}>{children}</div>
+ <div onMouseLeave={closeSoon}>{children}</div>
</DropdownMenuTrigger>
+ {/* `sideOffset={0}` plus inline-start *padding* closes the dead zone the
+ pointer used to cross: an offset (or a margin) puts those pixels
+ outside both elements, so travelling to the menu reads as leaving
+ both. Padding keeps the gap inside the panel's own hover area, so the
+ visual inset costs nothing in reachability. */}
<DropdownMenuContent
side="right"
align="start"
- sideOffset={4}
- onMouseLeave={() => setOpen(false)}
- onMouseEnter={() => setOpen(true)}
+ sideOffset={0}
+ className="ps-1"
+ onMouseLeave={closeSoon}
+ onMouseEnter={openNow}
>
{item.items!.map((subItem) => (
<DropdownMenuItem key={subItem.title} asChild>
@@ -85,10 +180,12 @@ function NavItemContent({
item,
currentPath,
isCollapsed,
+ hoverMenu,
}: {
item: NavItem
currentPath: string
isCollapsed: boolean
+ hoverMenu: HoverMenuController
}) {
const isExactActive = currentPath === item.url || currentPath === `${item.url}/`
// Only prefix-match for items with a sub-path after the storeId segment (e.g. /store_abc/orders)
@@ -106,14 +203,19 @@ function NavItemContent({
asChild
isActive={itemIsActive}
>
- <Link to={item.url}>
+ {/* `aria-label` because the visible label is hidden in collapsed icon
+ mode, which would otherwise leave the link with no accessible name —
+ an icon-only link is unusable to a screen reader. */}
+ <Link to={item.url} aria-label={isCollapsed ? item.title : undefined}>
<NavIcon icon={item.icon} isActive={itemIsActive} />
{/* Explicitly hide in collapsed icon mode: a trailing badge span would
otherwise steal the `span:last-child` position the base button style
relies on to hide the label, leaving the title visible. */}
<span className="group-data-[collapsible=icon]:hidden">{item.title}</span>
+ {/* `shrink-0` so the badge keeps its shape while the sidebar width
+ animates — a squeezed badge deforms before the label clips. */}
{item.badge && (
- <span className="ml-auto group-data-[collapsible=icon]:hidden">
+ <span className="ml-auto shrink-0 group-data-[collapsible=icon]:hidden">
<item.badge />
</span>
)}
@@ -122,9 +224,14 @@ function NavItemContent({
)
return (
- <SidebarMenuItem>
+ // Hovering an item with no submenu dismisses whatever menu is open: the
+ // pointer has clearly moved on, and leaving a neighbour's panel hanging
+ // over the rail reads as a stuck popup.
+ <SidebarMenuItem onMouseEnter={isCollapsed && !item.items ? hoverMenu.closeNow : undefined}>
{isCollapsed && item.items ? (
- <CollapsedDropdown item={item}>{button}</CollapsedDropdown>
+ <CollapsedDropdown item={item} controller={hoverMenu}>
+ {button}
+ </CollapsedDropdown>
) : (
button
)}
@@ -158,6 +265,15 @@ export function NavMain({ items, bottomItems }: { items: NavItem[]; bottomItems?
const currentPath = routerState.location.pathname
const { state } = useSidebar()
const isCollapsed = state === 'collapsed'
+ // One controller for the whole rail so only a single hover menu is ever open.
+ const hoverMenu = useHoverMenuController()
+
+ // Expanding the rail unmounts the dropdowns but leaves `openKey` set, so
+ // collapsing again would restore a menu the user never opened.
+ const { closeNow } = hoverMenu
+ useEffect(() => {
+ if (!isCollapsed) closeNow()
+ }, [isCollapsed, closeNow])
return (
<>
@@ -169,6 +285,7 @@ export function NavMain({ items, bottomItems }: { items: NavItem[]; bottomItems?
item={item}
currentPath={currentPath}
isCollapsed={isCollapsed}
+ hoverMenu={hoverMenu}
/>
))}
</SidebarMenu>
@@ -184,7 +301,10 @@ export function NavMain({ items, bottomItems }: { items: NavItem[]; bottomItems?
return (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton tooltip={item.title} asChild isActive={isActive}>
- <Link to={item.url}>
+ {/* `aria-label` for the same reason as the main nav above:
+ collapsed mode hides the label, and Settings lives here
+ — the one place the rail is collapsed by default. */}
+ <Link to={item.url} aria-label={isCollapsed ? item.title : undefined}>
<NavIcon icon={item.icon} isActive={isActive} />
<span>{item.title}</span>
</Link>
diff --git a/packages/dashboard-core/src/components/page-header.tsx b/packages/dashboard-core/src/components/page-header.tsx
index 3ab091cb2e..fa8ef1e964 100644
--- a/packages/dashboard-core/src/components/page-header.tsx
+++ b/packages/dashboard-core/src/components/page-header.tsx
@@ -15,6 +15,7 @@ import type { JsonPreviewDrawerProps } from '@spree/dashboard-ui/spree/json-prev
import { BracesIcon, CheckIcon, CopyIcon, EllipsisVerticalIcon, TrashIcon } from 'lucide-react'
import { lazy, type ReactNode, Suspense, useState } from 'react'
import { useTranslation } from 'react-i18next'
+import { useRegisterPageHeader } from '../providers/sticky-header-provider'
import { Slot } from './slot'
// JSON drawer is a developer-only feature; pulling its tree (which includes
@@ -120,15 +121,26 @@ export function PageHeader({
setJsonOpen(true)
}
const scrolled = useScrolled()
+ // Tells the TopBar there's a header here to take over the top of the
+ // viewport, so it may slide away once the user scrolls, and reports when
+ // that hand-over is happening.
+ const collapsed = useRegisterPageHeader()
return (
- // Sticky below the TopBar (which sticks at `top-0`, height
- // `--spacing-header-height`) so the title, badges, and primary actions
- // (notably Save on form pages) stay reachable as the user scrolls long
- // detail pages. `bg-background` masks the content scrolling behind it;
+ // This parks at `top-header-height`, directly below the TopBar, so the
+ // title, badges, and primary actions (notably Save on form pages) stay
+ // reachable as the user scrolls long detail pages.
+ //
+ // On scroll the TopBar retreats and this header rises to take its place.
+ // That rise is a `translateY`, not a change of `top`: `top` is a layout
+ // property with no transition, so animating it would teleport this header
+ // 58px while the TopBar slid, visibly breaking the pair apart. Both now
+ // move by the same distance, over the same duration and curve, off one
+ // shared scroll flag.
+ //
+ // `bg-background` masks the content scrolling behind it;
// `-mx-4 px-4 lg:-mx-6 lg:px-6` and `-mt-4 lg:-mt-6 pt-4 lg:pt-6` undo
- // and re-apply the parent padding so the sticky band runs edge-to-edge
- // and there's no transparent gap between the TopBar and the header.
+ // and re-apply the parent padding so the sticky band runs edge-to-edge.
//
// The `::after` pseudo-element is the bottom hairline — it fades in
// once the user scrolls (so the header blends at rest, separates when
@@ -139,7 +151,17 @@ export function PageHeader({
<header
className={cn(
'sticky top-header-height z-20 -mx-4 -mt-4 flex items-start gap-3 bg-background/90 backdrop-blur supports-[backdrop-filter]:bg-background/75 px-4 pt-4 pb-3 lg:-mx-6 lg:-mt-6 lg:px-6 lg:pt-6',
- 'after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-border after:opacity-0 after:transition-opacity after:duration-150 after:[mask-image:linear-gradient(to_right,transparent,black_8%,black_92%,transparent)]',
+ // `translate` is listed explicitly: Tailwind v4 compiles
+ // `-translate-y-*` to the standalone `translate` property, so a
+ // `transform`-only transition never animates it and the header would
+ // jump to its raised position while the TopBar slid — the exact desync
+ // this pairing exists to avoid.
+ 'transition-[transform,translate,box-shadow] duration-200 ease-out',
+ // Reduced motion: hold position rather than teleport. Suppressing only
+ // the transition would leave the 58px jump this pairing exists to avoid.
+ 'motion-reduce:transition-none motion-reduce:translate-y-0',
+ 'after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-border after:opacity-0 after:transition-opacity after:duration-200 after:[mask-image:linear-gradient(to_right,transparent,black_8%,black_92%,transparent)]',
+ collapsed && '-translate-y-header-height',
scrolled && 'after:opacity-100 shadow-xs',
)}
>
diff --git a/packages/dashboard-core/src/components/settings-sidebar.tsx b/packages/dashboard-core/src/components/settings-sidebar.tsx
index d201f0304f..8a88bb6149 100644
--- a/packages/dashboard-core/src/components/settings-sidebar.tsx
+++ b/packages/dashboard-core/src/components/settings-sidebar.tsx
@@ -56,9 +56,12 @@ export function SettingsSidebar({ open }: { open: boolean }) {
: 'lg:w-0 border-e-0 border-transparent',
)}
>
+ {/* `quiet-scrollbar` rather than the browser default: this nav is an
+ inset panel beside the primary sidebar, and a full-width native
+ scrollbar cuts a heavy grey stripe down the middle of the chrome. */}
<div
className={cn(
- 'flex h-full w-(--spacing-sidebar-width) flex-col gap-2 overflow-y-auto py-2 transition-opacity duration-200',
+ 'quiet-scrollbar flex h-full w-(--spacing-sidebar-width) flex-col gap-2 overflow-y-auto py-2 transition-opacity duration-200',
open ? 'opacity-100 delay-100' : 'pointer-events-none opacity-0',
)}
>
diff --git a/packages/dashboard-core/src/components/top-bar.tsx b/packages/dashboard-core/src/components/top-bar.tsx
index 99c5395bce..50385701f0 100644
--- a/packages/dashboard-core/src/components/top-bar.tsx
+++ b/packages/dashboard-core/src/components/top-bar.tsx
@@ -3,6 +3,7 @@ import {
AvatarFallback,
AvatarImage,
Button,
+ cn,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
@@ -12,6 +13,7 @@ import {
LanguageMenuItems,
SidebarTrigger,
ThemeMenuItems,
+ usePrefersReducedMotion,
} from '@spree/dashboard-ui'
import { Link } from '@tanstack/react-router'
import {
@@ -30,6 +32,7 @@ import { useSwitchAdminLocale } from '../hooks/use-switch-admin-locale'
import { getInitials } from '../lib/formatters'
import { i18n } from '../lib/i18n'
import { storefrontHref } from '../lib/storefront'
+import { useStickyHeader } from '../providers/sticky-header-provider'
import { useStore } from '../providers/store-provider'
const IS_MAC = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform ?? '')
@@ -52,8 +55,31 @@ export function TopBar({
}: {
uiLocales?: ReadonlyArray<{ code: string; name: string }>
}) {
+ // Give the vertical space back to the page: once the user scrolls a detail
+ // page, the PageHeader below carries the title and the primary actions, so
+ // the search/account bar retreats out of the viewport rather than parking a
+ // second band of chrome above it. The provider owns this flag so both bars
+ // move off one signal; it stays false on pages with no PageHeader to take
+ // over (list views), where hiding the bar would cost a header and give
+ // nothing back.
+ const { collapsed } = useStickyHeader()
+ const prefersReducedMotion = usePrefersReducedMotion()
+ // Under reduced motion the bar simply stays — sliding it is the movement
+ // the setting asks us to drop, and cutting only the transition would
+ // replace the slide with a jump, which is worse.
+ const hidden = collapsed && !prefersReducedMotion
+
return (
- <header className="sticky top-0 z-40 flex h-header-height shrink-0 items-center gap-3 bg-background/90 px-4 border-b border-border/50 backdrop-blur supports-[backdrop-filter]:bg-background/75">
+ <header
+ className={cn(
+ 'sticky top-0 z-40 flex h-header-height shrink-0 items-center gap-3 bg-background/90 px-4 border-b border-border/50 backdrop-blur supports-[backdrop-filter]:bg-background/75',
+ 'transition-transform duration-200 ease-out motion-reduce:transition-none',
+ hidden && '-translate-y-full',
+ )}
+ // Hidden from assistive tech and out of the tab order while off-screen,
+ // so keyboard focus can't land on a control the user cannot see.
+ inert={hidden || undefined}
+ >
<SidebarTrigger className="-ml-1 h-8 w-8" />
<div className="flex flex-1 justify-center">
diff --git a/packages/dashboard-core/src/hooks/use-auto-collapse-sidebar.ts b/packages/dashboard-core/src/hooks/use-auto-collapse-sidebar.ts
new file mode 100644
index 0000000000..5d44a04047
--- /dev/null
+++ b/packages/dashboard-core/src/hooks/use-auto-collapse-sidebar.ts
@@ -0,0 +1,57 @@
+import { useSidebar } from '@spree/dashboard-ui'
+import { useEffect, useRef } from 'react'
+
+/**
+ * Collapses the primary sidebar to its icon rail while `active` is true, and
+ * restores the previous state when it goes false.
+ *
+ * Used by the settings area, where a second full-width nav appears beside the
+ * primary one: two stacked 220px columns leave the settings forms squeezed, so
+ * the primary nav folds down to icons for the duration.
+ *
+ * Only the entering and leaving transitions are driven — a manual toggle while
+ * `active` stays true is left alone, and is what gets remembered on the way
+ * out, so the merchant always keeps the last word.
+ */
+export function useAutoCollapseSidebar(active: boolean) {
+ // Transient on purpose: this collapse is the app's doing, not the
+ // merchant's, so it must not overwrite their remembered preference.
+ const { open, setOpenTransient, isMobile } = useSidebar()
+ // Reading `open` through a ref keeps it out of the effect's dependencies:
+ // the effect must run on the `active` edges only, never on every toggle.
+ const openRef = useRef(open)
+ openRef.current = open
+ const restoreTo = useRef<boolean | null>(null)
+
+ useEffect(() => {
+ // On mobile the primary nav is an overlay sheet, not a column competing
+ // for width, so there is nothing to reclaim. Undo any collapse this hook
+ // already made before bailing out: `useIsMobile` reports false on its
+ // first render, so a phone loading straight into settings collapses the
+ // rail and only then learns it is mobile. Dropping the snapshot without
+ // restoring would strand the rail collapsed for the whole session.
+ if (isMobile) {
+ if (restoreTo.current) setOpenTransient(true)
+ restoreTo.current = null
+ return
+ }
+
+ if (active) {
+ // Only snapshot on the way in. Re-running while already active (e.g.
+ // navigating between two settings pages) must not re-capture a state
+ // this hook itself imposed.
+ if (restoreTo.current === null) restoreTo.current = openRef.current
+ if (openRef.current) setOpenTransient(false)
+ return
+ }
+
+ if (restoreTo.current !== null) {
+ const wasOpenOnEntry = restoreTo.current
+ restoreTo.current = null
+ // Restore only if the rail is still collapsed — i.e. still as this hook
+ // left it. A merchant who expanded it during settings has said what they
+ // want, and forcing the entry-time value back would overrule them.
+ if (wasOpenOnEntry && !openRef.current) setOpenTransient(true)
+ }
+ }, [active, isMobile, setOpenTransient])
+}
diff --git a/packages/dashboard-core/src/index.ts b/packages/dashboard-core/src/index.ts
index 103e81a034..5ede42cccb 100644
--- a/packages/dashboard-core/src/index.ts
+++ b/packages/dashboard-core/src/index.ts
@@ -47,6 +47,7 @@ export * from './components/top-bar'
// Infra hooks
// ---------------------------------------------------------------------------
export * from './hooks/use-auth'
+export * from './hooks/use-auto-collapse-sidebar'
export * from './hooks/use-command-palette'
export * from './hooks/use-countries'
export * from './hooks/use-custom-fields'
@@ -94,4 +95,5 @@ export * from './plugin'
// ---------------------------------------------------------------------------
export * from './providers/auth-provider'
export * from './providers/permission-provider'
+export * from './providers/sticky-header-provider'
export * from './providers/store-provider'
diff --git a/packages/dashboard-core/src/providers/sticky-header-provider.tsx b/packages/dashboard-core/src/providers/sticky-header-provider.tsx
new file mode 100644
index 0000000000..1ecfa891df
--- /dev/null
+++ b/packages/dashboard-core/src/providers/sticky-header-provider.tsx
@@ -0,0 +1,81 @@
+import { useScrolled } from '@spree/dashboard-ui'
+import { createContext, type ReactNode, useContext, useEffect, useMemo, useState } from 'react'
+
+interface StickyHeaderContextValue {
+ /** True while a `PageHeader` is mounted on the current page. */
+ hasPageHeader: boolean
+ /**
+ * True once the user has scrolled far enough for the TopBar to give up its
+ * place to the PageHeader. Both headers read this single value so they move
+ * as one — deriving it separately in each is what let them desync.
+ */
+ collapsed: boolean
+ /** Registers a mounted `PageHeader`; returns the deregistration callback. */
+ registerPageHeader: () => () => void
+}
+
+const StickyHeaderContext = createContext<StickyHeaderContextValue | null>(null)
+
+// Engage only once the page has scrolled by more than the TopBar's own height,
+// and disengage well before that. Without the gap, a slow scroll around a
+// single boundary toggles repeatedly and both headers judder.
+const COLLAPSE_AT = 64
+const RELEASE_AT = 8
+
+/**
+ * Coordinates the two stacked sticky bars — the `TopBar` (search, store
+ * switcher, account) and a page's `PageHeader` (title, badges, Save).
+ *
+ * Only one of them needs to stay on screen while the user scrolls a long
+ * page: the PageHeader carries the actions, the TopBar carries navigation
+ * the user isn't using mid-page. So the TopBar slides away on scroll and the
+ * PageHeader rises to take its place, giving detail pages back a full
+ * header's worth of vertical space.
+ *
+ * The TopBar only retreats when a PageHeader is actually mounted to replace
+ * it — on pages without one (list views), the search bar stays put.
+ */
+export function StickyHeaderProvider({ children }: { children: ReactNode }) {
+ const [count, setCount] = useState(0)
+ const scrolled = useScrolled(COLLAPSE_AT, RELEASE_AT)
+ const hasPageHeader = count > 0
+
+ const value = useMemo<StickyHeaderContextValue>(
+ () => ({
+ hasPageHeader,
+ collapsed: scrolled && hasPageHeader,
+ registerPageHeader: () => {
+ setCount((n) => n + 1)
+ return () => setCount((n) => n - 1)
+ },
+ }),
+ [hasPageHeader, scrolled],
+ )
+
+ return <StickyHeaderContext.Provider value={value}>{children}</StickyHeaderContext.Provider>
+}
+
+/**
+ * Reads the shared sticky-header state. Returns inert defaults outside a
+ * provider so `PageHeader`/`TopBar` remain usable standalone (tests, plugin
+ * previews) without throwing.
+ */
+export function useStickyHeader(): StickyHeaderContextValue {
+ return (
+ useContext(StickyHeaderContext) ?? {
+ hasPageHeader: false,
+ collapsed: false,
+ registerPageHeader: () => () => {},
+ }
+ )
+}
+
+/**
+ * Announces a mounted `PageHeader` for the lifetime of the calling component,
+ * and reports whether the pair is currently collapsed.
+ */
+export function useRegisterPageHeader(): boolean {
+ const { registerPageHeader, collapsed } = useStickyHeader()
+ useEffect(() => registerPageHeader(), [registerPageHeader])
+ return collapsed
+}
diff --git a/packages/dashboard-ui/src/hooks/use-prefers-reduced-motion.ts b/packages/dashboard-ui/src/hooks/use-prefers-reduced-motion.ts
new file mode 100644
index 0000000000..c1485f711e
--- /dev/null
+++ b/packages/dashboard-ui/src/hooks/use-prefers-reduced-motion.ts
@@ -0,0 +1,26 @@
+import * as React from 'react'
+
+/**
+ * Tracks the user's `prefers-reduced-motion` setting, live.
+ *
+ * For motion that CSS alone can't soften. Suppressing a transition in CSS
+ * turns a slide into a jump, which is the opposite of what the setting asks
+ * for; reading the preference here lets a component drop the movement
+ * altogether and simply hold its position.
+ *
+ * Starts `false` so a future SSR render and the first client paint agree; the
+ * effect resyncs on mount.
+ */
+export function usePrefersReducedMotion() {
+ const [prefersReducedMotion, setPrefersReducedMotion] = React.useState(false)
+
+ React.useEffect(() => {
+ const mql = window.matchMedia('(prefers-reduced-motion: reduce)')
+ const onChange = () => setPrefersReducedMotion(mql.matches)
+ onChange()
+ mql.addEventListener('change', onChange)
+ return () => mql.removeEventListener('change', onChange)
+ }, [])
+
+ return prefersReducedMotion
+}
diff --git a/packages/dashboard-ui/src/hooks/use-scrolled.ts b/packages/dashboard-ui/src/hooks/use-scrolled.ts
index 4171735aae..93fa1ca842 100644
--- a/packages/dashboard-ui/src/hooks/use-scrolled.ts
+++ b/packages/dashboard-ui/src/hooks/use-scrolled.ts
@@ -8,11 +8,16 @@ import * as React from 'react'
*
* Listens passively to `window` scroll. Default threshold is 4px to avoid
* flickering at the boundary on devices that report fractional scroll
- * positions. Initial value is computed synchronously on mount so the first
- * paint matches the actual scroll position (e.g., after browser scroll
- * restoration on navigation).
+ * positions.
+ *
+ * @param threshold Scroll offset, in pixels, at which the state flips to true.
+ * @param releaseThreshold Offset the user must scroll back above before it
+ * flips to false again. Defaults to `threshold` (no hysteresis). Set it
+ * lower than `threshold` when the flag drives motion: a single boundary
+ * makes a slow scroll across it toggle repeatedly, and anything animating
+ * off this flag then flickers.
*/
-export function useScrolled(threshold = 4) {
+export function useScrolled(threshold = 4, releaseThreshold = threshold) {
// Always start `false` so a future SSR render and the first client paint
// agree (no hydration mismatch). The effect below resyncs against the
// actual scroll position on mount, so any restored scroll position is
@@ -20,11 +25,18 @@ export function useScrolled(threshold = 4) {
const [scrolled, setScrolled] = React.useState(false)
React.useEffect(() => {
- const onScroll = () => setScrolled(window.scrollY > threshold)
+ const onScroll = () =>
+ // Reading the previous value here (rather than from a dependency) keeps
+ // the listener stable while still letting the two thresholds apply
+ // directionally: past `threshold` to engage, back above
+ // `releaseThreshold` to disengage.
+ setScrolled((wasScrolled) =>
+ wasScrolled ? window.scrollY > releaseThreshold : window.scrollY > threshold,
+ )
onScroll()
window.addEventListener('scroll', onScroll, { passive: true })
return () => window.removeEventListener('scroll', onScroll)
- }, [threshold])
+ }, [threshold, releaseThreshold])
return scrolled
}
diff --git a/packages/dashboard-ui/src/index.ts b/packages/dashboard-ui/src/index.ts
index b0181677b7..1ebcc01bf4 100644
--- a/packages/dashboard-ui/src/index.ts
+++ b/packages/dashboard-ui/src/index.ts
@@ -13,6 +13,7 @@
export * from './hooks/use-copy-to-clipboard'
export { useIsMobile } from './hooks/use-mobile'
+export * from './hooks/use-prefers-reduced-motion'
export * from './hooks/use-scrolled'
// ---------------------------------------------------------------------------
// Helpers + hooks
diff --git a/packages/dashboard-ui/src/styles.css b/packages/dashboard-ui/src/styles.css
index 5b3e843794..90fe587572 100644
--- a/packages/dashboard-ui/src/styles.css
+++ b/packages/dashboard-ui/src/styles.css
@@ -126,6 +126,16 @@
--spacing-sidebar-width: 220px;
--spacing-header-height: 58px;
+ /* Easing. Overrides Tailwind's built-in `ease-out`, so every `ease-out`
+ utility in the app picks this up: the stock curve is too weak to read as
+ deliberate on anything larger than a colour change. `ease-out` is the
+ right default for UI — it starts fast, so the moment the user is watching
+ happens immediately. Movement across the screen wants `ease-in-out`
+ instead; `ease-in` is wrong for UI at any size, since it delays that
+ same moment. */
+ --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
+ --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
+
/* Color mappings */
--color-sidebar-ring: var(--sidebar-ring);
--color-sidebar-border: var(--sidebar-border);
@@ -209,6 +219,49 @@
}
}
+@utility quiet-scrollbar {
+ /* Like `themed-scrollbar`, but the thumb stays invisible until the element
+ is hovered. For navigation panels and other chrome, where a permanently
+ visible track draws a heavy stripe down an otherwise calm surface. The
+ gutter is reserved either way, so revealing the thumb never reflows the
+ content. */
+ /* `scrollbar-color` is not animatable, so the Firefox path snaps between
+ states; the webkit thumb below fades. Both are acceptable — the reveal is
+ incidental, not something the user is watching for. */
+ scrollbar-color: transparent transparent;
+ scrollbar-width: thin;
+
+ &:hover,
+ &:focus-within {
+ scrollbar-color: var(--scrollbar-thumb) transparent;
+ }
+
+ &::-webkit-scrollbar {
+ width: 10px;
+ height: 10px;
+ }
+ &::-webkit-scrollbar-track {
+ background: transparent;
+ }
+ &::-webkit-scrollbar-thumb {
+ background-color: transparent;
+ border: 2px solid transparent;
+ border-radius: 9999px;
+ background-clip: padding-box;
+ transition: background-color 150ms ease-out;
+ }
+ &:hover::-webkit-scrollbar-thumb,
+ &:focus-within::-webkit-scrollbar-thumb {
+ background-color: var(--scrollbar-thumb);
+ }
+ &::-webkit-scrollbar-thumb:hover {
+ background-color: var(--scrollbar-thumb-hover);
+ }
+ &::-webkit-scrollbar-corner {
+ background: transparent;
+ }
+}
+
@layer base {
:root {
--scrollbar-thumb: oklch(0.7 0 0); /* gray-400-ish */
@@ -336,3 +389,38 @@
-5px 0;
}
}
+
+/* Reduced motion. Deliberately NOT inside `@layer base`: unlayered CSS always
+ outranks layered CSS, so a base-layer rule loses to every `transition-*`
+ utility and the preference would be silently ignored. Unlayered and last in
+ the file, this wins on source order instead.
+
+ Movement is what the setting asks us to drop, so `transform`, `translate`
+ and `scale` are absent from the property list below — no element can animate
+ position or size however it is styled. Colour, shadow and opacity keep their
+ normal timing: they change appearance in place rather than moving anything,
+ and killing them too reads as broken rather than calm.
+
+ Components needing more than this — where suppressing a transition leaves a
+ jump rather than removing a movement — read the preference directly via
+ `usePrefersReducedMotion` and hold position, or opt out with a
+ `motion-reduce:` utility. */
+@media (prefers-reduced-motion: reduce) {
+ *,
+ *::before,
+ *::after {
+ transition-property: color, background-color, border-color, box-shadow, opacity, fill, stroke;
+ transition-duration: 100ms;
+ /* Holds looping decorative animations at their first frame. */
+ animation-duration: 0.01ms;
+ animation-iteration-count: 1;
+ scroll-behavior: auto;
+ }
+
+ /* Spinners are the deliberate exception: they signal that work is ongoing
+ and have no static equivalent. */
+ .animate-spin {
+ animation-duration: 1s;
+ animation-iteration-count: infinite;
+ }
+}
diff --git a/packages/dashboard-ui/src/ui/badge.tsx b/packages/dashboard-ui/src/ui/badge.tsx
index d5937846a5..bf5cd10b6e 100644
--- a/packages/dashboard-ui/src/ui/badge.tsx
+++ b/packages/dashboard-ui/src/ui/badge.tsx
@@ -6,7 +6,7 @@ import { cn } from '../lib/utils'
import { Slot } from './slot'
const badgeVariants = cva(
- 'group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!',
+ 'group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,background-color,border-color,box-shadow] duration-100 ease-out focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!',
{
variants: {
variant: {
diff --git a/packages/dashboard-ui/src/ui/button.tsx b/packages/dashboard-ui/src/ui/button.tsx
index b9afc72415..fc7a73064e 100644
--- a/packages/dashboard-ui/src/ui/button.tsx
+++ b/packages/dashboard-ui/src/ui/button.tsx
@@ -4,7 +4,7 @@ import { cn } from '../lib/utils'
import { Slot } from './slot'
const buttonVariants = cva(
- "group/button inline-flex shrink-0 items-center justify-center gap-2 rounded-xl border border-transparent text-sm font-medium whitespace-nowrap cursor-pointer select-none no-underline transition-[color,background-color,border-color,box-shadow] duration-100 ease-linear outline-none focus-visible:border-blue-500 focus-visible:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] disabled:pointer-events-none disabled:opacity-70 disabled:cursor-not-allowed aria-invalid:border-destructive [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
+ "group/button inline-flex shrink-0 items-center justify-center gap-2 rounded-xl border border-transparent text-sm font-medium whitespace-nowrap cursor-pointer select-none no-underline transition-[color,background-color,border-color,box-shadow,transform,translate,scale] duration-100 ease-out outline-none active:scale-[0.98] motion-reduce:active:scale-100 focus-visible:border-blue-500 focus-visible:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] disabled:pointer-events-none disabled:opacity-70 disabled:cursor-not-allowed aria-invalid:border-destructive [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
{
variants: {
variant: {
diff --git a/packages/dashboard-ui/src/ui/combobox.tsx b/packages/dashboard-ui/src/ui/combobox.tsx
index d3c2512ed0..db15311f5e 100644
--- a/packages/dashboard-ui/src/ui/combobox.tsx
+++ b/packages/dashboard-ui/src/ui/combobox.tsx
@@ -100,6 +100,12 @@ function ComboboxContent({
data-slot="combobox-content"
data-chips={!!anchor}
className={cn(
+ // Deliberately keeps `animate-in`/`animate-out` keyframes where the
+ // other floating surfaces use transitions. Converting this one to
+ // `data-[starting-style]` transitions broke the multi-select chips
+ // picker: the list re-renders as the user filters, and options
+ // arriving mid-transition sit at `opacity-0` long enough to be
+ // unclickable. The keyframes make the panel opaque immediately.
'group/combobox-content relative max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-[calc(var(--anchor-width)+--spacing(7))] origin-(--transform-origin) overflow-hidden rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[chips=true]:min-w-(--anchor-width) data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 *:data-[slot=input-group]:m-1 *:data-[slot=input-group]:mb-0 *:data-[slot=input-group]:h-8 *:data-[slot=input-group]:border-input/30 *:data-[slot=input-group]:bg-input/30 *:data-[slot=input-group]:shadow-none data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',
className,
)}
@@ -197,7 +203,13 @@ function ComboboxChips({
<ComboboxPrimitive.Chips
data-slot="combobox-chips"
className={cn(
- 'flex flex-wrap items-center gap-1 rounded-lg border border-border bg-card text-foreground shadow-xs px-2.5 py-1.5 text-base transition-all duration-100 ease-in-out focus-within:border-blue-500 focus-within:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] has-aria-invalid:border-destructive has-data-[slot=combobox-chip]:px-1',
+ // Keeps `transition-all` where the sibling inputs narrowed theirs: this
+ // element is the popup's anchor, and adding a chip reflows it
+ // (`flex-wrap`, `has-data-[slot=combobox-chip]:px-1`). Animating that
+ // resize lets the positioner follow the anchor smoothly; making it
+ // instant jumps the open popup out from under the pointer, so the next
+ // option click lands on nothing.
+ 'flex flex-wrap items-center gap-1 rounded-lg border border-border bg-card text-foreground shadow-xs px-2.5 py-1.5 text-base transition-all duration-100 ease-out focus-within:border-blue-500 focus-within:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] has-aria-invalid:border-destructive has-data-[slot=combobox-chip]:px-1',
className,
)}
{...props}
diff --git a/packages/dashboard-ui/src/ui/dialog.tsx b/packages/dashboard-ui/src/ui/dialog.tsx
index c1bf2c4e27..9ebc90389b 100644
--- a/packages/dashboard-ui/src/ui/dialog.tsx
+++ b/packages/dashboard-ui/src/ui/dialog.tsx
@@ -105,7 +105,7 @@ function DialogContent({
<DialogPrimitive.Popup
data-slot="dialog-content"
className={cn(
- 'fixed top-1/2 left-1/2 z-50 flex w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border bg-card text-foreground text-sm shadow-lg duration-100 outline-none sm:max-w-[500px] data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 transition-[opacity,transform]',
+ 'fixed top-1/2 left-1/2 z-50 flex w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border bg-card text-foreground text-sm shadow-lg duration-100 outline-none sm:max-w-[500px] data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 transition-[opacity,transform,translate,scale]',
className,
)}
style={{ maxHeight: '90vh' }}
diff --git a/packages/dashboard-ui/src/ui/dropdown-menu.tsx b/packages/dashboard-ui/src/ui/dropdown-menu.tsx
index cb9d9661f9..d02730cd39 100644
--- a/packages/dashboard-ui/src/ui/dropdown-menu.tsx
+++ b/packages/dashboard-ui/src/ui/dropdown-menu.tsx
@@ -81,7 +81,9 @@ function DropdownMenuContent({
<MenuPrimitive.Popup
data-slot="dropdown-menu-content"
className={cn(
- 'z-50 max-h-[var(--available-height)] min-w-40 max-w-80 overflow-x-hidden overflow-y-auto rounded-2xl border border-border bg-popover p-1 text-popover-foreground shadow-lg duration-100 data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 transition-[opacity,transform]',
+ // `origin-(--transform-origin)` so the menu grows out of its
+ // trigger rather than its own centre.
+ 'z-50 max-h-[var(--available-height)] min-w-40 max-w-80 overflow-x-hidden overflow-y-auto rounded-2xl border border-border bg-popover p-1 text-popover-foreground shadow-lg origin-(--transform-origin) duration-100 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 transition-[opacity,transform,translate,scale]',
className,
)}
{...props}
@@ -317,7 +319,9 @@ function DropdownMenuSubContent({
<MenuPrimitive.Popup
data-slot="dropdown-menu-sub-content"
className={cn(
- 'z-50 min-w-[96px] overflow-hidden rounded-2xl border border-border bg-popover p-1 text-popover-foreground shadow-lg duration-100 data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 transition-[opacity,transform]',
+ // `origin-(--transform-origin)` so the submenu grows out of its
+ // parent item rather than its own centre.
+ 'z-50 min-w-[96px] overflow-hidden rounded-2xl border border-border bg-popover p-1 text-popover-foreground shadow-lg origin-(--transform-origin) duration-100 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 transition-[opacity,transform,translate,scale]',
className,
)}
{...props}
diff --git a/packages/dashboard-ui/src/ui/input-group.tsx b/packages/dashboard-ui/src/ui/input-group.tsx
index 0260f37aee..cd29758e93 100644
--- a/packages/dashboard-ui/src/ui/input-group.tsx
+++ b/packages/dashboard-ui/src/ui/input-group.tsx
@@ -11,7 +11,7 @@ function InputGroup({ className, ...props }: React.ComponentProps<'div'>) {
data-slot="input-group"
role="group"
className={cn(
- 'group/input-group relative flex w-full min-w-0 items-center rounded-lg border border-border bg-card text-foreground shadow-xs transition-all duration-100 ease-in-out outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:shadow-none has-disabled:bg-muted has-disabled:border-border has-disabled:opacity-50 has-disabled:shadow-none has-[[data-slot=input-group-control]:focus-visible]:border-blue-500 has-[[data-slot=input-group-control]:focus-visible]:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] has-[[data-slot][aria-invalid=true]]:border-destructive has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5',
+ 'group/input-group relative flex w-full min-w-0 items-center rounded-lg border border-border bg-card text-foreground shadow-xs transition-[color,background-color,border-color,box-shadow] duration-100 ease-out outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:shadow-none has-disabled:bg-muted has-disabled:border-border has-disabled:opacity-50 has-disabled:shadow-none has-[[data-slot=input-group-control]:focus-visible]:border-blue-500 has-[[data-slot=input-group-control]:focus-visible]:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] has-[[data-slot][aria-invalid=true]]:border-destructive has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5',
className,
)}
{...props}
diff --git a/packages/dashboard-ui/src/ui/input.tsx b/packages/dashboard-ui/src/ui/input.tsx
index a49c8fbb3b..668cc1410f 100644
--- a/packages/dashboard-ui/src/ui/input.tsx
+++ b/packages/dashboard-ui/src/ui/input.tsx
@@ -8,7 +8,7 @@ function Input({ className, type, ...props }: React.ComponentProps<'input'>) {
type={type}
data-slot="input"
className={cn(
- 'block w-full min-w-0 min-h-8 rounded-lg border border-border bg-card py-1.5 px-2.5 text-base font-normal leading-normal text-foreground shadow-xs transition-all duration-100 ease-in-out outline-none placeholder:text-muted-foreground focus:border-blue-500 focus:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-muted disabled:border-border disabled:text-muted-foreground disabled:shadow-none aria-invalid:border-destructive file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground',
+ 'block w-full min-w-0 min-h-8 rounded-lg border border-border bg-card py-1.5 px-2.5 text-base font-normal leading-normal text-foreground shadow-xs transition-[color,background-color,border-color,box-shadow] duration-100 ease-out outline-none placeholder:text-muted-foreground focus:border-blue-500 focus:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-muted disabled:border-border disabled:text-muted-foreground disabled:shadow-none aria-invalid:border-destructive file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground',
className,
)}
{...props}
diff --git a/packages/dashboard-ui/src/ui/popover.tsx b/packages/dashboard-ui/src/ui/popover.tsx
index 3a7aa227e2..9e0d4fc020 100644
--- a/packages/dashboard-ui/src/ui/popover.tsx
+++ b/packages/dashboard-ui/src/ui/popover.tsx
@@ -57,7 +57,9 @@ function PopoverContent({
data-slot="popover-content"
className={cn(
'z-50 w-auto rounded-lg border border-border bg-popover p-3 text-popover-foreground shadow-md',
- 'duration-100 data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 transition-[opacity,transform]',
+ // `origin-(--transform-origin)` (published by Base UI's Positioner)
+ // so the panel grows out of its trigger rather than its own centre.
+ 'origin-(--transform-origin) duration-100 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 transition-[opacity,transform,translate,scale]',
className,
)}
{...props}
diff --git a/packages/dashboard-ui/src/ui/progress.tsx b/packages/dashboard-ui/src/ui/progress.tsx
index c6732fd515..fc7df857bd 100644
--- a/packages/dashboard-ui/src/ui/progress.tsx
+++ b/packages/dashboard-ui/src/ui/progress.tsx
@@ -41,7 +41,10 @@ function ProgressIndicator({ className, ...props }: ProgressPrimitive.Indicator.
<ProgressPrimitive.Indicator
data-slot="progress-indicator"
className={cn(
- 'h-full rounded-full bg-primary transition-all',
+ // `width` is a layout property, but it's the right one here: a
+ // determinate bar has to grow, and `scaleX` would distort the fill's
+ // rounded ends. Narrowed from `transition-all` so only width animates.
+ 'h-full rounded-full bg-primary transition-[width] duration-200 ease-out',
'data-[indeterminate]:w-1/3 data-[indeterminate]:animate-pulse',
className,
)}
diff --git a/packages/dashboard-ui/src/ui/rich-text-editor.tsx b/packages/dashboard-ui/src/ui/rich-text-editor.tsx
index 47cfcf822d..b0e95516c7 100644
--- a/packages/dashboard-ui/src/ui/rich-text-editor.tsx
+++ b/packages/dashboard-ui/src/ui/rich-text-editor.tsx
@@ -139,7 +139,7 @@ export function RichTextEditor({
<div
ref={wrapperRef}
className={cn(
- 'rounded-lg border border-border bg-card text-foreground shadow-xs transition-all duration-100 ease-in-out focus-within:border-blue-500 focus-within:shadow-[0_0_0_3px_rgba(59,130,246,0.15)]',
+ 'rounded-lg border border-border bg-card text-foreground shadow-xs transition-[color,background-color,border-color,box-shadow] duration-100 ease-out focus-within:border-blue-500 focus-within:shadow-[0_0_0_3px_rgba(59,130,246,0.15)]',
disabled && 'pointer-events-none bg-muted border-border',
className,
)}
diff --git a/packages/dashboard-ui/src/ui/sheet.tsx b/packages/dashboard-ui/src/ui/sheet.tsx
index 662635b037..df09609324 100644
--- a/packages/dashboard-ui/src/ui/sheet.tsx
+++ b/packages/dashboard-ui/src/ui/sheet.tsx
@@ -122,7 +122,13 @@ function SheetContent({
data-side={side}
dir={dir}
className={cn(
- 'fixed z-50 flex flex-col border border-border bg-card text-foreground text-sm shadow-lg transition duration-250 ease-out',
+ // Tailwind v4 compiles `translate-*`/`scale-*` to the standalone
+ // `translate`/`scale` properties rather than folding them into
+ // `transform`, so all four are listed. The slide below needs
+ // `translate`; the rest are listed because `className` is merged, so
+ // a caller can animate any of them — and a missing entry fails
+ // silently, as a jump rather than an error.
+ 'fixed z-50 flex flex-col border border-border bg-card text-foreground text-sm shadow-lg transition-[opacity,transform,translate,scale] duration-250 ease-out',
'data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-[calc(100dvh-1rem)] data-[side=right]:max-h-[calc(100dvh-1rem)] data-[side=right]:w-[calc(100vw-1rem)] data-[side=right]:max-w-[600px] data-[side=right]:min-w-[320px] data-[side=right]:m-2 data-[side=right]:rounded-xl',
'data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=left]:sm:max-w-sm',
'data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t',
diff --git a/packages/dashboard-ui/src/ui/sidebar.tsx b/packages/dashboard-ui/src/ui/sidebar.tsx
index 0d31dd1215..6bec79fad5 100644
--- a/packages/dashboard-ui/src/ui/sidebar.tsx
+++ b/packages/dashboard-ui/src/ui/sidebar.tsx
@@ -22,7 +22,15 @@ const SIDEBAR_KEYBOARD_SHORTCUT = 'b'
type SidebarContextProps = {
state: 'expanded' | 'collapsed'
open: boolean
+ /** Sets the state and remembers it as the user's preference. */
setOpen: (open: boolean) => void
+ /**
+ * Sets the state without remembering it. For collapses the app imposes on
+ * the user's behalf (e.g. the settings area folding the nav to icons to make
+ * room for its own): the merchant's own choice, made through the trigger,
+ * must survive it.
+ */
+ setOpenTransient: (open: boolean) => void
openMobile: boolean
setOpenMobile: (open: boolean) => void
isMobile: boolean
@@ -64,19 +72,34 @@ function SidebarProvider({
return defaultOpen
})
const open = openProp ?? _open
+
+ // The updater form needs the current value, but reading it from a ref rather
+ // than closing over it keeps the setters referentially stable — effects that
+ // depend on them (e.g. the settings auto-collapse) must fire on their own
+ // trigger, not again on every toggle.
+ const openRef = React.useRef(open)
+ openRef.current = open
+ const setOpenPropRef = React.useRef(setOpenProp)
+ setOpenPropRef.current = setOpenProp
+
+ const setOpenTransient = React.useCallback((value: boolean | ((value: boolean) => boolean)) => {
+ const openState = typeof value === 'function' ? value(openRef.current) : value
+ if (setOpenPropRef.current) {
+ setOpenPropRef.current(openState)
+ } else {
+ _setOpen(openState)
+ }
+ return openState
+ }, [])
+
const setOpen = React.useCallback(
(value: boolean | ((value: boolean) => boolean)) => {
- const openState = typeof value === 'function' ? value(open) : value
- if (setOpenProp) {
- setOpenProp(openState)
- } else {
- _setOpen(openState)
- }
+ const openState = setOpenTransient(value)
// This sets the cookie to keep the sidebar state.
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
},
- [setOpenProp, open],
+ [setOpenTransient],
)
// Helper to toggle the sidebar.
@@ -106,12 +129,13 @@ function SidebarProvider({
state,
open,
setOpen,
+ setOpenTransient,
isMobile,
openMobile,
setOpenMobile,
toggleSidebar,
}),
- [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar],
+ [state, open, setOpen, setOpenTransient, isMobile, openMobile, setOpenMobile, toggleSidebar],
)
return (
@@ -273,7 +297,7 @@ function SidebarRail({ className, ...props }: React.ComponentProps<'button'>) {
onClick={toggleSidebar}
title={i18n.t('admin.a11y.toggle_sidebar')}
className={cn(
- 'absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2',
+ 'absolute inset-y-0 z-20 hidden w-4 transition-colors duration-100 ease-out group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2',
'in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize',
'[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize',
'group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar',
@@ -454,7 +478,12 @@ function SidebarMenuItem({ className, ...props }: React.ComponentProps<'li'>) {
}
const sidebarMenuButtonVariants = cva(
- 'peer/menu-button group/menu-button flex gap-2 w-full items-center overflow-hidden rounded-xl p-1 text-left text-base text-sidebar-foreground/80 outline-hidden transition-colors duration-100 ease-in-out group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-10! group-data-[collapsible=icon]:items-center group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:overflow-visible group-data-[collapsible=icon]:p-0! group-data-[collapsible=icon]:gap-0 group-data-[collapsible=icon]:[&>span:last-child]:hidden hover:bg-sidebar-accent hover:text-sidebar-foreground focus-visible:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-open:hover:bg-sidebar-accent data-open:hover:text-sidebar-foreground data-active:bg-sidebar-accent data-active:text-foreground data-active:font-semibold [&>span:last-child]:truncate',
+ // `whitespace-nowrap` matters during the collapse: the width animates over
+ // 200ms, and mid-transition the row is too narrow for a label plus a trailing
+ // badge. Without it the flex line wraps and the label visibly squashes to two
+ // lines inside the fixed height until the animation lands. Labels clip
+ // instead — which is what the `truncate` below already intends.
+ 'peer/menu-button group/menu-button flex gap-2 w-full items-center overflow-hidden whitespace-nowrap rounded-xl p-1 text-left text-base text-sidebar-foreground/80 outline-hidden transition-colors duration-100 ease-out group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-10! group-data-[collapsible=icon]:items-center group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:overflow-visible group-data-[collapsible=icon]:p-0! group-data-[collapsible=icon]:gap-0 group-data-[collapsible=icon]:[&>span:last-child]:hidden hover:bg-sidebar-accent hover:text-sidebar-foreground focus-visible:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-open:hover:bg-sidebar-accent data-open:hover:text-sidebar-foreground data-active:bg-sidebar-accent data-active:text-foreground data-active:font-semibold [&>span:last-child]:truncate',
{
variants: {
variant: {
diff --git a/packages/dashboard-ui/src/ui/textarea.tsx b/packages/dashboard-ui/src/ui/textarea.tsx
index 73d55f96a7..eb8e9a0764 100644
--- a/packages/dashboard-ui/src/ui/textarea.tsx
+++ b/packages/dashboard-ui/src/ui/textarea.tsx
@@ -7,7 +7,7 @@ function Textarea({ className, ...props }: React.ComponentProps<'textarea'>) {
<textarea
data-slot="textarea"
className={cn(
- 'flex field-sizing-content min-h-16 w-full rounded-lg border border-border bg-card px-2.5 py-1.5 text-base font-normal leading-normal text-foreground shadow-xs transition-all duration-100 ease-in-out outline-none placeholder:text-muted-foreground focus:border-blue-500 focus:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-muted disabled:border-border disabled:text-muted-foreground disabled:shadow-none aria-invalid:border-destructive',
+ 'flex field-sizing-content min-h-16 w-full rounded-lg border border-border bg-card px-2.5 py-1.5 text-base font-normal leading-normal text-foreground shadow-xs transition-[color,background-color,border-color,box-shadow] duration-100 ease-out outline-none placeholder:text-muted-foreground focus:border-blue-500 focus:shadow-[0_0_0_3px_rgba(59,130,246,0.15)] disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-muted disabled:border-border disabled:text-muted-foreground disabled:shadow-none aria-invalid:border-destructive',
className,
)}
{...props}
diff --git a/packages/dashboard-ui/src/ui/tooltip.tsx b/packages/dashboard-ui/src/ui/tooltip.tsx
index e423cbbe64..04041e7cbd 100644
--- a/packages/dashboard-ui/src/ui/tooltip.tsx
+++ b/packages/dashboard-ui/src/ui/tooltip.tsx
@@ -85,7 +85,9 @@ function TooltipContent({
<TooltipPrimitive.Popup
data-slot="tooltip-content"
className={cn(
- 'z-50 inline-flex w-fit max-w-[200px] items-center gap-1.5 rounded-lg border border-border bg-popover px-2 py-1 text-sm font-normal text-popover-foreground shadow-md data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 transition-[opacity,transform] duration-100',
+ // `origin-(--transform-origin)` so it grows out of the element it
+ // describes rather than its own centre.
+ 'z-50 inline-flex w-fit max-w-[200px] items-center gap-1.5 rounded-lg border border-border bg-popover px-2 py-1 text-sm font-normal text-popover-foreground shadow-md origin-(--transform-origin) data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 transition-[opacity,transform,translate,scale] duration-100 ease-out',
className,
)}
{...props}
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId.tsx
index 91fff789dd..6a76b9da40 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId.tsx
@@ -3,8 +3,10 @@ import {
adminClient,
CommandPaletteProvider,
SettingsSidebar,
+ StickyHeaderProvider,
StoreProvider,
TopBar,
+ useAutoCollapseSidebar,
} from '@spree/dashboard-core'
import { SidebarInset, SidebarProvider } from '@spree/dashboard-ui'
import { createFileRoute, Outlet, useRouterState } from '@tanstack/react-router'
@@ -31,27 +33,44 @@ function StoreLayout() {
return (
<StoreProvider storeId={storeId}>
<CommandPaletteProvider>
- <SidebarProvider>
- <AppSidebar />
- {/* `flex-row` so the secondary sidebar can sit flush against the
- primary and span full height. The TopBar moves into the content
- column so the secondary sidebar can extend above it. */}
- <SidebarInset className="flex-row">
- <SettingsSidebar open={inSettings} />
- <div className="flex min-w-0 flex-1 flex-col">
- <TopBar uiLocales={UI_LOCALES} />
- {inSettings ? (
- <Outlet />
- ) : (
- <div className="container mx-auto flex flex-1 flex-col gap-4 p-4 lg:p-6">
- <Outlet />
- </div>
- )}
- </div>
- </SidebarInset>
- </SidebarProvider>
- <CommandPalette />
+ <StickyHeaderProvider>
+ <SidebarProvider>
+ <StoreShell inSettings={inSettings} />
+ </SidebarProvider>
+ <CommandPalette />
+ </StickyHeaderProvider>
</CommandPaletteProvider>
</StoreProvider>
)
}
+
+/**
+ * Inside `SidebarProvider` so it can drive the primary nav's collapsed state:
+ * the settings area brings its own full-width nav, so the primary one folds to
+ * icons while the merchant is in there.
+ */
+function StoreShell({ inSettings }: { inSettings: boolean }) {
+ useAutoCollapseSidebar(inSettings)
+
+ return (
+ <>
+ <AppSidebar />
+ {/* `flex-row` so the secondary sidebar can sit flush against the
+ primary and span full height. The TopBar moves into the content
+ column so the secondary sidebar can extend above it. */}
+ <SidebarInset className="flex-row">
+ <SettingsSidebar open={inSettings} />
+ <div className="flex min-w-0 flex-1 flex-col">
+ <TopBar uiLocales={UI_LOCALES} />
+ {inSettings ? (
+ <Outlet />
+ ) : (
+ <div className="container mx-auto flex flex-1 flex-col gap-4 p-4 lg:p-6">
+ <Outlet />
+ </div>
+ )}
+ </div>
+ </SidebarInset>
+ </>
+ )
+}