# @sanity/color-input 中文文档

规范地址：https://npmcn.com/package/%40sanity/color-input/

版本：6\.1\.9
npm 元数据更新时间：2026-11-02T08:50:57.412Z
中文译文更新时间：2026-11-02T10:02:26.669Z
软件包许可：MIT

本文由上游 README 机器翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40sanity/color-input
原文对照：https://npmcn.com/package/%40sanity/color-input/?lang=original
项目主页：https://github.com/sanity-io/plugins/tree/main/plugins/%40sanity/color-input#readme
源码仓库：https://github.com/sanity-io/plugins

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：168 kB，12 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=20\.19 \<22 \|\| \>=22\.12
- 运行依赖：5 个
- peer 依赖：react ^19\.2，sanity ^5 \|\| ^6\.0\.0-0
- 首次发布：2018-01-05T10:41:05.786Z
- 最新版本发布：2026-11-02T08:50:56.822Z
- 已发布版本数：673（近 12 个月 37 个）

## 中文简介

颜色输入

## 安装

```sh
npm install @sanity/color-input
```

也可以使用：`pnpm add @sanity/color-input`、`yarn add @sanity/color-input`、`bun add @sanity/color-input`

## README

# @sanity / color-input

## 这是什么？

颜色输入插件 [理智](https://sanity.io/) 它以十六进制、hsl、HSV和RGB格式存储选定的颜色。

![Color input in the Studio](https://github.com/user-attachments/assets/070a3718-33fc-47f7-94fb-93988902e81e)

## 安装

```
npm install --save @sanity/color-input
```

或者

```
yarn add @sanity/color-input
```

## 使用

将其作为插件添加到sanity.config.ts（或.js）中：

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

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

现在你可以用 `color` 输入模式类型：

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

## 选项

### 禁用α

要禁用alpha选项，请设置 `disableAlpha` 来 `true`：

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

这将相应地呈现：

![This is an image](https://github.com/user-attachments/assets/f7095cbb-8014-4aef-bb95-58f6aa25672b)

### 颜色列表

添加预定义的可选择色板列表，供用户选择使用 `colorList`. 取色器是一个小叉 [`react-color`](https://github.com/casesandberg/react-color),所以 `colorList` 接受任何它支持的 [颜色格式](https://casesandberg.github.io/react-color/#api-color).

```js
// ...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 },
    ]
  }
}
```

这将相应地呈现：

![This is an image](https://github.com/user-attachments/assets/f2a35da3-8944-46b3-a626-9aa870800b65)

## 数据模型

```js
{
  _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
  }
}
```

## 许可证

swfobject。看到许可证。

## 常见问题

### @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 和提交记录判断。

