All files / src/components/docs LinkedText.tsx

100% Statements 5/5
100% Branches 4/4
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 493x                           3x                     595x   983x                             595x            
"use client";
 
/**
 * A translated text whose parts in <tag>...</tag> link to links[tag]: a docs
 * page by its route, anything else in a new tab. The links cross from the
 * server page as strings and become elements here, so a text with many
 * sources does not hand <T> elements through the server-client boundary,
 * which the dev server rendered as an element of undefined type (the
 * roadmap's first driver, 2026-11-07).
 */
import Link from "next/link";
import { T } from "@/lib/i18n/translate";
import type { Area } from "@/messages";
 
const LINK_CLASS = "text-(--accent) underline";
 
export function LinkedText({
  area,
  text,
  links,
}: {
  area: Area;
  text: string;
  links?: Readonly<Record<string, string>>;
}) {
  const tags = links
    ? Object.fromEntries(
        Object.entries(links).map(([tag, href]) => [
          tag,
          href.startsWith("/") ? (
            <Link href={href} className={LINK_CLASS} />
          ) : (
            <a
              href={href}
              target="_blank"
              rel="noopener noreferrer"
              className={LINK_CLASS}
            />
          ),
        ]),
      )
    : undefined;
  return (
    <T area={area} tags={tags}>
      {text}
    </T>
  );
}