{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "route-progress",
  "title": "RouteProgress",
  "description": "The thin bar across the top of the screen while the app loads the next page or submits a form, so a click that waits on the server never feels frozen: one global affordance instead of a pending state on every action.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/route-progress/route-progress.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useReducer, useRef, useState, type CSSProperties, type JSX, type Ref } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\n/** Props for {@link RouteProgress}. */\nexport interface RouteProgressProps {\n  /**\n   * Whether a navigation or a form submission is under way: in React Router,\n   * `useNavigation().state !== \"idle\"`; in Next.js, the pending state of `useTransition`\n   * around `router.push`.\n   */\n  active: boolean;\n  /** What screen readers hear when a navigation starts. @default \"Loading\" */\n  label?: string | undefined;\n  /** Layout only: rarely needed, since the bar places itself at the top of the screen. Appearance classes warn in development. */\n  className?: string | undefined;\n  /** Reaches the root, the status region. */\n  ref?: Ref<HTMLDivElement> | undefined;\n\n  /** Not a prop. Ouro UI uses `active`: `<RouteProgress active={navigation.state !== \"idle\"} />`. */\n  loading?: { 'Use <RouteProgress active={navigation.state !== \"idle\"} />': never };\n  /** Not a prop. Ouro UI uses `active`: `<RouteProgress active={navigation.state !== \"idle\"} />`. */\n  isLoading?: { 'Use <RouteProgress active={navigation.state !== \"idle\"} />': never };\n  /** Not a prop. RouteProgress shows that something is loading, not how much; use `Progress` for a known amount. */\n  value?: { 'RouteProgress has no amount; use <Progress value={50}> for a known one': never };\n}\n\n// Class strings are literal so the app's Tailwind finds them when it compiles.\nconst rootClass = \"pointer-events-none fixed inset-x-0 top-0 z-(--ouro-layer) block h-0.5 print:hidden\";\n// The bar fades in and out; with reduced motion it fades faster.\nconst barClass =\n  \"absolute inset-0 overflow-hidden transition-opacity duration-(--ouro-duration-base) ease-(--ouro-ease-out) data-closed:opacity-0 \" +\n  \"motion-reduce:duration-(--ouro-duration-fast)\";\n// The filled part grows from the start edge to --ouro-route-progress of the width, easing into each step while\n// the bar shows. With reduced motion it is the whole width and never grows. A child selector, not `group-data-open`:\n// Chrome restyles every element under anything that gains or loses `data-open` while a `group-data-*` rule on it\n// exists, so each sheet, menu and popover open restyled the whole of it again (ourostack/ouro-ui#648).\nconst indicatorClass =\n  \"h-full w-full origin-left rtl:origin-right bg-primary scale-x-(--ouro-route-progress) \" +\n  \"motion-safe:[[data-open]>&]:transition-[scale] motion-safe:[[data-open]>&]:duration-(--ouro-duration-slow) motion-safe:[[data-open]>&]:ease-(--ouro-ease-out) \" +\n  \"motion-reduce:scale-x-100 forced-colors:bg-[CanvasText]\";\n\n/** How long a navigation runs before the bar shows, so a fast one shows and says nothing. */\nconst DELAY = 150;\n/** How often the bar creeps on while it shows. */\nconst TRICKLE = 400;\n/**\n * Where the bar starts, where it creeps toward, and the share of the rest it covers each step.\n *\n * @claim \"Where the bar starts, where it\" registry/ouro/components/ouro/route-progress/route-progress.test.tsx verify:testExists(registry/ouro/components/ouro/route-progress/route-progress.test.tsx::RouteProgress > trickles toward 90%, more slowly the nearer it gets, and never reaches it)\n */\nconst START = 0.15;\nconst LIMIT = 0.9;\nconst STEP = 0.1;\n\n/**\n * `idle`: hidden. `waiting`: a navigation runs, but not yet for DELAY. `loading`: shown and creeping\n * on. `completing`: the navigation ended, and the bar fills to the end. `fading`: full, it fades out.\n */\ntype Phase = \"idle\" | \"waiting\" | \"loading\" | \"completing\" | \"fading\";\ninterface State {\n  phase: Phase;\n  /** The share of the width the bar is filled to. */\n  value: number;\n}\ntype Action = \"activate\" | \"deactivate\" | \"show\" | \"tick\" | \"settled\";\n\nfunction reduce(state: State, action: Action): State {\n  switch (action) {\n    case \"activate\":\n      // A navigation that starts while the last one's bar is still on screen carries on at once.\n      return state.phase === \"idle\" ? { phase: \"waiting\", value: 0 } : { phase: \"loading\", value: START };\n    case \"deactivate\":\n      return state.phase === \"waiting\" ? { phase: \"idle\", value: 0 } : { phase: \"completing\", value: 1 };\n    case \"show\":\n      return { phase: \"loading\", value: START };\n    case \"tick\":\n      return { phase: \"loading\", value: state.value + (LIMIT - state.value) * STEP };\n    case \"settled\":\n      // Filled, it fades out; faded, it empties for the next navigation.\n      return state.phase === \"completing\" ? { phase: \"fading\", value: 1 } : { phase: \"idle\", value: 0 };\n  }\n}\n\n/** Resolves once the element's transitions have ended, including any that started meanwhile. */\nasync function settled(element: Element): Promise<void> {\n  for (let running = element.getAnimations(); running.length > 0; running = element.getAnimations()) {\n    await Promise.allSettled(running.map((animation) => animation.finished));\n  }\n}\n\nconst fix = '<RouteProgress active={navigation.state !== \"idle\"} />';\n\n/**\n * The thin bar across the top of the screen while the app loads the next page or submits\n * a form, so a click that waits on the server never feels frozen: one global affordance\n * instead of a pending state on every action. Once `active` has held for 150ms the bar\n * fades in, and screen readers hear \"Loading\" once; a faster navigation shows and says\n * nothing. While it shows, it creeps toward 90% of the width, more slowly the nearer it\n * gets; when `active` turns false it fills to the end and fades out. With reduced motion\n * it is the whole width from the start and only fades.\n *\n * Render it once, in the root layout, with your router's navigation state.\n *\n * Use `Progress` instead for a task whose amount is known, `Spinner` inside the control\n * that is busy, and `Button`'s `loading` for the one action a person just took.\n *\n * @group Feedback\n * @see https://ui.ouroboros.bot/docs/route-progress\n *\n * @example\n * // React Router, in the root route:\n * const navigation = useNavigation();\n * <RouteProgress active={navigation.state !== \"idle\"} />\n * @claim \"Once `active` has held for 150ms\" registry/ouro/components/ouro/route-progress/route-progress.test.tsx verify:testExists(registry/ouro/components/ouro/route-progress/route-progress.test.tsx::RouteProgress > waits 150ms before it shows or speaks, so a fast navigation shows and says nothing)\n * @claim \"While it shows, it creeps toward\" registry/ouro/components/ouro/route-progress/route-progress.test.tsx verify:testExists(registry/ouro/components/ouro/route-progress/route-progress.test.tsx::RouteProgress > trickles toward 90%, more slowly the nearer it gets, and never reaches it)\n * @claim \"The thin bar across the top\" registry/ouro/components/ouro/route-progress/route-progress.test.tsx verify:testExists(registry/ouro/components/ouro/route-progress/route-progress.test.tsx::RouteProgress > is a 2px bar fixed across the top of the screen in the primary color, which no click reaches)\n */\nexport function RouteProgress(props: RouteProgressProps): JSX.Element {\n  const {\n    active,\n    label = \"Loading\",\n    className,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    loading,\n    isLoading,\n    value,\n  } = props;\n  useAppearanceClassNameCheck(\n    \"RouteProgress\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; RouteProgress takes the theme's --primary color`\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"RouteProgress\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          loading !== undefined && [\"loading is not a prop\", fix],\n          isLoading !== undefined && [\"isLoading is not a prop\", fix],\n          value !== undefined && [\"RouteProgress has no amount\", \"<Progress value={50}>\"],\n          typeof active !== \"boolean\" && [\"active is required; pass whether a navigation is under way\", fix],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const [{ phase, value: filled }, dispatch] = useReducer(reduce, active, (on): State => ({ phase: on ? \"waiting\" : \"idle\", value: 0 }));\n  // A change of `active` moves the phase in the same render, so the bar answers it at once.\n  const [seen, setSeen] = useState(active);\n  if (seen !== active) {\n    setSeen(active);\n    dispatch(active ? \"activate\" : \"deactivate\");\n  }\n  const barRef = useRef<HTMLDivElement>(null);\n  const indicatorRef = useRef<HTMLDivElement>(null);\n  useEffect(() => {\n    switch (phase) {\n      case \"waiting\": {\n        const timer = setTimeout(() => dispatch(\"show\"), DELAY);\n        return () => clearTimeout(timer);\n      }\n      case \"loading\": {\n        const timer = setInterval(() => dispatch(\"tick\"), TRICKLE);\n        return () => clearInterval(timer);\n      }\n      case \"completing\":\n      case \"fading\": {\n        // Waits for the fill, or the fade, to end; a new navigation meanwhile cancels the wait.\n        let current = true;\n        void settled((phase === \"completing\" ? indicatorRef : barRef).current!).then(() => {\n          if (current) dispatch(\"settled\");\n        });\n        return () => {\n          current = false;\n        };\n      }\n      default:\n        return undefined;\n    }\n  }, [phase]);\n  const shown = phase === \"loading\" || phase === \"completing\";\n  return (\n    // A status region that is always there, so screen readers hear the label when it appears in it.\n    <div ref={ref} role=\"status\" data-ouro=\"route-progress\" className={cn(rootClass, className)}>\n      <span className=\"sr-only\">{phase === \"loading\" ? label : \"\"}</span>\n      <div ref={barRef} aria-hidden=\"true\" data-ouro-part=\"bar\" data-open={shown ? \"\" : undefined} data-closed={shown ? undefined : \"\"} className={barClass}>\n        <div ref={indicatorRef} data-ouro-part=\"indicator\" className={indicatorClass} style={{ \"--ouro-route-progress\": filled } as CSSProperties} />\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/route-progress/route-progress.tsx"
    }
  ],
  "docs": "The thin bar across the top of the screen while the app loads the next page or submits a form, so a click that waits on the server never feels frozen: one global affordance instead of a pending state on every action. Import: import { RouteProgress } from \"@/components/ouro/route-progress/route-progress\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/route-progress.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}