@brightlocal/tokens

中文文档
1.2.0发布于 2026/11/03MITTypeScriptES Module近 30 天下载 2382

BrightLocal Design System tokens

原始使用文档
文档目录23 节
  1. Compatibility
  2. Installation
  3. Quick Start (Golden Path)
  4. 1. Install the package
  5. 2. Import the preset in your main CSS file
  6. 3. Enable dark mode
  7. 4. Use with @brightlocal/ui-components
  8. Usage
  9. Core Tokens (CSS Variables)
  10. Tailwind CSS Presets
  11. Available Exports
  12. Token Reference
  13. Semantic Colors
  14. Status Colors
  15. With CSS Custom Properties
  16. With Tailwind CSS Utilities
  17. Typography
  18. Self-hosted fonts
  19. Border Radius
  20. AI Usage Rules
  21. Development
  22. Repository
  23. License

@brightlocal/tokens

BrightLocal Design System tokens package containing design tokens, CSS variables, and Tailwind CSS v4 presets.

Compatibility

DependencyVersion
Tailwind CSS^4.1.18 (v4 required)
CSS Import Syntax@import / @theme (Tailwind v4 CSS-first config)
Build SystemsVite, Next.js, PostCSS — any bundler with CSS @import support

Important: This package uses Tailwind CSS v4 directives (@import "tailwindcss", @theme inline, @variant). It is not compatible with Tailwind CSS v3.

Installation

npm install @brightlocal/tokens --registry=https://npm.pkg.github.com

This package is published to GitHub Packages. You'll need to authenticate with GitHub Packages to install it.

Quick Start (Golden Path)

Follow these steps to integrate the tokens package into your project:

1. Install the package

npm install @brightlocal/tokens tailwindcss@^4.1.18

2. Import the preset in your main CSS file

/* app.css / globals.css */
@import "@brightlocal/tokens/tailwind-preset.css";

This single import gives you:

  • Tailwind CSS v4 base styles
  • All semantic color tokens (light + dark mode)
  • Typography, spacing, radius, and shadow tokens
  • Tailwind utility mappings for all tokens
  • Self-hosted fonts — @font-face rules and woff2 files for Inter, Poppins, and Geist Mono are bundled in, so font-sans, font-display, and font-mono render correctly for end users with no extra setup (no Google Fonts <link>, no manual @font-face). See Self-hosted fonts.

3. Enable dark mode

Add the .dark class to your root element:

<!-- Light mode (default) -->
<html>
  <body class="bg-background text-foreground">...</body>
</html>

<!-- Dark mode -->
<html class="dark">
  <body class="bg-background text-foreground">...</body>
</html>

4. Use with @brightlocal/ui-components

import { Button } from "@brightlocal/ui-components/button";

// Components automatically use the semantic tokens from the preset
<Button variant="default">Primary Action</Button>

Usage

Core Tokens (CSS Variables)

Import individual token CSS files for granular control:

@import "@brightlocal/tokens/core-tokens/colors.css";
@import "@brightlocal/tokens/core-tokens/spacing.css";
@import "@brightlocal/tokens/core-tokens/typography.css";

Tailwind CSS Presets

/* Standard preset (recommended) */
@import "@brightlocal/tokens/tailwind-preset.css";

/* Lab preset (experimental features) */
@import "@brightlocal/tokens/tailwind-preset-lab.css";

Available Exports

Export PathDescription
@brightlocal/tokens/tailwind-preset.cssMain Tailwind CSS v4 preset (includes all tokens and self-hosted fonts)
@brightlocal/tokens/tailwind-preset-lab.cssExperimental Tailwind CSS preset
@brightlocal/tokens/fonts.cssStandalone @font-face rules for Inter, Poppins, Geist Mono (already included by the preset)
@brightlocal/tokens/core-tokens/colors.cssColor design tokens (CSS variables)
@brightlocal/tokens/core-tokens/spacing.cssBorder radius, shadow, breakpoint, and container tokens
@brightlocal/tokens/core-tokens/typography.cssTypography tokens (fonts, sizes, weights)
@brightlocal/tokens/tokens.jsonMachine-readable token reference for AI tools and MCP servers (not for runtime code — read-only reference)

Token Reference

Semantic Colors

The design system uses semantic color tokens — not raw palette values. Always use these:

Token (CSS)Tailwind UtilityPurpose
var(--background)bg-backgroundPage/app background
var(--foreground)text-foregroundDefault text color
var(--primary)bg-primary, text-primaryPrimary brand/action color
var(--primary-foreground)text-primary-foregroundText on primary backgrounds
var(--secondary)bg-secondarySecondary actions
var(--secondary-foreground)text-secondary-foregroundText on secondary backgrounds
var(--muted)bg-mutedMuted/subtle backgrounds
var(--muted-foreground)text-muted-foregroundMuted/subtle text
var(--accent)bg-accentAccent/highlight backgrounds
var(--accent-foreground)text-accent-foregroundText on accent backgrounds
var(--destructive)bg-destructive, text-destructiveError/danger states
var(--destructive-foreground)text-destructive-foregroundText on destructive backgrounds
var(--border)border-borderDefault border color
var(--input)border-inputInput field borders
var(--outline)shadow-defaultFocus ring color (used via shadow utility)
var(--card)bg-cardCard backgrounds
var(--card-foreground)text-card-foregroundText on card backgrounds
var(--card-border)border-card-borderCard border color
var(--popover)bg-popoverPopover/dropdown backgrounds
var(--popover-foreground)text-popover-foregroundText on popover backgrounds
var(--link)text-linkLink color
var(--link-visited)text-link-visitedVisited link color

