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.
Motion Tokens
Section titled “Motion Tokens”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.
Shared Primitives
Section titled “Shared Primitives”src/components/ui/motion.tsx:Presence,Fade,Slide,Scale,Collapse(viagrid-template-rows),RouteProgressBar, andRegionErrorBoundary.src/components/ui/skeleton.tsx:Surface,Skeleton,SkeletonText,SkeletonCircle,SkeletonChip,SkeletonRegion, andRevalidateBar.src/components/skeletons/: Domain-matched skeletons (WorkspaceSkeleton,BoardSkeleton,TicketPanelSkeleton,SystemConfigSkeleton,SetupWizardSkeleton,SearchPaletteSkeleton) plus Next.js App Routerloading.tsxboundaries.
Surface-Derived Skeleton Tokens
Section titled “Surface-Derived Skeleton Tokens”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 |
Adding a New Surface
Section titled “Adding a New Surface”- Wrap every container that renders skeletons in
<Surface variant="...">(or setdata-sk-surface="..."). Nested surfaces automatically override--sk-surfaceand recompute--sk-baseand--sk-shine. - Never hardcode hex,
rgb(),hsl(), or Tailwind gray utility classes inside skeleton components. prefers-contrast: moreincreases--sk-base-mixto13%, andforced-colors: activedraws a1px solid CanvasTextoutline with no shimmer.
Allowed Exceptions
Section titled “Allowed Exceptions”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
RouteProgressBarfor stale-while-revalidate. - Short inline autosave status (“Saving…” / “Saved”).
- The native installer CLI.
Latency Harness, Dev Gallery, and Enforcement
Section titled “Latency Harness, Dev Gallery, and Enforcement”- Dev Gallery: Visit
/dev/skeletonsin development (npm run dev) to inspect all 25 surface variants, nested surfaces, theme/reduced-motion/forced-colors toggles, and region compositions. Returns404in production builds. - Latency Harness: Set
PATCHWORK_TEST_LATENCY_MS=1800in 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 bynpm run lintandnpm run verify) fails on forbidden loading text literals, un-allowlisted spinners,fallback={null},if (loading) return null, hardcoded skeleton colors, or route segments missingloading.tsx.
Anti-Flash & Stale-While-Revalidate
Section titled “Anti-Flash & Stale-While-Revalidate”useAntiFlashLoading(isLoading, 150, 300)waits150msbefore showing a skeleton so fast cached responses never flash, and holds a visible skeleton for at least300msonce shown.- Refetches (board switches, filters, SSE sync) keep existing content visible at
opacity: 0.6with a thin topRevalidateBarinstead of replacing content with a skeleton.
Reduced Motion & Test Determinism
Section titled “Reduced Motion & Test Determinism”- Respects OS
prefers-reduced-motion: reduce. - Users can also toggle Reduce motion in Preferences & Keyboard Shortcuts (
UserSettingsModal), persisted underpatchwork_reduce_motionand applied before paint viadata-reduce-motion="true". - Background tabs pause CSS animations automatically via
useDocumentHidden(). - Automated tests can disable animations via
NEXT_PUBLIC_DISABLE_ANIMATIONS=1orwindow.__PATCHWORK_TEST_DISABLE_ANIMATIONS__ = true.