Skip to content
Website

UI Motion & Loading States

Patchwork uses a lightweight CSS-and-React motion and skeleton system designed for zero layout shift (CLS <= 0.05) and zero heavy animation dependencies.

Defined in src/app/globals.css and mirrored in src/lib/motion.ts:

Token Value Usage
--pw-dur-instant 0ms Immediate state switches and reduced motion
--pw-dur-fast 120ms Micro-transitions, fade-ins, command palette
--pw-dur-base 180ms Drawers, modals, snackbars, collapse panels
--pw-dur-slow 260ms Rollback shake and multi-step confirmations
--pw-dur-page 320ms Route-level transitions
--pw-ease-out cubic-bezier(0.16, 1, 0.3, 1) Entering elements
--pw-ease-in cubic-bezier(0.7, 0, 0.84, 0) Exiting elements
--pw-ease-in-out cubic-bezier(0.65, 0, 0.35, 1) Shimmer and progress loops
--pw-dist-xs / sm / md 4px / 8px / 16px Slide offsets
--pw-stagger-step 24ms List stagger step (capped at 12 items)

All keyframes and transitions animate transform and opacity only — never width, height, top, left, margin, or box-shadow on large elements.

  • src/components/ui/motion.tsx: Presence, Fade, Slide, Scale, Collapse (via grid-template-rows), RouteProgressBar, and RegionErrorBoundary.
  • src/components/ui/skeleton.tsx: Surface, Skeleton, SkeletonText, SkeletonCircle, SkeletonChip, SkeletonRegion, and RevalidateBar.
  • src/components/skeletons/: Domain-matched skeletons (WorkspaceSkeleton, BoardSkeleton, TicketPanelSkeleton, SystemConfigSkeleton, SetupWizardSkeleton, SearchPaletteSkeleton) plus Next.js App Router loading.tsx boundaries.

Skeleton colors are derived from their immediate surface via color-mix(in oklab, var(--sk-surface), var(--sk-ink) ...) with solid fallbacks, so skeletons maintain quiet contrast (1.08–1.50 WCAG ratio, 0.03–0.10 OKLCH lightness delta) on every background in both light and dark themes:

Surface (data-sk-surface) Light Base (--sk-surface) Dark Base (--sk-surface) Direction
page, card, input, code --pw-bg (#F6F5F2) --pw-bg (#0D1014) Darker in light, lighter in dark
surface, panel, popover, dialog, table-row, command --pw-surface (#FFFFFF) --pw-surface (#13181E) Darker in light, lighter in dark
rail --pw-rail-bg (#141920) --pw-rail-bg (#090C10) Always lighter (dark rail)
table-header, table-stripe, chip --pw-surface-muted (#ECEAE4) --pw-surface-muted (#1A2129) Darker in light, lighter in dark
table-hover --pw-surface-hover (#F0EFEA) --pw-surface-hover (#1E2630) Darker in light, lighter in dark
accent, table-selected --pw-accent-soft (#FCECE6) --pw-accent-soft (#2D1A14) Tinted toward surface ink
success, warning, destructive, info Semantic soft tokens Dark semantic soft tokens Tinted toward surface ink
  1. Wrap every container that renders skeletons in <Surface variant="..."> (or set data-sk-surface="..."). Nested surfaces automatically override --sk-surface and recompute --sk-base and --sk-shine.
  2. Never hardcode hex, rgb(), hsl(), or Tailwind gray utility classes inside skeleton components.
  3. prefers-contrast: more increases --sk-base-mix to 13%, and forced-colors: active draws a 1px solid CanvasText outline with no shimmer.

All data-dependent regions must render geometry-matched skeletons. Allowed exceptions (documented in loading-allowlist.yaml):

  • In-button pending states for user-initiated actions (e.g. “Saving…”, inline spinner inside the button).
  • Determinate progress bars (uploads, setup progress) and RouteProgressBar for stale-while-revalidate.
  • Short inline autosave status (“Saving…” / “Saved”).
  • The native installer CLI.
Section titled “Latency Harness, Dev Gallery, and Enforcement”
  • Dev Gallery: Visit /dev/skeletons in development (npm run dev) to inspect all 25 surface variants, nested surfaces, theme/reduced-motion/forced-colors toggles, and region compositions. Returns 404 in production builds.
  • Latency Harness: Set PATCHWORK_TEST_LATENCY_MS=1800 in non-production environments to delay /api/* requests and inspect skeleton geometry and zero-CLS transitions.
  • Static Enforcement: npm run loading:check (scripts/check-loading-states.mjs, run by npm run lint and npm run verify) fails on forbidden loading text literals, un-allowlisted spinners, fallback={null}, if (loading) return null, hardcoded skeleton colors, or route segments missing loading.tsx.
  • useAntiFlashLoading(isLoading, 150, 300) waits 150ms before showing a skeleton so fast cached responses never flash, and holds a visible skeleton for at least 300ms once shown.
  • Refetches (board switches, filters, SSE sync) keep existing content visible at opacity: 0.6 with a thin top RevalidateBar instead of replacing content with a skeleton.
  • Respects OS prefers-reduced-motion: reduce.
  • Users can also toggle Reduce motion in Preferences & Keyboard Shortcuts (UserSettingsModal), persisted under patchwork_reduce_motion and applied before paint via data-reduce-motion="true".
  • Background tabs pause CSS animations automatically via useDocumentHidden().
  • Automated tests can disable animations via NEXT_PUBLIC_DISABLE_ANIMATIONS=1 or window.__PATCHWORK_TEST_DISABLE_ANIMATIONS__ = true.