npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rc-component/color-picker

v3.2.0

Published

React Color Picker

Readme

特性

  • 支持受控和非受控颜色值。
  • 支持字符串、数字、RGB、RGBA、HSB、HSBA 和 Color 输入。
  • 提供带有更改和拖动完成回调的色调和 alpha 控件。
  • 暴露 Color 辅助方法,用于 hex、RGB 和 HSB 转换。
  • 提供可用键盘操作、带屏幕阅读器标签的控件,文案可覆盖。

安装

npm install @rc-component/color-picker

使用

import ColorPicker from '@rc-component/color-picker';
import '@rc-component/color-picker/assets/index.css';

export default function App() {
  return (
    <ColorPicker
      defaultValue="#1677ff"
      onChange={(color, info) => {
        console.log(color.toHexString(), info?.type);
      }}
    />
  );
}

示例

运行本地 dumi 站点:

npm install
npm start

然后打开 http://localhost:8000。

API

ColorPicker

| 参数 | 说明 | 类型 | 默认值 | | ---------------- | ------------------------ | ---------------------------------------------------------------------------- | ----------------- | | defaultValue | 默认颜色值 | ColorGenInput | - | | disabled | 颜色选择器是否禁用 | boolean | false | | disabledAlpha | 是否隐藏 alpha 滑块 | boolean | false | | locale | 选择器与滑块的无障碍标签 | Locale | - | | panelRender | 自定义面板渲染器 | (panel: React.ReactElement) => React.ReactElement | - | | prefixCls | 组件 className 前缀 | string | rc-color-picker | | value | 当前颜色值 | ColorGenInput | - | | onChange | 颜色变化时的回调 | (color: Color, info?: { type?: 'hue' \| 'alpha'; value?: number }) => void | - | | onChangeComplete | 拖动操作完成时的回调 | (color: Color, info?: { type?: 'hue' \| 'alpha'; value?: number }) => void | - |

Locale

覆盖控件向辅助技术暴露的无障碍名称。所有字段均为可选,未传入时回退到默认值,因此只需覆盖需要翻译的字段。

| 参数 | 说明 | 类型 | 默认值 | | ----------------- | ----------------------------------------- | ------ | -------------- | | alpha | alpha 滑块的 aria-label | string | Alpha | | brightness | 明度轴 aria-valuetext 中的通道名称 | string | Brightness | | hue | 色相滑块的 aria-label | string | Hue | | picker | 饱和度轴与明度轴的 aria-label | string | Color picker | | pickerDescription | 饱和度轴与明度轴的 aria-roledescription | string | 2D slider | | saturation | 饱和度轴 aria-valuetext 中的通道名称 | string | Saturation |

<ColorPicker
  locale={{
    picker: '颜色选择器',
    pickerDescription: '二维滑块',
    hue: '色相',
    alpha: '透明度',
    saturation: '饱和度',
    brightness: '明度',
  }}
/>

二维选择区域为每个轴渲染一个 range 输入框。两者共享 picker 名称与 pickerDescription 角色描述,并各自通过 aria-valuetext 播报自身通道(如 Saturation: 91%、Brightness: 100%),因此 saturation 与 brightness 是通道名称而非完整标签。

Color

| Method | 说明 | 类型 | | ----------- | --------------------- | ------------------------------------------------------ | | toHexString | 转换为 hex 颜色字符串 | () => string | | toHsb | 转换为 HSB 对象 | () => { h: number; s: number; b: number; a: number } | | toHsbString | 转换为 HSB 颜色字符串 | () => string | | toRgb | 转换为 RGB 对象 | () => { r: number; g: number; b: number; a: number } | | toRgbString | 转换为 RGB 颜色字符串 | () => string |

ColorBlock

独立的色块组件,用于构建自定义触发器与面板。

import { ColorBlock } from '@rc-component/color-picker';

<ColorBlock
  color="#1677ff"
  prefixCls="rc-color-picker"
  title="当前颜色"
  onClick={handleClick}
/>;

| 参数 | 说明 | 类型 | 默认值 | | --------- | ---------------------- | ----------------------------------------------------------- | ------ | | color | 用于填充色块的颜色 | string | - | | prefixCls | 组件 className 前缀 | string | - | | className | 最外层元素的 className | string | - | | style | 最外层元素的样式 | React.CSSProperties | - | | ...rest | 透传到最外层元素 | React.HTMLAttributes<HTMLDivElement \| HTMLButtonElement> | - |

ColorBlockProps 继承 React.HTMLAttributes<HTMLDivElement | HTMLButtonElement>,标准属性和事件处理器会透传到最外层元素。innerClassName 与 innerStyle 是 antd 语义化结构的内部实现,请视为私有。

传入 onClick 时渲染原生 <button type="button">,aria-label 默认取 color,Enter 和空格激活由浏览器处理。自定义的 role、tabIndex、aria-label 和 onKeyDown 会透传。未传 onClick 时仍渲染普通 div。

本地开发

npm install
npm start

dumi 站点默认运行在 http://localhost:8000。

npm test
npm run tsc
npm run lint
npm run compile
npm run build

发布

npm run prepublishOnly

包构建完成后,发布流程由 @rc-component/np 通过 rc-np 命令处理。

许可证

@rc-component/color-picker 基于 MIT 许可证发布。