# 颜色选择器

- 页面: https://jiguang132.com/zh/resources/chakra-ui/docs/color-picker
- 资源: Chakra UI (https://jiguang132.com/zh/resources/chakra-ui.md)
- 全部指南: https://jiguang132.com/zh/resources/chakra-ui/docs.md

组合色域、色相、透明度与文本输入来选色。颜色值有自己的格式与解析规则，不应把任意字符串当有效颜色；同时提供键盘和文本方式，并核对透明色预览。

## 随附图标许可

源码查看器包含 ICON_ATTRIBUTION.md，以及本组示例实际使用的图标集合原始许可。再分发示例时请保留；react-icons 封装包的许可证不能替代各图标集合自身的条款。

- Lucide: ISC

## 安装与初始化

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

渲染前配置 ChakraProvider、defaultSystem 和 Emotion。保留宿主项目的 React 版本并检查 peer 兼容。官方 npm 安装提供组件包，不会复制以下示例源码。locale、next-themes 和框架专属 SSR 配置见资源安装指南；npm 安装之外还需单独复制所选示例源码。

## 完整原生使用示例

这是固定版本的真实示例，不是通用 API 伪代码。复制完整源码依赖并保留命名导出；附加依赖逐例列在下方。

```tsx
"use client"

import { ColorPicker, HStack, Portal, parseColor } from "@chakra-ui/react"

export const ColorPickerBasic = () => {
  return (
    <ColorPicker.Root defaultValue={parseColor("#eb5e41")} maxW="200px">
      <ColorPicker.HiddenInput />
      <ColorPicker.Label>Color</ColorPicker.Label>
      <ColorPicker.Control>
        <ColorPicker.Input />
        <ColorPicker.Trigger />
      </ColorPicker.Control>
      <Portal>
        <ColorPicker.Positioner>
          <ColorPicker.Content>
            <ColorPicker.Area />
            <HStack>
              <ColorPicker.EyeDropper size="xs" variant="outline" />
              <ColorPicker.Sliders />
            </HStack>
          </ColorPicker.Content>
        </ColorPicker.Positioner>
      </Portal>
    </ColorPicker.Root>
  )
}
```

## 全部示例与复现要求

示例名称用于选择演示，不是组件通用 variant 属性。复制所选示例全部 sourceFiles；compositions 别名表示本地文件，不是 npm 包。保留相对导入或映射到宿主真实目录。React peer 单独检查；编辑器示例保留一致的固定 Tiptap 扩展版本。

### 基础用法

`color-picker-basic` · 命名导出 `ColorPickerBasic` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-basic.tsx`

### 不同尺寸

`color-picker-with-sizes` · 命名导出 `ColorPickerWithSizes` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0 react-icons@5.6.0
```

- `vendor/apps/compositions/src/examples/color-picker-with-sizes.tsx`

### 不同变体

`color-picker-with-variants` · 命名导出 `ColorPickerWithVariants` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-with-variants.tsx`

### 输入仅

`color-picker-input-only` · 命名导出 `ColorPickerInputOnly` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-input-only.tsx`

### 色样仅

`color-picker-swatch-only` · 命名导出 `ColorPickerSwatchOnly` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-swatch-only.tsx`

### 触发器仅

`color-picker-trigger-only` · 命名导出 `ColorPickerTriggerOnly` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-trigger-only.tsx`

### 受控状态

`color-picker-controlled` · 命名导出 `ColorPickerControlled` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-controlled.tsx`

### 外部状态仓库

`color-picker-with-store` · 命名导出 `ColorPickerWithStore` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-with-store.tsx`

### 变化结束

`color-picker-change-end` · 命名导出 `ColorPickerChangeEnd` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-change-end.tsx`

### 通道滑块仅

`color-picker-channel-slider-only` · 命名导出 `ColorPickerChannelSliderOnly` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-channel-slider-only.tsx`

### React Hook Form 集成

`color-picker-with-hook-form` · 命名导出 `ColorPickerWithHookForm` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0 react-hook-form@7.77.0
```

- `vendor/apps/compositions/src/examples/color-picker-with-hook-form.tsx`

### 行内

`color-picker-inline` · 命名导出 `ColorPickerInline` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-inline.tsx`

### 打开来源对话框

`color-picker-open-from-dialog` · 命名导出 `ColorPickerOpenFromDialog` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-open-from-dialog.tsx`

### 禁用状态

`color-picker-with-disabled` · 命名导出 `ColorPickerWithDisabled` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-with-disabled.tsx`

### 通道输入

`color-picker-with-channel-input` · 命名导出 `ColorPickerWithChannelInput` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-with-channel-input.tsx`

### 适配内容

`color-picker-with-fit-content` · 命名导出 `ColorPickerWithFitContent` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
```

- `vendor/apps/compositions/src/examples/color-picker-with-fit-content.tsx`

### 保存色样

`color-picker-with-save-swatch` · 命名导出 `ColorPickerWithSaveSwatch` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0 react-icons@5.6.0
```

- `vendor/apps/compositions/src/examples/color-picker-with-save-swatch.tsx`

### 色样

`color-picker-with-swatches` · 命名导出 `ColorPickerWithSwatches` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0 react-icons@5.6.0
```

- `vendor/apps/compositions/src/examples/color-picker-with-swatches.tsx`

### 色样与输入

`color-picker-with-swatch-and-input` · 命名导出 `ColorPickerWithSwatchAndInput` · 上游原始示例

```bash
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0 react-icons@5.6.0
```

- `vendor/apps/compositions/src/examples/color-picker-with-swatch-and-input.tsx`

## 原生 API 与源码参考

源码查看器保留原始声明、import 与继承关系。Ark UI 事件契约、Chakra 样式属性和 recipe 类型仍以原生包为准；本指南不平铺或编造默认值。代码注释保留原文，不冒充正文翻译。

- `npm/@chakra-ui/react@3.37.0/dist/types/components/color-picker/color-picker.d.ts`
- `npm/@chakra-ui/react@3.37.0/dist/types/components/color-picker/index.d.ts`
- `npm/@chakra-ui/react@3.37.0/dist/types/components/color-picker/namespace.d.ts`

## 状态与安装后检查

执行严格类型检查、目标项目生产构建和实际操作。检查名称／焦点／键盘、深浅色、窄屏、原生支持的空／加载／错误状态以及卸载清理。预览限制远程接口、上传与下载，业务服务需自行配置。复制命令或预览就绪不代表安装完成或后端成功。

## 来源与许可边界

https://github.com/chakra-ui/chakra-ui/tree/2e7517745cff2fcde0b8012f136cf99611ff262a

本页是 JGuang 双语实用说明，不声称全文翻译上游 MDX。原始文档与示例字节保留在 vendor。保留仓库 MIT、compositions 的 ISC 元数据和独立依赖声明；原始许可元数据差异与缺失完整声明仍作为显式审查事项，不包含 Chakra Pro 付费内容。

---

JGuang 全部资源索引: https://jiguang132.com/llms.txt
