@canonical/ds-types

中文文档
0.45.0发布于 2026/10/23LGPL-3.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 1万

Types and related type utilities for Pragma.

原始使用文档
文档目录5 节
  1. Installation
  2. Modifier Families
  3. Usage
  4. Runtime Constants
  5. Design System Ontology

@canonical/ds-types

TypeScript types for modifier families and component props in the Pragma design system.

Installation

bun add @canonical/ds-types

Modifier Families

A modifier family is a set of related visual variants that components can support. Instead of accepting arbitrary strings for appearance props, components use modifier family types to ensure type safety and enable IDE autocomplete.

The package currently defines two modifier families:

severity controls intent-based colouring for communicating status or importance:

  • neutral - Default state with no specific intent
  • positive - Success, confirmation, or approval
  • negative - Error, danger, or destructive actions
  • caution - Warning or attention required
  • information - Informational content

emphasis controls visual prominence:

  • neutral - Standard presentation
  • highlighted - Increased visual weight
  • muted - Reduced visual weight
  • accented - Brand or accent colouring

Usage

Import the ModifierFamily type helper and use it to constrain props:

import type { ModifierFamily } from "@canonical/ds-types";

interface ButtonProps {
  appearance?: ModifierFamily<"severity">;
}

The ModifierFamily<"severity"> type resolves to the union "neutral" | "positive" | "negative" | "caution" | "information". TypeScript will reject invalid values at compile time.

Runtime Constants

The same values are available as runtime constants for cases where you need to iterate over options or validate user input:

import { MODIFIER_FAMILIES } from "@canonical/ds-types";

// MODIFIER_FAMILIES.severity = ["neutral", "positive", "negative", "caution", "information"]
// MODIFIER_FAMILIES.emphasis = ["neutral", "highlighted", "muted", "accented"]

const isValidSeverity = (value: string): value is ModifierFamily<"severity"> =>
  MODIFIER_FAMILIES.severity.includes(value as ModifierFamily<"severity">);

Design System Ontology

The modifier families defined in this package derive from the Design System Ontology. The ontology provides the authoritative specification for which modifiers exist and their semantic meaning. Changes to modifier families should originate in the ontology and propagate to this package to maintain consistency between design specifications and implementation.

版本与发布记录

@canonical/ds-types 共发布 37 个版本,首次发布于 2026/02/06;过去 12 个月发布了 37 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.45.0latest2026/10/2317 天前
0.44.12026/10/081 个月前
0.44.02026/10/051 个月前
0.43.02026/10/011 个月前
0.42.02026/09/281 个月前
0.40.02026/09/211 个月前

其他发布通道:a → 0.12.0-experimental.0。

关于 @canonical/ds-types 的常见问题

@canonical/ds-types 是什么?

Types and related type utilities for Pragma.

如何安装 @canonical/ds-types?

在项目目录运行 npm install @canonical/ds-types,或使用 pnpm add / yarn add / bun add。

@canonical/ds-types 支持 TypeScript 吗?

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

@canonical/ds-types 支持 ESM 还是 CommonJS?

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

@canonical/ds-types 可以商用吗?

@canonical/ds-types 使用 LGPL-3.0 许可。弱 Copyleft:作为库被调用时通常不要求开源你自己的代码,但修改库本身需以 LGPL 开源;前端打包合并后的适用边界存在不同理解。以上为概括,不构成法律意见,请以许可原文为准。

@canonical/ds-types 的下载量有多少?

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

@canonical/ds-types 还在维护吗?

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