Back to Shark UI

Color Picker

docs/components/color-picker

latest19.1 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Color Picker

Copy Markdown

Pick colors with hue and alpha controls.

DocsAPI

PreviewCode

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/color-picker

Modes#

You can use multiple modes to build the color picker that fits your needs:

  • Input for hex or channel editing
  • Popover for area and slider selection
  • Swatch picker for preset colors
  • Area standalone component for color selection
  • Slider for color adjustment

Input#

Anatomy#

ColorPicker
├── ColorPickerControl
│ └── InputGroup
│ ├── ColorPickerTrigger
│ │ └── ColorPickerSwatchPreview
│ └── ColorPickerInput
└── ColorPickerContent
    ├── ColorPickerArea
    │ └── ColorPickerAreaThumb
    └── ColorPickerView
        └── ColorPickerSlider

Usage#

import {
  ColorPicker,
  ColorPickerInput,
} from "@/components/ui/color-picker";
<ColorPicker>
  <ColorPickerInput asChild channel="hex">
    <Input />
  </ColorPickerInput>
</ColorPicker>

Controlled#

Use the value and onValueChange props to programmatically control the color picker's state.

PreviewCode

#EB5E41

States#

Invalid#

PreviewCode

Color

Please enter a valid hex color

Disabled#

PreviewCode

Examples#

With Field#

PreviewCode

Color

Enter your brand's primary color

Channel Editing#

PreviewCode

RGB

HSB

HSL

Hex

With Swatch#

Input with ColorPickerSwatchPreview showing the current color alongside the hex input.

PreviewCode

With Popover#

An input with trigger and popover content for area, hue, and alpha selection.

PreviewCode

Compact#

Inspired by Figma's color input.

PreviewCode

Popover#

Color picker with trigger and popover content.

Anatomy#

ColorPicker
├── ColorPickerControl
│ └── ColorPickerTrigger
└── ColorPickerContent
    ├── ColorPickerArea
    │ └── ColorPickerAreaThumb
    ├── ColorPickerView
    │ ├── ColorPickerEyeDropperTrigger
    │ └── ColorPickerSlider
    │ └── ColorPickerTransparencyGrid
    └── ColorPickerSwatchGroup
        └── ColorPickerSwatchTrigger
            └── ColorPickerSwatch

Usage#

import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerAreaThumb,
  ColorPickerContent,
  ColorPickerEyeDropperTrigger,
  ColorPickerSlider,
  ColorPickerTrigger,
  ColorPickerTransparencyGrid,
  ColorPickerView,
} from "@/components/ui/color-picker";
<ColorPicker>
  <ColorPickerTrigger />
  <ColorPickerContent>
    <ColorPickerArea>
      <ColorPickerAreaThumb />
    </ColorPickerArea>
    <ColorPickerView>
      <ColorPickerEyeDropperTrigger />
      <ColorPickerSlider channel="hue" />
      <ColorPickerSlider channel="alpha">
        <ColorPickerTransparencyGrid />
      </ColorPickerSlider>
    </ColorPickerView>
  </ColorPickerContent>
</ColorPicker>

States#

Disabled#

Set disabled to prevent user interaction.

PreviewCode

Pick as color

Examples#

With Eye Dropper#

PreviewCode

With Channel Editing#

Popover with area, sliders, and input fields for editing red, green, and blue values.

PreviewCode

Pick a color

With Only Sliders#

Popover with hue, saturation, lightness, and alpha sliders only, no color area.

PreviewCode

Pick a color

With Swatch Picker#

Popover with preset color swatches for quick selection.

PreviewCode

Pick a color

Color Swatch Picker#

Set inline on ColorPicker so swatches render without a popover.

Anatomy#

ColorPicker
└── ColorPickerSwatchGroup
    └── ColorPickerSwatchTrigger
        └── ColorPickerSwatch
            └── ColorPickerSwatchIndicator

Usage#

import {
  ColorPicker,
  ColorPickerSwatchTrigger,
  ColorPickerSwatchGroup,
  ColorPickerSwatch,
  ColorPickerSwatchIndicator,
} from "@/components/ui/color-picker";
<ColorPicker>
  <ColorPickerSwatchGroup>
    <ColorPickerSwatchTrigger value="#0485F7">
      <ColorPickerSwatch value="#0485F7">
          <ColorPickerSwatchIndicator />
      </ColorPickerSwatch>
    </ColorPickerSwatchTrigger>
  </ColorPickerSwatchGroup>
</ColorPicker>

Controlled#

Use the value and onValueChange props to programmatically control the swatch picker's state.

PreviewCode

#0485F7

States#

Disabled#

Set disabled to prevent user interaction.

PreviewCode

Examples#

Custom Size#

Customize swatch size using the size-* on ColorPickerSwatchTrigger.

PreviewCode

Custom Radius#

Override the default rounded style on ColorPickerSwatchTrigger using the rounded-* utility class.

PreviewCode

Custom Indicator#

Replace the default check icon with a custom indicator via the children of ColorPickerSwatchIndicator.

PreviewCode

Area#

Set inline on ColorPicker for a standalone color area.

Anatomy#

ColorPicker
└── ColorPickerArea
    └── ColorPickerAreaThumb

Usage#

import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerAreaThumb,
} from "@/components/ui/color-picker";
<ColorPicker>
  <ColorPickerArea>
    <ColorPickerAreaThumb />
  </ColorPickerArea>
</ColorPicker>

Examples#

Color Channels#

PreviewCode

With Dots#

PreviewCode

Slider#

Set inline on ColorPicker for standalone sliders. Wrap multiple sliders in ColorPickerView.

