Skip to main content
Migrate to Polaris

Version 2025-07 is the last API version to support React-based UI components. Later versions use web components, native UI elements with built-in accessibility, better performance, and consistent styling with Shopify's design system. Check out the migration guide to upgrade your extension.

ColorPicker

The ColorPicker component provides a visual interface for merchants to select a color. It displays a color spectrum and outputs the selected color as a hex string. It optionally supports alpha (transparency) selection.

To let merchants type a hex value directly, add a TextField alongside the picker.

Support
Targets (46)

Supported targets


Props for the ColorPicker component, which provides a visual interface for the merchant to select a color, with optional alpha (transparency) support.

Anchor to allowAlpha
allowAlpha
boolean
Default: false

Whether to show an alpha (transparency) slider, allowing the merchant to select a color with transparency. When true, then onChange emits an 8-character hex string (#RRGGBBAA). When false, then onChange emits a 6-character hex string (#RRGGBB).

string

A unique identifier for the color picker. Use this when you need to reference the component programmatically or for form association.

Anchor to onChange
onChange
(value: string) => void

A callback fired when the merchant selects a new color. The value is always emitted as a hex string. If allowAlpha is true, then the value is an 8-character hex (#RRGGBBAA). If allowAlpha is false, then the value is a 6-character hex (#RRGGBB).

Anchor to value
value
string

The currently selected color value. Accepts hex, rgb, and rgba strings. Defaults to rgb(0, 0, 0) if the value is invalid.


Anchor to Select product accent colorSelect product accent color

Pick a product accent color from a visual selector and save it. This example uses ColorPicker to capture the selected hex value, with a Button that saves the color.

Select product accent color

Pick a product accent color from a visual selector and save it. This example uses `ColorPicker` to capture the selected hex value, with a [Button](/docs/api/admin-extensions/2025-07/ui-components/actions/button) that saves the color.

Select product accent color

import {useState} from 'react';
import {reactExtension, useApi, ColorPicker, Button, BlockStack, Text} from '@shopify/ui-extensions-react/admin';

function App() {
const {data, close} = useApi('admin.product-details.action.render');
const productId = data.selected[0]?.id;
const [color, setColor] = useState('#000000');

return (
<BlockStack>
<Text fontWeight="bold">Product accent color</Text>
<ColorPicker value={color} onChange={setColor} />
<Button
variant="primary"
onPress={async () => {
await fetch('/api/products/accent-color', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({productId, color}),
});
close();
}}
>
Save color
</Button>
</BlockStack>
);
}

export default reactExtension(
'admin.product-details.action.render',
() => <App />,
);
import {extension, ColorPicker, Button, BlockStack, Text} from '@shopify/ui-extensions/admin';

export default extension(
'admin.product-details.action.render',
(root, api) => {
const {data, close} = api;
const productId = data.selected[0]?.id;
let color = '#000000';

const stack = root.createComponent(BlockStack);

const heading = root.createComponent(
Text,
{fontWeight: 'bold'},
'Product accent color',
);

const picker = root.createComponent(ColorPicker, {
value: color,
onChange: (value) => {
color = value;
},
});

const saveButton = root.createComponent(
Button,
{
variant: 'primary',
onPress: async () => {
await fetch('/api/products/accent-color', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({productId, color}),
});
close();
},
},
'Save color',
);

stack.appendChild(heading);
stack.appendChild(picker);
stack.appendChild(saveButton);
root.appendChild(stack);
},
);

Anchor to Enable alpha transparency selectionEnable alpha transparency selection

