FLOWDocs

排版

Geist 字体家族与排版原语。

Flow UI 提供两套字体家族 —— Geist Sans 和 Geist Mono —— 以及一小组封装常见文字角色的 React 组件。

字体

两套字体都是自托管的 —— woff2 文件被随包内置(src/styles/fonts/)并由 fonts.css 注册,因此使用方会直接打包它们,不会发出任何外部字体请求。加载方式是 font-display: swap(FOUT,而非 FOIT),确保文字第一时间出现在屏幕上。

Geist Sans

可变字体,字重 100–900,含斜体轴。除代码用途之外的场景都用它。

font-family: var(--font-sans);

Geist Mono

可变字体,字重 100–900,含斜体。用于代码、键盘按键、终端输出,以及任何对字符对齐敏感的地方。

font-family: var(--font-mono);

文字字号阶梯

每个字号都对应一个 CSS 变量。Tailwind 的 text-xs 到 text-9xl 工具类映射到这些 token。

完整列表见 Token → 字号阶梯。

组件

从 @flow-industries/ui/components/typography 导入。导出:Title、Subtitle、Overline、Paragraph、Mono。

在 GitHub 上查看源码 →

用法:

import { Title, Subtitle, Overline, Paragraph, Mono } from "@flow-industries/ui/components/typography";

<Title size="lg">欢迎来到 Flow</Title>
<Subtitle size="lg">一个去中心化的平台。</Subtitle>
<Overline variant="brand">Now shipping</Overline>
<Paragraph>一段跨越好几行、并不算短的正文。</Paragraph>
<Mono>bun add @flow-industries/ui</Mono>

Title 的各尺寸映射到不同 HTML 标签:sm → <h3>、default → <h2>、md → <h2>、lg → <h1>——或传入 level(1–6)直接指定标题标签(<h1>–<h6>),在保持视觉尺寸的同时让文档大纲保持正确。Subtitle 同样提供这四种尺寸。Overline 支持 default 与 brand 两种 variant。Paragraph 接受 size —— "xs" | "sm" | "default" | "lg" —— 且默认值为 "sm",而非 "default"。

源码:

components/ui/typography.tsx
import { cn } from "../../utils/cn";

const titleStyles = {
  sm: "text-sm font-semibold",
  default: "text-base font-bold tracking-tighter",
  md: "text-2xl font-bold tracking-tighter",
  lg: "text-3xl font-bold tracking-tighter",
} as const;

const titleTags = { sm: "h3", default: "h2", md: "h2", lg: "h1" } as const;

const headingTags = {
  1: "h1",
  2: "h2",
  3: "h3",
  4: "h4",
  5: "h5",
  6: "h6",
} as const;

function Title({
  className,
  size = "default",
  level,
  ...props
}: React.ComponentProps<"h1"> & {
  size?: "sm" | "default" | "md" | "lg";
  level?: 1 | 2 | 3 | 4 | 5 | 6;
}) {
  const Tag = level ? headingTags[level] : titleTags[size];
  return (
    <Tag
      data-slot="title"
      className={cn(titleStyles[size], className)}
      {...props}
    />
  );
}

const subtitleStyles = {
  sm: "text-xs font-medium text-muted-foreground",
  default: "text-sm font-medium text-muted-foreground",
  md: "text-base font-medium text-muted-foreground",
  lg: "text-lg font-medium text-muted-foreground",
} as const;

function Subtitle({
  className,
  size = "default",
  ...props
}: React.ComponentProps<"p"> & { size?: "sm" | "default" | "md" | "lg" }) {
  return (
    <p
      data-slot="subtitle"
      className={cn(subtitleStyles[size], className)}
      {...props}
    />
  );
}

function Overline({
  className,
  variant = "default",
  ...props
}: React.ComponentProps<"span"> & { variant?: "default" | "brand" }) {
  return (
    <span
      data-slot="overline"
      className={cn(
        "text-sm font-[550] tracking-wide",
        variant === "brand" ? "text-brand-text" : "text-muted-foreground",
        className,
      )}
      {...props}
    />
  );
}

const paragraphVariants = {
  xs: "text-xs",
  sm: "text-sm",
  default: "text-base",
  lg: "text-lg",
} as const;

function Paragraph({
  className,
  size = "sm",
  ...props
}: React.ComponentProps<"p"> & { size?: "xs" | "sm" | "default" | "lg" }) {
  return (
    <p
      data-slot="paragraph"
      className={cn(
        "font-[450] leading-[150%] tracking-wide text-foreground/80",
        paragraphVariants[size],
        className,
      )}
      {...props}
    />
  );
}

function Mono({ className, ...props }: React.ComponentProps<"code">) {
  return (
    <code
      data-slot="mono"
      className={cn(
        "text-sm font-mono tracking-normal text-muted-foreground",
        className,
      )}
      {...props}
    />
  );
}

export { Mono, Overline, Paragraph, Subtitle, Title };

直接使用 Tailwind

没什么能拦你直接写 class —— 所有 Flow 组件都接受 className,并通过 cn() 合并:

<h1 className="font-sans text-6xl font-bold tracking-tight">Hello</h1>
<code className="font-mono text-sm">example</code>

当你想要设计系统认可的默认值时用组件;需要更定制化的样式时直接写 class。

On this page