Skip to documentation

Design system / Sources & standards

Current repository source

text.tsx

src/components/ui/text.tsx

This view contains the escaped source read during the deployment build. Code and policy text are unchanged. Markdown is shown as source, not rendered as a document. A new deployment refreshes the content.

import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { extendTailwindMerge } from "tailwind-merge";

// Text promises independent size/rhythm composition. Unlike the generic merge
// contract, a caller's plain font-size utility must not discard its rhythm.
// Explicit leading utilities (and size/leading postfixes) still override it.
const mergeTextClasses = extendTailwindMerge({
  extend: { theme: { leading: ["compact", "prose"], text: ["body", "supporting", "eyebrow", "title-jumbo", "secondary-title-jumbo"], "font-weight": ["eyebrow"], tracking: ["eyebrow"] } },
  override: { conflictingClassGroups: { "font-size": [] } },
});

const textVariants = cva("", {
  variants: {
    variant: {
      body: "text-body",
      supporting: "text-supporting",
      eyebrow: "text-eyebrow font-eyebrow tracking-eyebrow",
      inherit: "",
    },
    rhythm: {
      tight: "leading-compact",
      loose: "leading-prose",
    },
    accent: {
      none: "",
      monospace: "font-monospace-accent",
    },
  },
  defaultVariants: { variant: "body", rhythm: "tight", accent: "none" },
});

type TextElement = "p" | "span" | "div" | "li" | "dd";
type TextProps<T extends TextElement = "p"> = React.ComponentProps<T> &
  VariantProps<typeof textVariants> & { as?: T };

/** Product-neutral text atom. Size role, rhythm and family accent are independent;
 * as preserves native document semantics, with no wrapper or client state. */
function Text<T extends TextElement = "p">({
  as,
  variant = "body",
  rhythm = "tight",
  accent = "none",
  className,
  ...props
}: TextProps<T>) {
  return React.createElement(as ?? "p", {
    "data-slot": "text",
    "data-rhythm": rhythm,
    "data-accent": accent,
    className: mergeTextClasses(textVariants({ variant, rhythm, accent }), className),
    ...props,
  });
}

export { Text, textVariants, type TextProps };
All sources and standards
Current components and theme tokens. Fictional example data. Source views refresh on deployment; authors maintain contract notes.