{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "link",
  "title": "Link",
  "description": "A text link that navigates through your router.",
  "registryDependencies": [
    "@ouro/lib-appearance-hints",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-router-link",
    "@ouro/lib-tones",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/link/link.tsx",
      "content": "\"use client\";\n\nimport type { AnchorHTMLAttributes, JSX, ReactNode, Ref } from \"react\";\nimport { fontFor, toneFor } from \"@/registry/ouro/lib/ouro/appearance-hints\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { RouterLink, safeRel } from \"@/registry/ouro/lib/ouro/router-link\";\nimport { toneWarning } from \"@/registry/ouro/lib/ouro/tones\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\n/** The props Link adds to the anchor attributes it passes through. */\nexport interface LinkOwnProps {\n  /**\n   * Where the link goes. Internal paths render through `OuroProvider`'s `linkComponent`\n   * (your router's link), so navigation stays client-side; `http(s)://`, `mailto:` and\n   * other absolute URLs render as a plain `<a>`. Router links that take `to` take `href`\n   * here: the adapter maps it.\n   */\n  href: string;\n  /**\n   * Navigates with a full page load: renders a plain `<a>` for an internal path too, skipping\n   * `OuroProvider`'s `linkComponent`, so your router never handles it. Use it for a path your\n   * router has no page for: a resource route (`/mcp`, `/feed.xml`), a file download, a sign-in\n   * that starts on the server (`/auth/github`). A link with `download` does the same.\n   * @claim \"Navigates with a full page load:\" registry/ouro/components/ouro/link/link.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.test.tsx::Link > renders a plain <a> with reloadDocument or download, skipping the router's link, in the same look)\n   */\n  reloadDocument?: boolean | undefined;\n  /**\n   * Opens the link in a new tab: sets `target=\"_blank\"`, adds `rel=\"noopener noreferrer\"`\n   * (keeping your own `rel` tokens) and an icon, and tells screen readers \"opens in a new tab\".\n   */\n  external?: boolean | undefined;\n  /**\n   * Text color from the theme, named after its token. `secondary` is the page's foreground,\n   * for links in navigation and lists; the underline still marks it as a link. `primary`\n   * reads `--primary`, not a theme's `--ouro-action`: a link is text in a sentence and the\n   * action colour is a fill. For a link that looks like the page's main action, use\n   * `<Button href>`.\n   * @claim \"`primary` reads `--primary`, not a theme's\" test/action-token.test.tsx verify:testExists(test/action-token.test.tsx::the action token > repaints the solid primary Button, as a button and as a link, and leaves every selection on --primary)\n   * @default \"primary\"\n   */\n  tone?:\n    | \"primary\"\n    | \"secondary\"\n    | \"destructive\"\n    | \"success\"\n    | \"warning\"\n    | (string & { 'danger is \"destructive\"; accent is \"primary\"; neutral is \"secondary\"': never })\n    | undefined;\n  /**\n   * Whether the link sits in running text. On a touch screen a link that stands alone\n   * (\"Forgot password?\", \"Back to recipes\", a link in a list item or a table cell) is a box at\n   * least 44px tall and wide with its text centred, which takes its room in the layout; a link in\n   * running text stays as tall as its line. Unset, a link is in running text inside a `<p>`,\n   * a `<label>`, a `<dt>` or `<dd>`, a `Text`, and Ouro's own text (a field's description and\n   * error, a Form's message, an Alert's text, an Item's description). Pass `inline` for a\n   * sentence in another element, and `inline={false}` for a link that is alone in its `Text`.\n   * @claim \"On a touch screen a link\" registry/ouro/components/ouro/link/link.touch.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.touch.test.tsx::gives a link on its own line a 44px box, centred on its text)\n   * @claim \"On a touch screen a link\" registry/ouro/components/ouro/link/link.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.test.tsx::Link with a mouse > is as tall as its text with a fine pointer, standing alone or in a sentence)\n   * @claim \"On a touch screen a link\" registry/ouro/components/ouro/link/link.touch.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.touch.test.tsx::a link in running text keeps to its line)\n   */\n  inline?: boolean | undefined;\n  /**\n   * Marks this link as the current one: the page you are on in a list of chapters, steps or\n   * sections. `true` sets `aria-current=\"page\"`; pass another value (`\"step\"`, `\"location\"`,\n   * `\"true\"`) for a link that is not a page of its own. The link is then drawn as `Navbar` and\n   * `NavigationMenu` draw their current link: semibold, in the page's text colour, with a 2px\n   * underline in the primary colour, so a reader tells it from the others at a glance. Under\n   * forced colours it takes the selection's colours. `false` or unset marks nothing.\n   * @claim \"Marks this link as the current\" registry/ouro/components/ouro/link/link.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.test.tsx::Link current > marks the current link aria-current=\"page\", or the value passed, and nothing for false)\n   * @claim \"The link is then drawn as\" registry/ouro/components/ouro/link/link.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.test.tsx::Link current > draws the current link as Navbar draws its current link: semibold, the page's text colour, a 2px primary underline)\n   */\n  current?: boolean | \"page\" | \"step\" | \"location\" | \"date\" | \"time\" | \"true\" | (string & { 'Use current or current=\"step\"': never }) | undefined;\n  /** The link text. Make it say where the link goes: \"Browse recipes\", not \"click here\". */\n  children: ReactNode;\n  /** Layout only: margins, display, grid placement (`ms-2`). Appearance classes warn in development; use `tone`. */\n  className?: string | undefined;\n  ref?: Ref<HTMLAnchorElement> | undefined;\n\n  /** Not a prop. Ouro UI uses `href`, for router links too: `<Link href=\"/recipes\">`. */\n  to?: { 'Use <Link href=\"/recipes\">': never };\n  /** Not a prop. Ouro UI uses `external`: `<Link href=\"https://…\" external>`. */\n  isExternal?: { 'Use <Link href=\"https://...\" external>': never };\n  /** Not a prop. Ouro UI uses `tone`: `<Link tone=\"destructive\">`. */\n  color?: { 'Use <Link tone=\"destructive\">': never };\n  /** Not a prop. Ouro UI uses `current`: `<Link href=\"/chapter-2\" current>`. */\n  active?: { 'Use <Link current>': never };\n  /** Not a prop. Ouro UI uses `current`: `<Link href=\"/chapter-2\" current>`. */\n  isActive?: { 'Use <Link current>': never };\n}\n\n/** Props for {@link Link}: its own props and the anchor attributes it passes through. */\nexport type LinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof LinkOwnProps> & LinkOwnProps;\n\n// Class strings are literal so the app's Tailwind finds them when it compiles.\nconst base =\n  \"rounded-xs underline decoration-current/40 decoration-1 underline-offset-4 \" +\n  \"transition-[text-decoration-color] duration-(--ouro-duration-fast) ease-[ease] pointer-fine:hover:decoration-current active:opacity-70 \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid\";\n\n// On a coarse pointer a link that is not in running text is a 44px box with its text\n// centred. Running text is found with CSS ancestor selectors, so the server HTML is right.\nconst standalone =\n  \"pointer-coarse:not-in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:inline-flex \" +\n  \"pointer-coarse:not-in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:min-h-11 \" +\n  \"pointer-coarse:not-in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:min-w-11 \" +\n  \"pointer-coarse:not-in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:items-center\";\nconst alwaysStandalone = \"pointer-coarse:inline-flex pointer-coarse:min-h-11 pointer-coarse:min-w-11 pointer-coarse:items-center\";\n\n// In running text an outline would cover the next character (a comma right after the link), so\n// focus thickens the underline in the ring's colour. The outline stays, transparent, because\n// forced colours show it and drop the underline's colour.\nconst inTextFocus =\n  \"in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:focus-visible:outline-transparent \" +\n  \"in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:focus-visible:decoration-ring \" +\n  \"in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:focus-visible:decoration-2\";\nconst inlineFocus = \"focus-visible:outline-transparent focus-visible:decoration-ring focus-visible:decoration-2\";\n\n// An icon of the app's own (a back arrow) stays on its text's line, a little apart. The base styles make an svg a\n// block, which in a link laid out as a block (one in a column) takes a line of its own: the icon is inline instead.\n// A link that stands alone lays its icon and text out in a row with a gap; one in running text stays inline, so it\n// sits on the sentence's baseline and wraps, and its icon takes a little room on each side. The rules sit in a nested\n// layer, so the app's own classes still win; the external icon, already inline, is left out.\nconst iconInlineClass =\n  \"[@layer_ouro-reset]:[&>svg:not([data-ouro-external])]:inline-block \" +\n  \"[@layer_ouro-reset]:[&>svg:not([data-ouro-external])]:align-[-0.125em]\";\nconst iconRowClass =\n  \"[@layer_ouro-reset]:not-in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:has-[>svg:not([data-ouro-external])]:inline-flex \" +\n  \"[@layer_ouro-reset]:not-in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:has-[>svg:not([data-ouro-external])]:items-center \" +\n  \"[@layer_ouro-reset]:not-in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:has-[>svg:not([data-ouro-external])]:gap-1.5\";\nconst iconInTextClass =\n  \"[@layer_ouro-reset]:in-[:is(p,label,dt,dd,[data-ouro=text],[data-ouro-text])]:[&>svg:not([data-ouro-external])]:mx-[0.25em]\";\nconst alwaysIconRowClass =\n  \"[@layer_ouro-reset]:has-[>svg:not([data-ouro-external])]:inline-flex \" +\n  \"[@layer_ouro-reset]:has-[>svg:not([data-ouro-external])]:items-center \" +\n  \"[@layer_ouro-reset]:has-[>svg:not([data-ouro-external])]:gap-1.5\";\nconst alwaysIconInTextClass = \"[@layer_ouro-reset]:[&>svg:not([data-ouro-external])]:mx-[0.25em]\";\n\nconst tones = {\n  primary: \"text-primary\",\n  secondary: \"text-foreground\",\n  destructive: \"text-destructive\",\n  success: \"text-success\",\n  warning: \"text-warning\",\n} as const;\n\n// The current link, drawn as Navbar and NavigationMenu draw theirs: semibold, the page's text\n// colour, a 2px underline in the primary colour that hover keeps. Forced colours paint every link\n// alike, so there it takes the selection's colours.\nconst currentClass =\n  \"data-current:font-semibold data-current:text-foreground data-current:decoration-primary data-current:decoration-2 \" +\n  \"data-current:underline-offset-5 data-current:[text-decoration-skip-ink:none] data-current:pointer-fine:hover:decoration-primary \" +\n  \"forced-colors:data-current:bg-[Highlight] forced-colors:data-current:text-[HighlightText]\";\n\nconst ariaCurrents: readonly string[] = [\"page\", \"step\", \"location\", \"date\", \"time\", \"true\"];\n\nfunction linkHint(token: string): string {\n  if (token.startsWith(\"font-\")) return fontFor(\"Link\", token);\n  return `tone=\"${toneFor(token)}\"`;\n}\n\n/**\n * A text link that navigates through your router. Internal `href`s render through\n * `OuroProvider`'s `linkComponent`, the same path `Button` with `href` takes, and\n * `external` opens a new tab safely and says so.\n *\n * Link is for text links only: it sets the text color and the underline, so wrapping a\n * card, a list row or a tab in it restyles their text. Inside running text, put the Link in\n * a `Text`.\n *\n * Use `Button` with `href` instead when the link is the main action and should look like a\n * button. Use `Card` with `href` instead when a whole card is the link, `Item` with `href`\n * for a whole list row, and `Table` with `rowHref` (or `TableRow` with `href`) for a\n * table row: each makes the surface one link with one tab stop, through the same router\n * link, and keeps its own look. Use `Navbar` or `Sidebar` instead for the links that move\n * between an app's pages, which mark the current one: `Tabs` and `SegmentedControl` switch\n * a view in place and take no `href`.\n *\n * On a touch screen a link that stands alone is a box at least 44px tall and wide, with its text\n * centred, so it is easy to tap and never overlaps a neighbour. A link in running text (a\n * `<p>`, a `<label>`, a `Text`, a field's description or error) stays as tall as its line;\n * `inline` says the same anywhere else. With a mouse every link is as tall as its text.\n *\n * In a list of chapters, steps or sections, `current` marks the one you are on\n * (`aria-current=\"page\"`) with the same look as `Navbar`'s current link.\n *\n * Keyboard focus draws an outline around a link that stands alone. In running text it thickens\n * the underline in the ring's colour instead, since an outline would cover the next character.\n *\n * An icon you put in the link (a back arrow before \"Recipes\") stays on its text's line, a little\n * apart, wherever the link is laid out; mark it `aria-hidden` so the link's name is its text.\n *\n * @group Text\n * @see https://ui.ouroboros.bot/docs/link\n *\n * @example\n * <Link href=\"/recipes\">Browse recipes</Link>\n * <Link href=\"https://ouro.bot\" external>Ouro</Link>\n * <Link href=\"/mcp\" reloadDocument>MCP server metadata</Link>\n * <Text>Read the <Link href=\"/terms\">terms</Link> first.</Text>\n * <Text size=\"sm\"><Link href=\"/forgot\" inline={false}>Forgot password?</Link></Text>\n * <Link href=\"/guide/2\" current>Chapter 2</Link>\n * @claim \"On a touch screen a link\" registry/ouro/components/ouro/link/link.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.test.tsx::Link with a mouse > is as tall as its text with a fine pointer, standing alone or in a sentence)\n * @claim \"On a touch screen a link\" registry/ouro/components/ouro/link/link.touch.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.touch.test.tsx::gives a link on its own line a 44px box, centred on its text)\n * @claim \"Keyboard focus draws an outline\" registry/ouro/components/ouro/link/link.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.test.tsx::Link > marks keyboard focus in running text with a thick underline in the ring's colour, not an outline drawn over the next character)\n * @claim \"An icon you put in the\" registry/ouro/components/ouro/link/link.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.test.tsx::Link > keeps an icon of the app's own on its text's line, a little apart, wherever the link is laid out)\n * @claim \"With a mouse every link is\" registry/ouro/components/ouro/link/link.test.tsx verify:testExists(registry/ouro/components/ouro/link/link.test.tsx::Link with a mouse > is as tall as its text with a fine pointer, standing alone or in a sentence)\n */\nexport function Link(props: LinkProps): JSX.Element {\n  const {\n    href,\n    external,\n    reloadDocument,\n    tone: toneProp = \"primary\",\n    inline: inlineProp,\n    current: currentProp,\n    children,\n    className,\n    target,\n    rel,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    to,\n    isExternal,\n    color,\n    active,\n    isActive,\n    ...rest\n  } = props;\n  // `true` is the page; a value that is not one of aria-current's (a type error) warns and marks the page.\n  const current: AnchorHTMLAttributes<HTMLAnchorElement>[\"aria-current\"] =\n    currentProp === undefined || currentProp === false\n      ? undefined\n      : ariaCurrents.includes(currentProp as string)\n        ? (currentProp as AnchorHTMLAttributes<HTMLAnchorElement>[\"aria-current\"])\n        : \"page\";\n  // An `aria-current` passed straight through (a NavLink habit) gets the same look.\n  const passed = rest[\"aria-current\"];\n  const marked = current !== undefined || (passed !== undefined && passed !== false && passed !== \"false\");\n  // A tone that is not one of Ouro UI's (a type error) warns and renders the default.\n  const tone = Object.hasOwn(tones, toneProp) ? (toneProp as keyof typeof tones) : \"primary\";\n  useAppearanceClassNameCheck(\n    \"Link\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? linkHint : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Link\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          tone !== toneProp && toneWarning(\"Link\", String(toneProp), Object.keys(tones)),\n          to !== undefined && [\"to is not a prop\", `<Link href=\"${typeof to === \"string\" ? to : \"/path\"}\">`],\n          isExternal !== undefined && [\"isExternal is not a prop\", '<Link href=\"https://…\" external>'],\n          color !== undefined && [\"color is not a prop\", `<Link tone=\"${toneFor(`text-${String(color)}`)}\">`],\n          active !== undefined && [\"active is not a prop\", \"<Link current>\"],\n          isActive !== undefined && [\"isActive is not a prop\", \"<Link current>\"],\n          currentProp !== undefined &&\n            typeof currentProp !== \"boolean\" &&\n            !ariaCurrents.includes(currentProp) && [`current=\"${currentProp}\" is not an aria-current value`, '<Link current> or <Link current=\"step\">'],\n          !external &&\n            target === \"_blank\" && ['target=\"_blank\" opens a new tab without saying so', '<Link href=\"https://…\" external>'],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  return (\n    <RouterLink\n      data-ouro-control=\"link\"\n      data-ouro-part=\"root\"\n      {...rest}\n      href={href}\n      reloadDocument={reloadDocument}\n      target={external ? \"_blank\" : target}\n      rel={external ? safeRel(rel) : rel}\n      data-ouro=\"link\"\n      data-inline={inlineProp ? \"\" : undefined}\n      {...(current ? { \"aria-current\": current } : {})}\n      data-current={marked ? \"\" : undefined}\n      className={cn(base, iconInlineClass, inlineProp === undefined ? [standalone, inTextFocus, iconRowClass, iconInTextClass] : inlineProp ? [inlineFocus, alwaysIconInTextClass] : [alwaysStandalone, alwaysIconRowClass], tones[tone], currentClass, className)}\n    >\n      {children}\n      {external && (\n        <>\n          <svg\n            aria-hidden=\"true\"\n            data-ouro-external=\"\"\n            viewBox=\"0 0 16 16\"\n            fill=\"none\"\n            stroke=\"currentColor\"\n            strokeWidth=\"1.5\"\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            className=\"ms-0.5 inline size-[0.75em] align-baseline\"\n          >\n            <path d=\"M6 3h7v7M13 3 4 12\" />\n          </svg>\n          <span className=\"sr-only\"> (opens in a new tab)</span>\n        </>\n      )}\n    </RouterLink>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/link/link.tsx"
    }
  ],
  "docs": "A text link that navigates through your router. Import: import { Link } from \"@/components/ouro/link/link\", 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/link.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}