Route transitions

How this site covers the screen when you move between sections.

The scrim

One scrim for the whole site. Its first curtain covers the first paint and waits for the fonts. meta carries the duration and the easing, so the page underneath can keep pace.

tsx
// features/app.scrim.tsx
export const AppCurtain = ({ scrim }: ScrimProps<AppScrimMeta>) => (
  <m.div
    initial={scrim.phase === "covered" ? false : { x: "-100%" }}
    animate={{ x: scrim.phase === "leaving" ? "100%" : "0%" }}
    transition={scrim.meta}
    onAnimationComplete={() => scrim.done()}
    className="fixed inset-y-0 left-[-12vh] z-max w-[calc(100vw+24vh)]"
  >
    <div className="absolute inset-0 -skew-x-12 border-x-4 border-main bg-primary-darken" />
  </m.div>
);

export const AppScrim = createScrim(AppCurtain, {
  hold: 650,
  until: () => document.fonts.ready,
  meta: { duration: 0.65, ease: [0.65, 0, 0.35, 1] },
});

The root

Root wraps everything the curtains should cover, together with the other providers.

tsx
// screens/app/app-root.tsx
export const AppRoot = () => (
  <Wrap components={[IntlProvider, MotionProvider, Document, AppScrim.Root]}>
    <AppHeader />
    <Outlet />
  </Wrap>
);

The routes

Every section covers in beforeLoad, which the router waits for before loading the page. Each section brings its own curtain, so jumping between sections stacks different curtains.

tsx
// app/margo-ui/route.tsx
export const Route = createFileRoute("/margo-ui")({
  component: AppDocOutlet,
  beforeLoad: async ({ cause, routeId }) => {
    const scrim = AppScrim.getStatus();
    const isCovering = scrim?.status === "entering" || scrim?.status === "covered";

    if (isCovering ? scrim.key !== routeId : cause === "enter")
      await AppScrim.cover(MargoUiScrim, { key: routeId, hold: 650 });
  },
});

The router

Once a navigation has resolved, the router uncovers.

tsx
// app/router.ts
if (typeof window !== "undefined") router.subscribe("onResolved", AppScrim.uncover);

The page

Every page reads the top curtain, and rises in as soon as it starts leaving, at its pace.

tsx
// components/doc-page/doc-page.tsx
const { status, meta } = AppScrim.useStatus();

<m.main
  initial={false}
  animate={
    status === "covered"
      ? { opacity: 0, y: "4rem" }
      : { opacity: 1, y: 0, transition: { duration: meta.duration, ease: meta.ease } }
  }
/>