Anatomy#

ColorPicker
└── ColorPickerView
    └── ColorPickerSlider
        └── ColorPickerTransparencyGrid

Usage#

import {
  ColorPicker,
  ColorPickerSlider,
} from "@/components/ui/color-picker";
<ColorPicker>
  <ColorPickerSlider channel="hue" />
</ColorPicker>

Controlled#

PreviewCode

rgba(82, 65, 235, 1)

States#

Disabled#

PreviewCode

Examples#

Alpha Channel#

PreviewCode

HSL Channels#

PreviewCode

HSBA Channels#

PreviewCode

RGB Channels#

PreviewCode

Vertical#

PreviewCode

Custom spacing#

Use [--space:--spacing("value")] on ColorPickerContent to adjust internal spacing.

Default spacing is --spacing(3).

PreviewCode

You can use breakpoint utilities to change the internal spacing at different screen sizes.

md:[--space:--spacing(6)] lg:[--space:--spacing(8)]

API Reference#

ColorPicker#

Root element of the color picker.

PropTypeDefault
valuestring-
defaultValuestring-
onValueChange(details: ColorPickerValueChangeDetails) => void-
disabledbooleanfalse
format`"hex""hexa"
inlinebooleanfalse
positioningPositioningOptions{ placement: "top-start" }
lazyMountbooleantrue
unmountOnExitbooleantrue
classNamestring-

ColorPickerTrigger#

Button or element that opens the color picker popover.

PropTypeDefault
classNamestring-
asChildbooleanfalse

ColorPickerContent#

Holds the color picker popover. Displayed in a portal.

PropTypeDefault
classNamestring-
AttributeDefault
--space--spacing(3)

ColorPickerControl#

Container for grouping control elements such as area, sliders, and inputs.

PropTypeDefault
classNamestring-

ColorPickerView#

Container for sliders and inputs. Can specify format for child value display.

PropTypeDefault
format`"hex""hexa"
classNamestring-

ColorPickerArea#

Two-dimensional color selection area.

PropTypeDefault
showDotsbooleanfalse
xChannel`"hue""saturation"
yChannel`"hue""saturation"
classNamestring-

ColorPickerAreaThumb#

Draggable thumb within the color area.

PropTypeDefault
classNamestring-

ColorPickerSlider#

Slider for adjusting a color channel.

PropTypeDefault
channel`"hex""hexa"
orientation`"horizontal""vertical"`
classNamestring-

ColorPickerTransparencyGrid#

Checkerboard pattern for transparency. Shown as child of ColorPickerSlider when editing alpha.

PropTypeDefault
classNamestring-

ColorPickerEyeDropperTrigger#

Button that activates the native Eye Dropper API to sample colors from the screen.

PropTypeDefault
variantButtonProps["variant"]"outline"
sizeButtonProps["size"]"icon-md"
childrenReactNodePipette
classNamestring-

ColorPickerInput#

Input for displaying and editing a color channel value. Use asChild with a custom input.

PropTypeDefault
channel`"hex""hexa"
asChildbooleanfalse

ColorPickerSwatchPreview#

Compact swatch that displays the current color. Use inside an input group for input mode.

PropTypeDefault
classNamestring-

ColorPickerSwatchGroup#

Container for swatch triggers in swatch picker mode.

PropTypeDefault
classNamestring-

ColorPickerSwatchTrigger#

Button that selects a color when clicked. Wraps ColorPickerSwatch and optionally ColorPickerSwatchIndicator.

PropTypeDefault
valuestring-
classNamestring-

ColorPickerSwatch#

Color swatch display. Use as a child of ColorPickerSwatchTrigger.

PropTypeDefault
valuestring-
classNamestring-

ColorPickerSwatchIndicator#

Check mark or custom icon shown when a swatch is selected. Pass children to customize.

PropTypeDefault
childrenReactNodeCheckIcon
classNamestring-

ColorPickerValue#

Displays the current color as formatted text.

PropTypeDefault
format`"hex""hexa"
classNamestring-

ColorPickerValueSwatch#

Displays the current color as a swatch. Use for standalone value preview.

PropTypeDefault
classNamestring-

parseColor#

Exported utility to parse color strings. Use for programmatic color handling.


For the complete list of props and additional subcomponents, see the Ark UI Color Picker documentation.

[

Previous page

Collapsible ](/docs/components/collapsible)[

Next page

Combobox ](/docs/components/combobox)

On This Page

InstallationModesInputAnatomyUsageControlledStatesInvalidDisabledExamplesWith FieldChannel EditingWith SwatchWith PopoverCompactPopoverAnatomyUsageStatesDisabledExamplesWith Eye DropperWith Channel EditingWith Only SlidersWith Swatch PickerColor Swatch PickerAnatomyUsageControlledStatesDisabledExamplesCustom SizeCustom RadiusCustom IndicatorAreaAnatomyUsageExamplesColor ChannelsWith DotsSliderAnatomyUsageControlledStatesDisabledExamplesAlpha ChannelHSL ChannelsHSBA ChannelsRGB ChannelsVerticalCustom spacingAPI ReferenceColorPickerColorPickerTriggerColorPickerContentColorPickerControlColorPickerViewColorPickerAreaColorPickerAreaThumbColorPickerSliderColorPickerTransparencyGridColorPickerEyeDropperTriggerColorPickerInputColorPickerSwatchPreviewColorPickerSwatchGroupColorPickerSwatchTriggerColorPickerSwatchColorPickerSwatchIndicatorColorPickerValueColorPickerValueSwatchparseColor