Skip to main content

Color-Picker

The TkColorPicker component provides a color selection interface with various input formats. It supports HEX and RGB color formats with an optional alpha channel.

import { TkColorPicker } from '@takeoff-ui/react'

Basic

The default TkColorPicker renders with a trigger input that displays the selected color. Clicking the trigger opens a panel where users can select colors using the saturation area, hue slider, and direct value inputs.

View Code
const [color, setColor] = useState('#326FD1');

<TkColorPicker
label="Select Color"
showAsterisk
value={color}
onTkChange={(e) => setColor(e.detail)}
/>

Inline Mode

Set inline to display the color picker panel directly without a trigger element. This is ideal for settings pages, theme builders, or anywhere the color picker should always be visible.

View Code
<TkColorPicker inline />

Header Types

The headerType prop allows you to customize the header appearance. Available options are basic, divided, light, dark, and primary. Each type provides a distinct visual style to match your application's design language.

View Code

The footer is slot-based and only renders when you provide content via footer or footer-actions slots. Use the footerType prop to style the footer container with basic, divided, or light variants. Use the apply() and cancel() methods to handle user actions programmatically.

Selected color: #C79807
View Code

Controlled Closing

Use preventDismiss and showCloseButton props to control how the panel can be closed. When preventDismiss is true, clicking outside the panel won't close it - users must use the provided action buttons. Set showCloseButton to false to hide the header close icon, forcing users to interact with footer actions.

View Code
const [color, setColor] = useState('#326FD1');
const pickerRef = useRef<HTMLTkColorPickerElement>(null);

const handleApply = () => {
pickerRef.current?.apply();
};

const handleCancel = () => {
pickerRef.current?.cancel();
};

<TkColorPicker
ref={pickerRef}
label="Select Color"
value={color}
preventDismiss
showCloseButton={false}
onTkChange={(e) => setColor(e.detail)}
>
<div slot="footer-actions">
<TkButton label='Cancel' variant="secondary" size="small" onTkClick={handleCancel}>
</TkButton>
<TkButton label='Apply' variant="primary" size="small" onTkClick={handleApply}>
</TkButton>
</div>
</TkColorPicker>

Orientation

The component supports two panel layouts via the orientation prop. The default vertical layout places the saturation area above the controls, while horizontal arranges them side by side for a more compact footprint.

Vertical
Horizontal
View Code
<TkColorPicker inline orientation="vertical" />
<TkColorPicker inline orientation="horizontal" />

Custom Presets

The presets prop accepts an array of color strings to display as quick-select swatches. Use this to provide brand colors, theme palettes, or frequently used colors for your users.

View Code
const [color, setColor] = useState('#E63946');

const customPresets = [
'#E63946', '#F1FAEE', '#A8DADC', '#457B9D', '#1D3557',
'#F4A261', '#2A9D8F', '#E9C46A', '#264653', '#E76F51'
];

<TkColorPicker
label="Brand Colors"
presets={customPresets}
value={color}
inline
onTkChange={(e) => setColor(e.detail)}
/>

Feature Visibility

Toggle individual features to customize the picker interface. Use showAlphaSlider for transparency support, showPresets for quick-access color swatches, and showFormatSelector to allow switching between HEX and RGBA formats.

View Code

States

View Code
<TkColorPicker label="Disabled" placeholder="Select Color" hint="Hint text" disabled />
<TkColorPicker label="Readonly" placeholder="Select Color" hint="Hint text" readonly />
<TkColorPicker label="Error" placeholder="Select Color" error="Error text" invalid />

API

Props

NameTypeDefaultDescription
booleanfalseDisables the color picker
stringnullThis is the error message that will be displayed.
"basic", "divided", "light"'basic'The type of the footer styling
"hex", "rgba"'hex'Color format for display and output
stringnullTitle displayed in the panel header
"basic", "dark", "divided", "light", "primary"'basic'The type of the header styling
stringnullProvided a hint or additional information about the input.
booleanfalseDisplays the picker inline without trigger
booleanfalseIndicates whether the input is in an invalid state
stringnullLabel text displayed above the trigger input
stringnullThe name of the control, which is submitted with the form data.
"horizontal", "vertical"'vertical'Panel layout orientation
stringnullPlaceholder text displayed when the input is empty.
string[]['#326FD1', '#C79807', '#A45E3C', '#119C8D', '#EDBBA3', '#ABC9FB', '#D0E1FD', '#FF6259', '#717784', '#85B2F9', '#EAD6FD']Array of preset color values
booleanfalsePrevents the panel from being dismissed by clicking outside. Use with footer actions (Apply/Cancel buttons) for controlled closing.
booleanfalseIf true, the user cannot modify the value.
booleantrueShows/hides the alpha slider
booleanfalseDisplays a red asterisk (*) next to the label for visual emphasis.
booleanfalseControls whether the close button is shown in the header. Set to false when using footer actions for controlled closing.
booleantrueShows/hides the format selector
booleanfalseControls whether the header is shown
booleantrueShows/hides the preset colors section
"base", "large", "small"'base'Sets size for the component.
string''The current color value (supports HEX and RGB formats)

Events

NameDescription
tk-applyEmitted when the apply button is clicked
tk-cancelEmitted when the cancel button is clicked
tk-changeEmitted when the color is applied/confirmed
tk-closeEmitted when the panel closes
tk-openEmitted when the panel opens

Methods

NameTypeDescription
applyapply() => Promise<void>Applies the current color selection and closes the panel Use this method in custom footer actions
cancelcancel() => Promise<void>Cancels the color selection, reverts to previous value, and closes the panel Use this method in custom footer actions
closeclose() => Promise<void>Closes the color picker panel
getValuegetValue(format?: "hex" | "rgba") => Promise<string>Gets the current color value in the specified format
openopen() => Promise<void>Opens the color picker panel

Slots

NameDescription
footerCustom footer template (replaces default footer container).
footer-actionsCustom actions template for footer layout with styled container.
headerCustom header template (replaces default header completely).
header-actionsCustom actions template for header (replaces close button).