PeakUI

ColorSlider

Slider for one color channel

Usage

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

Anatomy

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

export default () => (
  <ColorSlider channel="hue" colorSpace="hsb">
    <Label />
    <ColorSlider.Output />
    <ColorSlider.Track>
      <ColorSlider.Thumb />
    </ColorSlider.Track>
  </ColorSlider>
);

Examples

Alpha

RGB

Vertical

Without Label

Customization

Tailwind CSS

<ColorSlider className="w-64" channel="hue" colorSpace="hsb">
  <ColorSlider.Track className="h-4">
    <ColorSlider.Thumb />
  </ColorSlider.Track>
</ColorSlider>

Global CSS

@layer components {
  .color-slider__track {
    @apply h-6;
  }
}

Styling Reference

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

CSS Classes

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

Base Classes

  • .color-slider - Grid of label, output and track
  • .color-slider__track - Gradient track with edge caps
  • .color-slider__thumb - Draggable thumb with a white border
  • .color-slider__output - Formatted channel value

Slots

  • [data-slot="color-slider"]
  • [data-slot="color-slider-track"]
  • [data-slot="color-slider-thumb"]
  • [data-slot="color-slider-output"]

CSS Variables

VariablePurpose
--track-start-colorColour at the channel minimum, set by ColorSlider.Track
--track-end-colorColour at the channel maximum, set by ColorSlider.Track
--color-slider-checkerTransparency checkerboard under the gradient
--color-slider-ringThe inset ring on the track and its caps
--color-slider-thumb-borderThe thumb border colour

Interactive States

  • Focus: [data-focus-visible="true"] on .color-slider__thumb
  • Dragging: [data-dragging="true"] on .color-slider__thumb
  • Orientation: [data-orientation="horizontal"] or [data-orientation="vertical"] on .color-slider
  • Disabled: [data-disabled="true"] on .color-slider and .color-slider__thumb

API Reference

ColorSlider

PropTypeDefaultDescription
channel"hue" | "saturation" | "lightness" | "brightness" | "red" | "green" | "blue" | "alpha"-The channel the slider edits; an invalid pair with colorSpace is corrected in development
colorSpace"rgb" | "hsl" | "hsb"-The colour space of the channel
orientation"horizontal" | "vertical""horizontal"The slider axis
valuestring | Color-The current colour (controlled)
defaultValuestring | Color-The initial colour (uncontrolled)
onChange(value: Color) => void-Called as the thumb moves
onChangeEnd(value: Color) => void-Called when a drag or key press ends
isDisabledbooleanfalseDisables the slider
classNamestring | ((values: ColorSliderRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria ColorSlider prop, including aria-label

ColorSlider.Output

PropTypeDefaultDescription
childrenReactNode | ((values: SliderRenderProps) => ReactNode)The formatted channel valueReplaces the value, for example 210°
classNamestring | ((values: SliderRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria SliderOutput prop

ColorSlider.Track

PropTypeDefaultDescription
classNamestring | ((values: SliderTrackRenderProps) => string)-Additional classes, or a function of the render props
styleCSSProperties | ((values: SliderTrackRenderProps) => CSSProperties)-Inline styles, merged over the gradient
...restEvery React Aria SliderTrack prop

ColorSlider.Thumb

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

Render Props

children and className functions on ColorSlider receive these values:

PropTypeDescription
orientationOrientationThe slider axis
isDisabledbooleanWhether the slider is disabled
stateColorSliderStateThe state of the underlying slider

On this page