Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Buttons

  • Button
  • ShimmerButton
  • InteractiveHoverButton
  • RainbowButton
  • PulsatingButton
  • RippleButton
  • ButtonGroup
  • SocialButton

Basic Inputs

  • Input
  • Textarea
  • CellEditor
  • Select
  • Checkbox
  • CheckboxGroup
  • Radio
  • Switch
  • Toggle
  • Segmented
  • Slider
  • NumberField
  • ElasticSlider

Advanced Inputs

  • MathTextarea
  • QuestionEditor
  • QuestionAnswer
  • MathField
  • SecretField
  • PasswordGenerator
  • Combobox
  • RemoteSelect
  • Listbox
  • Mentions
  • InputOTP
  • Rating
  • Upload
  • RegionSelect
  • ImageCropper
  • ScopeMatrix
  • Transfer
  • Cascader
  • TreeSelect
  • RegionCascader
  • CountrySelect
  • MarkdownEditor
  • Novel editor
  • RichTextEditor
  • CodeEditor
  • IssueReporter
  • ColorPicker
  • ColorField
  • ColorSwatchPicker
  • Choicebox
  • EmojiPicker
  • VoiceRecord
  • IconPicker
  • InspectorPanel

Date and Time

  • Calendar
  • DatePicker
  • DateTimePicker
  • DateRangePicker
  • TimePicker
  • TimeField

Form Frameworks

  • Form
  • ModalForm / DrawerForm
  • ProForm
  • StepsForm
  • LoginForm
  • AuthPanel
  • ClickCaptcha
  • Label
  • Field
  • SearchForm

ColorSwatchPicker

color-swatch-picker

Chooses a color from a labeled, keyboard-accessible swatch collection.

Usage

Basic usage

Discrete preset color block radio selection, uncontrolled use defaultValue for initial selection.

tsx
const PALETTE = ["#ef4444", "#f97316", "#eab308", "#22c55e", "#06b6d4", "#3b82f6", "#8b5cf6", "#ec4899"];

<ColorSwatchPicker colors={PALETTE} defaultValue="#3b82f6" />

Size

size supports sm / md / lg.

tsx
<>
  <ColorSwatchPicker colors={PALETTE} defaultValue="#22c55e" size="sm" />
  <ColorSwatchPicker colors={PALETTE} defaultValue="#22c55e" size="lg" />
</>

Theme token palette with readable names

A swatch can be written as { color, label }: the label becomes the accessible name and hover hint, while selection identity stays the color. A token color must carry a label, otherwise a screen reader announces the raw var(--color-primary) string.

var(--color-primary)
tsx
const TOKENS = [
  { color: "var(--color-primary)", label: "Primary" },
  { color: "var(--color-success)", label: "Success" },
  { color: "var(--color-warning)", label: "Warning" },
  { color: "var(--color-danger)", label: "Danger" },
];

// The emitted value is still the color string, not the label
<ColorSwatchPicker colors={TOKENS} value={v} onValueChange={setV} />

Disabled

disabled Reduces the transparency of the entire group and blocks interaction.

tsx
<ColorSwatchPicker colors={PALETTE} defaultValue="#8b5cf6" disabled />

Round swatches

shape="circle" is fully round with no border, only a very faint inner shadow; the gap in the selected ring is transparent, so on a card it shows the card surface.

tsx
<ColorSwatchPicker colors={PALETTE} defaultValue="#22c55e" shape="circle" size="sm" />

When to use

Use ColorSwatchPicker to choose one value from a fixed palette, such as brand or label colors. It presents RadioGroup semantics as color swatches and includes arrow-key navigation. Use ColorPicker when the user needs an arbitrary color.

Import

ts
import { ColorSwatchPicker, normalizeSwatches } from "@hulianui/ui"

Props

NameTypeDefaultDescription
colors*(string | { color: string; label?: string })[]-Preset swatch list. A string is any CSS color (hex / rgb / hsl / named color / var(--color-x)); an object may add a label used as the accessible name and hover hint. Both forms can be mixed
valuestring-Controlled selection value (must be strictly equal to a swatch color)
defaultValuestring-Uncontrolled initial selection value
size"sm" | "md" | "lg""md"Color block size
shape"square" | "circle""square"square has token corners and a thin border; circle is fully round with no border, only a very faint inner shadow (theme or palette pickers). The gap in the selected ring is transparent, so on a card it shows the card surface itself.
disabledbooleanfalseDisable entire group
classNamestring-Additional class name for the container.
aria-labelstringLocale defaultAccessible name; enUS provides “Color swatches”, and an explicit value takes precedence.

ColorSwatchItem (the object form of colors)

NameTypeDefaultDescription
color *string-Any CSS color string. It is also the selection value compared strictly against value.
labelstringFalls back to color itselfAccessible name and hover hint. Always provide it for token colors such as var(--color-primary), otherwise a screen reader announces the variable name.

Events

EventTypeDescription
onValueChange(color: string) => voidSelect change callback; the argument is always the swatch color, never the label

Utilities

NameSignatureDescription
normalizeSwatches(colors: (string | ColorSwatchItem)[]) => { color: string; label: string }[]Normalizes the mixed array into labelled swatches; string entries and missing or blank labels fall back to the color value itself

Usage guidelines

  • Token colors need a label. A bare string in colors becomes the swatch aria-label verbatim, so var(--color-primary) is announced as the variable name and means nothing to a screen reader user; #3b82f6 and oklch(...) are read as character strings for the same reason. Only named colors such as red or tomato survive without a label.
  • Identity for value and onValueChange is always the color string, never the label. Do not pass a label back as the selected value.
  • A controlled value must be strictly equal to a swatch color to show as selected. "#FFF" differs from "#ffffff", and "#3b82f6" differs from "rgb(59,130,246)"; normalize casing and format before passing values.
  • The component supports single selection only.
  • The default group label follows ConfigProvider locale; the no-provider fallback remains Chinese.

Related

SecretField · Combobox · Listbox · Mentions · InputOTP · Rating

Playground

#3b82f6
<ColorSwatchPicker colors={PALETTE} defaultValue="#3b82f6" />
PreviousColorFieldFormsNextChoicebox

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Utilities
    • Usage guidelines
    • Related
  • Playground