Status Colors

Token (CSS)Tailwind UtilityPurpose
var(--success-background)bg-success-backgroundSuccess notification background
var(--success-foreground)text-success-foregroundSuccess text
var(--info-background)bg-info-backgroundInfo notification background
var(--info-foreground)text-info-foregroundInfo text
var(--warning-background)bg-warning-backgroundWarning notification background
var(--warning-foreground)text-warning-foregroundWarning text

With CSS Custom Properties

.my-component {
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.my-button {
  background: var(--primary);
  color: var(--primary-foreground);
}

With Tailwind CSS Utilities

<!-- Page layout -->
<div class="bg-background text-foreground min-h-screen">

  <!-- Card -->
  <div class="bg-card text-card-foreground rounded-md border border-border p-4">
    <h2 class="text-lg font-semibold">Title</h2>
    <p class="text-muted-foreground text-sm">Description</p>
  </div>

  <!-- Button -->
  <button class="bg-primary text-primary-foreground rounded-md px-4 py-2">
    Click me
  </button>

  <!-- Destructive action -->
  <button class="bg-destructive text-destructive-foreground rounded-md px-4 py-2">
    Delete
  </button>
</div>

Typography

Use font-display with text size and weight utilities for headings:

HeadingClassesSize
XLfont-display text-5xl font-medium48px
LGfont-display text-4xl font-medium36px
MDfont-display text-3xl font-medium30px
SMfont-display text-2xl font-medium24px

Font families: font-sans (Inter), font-serif (Georgia), font-mono (Geist Mono), font-display (Poppins)

Self-hosted fonts

The preset ships self-hosted @font-face declarations and woff2 files for the three brand fonts, so they render for end users without the font being installed locally and without any CDN request. Importing @brightlocal/tokens/tailwind-preset.css is all that's required — no Google Fonts <link>, no manual @font-face.

Bundled weights (latin subset, normal style, font-display: swap):

FamilyUtilityWeights shipped
Interfont-sans300, 400, 500, 600, 700
Poppinsfont-display400, 500, 600, 700
Geist Monofont-mono300, 400

These cover every weight the design system uses through its shifted font-weight scale (font-normal → 300, font-medium → 400, font-semibold → 500, font-bold → 600, font-extrabold → 700). Rare extremes (100/200/800/900), italics, and non-latin subsets are intentionally omitted to keep the payload small; they fall back to the nearest shipped weight. font-serif uses the system Georgia stack and is not self-hosted.

The woff2 files are emitted as assets by your bundler (Vite, Next.js, etc.) and lazy-loaded per weight — a consumer only downloads the weights it actually renders. Fonts are licensed under the SIL Open Font License 1.1 (see the *-LICENSE.txt files shipped in fonts/).

Border Radius

Tailwind UtilityValue
rounded-none0px
rounded-xs2px
rounded-sm6px
rounded-md8px
rounded-lg10px
rounded-xl14px
rounded-2xl16px
rounded-3xl24px
rounded-4xl32px
rounded-full9999px

AI Usage Rules

See AI_USAGE.md for the full AI usage guide, including semantic token reference, common mistakes, and setup instructions.

Key rules:

  1. Never hardcode colors — always use semantic tokens or their Tailwind utility equivalents
  2. Use bg-background text-foreground as the page baseline
  3. Prefer semantic tokens over palette tokens — use bg-primary not bg-blue-600
  4. Dark mode uses .dark class — tokens switch automatically, no manual dark: variants needed
  5. Import the preset — a single @import "@brightlocal/tokens/tailwind-preset.css" provides everything

Development

This package is part of the BrightLocal Design System monorepo. Tokens are generated from Tokens Studio definitions in src/core-tokens/tokens-studio/.

Build pipeline: Tokens Studio JSON → Style Dictionary → CSS variables → Tailwind v4 preset

# Build all tokens (from packages/tokens/)
pnpm build:tokens

# Full build (tokens + copy to dist + tokens.json)
pnpm build

# From monorepo root
pnpm --filter @brightlocal/tokens build

Repository

GitHub Repository

License

Private package — BrightLocal internal use only.

版本与发布记录

@brightlocal/tokens 共发布 22 个版本,首次发布于 2025/11/14;过去 12 个月发布了 22 个版本。

版本发布日期距今
1.2.0latest2026/11/035 天前
1.1.02026/10/1623 天前
1.0.12026/09/291 个月前
1.0.02026/09/191 个月前
0.13.02026/09/072 个月前
0.12.02026/08/132 个月前

关于 @brightlocal/tokens 的常见问题

@brightlocal/tokens 是什么?

BrightLocal Design System tokens

如何安装 @brightlocal/tokens?

在项目目录运行 npm install @brightlocal/tokens,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:tailwindcss(^4.3.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@brightlocal/tokens 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@brightlocal/tokens 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@brightlocal/tokens 可以商用吗?

@brightlocal/tokens 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@brightlocal/tokens 的下载量有多少?

根据 npm 官方下载统计,@brightlocal/tokens 在 2026/10/09 – 2026/11/07 这 30 天内被下载 2,382 次,日均约 79 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@brightlocal/tokens 还在维护吗?

最新版本 1.2.0 发布于 2026/11/03(5 天前);至今共发布 22 个版本,其中过去 12 个月发布了 22 个;首次发布于 2025/11/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。