@sanity/color-input

中文文档
6.1.9发布于 2026/11/02MITTypeScriptES Module构建来源已验证

Color input

原始使用文档
文档目录8 节
  1. What is it?
  2. Installation
  3. Usage
  4. Options
  5. Disable alpha
  6. Color list
  7. Data model
  8. License

@sanity/color-input

What is it?

Color input plugin for Sanity that stores selected colors in hex, hsl, hsv and rgb format.

Color input in the Studio

Installation

npm install --save @sanity/color-input

or

yarn add @sanity/color-input

Usage

Add it as a plugin in sanity.config.ts (or .js):

import {colorInput} from '@sanity/color-input'

export default defineConfig({
  // ...
  plugins: [colorInput()],
})

Now you can use the color type in your schema types:

// [...]
{
  fields: [
    // [...]
    {
      name: 'favoriteColor',
      title: 'Favorite color',
      type: 'color',
    },
  ]
}

Options

Disable alpha

To disable the alpha option, set disableAlpha to true:

// ...fields...
{
  name: 'favoriteColor',
  title: 'Color no-alpha',
  type: 'color',
  options: {
    disableAlpha: true
  }
}

Which will render accordingly:

This is an image

Color list

To add list of predefined selectable color swatches for the user to choose from use colorList. The color picker is a small fork of react-color, so colorList accepts any of its supported color formats.

// ...fields...
{
  name: 'favoriteColor',
  title: 'Color with list',
  type: 'color',
  options: {
    colorList: [
      '#FF6900',
      { hex: '#FCB900' },
      { r: 123, g: 220, b: 181 },
      { r: 0, g: 208, b: 132, a: 0.5 },
      { h: 203, s: 95, l: 77, a: 1 },
      { h: 202, s: 95, l: 46, a: 0.5 },
      { h: 345, s: 43, v: 97 },
      { h: 344, s: 91, v: 92, a: 0.5 },
    ]
  }
}

Which will render accordingly:

This is an image

Data model

{
  _type: 'color',
  hex: '#29158a',
  alpha: 0.9,
  hsl: {
    _type: 'hslaColor',
    h: 249.99999999999994,
    s: 0.7328000000000001,
    l: 0.313,
    a: 0.9
  },
  hsv: {
    _type: 'hsvaColor',
    h: 249.99999999999994,
    s: 0.8457987072945522,
    v: 0.5423664,
    a: 0.9
  },
  rgb: {
    _type: 'rgbaColor',
    r: 41
    g: 21,
    b: 138,
    a: 0.9
  }
}

License

MIT-licensed. See LICENSE.

版本与发布记录

@sanity/color-input 共发布 673 个版本,首次发布于 2018/01/05;过去 12 个月发布了 37 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
6.1.9latest2026/11/021 天前
6.1.82026/10/1420 天前
6.1.72026/10/1321 天前
6.1.62026/10/0925 天前
6.1.52026/09/291 个月前
6.1.42026/08/212 个月前

其他发布通道:custom-login → 0.124.0-default-login.063643d2,rc → 0.125.0-rc.4,fix-span-keys → 0.126.0-fix-span-keys.12d2645d,vega → 0.133.0-vega.cb3cdeee,babel-7 → 0.133.0-babel-7.06032ac5,structure → 0.134.0-alpha.d19d4c0c。

关于 @sanity/color-input 的常见问题

@sanity/color-input 是什么?

颜色输入

如何安装 @sanity/color-input?

在项目目录运行 npm install @sanity/color-input,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.2)、sanity(^5 || ^6.0.0-0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@sanity/color-input 支持 TypeScript 吗?

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

@sanity/color-input 支持 ESM 还是 CommonJS?

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

@sanity/color-input 需要什么版本的 Node.js?

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

@sanity/color-input 可以商用吗?

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

@sanity/color-input 还在维护吗?

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