@abtion-oss/design-system-colors

中文文档
1.1.2发布于 2024/11/02MITTypeScriptESM + CJS近 30 天下载 4872

Utilities for generating tailwind color schemes with contrast colors

原始使用文档

Design System Colors

Utilities to standardize colors across differently themed projects - making it possible to share components through Abtion's component library

Usage

The idea is that:

  1. A designer creates a style guide for a project, with contextual colors (neutral, primary, secondary, success, danger, warning, info)

  2. The designer creates color shades for each contextual color 100-900, and dark/light colors, which will be used to provide contrast for light/dark shades respectively.

  3. A colors.json-file with all the colors is created:

    {
      "dark": "#111827",
      "light": "#F3F4F6",
      "neutral": {
        "DEFAULT": "#6B7280",
        "100": "#F3F4F6",
        ...
        "900": "#111827"
      },
      "primary": {
        "DEFAULT": "#2563EB",
        "100": "#D3E6FE",
        ...
        "900": "#071A70"
      },
    
      ...
    }
    
  4. getColorStyles is used to generate a stylesheet with all colors specified as CSS variables (R G B), and each shade with a contrast colors added ("dark" or "light" based on relative luminance):

    :root {
      --color-dark: 17 24 39;
      --color-light: 243 244 246;
    
      --color-neutral: 107 114 128;
      --color-neutral-contrast: 243 244 246;
    
      --color-neutral-100: 243 244 246;
      --color-neutral-100-contrast: 17 24 39;
      ...
      --color-neutral-900: 17 24 39;
      --color-neutral-900-contrast: 243 244 246;
    
      --color-primary: 37 99 235;
      --color-primary-contrast: 243 244 246;
    
      --color-primary-100: 211 230 254;
      --color-primary-100-contrast: 17 24 39;
      ...
      --color-primary-900: 7 26 112;
      --color-primary-900-contrast: 243 244 246;
    
      ...
    }
    
  5. getTailwindColors is used to provide the colors to the tailwind configuration (with contrast colors and support for opacity):

    {
      dark: 'rgb(var(--color-dark) / <alpha-value>)',
      light: 'rgb(var(--color-light) / <alpha-value>)',
      neutral: {
        DEFAULT: 'rgb(var(--color-neutral) / <alpha-value>)',
        contrast: 'rgb(var(--color-neutral-contrast) / <alpha-value>)',
    
        '100': 'rgb(var(--color-neutral-100) / <alpha-value>)',
        '100-contrast': 'rgb(var(--color-neutral-100-contrast) / <alpha-value>)',
        ...
        '900': 'rgb(var(--color-neutral-900) / <alpha-value>)',
        '900-contrast': 'rgb(var(--color-neutral-900-contrast) / <alpha-value>)',
      },
      primary: {
        DEFAULT: 'rgb(var(--color-info) / <alpha-value>)',
        contrast: 'rgb(var(--color-info-contrast) / <alpha-value>)'
    
        '100-contrast': 'rgb(var(--color-danger-100-contrast) / <alpha-value>)',
        ...
        '900': 'rgb(var(--color-primary-900) / <alpha-value>)',
        '900-contrast': 'rgb(var(--color-info-900-contrast) / <alpha-value>)',
      },
      ...
    }
    
  6. Now the project can be styled using the contextual colors (and contrast colors), and shared components from the component library can be dropped in and used with few adjustments needed.

Utilities

Usually a project would only need to use:

Other utilities are:

版本与发布记录

@abtion-oss/design-system-colors 共发布 6 个版本,首次发布于 2024/11/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.2latest2024/11/022 年前
1.1.12024/11/022 年前
1.1.02024/11/022 年前
1.0.22024/11/022 年前
1.0.12024/11/022 年前
1.0.02024/11/022 年前

关于 @abtion-oss/design-system-colors 的常见问题

@abtion-oss/design-system-colors 是什么?

Utilities for generating tailwind color schemes with contrast colors

如何安装 @abtion-oss/design-system-colors?

在项目目录运行 npm install @abtion-oss/design-system-colors,或使用 pnpm add / yarn add / bun add。

@abtion-oss/design-system-colors 支持 TypeScript 吗?

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

@abtion-oss/design-system-colors 支持 ESM 还是 CommonJS?

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

@abtion-oss/design-system-colors 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.16.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@abtion-oss/design-system-colors 可以商用吗?

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

@abtion-oss/design-system-colors 的下载量有多少?

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

@abtion-oss/design-system-colors 还在维护吗?

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