@department-of-veterans-affairs/mobile-tokens

中文文档
0.24.0发布于 2026/09/30ISCTypeScriptCommonJS零依赖近 30 天下载 4647

VA Design System Mobile Token Library

原始使用文档
文档目录5 节
  1. For consumers
  2. Token Usage
  3. Themes
  4. For contributors
  5. Yarn Commands

VA Mobile Design System - Tokens Package

The Tokens package contains the design tokens for the VA Mobile Design Library. It uses Style Dictionary as a build system to define our styles in JSON and export them to different formats.

For consumers

Direct consumption of the tokens package is optional, but recommended. The tokens package contains the same building blocks used to build the design system components which will more easily allow screen content and app-level custom components to follow design system conventions, helping maintain consistency in experience for users. It is also recommended to match the tokens package version to the version of tokens used by the components package you are leveraging, to ensure consistency.

Token Usage

To use the tokens, simply:

  1. Add @department-of-veterans-affairs/mobile-tokens to your project via your package manager (e.g. yarn)
  2. Add import { colors } from '@department-of-veterans-affairs/mobile-tokens to files you wish to use them in.
  3. Reference colors in your code: e.g. buttonColor = colors.vadsColorGrayMedium

Themes

The tokens package also has light and dark themes available. These themes are a subset of the colors tokens above, containing primitive colors, semantic tokens without an OnLight or OnDark mode specified, and the colors for only the light or dark themes respectively. The OnLight and OnDark mode suffixes are also removed.

The purpose of themes is to allow for assignment of color tokens without the need to specify the light or dark mode, and let your theme provider or handler return the correct theme. For example: instead of having a conditional where you'd assign either the colors.vadsColorForegroundDefaultOnLight or colors.vadsColorForegroundDefaultOnDark token, you could instead use theme.vadsColorForegroundDefault if your app already knows which color scheme it wants to use.

Using theme tokens directly

  1. Add @department-of-veterans-affairs/mobile-tokens to your project via your package manager (e.g. yarn)
  2. Add import { themes } from '@department-of-veterans-affairs/mobile-tokens to files you wish to use them in.
  3. Reference the theme in your code using either themes.light or themes.dark

useTheme hook

We have also made a hook available in the component library that will return the appropriate light or dark theme based on the user's OS setting. To use the hook:

  1. Add @department-of-veterans-affairs/mobile-component-library to your project via your package manager (e.g. yarn)
  2. Add import { useTheme } from '@department-of-veterans-affairs/mobile-component-library'
  3. Use the hook to at the top of your component function to retrieve either the light or dark theme based on the device's current color scheme. e.g.
const theme = useTheme()

const componentStyle = {
  color: theme.vadsColorForegroundDefault,
}

For contributors

Depending on what is being contributed, the recommendation for how to proceed differs.

If you are contributing a simple addition or update of an existing token, the recommendation is to do so in the GitHub web interface by updating the relevant src tokens file and running an alpha publish against the branch for the package to affirm the dist/ folder correctly forms up your updated/added token as expected in the resulting NPM package.

If you are contributing many tokens or need to adjust build processes, you should get set up locally. See the directions in the components package documentation for doing so with minor modifications to that process of changing directory to the tokens package (va-mobile-library/packages/tokens) instead of components and not having the final running steps as the tokens:build command is essentially running the tokens as it generates the output folders based on the build/config setup and tokens in the src/ folder.

Note: the folder structure and file naming within the src/ folder is relevant so follow the existing structure and direct questions to the DSVA Slack channel.

Yarn Commands

CommandDescription
tokens:buildTakes any JSON files in the src/tokens folder and transforms them according to the defined transformations in the config.js

版本与发布记录

@department-of-veterans-affairs/mobile-tokens 共发布 84 个版本,首次发布于 2023/08/31;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.24.0latest2026/09/301 个月前
0.23.1-alpha.1alpha2026/09/211 个月前
0.23.1-alpha.02026/09/181 个月前
0.23.02024/12/131.9 年前
0.22.02024/12/121.9 年前
0.21.1-alpha.12024/12/111.9 年前

关于 @department-of-veterans-affairs/mobile-tokens 的常见问题

@department-of-veterans-affairs/mobile-tokens 是什么?

VA Design System Mobile Token Library

如何安装 @department-of-veterans-affairs/mobile-tokens?

在项目目录运行 npm install @department-of-veterans-affairs/mobile-tokens,或使用 pnpm add / yarn add / bun add。

@department-of-veterans-affairs/mobile-tokens 支持 TypeScript 吗?

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

@department-of-veterans-affairs/mobile-tokens 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@department-of-veterans-affairs/mobile-tokens 可以商用吗?

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

@department-of-veterans-affairs/mobile-tokens 的下载量有多少?

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

@department-of-veterans-affairs/mobile-tokens 还在维护吗?

最新版本 0.24.0 发布于 2026/09/30(1 个月前);至今共发布 84 个版本,其中过去 12 个月发布了 3 个;首次发布于 2023/08/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。