ui.addColorPicker()
Renders a color swatch that opens a full-featured HSV/RGB color picker popup when clicked. The popup includes a saturation/value gradient, hue bar, RGB inputs, hex input, an eyedropper tool, and format toggle.
ui.addColorPicker(options);INFO
Also accepts all General Element Options.
Table of Contents
Quick Example
ui.addColorPicker({
id: "my-picker",
x: 16, y: 16,
width: 40, height: 40,
color: "#FF5500",
borderRadius: 8,
onChange: (color) => {
console.log("Color changed:", color);
}
});Clicking the swatch opens a popup where the user can pick a color. The selected color is reflected back on the swatch automatically.
Options
Color
"#000000"Initial color of the swatch. Supports hex (#RRGGBB), rgb(r,g,b), and rgba(r,g,b,a) formats.
color: "#FF5500"
color: "rgb(255, 85, 0)"
color: "rgba(255, 85, 0, 0.8)"Swatch Styling
0Corner rounding radius in pixels. Set to 0 for sharp corners.
borderRadius: 80Border width in pixels. Set to 0 for no border.
borderWidth: 2"#000000"Border color. Supports hex, rgb(), and rgba() formats.
borderColor: "#333333"
borderColor: "rgba(0, 0, 0, 0.3)"1.0Swatch opacity from 0.0 (fully transparent) to 1.0 (fully opaque).
opacity: 0.8"rectangle"Swatch shape. Either "rectangle" or "circle".
shape: "circle"Popup Appearance
"#FFFFFF"Background color of the picker popup.
popupBackground: "#1E1E1E"
popupBackground: "rgba(30, 30, 30, 0.95)""#000000"Accent color used for the hue indicator, selection border, and interactive highlights in the popup.
popupAccentColor: "#0078D4""#000000"Border color of the popup window.
popupBorderColor: "#444444"Background color of the RGB/hex input fields in the popup. Also accepts alias popupInputBgColor.
popupInputBackground: "#2A2A2A"Text color of the RGB/hex input fields in the popup. Also accepts alias popupInputTextColor.
popupInputColor: "#FFFFFF"Popup Behavior
trueWhether to show the eyedropper button in the popup. The eyedropper lets the user pick a color from anywhere on screen.
showEyedropper: falsetrueWhether to show the format toggle button (RGB / HEX) in the popup.
showFormatToggle: false"rgb"Default input mode when the popup opens. Either "rgb" or "hex".
defaultMode: "hex"Callbacks
Fired whenever the user selects a new color (while dragging or typing). Receives the color as a hex string ("#RRGGBB").
onChange: (color) => {
console.log("New color:", color);
}Fired when the picker popup opens.
onOpen: () => {
console.log("Picker opened");
}Fired when the picker popup closes (user clicks outside or presses Escape).
onClose: () => {
console.log("Picker closed");
}Fired when the user cancels the color selection (the color reverts to what it was before the popup opened).
onCancel: () => {
console.log("Selection cancelled");
}Fired when the eyedropper tool is activated.
onEyedropperOpen: () => {
console.log("Eyedropper started");
}Fired when the eyedropper picks a color from the screen. Receives the picked color as a hex string.
onEyedropperPick: (color) => {
console.log("Picked from screen:", color);
}Reading and Updating at Runtime
Get current color
const currentColor = ui.getElementProperty("my-picker", "color");
console.log(currentColor); // "#FF5500"Set color programmatically
ui.setElementProperties("my-picker", {
color: "#00FF00"
});Open / close the popup
// Open the picker popup
ui.setElementProperties("my-picker", { isOpen: true });
// Close the picker popup
ui.setElementProperties("my-picker", { isOpen: false });
// Check if open
const open = ui.getElementProperty("my-picker", "isOpen");Update styling at runtime
ui.setElementProperties("my-picker", {
borderRadius: 12,
shape: "circle",
opacity: 0.9
});Practical Examples
Basic color picker with live preview
ui.addColorPicker({
id: "color-picker",
x: 16, y: 16,
width: 40, height: 40,
color: "#FF5500",
borderRadius: 8,
onChange: (color) => {
// Update a background preview with the selected color
ui.setElementProperties("preview", { backgroundColor: color });
}
});
// A shape that shows the selected color
ui.addShape({
id: "preview",
x: 70, y: 16,
width: 200, height: 40,
backgroundColor: "#FF5500",
borderRadius: 6
});Dark-themed picker
ui.addColorPicker({
id: "dark-picker",
x: 16, y: 16,
width: 36, height: 36,
color: "#0078D4",
shape: "circle",
borderWidth: 2,
borderColor: "#555555",
popupBackground: "#1E1E1E",
popupAccentColor: "#0078D4",
popupBorderColor: "#444444",
popupInputBackground: "#2A2A2A",
popupInputColor: "#FFFFFF",
defaultMode: "hex",
onChange: (color) => console.log("Selected:", color)
});Eyedropper color sampling
ui.addColorPicker({
id: "eyedropper-demo",
x: 16, y: 16,
width: 48, height: 48,
color: "#FFFFFF",
shape: "circle",
borderRadius: 24,
showEyedropper: true,
onEyedropperPick: (color) => {
console.log("Picked from screen:", color);
// Use the picked color for something
ui.setElementProperties("target", { backgroundColor: color });
}
});Multiple pickers for a palette
const palette = ["#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#FF00FF"];
palette.forEach((color, i) => {
ui.addColorPicker({
id: `palette-${i}`,
x: 16 + i * 48, y: 16,
width: 40, height: 40,
color: color,
borderRadius: 6,
onChange: (newColor) => {
console.log(`Palette ${i} changed:`, newColor);
}
});
});