PeakUI

ColorInputGroup

Hex input with a swatch prefix or suffix

Usage

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

Anatomy

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

export default () => (
  <ColorField aria-label="Colour" defaultValue="#0485F7">
    <ColorInputGroup>
      <ColorInputGroup.Prefix>
        <ColorSwatch size="xs" />
      </ColorInputGroup.Prefix>
      <ColorInputGroup.Input />
      <ColorInputGroup.Suffix>hex</ColorInputGroup.Suffix>
    </ColorInputGroup>
  </ColorField>
);

Examples

Secondary

With Suffix

Full Width

Customization

Tailwind CSS

<ColorInputGroup className="w-40">
  <ColorInputGroup.Input />
</ColorInputGroup>

Global CSS

@layer components {
  .color-input-group {
    --color-input-group-radius: var(--radius-lg);
  }
}

Styling Reference

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

CSS Classes

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

Base Classes

  • .color-input-group - Shell with fill, border and focus ring
  • .color-input-group__input - Borderless, transparent control
  • .color-input-group__prefix - Slot before the control
  • .color-input-group__suffix - Slot after the control

Variant Classes

  • .color-input-group--primary - Field fill with shadow (default)
  • .color-input-group--secondary - Neutral fill without shadow

Modifier Classes

  • .color-input-group--full-width - Fills the container width

Slots

  • [data-slot="color-input-group"]
  • [data-slot="color-input-group-input"]
  • [data-slot="color-input-group-prefix"]
  • [data-slot="color-input-group-suffix"]

CSS Variables

VariablePurpose
--color-input-group-bgFill
--color-input-group-bg-hoverFill on hover
--color-input-group-bg-focusFill on focus
--color-input-group-fgText colour
--color-input-group-placeholderPlaceholder and slot colour
--color-input-group-borderBorder colour
--color-input-group-border-hoverBorder colour on hover
--color-input-group-border-focusBorder colour on focus
--color-input-group-radiusCorner radius
--color-input-group-shadowField shadow

Interactive States

  • Hover: :hover or [data-hovered] on .color-input-group
  • Focus: the shell shows the ring while .color-input-group__input has :focus or [data-focused]
  • Invalid: [data-invalid] or [aria-invalid="true"] on .color-input-group
  • Disabled: [data-disabled] or [aria-disabled="true"] on .color-input-group

API Reference

ColorInputGroup

PropTypeDefaultDescription
variant"primary" | "secondary""primary"Visual style of the group
fullWidthbooleanfalseMakes the group fill its container
classNamestring | ((values: GroupRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria Group prop

ColorInputGroup.Prefix

PropTypeDefaultDescription
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to "div"
classNamestring-Additional classes
...restEvery attribute of the rendered element

ColorInputGroup.Input

PropTypeDefaultDescription
classNamestring | ((values: InputRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria Input prop

ColorInputGroup.Suffix

PropTypeDefaultDescription
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to "div"
classNamestring-Additional classes
...restEvery attribute of the rendered element

Render Props

className on ColorInputGroup receives these values:

PropTypeDescription
isHoveredbooleanWhether the group is hovered
isFocusWithinbooleanWhether focus is inside the group
isDisabledbooleanWhether the group is disabled
isInvalidbooleanWhether the group is invalid

On this page