@dt-dds/themes

中文文档
1.0.0-beta.20发布于 2026/10/28MITTypeScriptESM + CJS零依赖近 30 天下载 6307

DT-DDS Design System Themes

原始使用文档
文档目录27 节
  1. Installation
  2. Usage
  3. Development
  4. Theme Generation
  5. JSON token files
  6. GitHub Actions Workflow
  7. Automatic Theme Generation
  8. Manual Theme Generation
  9. Token Matrix
  10. Core Colors
  11. Product Colors
  12. Semantic Colors
  13. Typography
  14. Spacing
  15. Radius
  16. Shadows/Elevations
  17. Shapes
  18. Breakpoints
  19. Icon Sizes
  20. Fonts
  21. Component Tokens
  22. File Structure
  23. Validation
  24. Error Handling
  25. Contributing
  26. Adding New Components
  27. © License

@dt-dds/themes

DT-DDS Themes Package

This package contains the themes system for DT-DDS, including:

  • Theme definitions and types
  • Theme generation utilities
  • Token processing and validation
  • Theme utilities and helpers

Installation

yarn add @dt-dds/themes

Usage

import { daimlerTruckTheme } from '@dt-ui/themes';

const theme: CustomTheme = daimlerTruckTheme;

Development

# Install dependencies
yarn install

# Build the package
yarn build

# Run tests
yarn test

# Generate themes from tokens
yarn build:theme

Theme Generation

The theme generation system automatically processes JSON token files and generates corresponding TypeScript theme files that match the CustomTheme type structure. It supports multiple themes and handles token validation, reference resolution, and fallback values.

JSON token files

The JSON token files are being generated from Figma Variables, with the use of the following plugin Design Token Manager.

The exported JSON file format follows the spec of the Design Tokens format purposed by the W3C work group.

GitHub Actions Workflow

Automatic Theme Generation

Includes a GitHub Actions workflow (.github/workflows/theme-generation.yml) that automatically generates themes when token files are modified in pull requests.

How it works:

  1. Trigger: The workflow runs when a PR is opened, updated, or reopened and contains changes to:

    • packages/themes/src/tokens/**/*.json
    • packages/themes/src/utils/theme-generator/**/*
    • packages/themes/src/types/theme.ts
    • packages/themes/package.json
  2. Process:

    • Checks out the PR branch
    • Installs dependencies
    • Runs yarn build:theme
    • Commits generated theme files back to the PR
    • Comments on the PR with status information
  3. Outcomes:

    • Success with changes: Theme files are updated and committed to the PR
    • Success without changes: No theme changes needed
    • Failure: Error details are posted as a comment

Benefits:

  • Designer-friendly: Designers can focus on token files without worrying about theme generation
  • Automatic: No manual intervention required
  • Transparent: Clear feedback on what was generated
  • Safe: Only runs on PRs, not on main branch

Example Workflow:

  1. Designer creates a new branch
  2. Designer modifies token JSON files
  3. Designer commits and pushes changes
  4. Designer creates a PR
  5. GitHub Actions automatically:
    • Detects token file changes
    • Runs theme generation
    • Commits generated theme files to the PR
    • Comments on the PR with results
  6. Designer reviews both token changes and generated theme files
  7. PR can be merged with both token and theme changes

Manual Theme Generation

To generate themes manually, run:

cd packages/themes
yarn build:theme

This will:

  • Discover all theme files in src/tokens/
  • Process each theme with its semantic file
  • Generate theme files in src/themes/
  • Format and lint the generated files

Token Matrix

Core Colors

  • Core_colors.Grey.grey-* (00-120)
  • Core_colors.Petrol.petrol-* (00-100)
  • Core_colors.Blue.blue-* (00-100)
  • Core_colors.Green.green-* (00-100)
  • Core_colors.Orange.orange-* (00-100)
  • Core_colors.Red.red-* (00-100)

Product Colors

  • Product_colors.Bright_yellow.brightyellow-* (00-100)
  • Product_colors.True_blue.trueblue-* (00-100)

Semantic Colors

  • Contextual_colors.Surface.* (default, light, medium, dark, contrast)
  • Contextual_colors.Content.* (default, light, medium, dark, contrast)
  • Contextual_colors.Border.* (default, light, medium, dark, contrast)
  • Contextual_colors.Primary.* (default, light, medium, dark)
  • Contextual_colors.Secondary.* (default, light, medium, dark)
  • Contextual_colors.Accent.* (default, light, medium, dark)
  • Contextual_colors.Informative.* (default, light, medium, dark)
  • Contextual_colors.Success.* (default, light, medium, dark)
  • Contextual_colors.Warning.* (default, light, medium, dark)
  • Contextual_colors.Error.* (default, light, medium, dark)

