Colors

Color Picker

A complete color picking surface in a popover.

Rust
1use herogpui::components::color_picker::ColorPicker;

Usage

The panel flips near window edges and scrolls to keep the alpha control reachable in short windows.

Rust
1use herogpui::prelude::{ColorPicker, PickerColor};
2
3ColorPicker::new("color-picker-main", value)
4    // v3's Usage is uncontrolled; "Controlled" is separate.
5    .default_value(value)
6    .label("Accent")
7    .show_alpha(true)
8    .on_change(color_cb(cx.listener(|this, c: &PickerColor, _, cx| {
9        this.picker_color = *c;
10        cx.notify();
11    })))

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

ColorPicker

Color Picker is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Color Picker uses.

Styling

Color Picker styling
StyleDescription
relative + flex_col + gap(8)The Rust root also establishes a relative column and optional eight-pixel label gap around its monolithic composition.
flex row + gap(12) + hairline_radius + 14pxTrigger alignment, 12px gap, 4px radius, and 14px/20px type match regardless of parent line height.
cursor_pointerEnabled triggers use the interactive pointer cursor.
ring_if_focusedKeyboard focus uses theme status ring.
disabled_opacity + no listenersDisabled opacity and pointer suppression match.
min_w(248) + px/pt(8) + pb/gap(12)The 248px minimum, 8px horizontal/top inset, 12px bottom inset and gap, and overlay fill match.
scrollable_popover + max_h_full + overflow_y_scrollThe panel hides horizontal overflow and scrolls vertically within the available viewport height without shrinking its controls; Tab reveals each slider and boundary scrolling never moves the page, and scrollbars are not drawn.
layout.capped(radius_lg * 2.5) + overlay_shadowTheme-derived 2.5x radius and overlay shadow match, including the optional dark inset hairline.
anim::entering_zoom(Motion::LIST_IN)Duration, curve, fade, and scale match; the placement-specific four-pixel translation is not animated.
anim::exiting(Motion::LIST_OUT)Exit lifetime, curve, opacity, and scale match and reduced motion snaps them.

API reference

Builders

Color Picker builders
BuilderTypeDefaultDescription
new(id, value)id, valueControlled color value; owner acceptance drives the next frame.
default_value(PickerColor)PickerColorSeeds the picker-owned color once.
on_change(callback)Fn(color: Color) -> ()Reports changes from the area and each rendered slider.
label / show_alphaAnyElementThe Rust root renders a fixed trigger, area, hue slider, optional alpha slider, and readout rather than arbitrary compound children.
built-in triggerAnyElement | render closureThe trigger is the fixed swatch and hexadecimal value and does not delegate Button render state.
is_disabled(bool)boolfalseInherited Button state disables the trigger and suppresses the panel.
placement(Placement)PlacementPlacement::BottomLeftPositions and flips the floating panel to the side with more room when the preferred side cannot fit through the shared placement engine, keeping a 12px cross-axis viewport inset with the scroller capped to the available height.
built-in popover contentAnyElementThe built-in area, sliders, and hexadecimal readout cannot be replaced independently.

Parts

Color Picker parts
PartDescription
ColorPickerColor-value and internal DialogTrigger state owner.
ColorPickerFocusable swatch and hexadecimal-value trigger with fixed content.
ColorPickerDismissible floating color controls with fixed built-in children.

States

Color Picker states
BuilderStateDescription
internal keyed state / is_openOpenThe default trigger owns open state; Rust's composition-only is_open builder reports without mutating until its owner accepts the change.
tab_stop_handleFocusedThe trigger participates in tab order and regains focus after dismissal.
ring_if_focusedFocus visibleKeyboard focus draws the status ring.
trigger_pressed dismissal guardPressedPress tracking protects outside dismissal but is not delegated to trigger content.
is_disabledDisabledThe trigger dims, leaves pointer interaction, and suppresses its panel.
Motion::LIST_INEnteringPanel fades and grows from 95% over 150ms with ease-smooth.
Motion::LIST_OUTExitingPanel is retained while fading and shrinking to 95% over 100ms.