Data Entryduskmoonimplemented8 demos

ColorPicker

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

Import@duskmoon-dev/components/color-picker
9API sections
25documented props
6behavior scenarios
Key API
valuedefaultValueformatpresetstriggeropen

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 `value`, `defaultValue`, `format`, `presets`.

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
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 `value`, `defaultValue`, `format`, `presets` 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
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
"hex" | "rgb" | "hsb"
ColorPickerTriggertype
"hover" | "click"
ColorPickerSizetype
"small" | "middle" | "large" | "sm" | "md" | "lg"
ColorValuetype
string | RGBColor | HSBColor
ColorPickerComponenttype
ForwardRefExoticComponent< ColorPickerProps & RefAttributes<HTMLDivElement> >