Typography

  • Typography.Font-family.*
  • Typography.Weight.*
  • Typography.Size.*
  • Typography.Line-height.*
  • Typography.Letter-spacing.*
  • Typography.Headings.* (h1-regular, h1-bold, h1-xs-regular, h1-xs-bold, etc.)
  • Typography.Body.* (body-lg-regular, body-lg-bold, body-md-regular, etc.)
  • Typography.Buttons.* (button-lg, button-md, button-sm)
  • Typography.Links.* (link-lg-regular, link-lg-bold, link-md-regular, etc.)

Spacing

  • Spacings.spacing-* (0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500)

Radius

  • Radius.radius-* (0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500)

Shadows/Elevations

  • Elevations.* (100, 200, 300, 400, 500, 600, inset)

Shapes

  • Shape.shape-* (avatar, accordion, badge, button, card, checkbox, container, datepicker, drawer, emptyState, timepicker, messages, inputFields, modal, progressBar, pagination, radioButton, tab, toggle, toast, tag-rounded, segmentedControl, tag-squared, switch, tooltip, definitionList, header, navigationMenu, option, KPIcard, footer, slider, skeleton)

Breakpoints

  • Grid.MQ*.width-default-MQ* (MQ1-MQ6)

Icon Sizes

  • Icon_size.icon-size-* (xsmall, small, medium, large, xlarge)

Fonts

  • Fonts.* (daimlerTruck-primary, truckAPI-primary, dtCompanion-primary, [brand]-secondary)

Component Tokens

Component-specific tokens that are generated from the Themes.*.tokens.json files.

File Structure

src/
├── tokens/
│   ├── Primitives.Value.tokens.json
│   ├── text.styles.tokens.json
│   ├── Themes.*.tokens.json
│   └── Semantic *.Default theme.tokens.json
├── themes/
│   ├── [generated-theme]/
│      ├── colors.ts
│      ├── palette.ts
│      ├── spacing.ts
│      ├── radius.ts
│      ├── shadows.ts
│      ├── shape.ts
│      ├── breakpoints.ts
│      ├── typography.ts
│      ├── icons.ts
│      ├── animations.ts
│      ├── components.ts
│      └── index.ts
│
└── utils/
    └── theme-generator/
        ├── tokenUtils.ts
        ├── fileUtils.ts
        ├── validation.ts
        ├── formatter.ts
        ├── generators/
        │   ├── colors.ts
        │   ├── spacing.ts
        │   ├── radius.ts
        │   ├── shadows.ts
        │   ├── shape.ts
        │   ├── breakpoints.ts
        │   ├── typography.ts
        │   ├── icons.ts
        │   ├── animations.ts
        │   └── components.ts
        ├── index.ts
        └── runner.ts

Validation

The system includes comprehensive validation:

  • Theme Completeness: Checks for required token categories
  • Token Validation: Ensures tokens exist and have valid values
  • Reference Resolution: Handles nested token references
  • Fallback Handling: Provides fallback values for missing tokens

Error Handling

  • Missing Tokens: Themes with missing required tokens are skipped with warnings
  • Invalid References: Unresolvable token references fall back to inherit
  • Syntax Errors: JSON parsing errors are caught and reported
  • Type Errors: TypeScript compilation errors are reported

Contributing

When modifying the theme generation system:

  1. Update the appropriate generator in src/utils/theme-generator/generators/
    • For component tokens, modify components.ts generator
    • For other tokens, update the relevant generator (colors.ts, spacing.ts, etc.)
  2. Update the CustomTheme type in src/types/theme.ts if adding new token categories
  3. Update the default theme files if needed
  4. Run yarn build:theme to test changes
  5. Run yarn test to ensure all tests pass
  6. Update this documentation

Adding New Components

To add support for new components:

  1. Add the component key to the COMPONENT_KEYS array in src/utils/theme-generator/generators/components.ts
  2. Ensure the component tokens exist in the Themes.*.tokens.json files
  3. Run yarn build:theme to generate the updated components

© License

Licensed under MIT License

版本与发布记录

@dt-dds/themes 共发布 19 个版本,首次发布于 2025/08/27;过去 12 个月发布了 11 个版本。

版本发布日期距今
1.0.0-beta.20latest2026/10/2816 天前
1.0.0-beta.192026/10/121 个月前
1.0.0-beta.182026/10/091 个月前
1.0.0-beta.172026/10/081 个月前
1.0.0-beta.162026/09/032 个月前
1.0.0-beta.152026/04/306 个月前

关于 @dt-dds/themes 的常见问题

@dt-dds/themes 是什么?

DT-DDS Design System Themes

如何安装 @dt-dds/themes?

在项目目录运行 npm install @dt-dds/themes,或使用 pnpm add / yarn add / bun add。

@dt-dds/themes 支持 TypeScript 吗?

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

@dt-dds/themes 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dt-dds/themes 可以商用吗?

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

@dt-dds/themes 的下载量有多少?

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

@dt-dds/themes 还在维护吗?

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