Enable the alpha (transparency) channel by setting allowAlpha to true. This example lets merchants pick an overlay color with adjustable opacity, returning a hex color string with alpha (for example, #RRGGBBAA) for use on product pages.

Enable alpha transparency selection

import {useState} from 'react';
import {reactExtension, ColorPicker, BlockStack, Text} from '@shopify/ui-extensions-react/admin';

function App() {
const [color, setColor] = useState('rgba(0, 0, 0, 0.5)');

return (
<BlockStack>
<Text fontWeight="bold">Overlay color with transparency</Text>
<ColorPicker value={color} allowAlpha onChange={setColor} />
<Text>Selected: {color}</Text>
</BlockStack>
);
}

export default reactExtension(
'admin.product-details.block.render',
() => <App />,
);
import {extension, ColorPicker, BlockStack, Text} from '@shopify/ui-extensions/admin';

export default extension(
'admin.product-details.block.render',
(root) => {

const stack = root.createComponent(BlockStack);

const heading = root.createComponent(
Text,
{fontWeight: 'bold'},
'Overlay color with transparency',
);

const picker = root.createComponent(ColorPicker, {
value: 'rgba(0, 0, 0, 0.5)',
allowAlpha: true,
onChange: (value) => {
preview.replaceChildren(`Selected: ${value}`);
},
});

const preview = root.createComponent(Text, {}, 'Selected: rgba(0, 0, 0, 0.5)');

stack.appendChild(heading);
stack.appendChild(picker);
stack.appendChild(preview);
root.appendChild(stack);
},
);

Anchor to Configure brand color paletteConfigure brand color palette

Present multiple color pickers for a complete brand color configuration. This example renders primary and secondary brand color pickers separated by a Divider, letting merchants define a full product page color scheme.

Configure brand color palette

import {useState} from 'react';
import {reactExtension, ColorPicker, Text, Divider, BlockStack} from '@shopify/ui-extensions-react/admin';

function App() {
const [primary, setPrimary] = useState('#2C6ECB');
const [secondary, setSecondary] = useState('#F4F6F8');

return (
<BlockStack>
<Text fontWeight="bold">Brand colors for product page</Text>
<Text>Primary brand color</Text>
<ColorPicker value={primary} onChange={setPrimary} />
<Divider />
<Text>Secondary brand color</Text>
<ColorPicker value={secondary} onChange={setSecondary} />
</BlockStack>
);
}

export default reactExtension(
'admin.product-details.action.render',
() => <App />,
);
import {extension, ColorPicker, Text, Divider, BlockStack} from '@shopify/ui-extensions/admin';

export default extension(
'admin.product-details.action.render',
(root) => {

const stack = root.createComponent(BlockStack);

const heading = root.createComponent(
Text,
{fontWeight: 'bold'},
'Brand colors for product page',
);

const primaryLabel = root.createComponent(Text, {}, 'Primary brand color');
const primaryPicker = root.createComponent(ColorPicker, {
value: '#2C6ECB',
onChange: (color) => console.log('Selected:', color),
});

const divider = root.createComponent(Divider);

const secondaryLabel = root.createComponent(Text, {}, 'Secondary brand color');
const secondaryPicker = root.createComponent(ColorPicker, {
value: '#F4F6F8',
onChange: (color) => console.log('Selected:', color),
});

stack.appendChild(heading);
stack.appendChild(primaryLabel);
stack.appendChild(primaryPicker);
stack.appendChild(divider);
stack.appendChild(secondaryLabel);
stack.appendChild(secondaryPicker);
root.appendChild(stack);
},
);

  • Show the current color: Display the selected color value near the picker (using a colored Badge, a swatch, or the hex string) so merchants can confirm their choice without relying solely on the picker's visual state.
  • Use within a labeled context: ColorPicker doesn't have a built-in label. Pair it with a Heading or Text component to describe what the color selection controls, such as "Background color" or "Accent color".

  • ColorPicker doesn't include a text input for manually entering hex values. Merchants can only select colors visually.
  • The value prop accepts RGB, RGBA, and hex color strings (3, 4, 6, or 8-character hex). Named CSS colors (like "red" or "blue") aren't supported.
  • The onChange callback returns a hex string (#RRGGBB or #RRGGBBAA when alpha is enabled). Other color formats like HSL or RGB tuples aren't returned.
  • ColorPicker doesn't support preset color swatches or a palette of predefined colors. To offer common color options, build a custom palette using buttons alongside the picker.

Was this page helpful?