Data Entryduskmoonimplemented16 demos

ColorPicker

ColorPicker captures theme colors, brand swatches, or user-selected color values.

Import@duskmoon-dev/components/color-picker
9API sections
26documented props
14behavior scenarios
Key API
triggerPropsvaluedefaultValueformatpresetstrigger

Usage

When to use

  • Use it inside forms, filters, settings, and any workflow that captures user input.
  • Prefer controlled props when the value must stay synchronized with application state.

Implementation notes

StylesheetImport @duskmoon-dev/components/styles.css once in the app or docs shell.
StateStart with default props for static examples, then switch to controlled props when state must be shared.
ThemeThe preview inherits the active DuskMoon data-theme value from the docs layout.

Features

Controlled and uncontrolled usage

Documents default values, value props, and change callbacks for form integration.

Validation state

Surfaces status, size, disabled, and option data patterns where the component supports them.

Primary API surface

ColorPicker is most often configured through `triggerProps`, `value`, `defaultValue`, `format`.

Covered behavior

Renders value, size, format, and text

Feature Demos

Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.

Preview
#1677ff

Basic usage

authored

Import the component stylesheet and ColorPicker from its package subpath, then render it with the core props.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function Example() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Renders value, size, format, and text

test-backed

ColorPicker scenario from the component test coverage: renders value, size, format, and text.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerRendersValueSizeFormatDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Supports uncontrolled open and input changes

test-backed

ColorPicker scenario from the component test coverage: supports uncontrolled open and input changes.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerSupportsUncontrolledOpenAndDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Supports presets and showText render function

test-backed

ColorPicker scenario from the component test coverage: supports presets and showtext render function.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerSupportsPresetsAndShowTextDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Supports format changes and hover trigger

test-backed

ColorPicker scenario from the component test coverage: supports format changes and hover trigger.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerSupportsFormatChangesAndDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Respects disabled state

test-backed

ColorPicker scenario from the component test coverage: respects disabled state.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerRespectsDisabledStateDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Has package stylesheet selectors for local color picker classes

test-backed

ColorPicker scenario from the component test coverage: has package stylesheet selectors for local color picker classes.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerHasPackageStylesheetSelectorsDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Forwards native trigger labels and errors while retaining picker actions

test-backed

ColorPicker scenario from the component test coverage: forwards native trigger labels and errors while retaining picker actions.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerForwardsNativeTriggerLabelsDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Selects saturation/brightness with a captured pointer and completes on release

test-backed

ColorPicker scenario from the component test coverage: selects saturation/brightness with a captured pointer and completes on release.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerSelectsSaturationBrightnessWithDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Keyboard selection and hue update hex without changing the chosen format

test-backed

ColorPicker scenario from the component test coverage: keyboard selection and hue update hex without changing the chosen format.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerKeyboardSelectionAndHueDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Disabled open panels block visual, input, and preset changes

test-backed

ColorPicker scenario from the component test coverage: disabled open panels block visual, input, and preset changes.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerDisabledOpenPanelsBlockDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Invalid hex text stays editable until a graphical selection corrects it

test-backed

ColorPicker scenario from the component test coverage: invalid hex text stays editable until a graphical selection corrects it.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerInvalidHexTextStaysDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Clamps touch/pointer selection outside the plane and ignores unrelated pointer movement

test-backed

ColorPicker scenario from the component test coverage: clamps touch/pointer selection outside the plane and ignores unrelated pointer movement.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerClampsTouchPointerSelectionDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Escape returns focus to the labeled trigger and outside pointer closes without losing value

test-backed

ColorPicker scenario from the component test coverage: escape returns focus to the labeled trigger and outside pointer closes without losing value.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerEscapeReturnsFocusToDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
#1677ff

Controlled open remains visible on dismissal until the owner updates

test-backed

ColorPicker scenario from the component test coverage: controlled open remains visible on dismissal until the owner updates.

Source
import "@duskmoon-dev/components/styles.css";
import { ColorPicker } from "@duskmoon-dev/components/color-picker";

export function ColorPickerControlledOpenRemainsVisibleDemo() {
  return (<ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>);
}
Preview
Sunshine Theme
#1677ff
Moonlight Theme
#1677ff

Theme aware

authored

Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.

Source
<div data-theme="sunshine">
  <ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>
</div>

<div data-theme="moonlight">
  <ColorPicker
  defaultValue="#1677ff"
  size="large"
  format="hex"
  showText
  onChange={(value, css) => console.log(value, css)}
/>
</div>

API

The API reference below lists every parsed exported type or interface for ColorPicker. Start with `triggerProps`, `value`, `defaultValue`, `format` for common usage.

Types: packages/components/src/components/color-picker/ColorPicker.types.tsScenarios: packages/components/src/components/color-picker/ColorPicker.test.tsx
ColorPickerPropsinterface extends Omit< ComponentPropsWithoutRef<"div">, "children" | "defaultValue" | "onChange" >
PropTypeRequiredDescription
triggerPropsComponentProps<"button">NotriggerProps configures ColorPicker.
valueColorValueNovalue configures ColorPicker.
defaultValueColorValueNodefaultValue configures ColorPicker.
formatColorPickerFormatNoformat configures ColorPicker.
presetsColorPreset[]Nopresets configures ColorPicker.
triggerColorPickerTriggerNotrigger configures ColorPicker.
openbooleanNoopen configures ColorPicker.
defaultOpenbooleanNodefaultOpen configures ColorPicker.
disabledbooleanNodisabled configures ColorPicker.
showTextboolean | ((color: string) => ReactNode)NoshowText configures ColorPicker.
sizeColorPickerSizeNosize configures ColorPicker.
panelRender(panel: ReactNode) => ReactNodeNopanelRender configures ColorPicker.
onChange(value: ColorValue, css: string) => voidNoonChange configures ColorPicker.
onChangeComplete(value: ColorValue, css: string) => voidNoonChangeComplete configures ColorPicker.
onFormatChange(format: ColorPickerFormat) => voidNoonFormatChange configures ColorPicker.
onOpenChange(open: boolean) => voidNoonOpenChange configures ColorPicker.
RGBColorinterface
PropTypeRequiredDescription
rnumberYesr configures ColorPicker.
gnumberYesg configures ColorPicker.
bnumberYesb configures ColorPicker.
anumberNoa configures ColorPicker.
HSBColorinterface
PropTypeRequiredDescription
hnumberYesh configures ColorPicker.
snumberYess configures ColorPicker.
bnumberYesb configures ColorPicker.
anumberNoa configures ColorPicker.
ColorPresetinterface
PropTypeRequiredDescription
labelReactNodeNolabel configures ColorPicker.
colorsColorValue[]Yescolors configures ColorPicker.
ColorPickerFormattype
Type definition
"hex" | "rgb" | "hsb"
ColorPickerTriggertype
Type definition
"hover" | "click"
ColorPickerSizetype
Type definition
"small" | "middle" | "large" | "sm" | "md" | "lg"
ColorValuetype
Type definition
string | RGBColor | HSBColor
ColorPickerComponenttype
Type definition
ForwardRefExoticComponent< ColorPickerProps & RefAttributes<HTMLDivElement> >