PeakUI

ColorField

Text field for editing a hex color

Usage

import {ColorField, ColorInputGroup, Label} from "@peakui/react";

Examples

With Swatch

Invalid

Customization

Tailwind CSS

<ColorField className="w-48" defaultValue="#0485F7">
  <Label>Colour</Label>
  <ColorInputGroup>
    <ColorInputGroup.Input />
  </ColorInputGroup>
</ColorField>

Global CSS

@layer components {
  .color-field {
    @apply gap-2;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The ColorField component uses these CSS classes (view source styles):

Base Classes

  • .color-field - Column of label, group and messages

Modifier Classes

  • .color-field--full-width - Fills the container width

Slots

  • [data-slot="color-field"]

Interactive States

  • Invalid: [data-invalid="true"] or [aria-invalid="true"] hides the description

API Reference

ColorField

PropTypeDefaultDescription
fullWidthbooleanfalseMakes the field fill its container
valuestring | Color | null-The current color (controlled)
defaultValuestring | Color-The initial color (uncontrolled)
onChange(color: Color | null) => void-Called when a typed value is committed
channelColorChannel-Edit one channel instead of the whole hex color
isDisabledbooleanfalseDisables the field
isInvalidboolean-Marks the field invalid
isRequiredbooleanfalseRequires a value; sets data-required
classNamestring | ((values: ColorFieldRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria ColorField prop

Render Props

className and children functions receive these values:

PropTypeDescription
isDisabledbooleanWhether the field is disabled
isInvalidbooleanWhether the field is invalid

On this page