<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

Color Swatches

A collection of color samples to present and select color options for products.

Use Color Swatches...

  • To provide a visual representation of available colors for selection.
  • To allow users to compare and make more informed color decisions.
  • To help users with color blindness to make accurate color choices by including textual labels.

Don't use Color Swatches...

  • When color choice is not critical to the task as it can add clutter.
  • As is when there is a large set of Color Swatches. Use Accordion with skin="color-swatches" instead.

Info:

Always use the ColorSwatches wrapper to encase one or more ColorSwatch items to ensure they are properly styled.

Info:

Use an accessibleText attribute (for color-blind users) on each swatch. Its value is a localized description of the color choice, such as accessibleText="Light Blue".

The preview has been updated.

Super

Use size="super" to display a bigger swatch.

The preview has been updated.

Fill

By default, color swatches have a transparent background.

  • In the React API, use the primaryColor property, and the secondaryColor property if needed, to define the colors.
  • In the Vanilla API, define each swatch's background-color CSS property, either with an inline style attribute, or via an external stylesheet. To create a two-tone swatch, use the CSS background-color attribute to define the shade on the bottom (bottom/right when using linear gradient) and the CSS color attribute to define the color on the top (top/left when using linear gradient).

Primary Color

Use primaryColor to display a one-tone swatch.

The preview has been updated.

Secondary Color

Use both primaryColor and secondaryColor to display a two-tone swatch.

The preview has been updated.

Gradient

Use either gradient="linear" or gradient="radial" to display a two-tone swatch as a gradient, rather than as two distinct color zones.

The preview has been updated.

Background Image

Use backgroundImage to display an image instead of a color.

The preview has been updated.

Label position

Use labelPosition on ColorSwatches to change for all swatches the default top position of the accessibleText that appears on hover.

Use labelPosition on one or several ColorSwatch items to change their position individually. This value overrides the general value passed on ColorSwatches.

The preview has been updated.

Color Swatches More

Use ColorSwatchesMore, filling it with a + sign and a number, to indicate how many swatches are available, if there is not enough space to show them all.

The preview has been updated.

With a Selection Set

Use a Selection Set to present a collection of color samples the customer can choose from.

  • In the React API, add as="span" to each swatch.
  • In the Vanilla API, use a span tags for a valid HTML, since the swatches are inside label tags.

Refer to the Selection Set’s Accessibility documentation.

Radio Buttons

Use with variant="single-select" to prompt users to choose from a set of mutually-exclusive choices (Radio Button behavior).

The preview has been updated.

Checkboxes

Use with variant="multi-select" to prompt users to select more than one option (Checkbox behavior).

The preview has been updated.

With an Accordion

Refer to Accordion with skin="color-swatches" to wrap a large set of Color Swatches, to avoid making the content excessively tall.

Disabled

For color swatches not acting as radio buttons or checkboxes, add the swan-color-swatch-disabled CSS class to the swatch itself.

The preview has been updated.

For color swatches acting as radio buttons or checkboxes, use disabled on the associated input tag to set the swatch with the corresponding disabled state.

The preview has been updated.

Content

Color value

Use one of the following format to input a color value for each swatch:

Background image

  • Use a square image for the backgroundImage property.

Label

  • Capitalize each word of a color name: Court Green, Oxford Blue, Tarmac Grey Heather.
  • In a two-tone swatch, separate the two color names with a slash: True Blue / White.
  • Localize each color name.

Props

ColorSwatch
This component is implemented using the <div /> as the root element. You can utilize the native attributes supported by <div /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
proptyperequireddescriptiondefault
disabledboolean | nullfalse
Whether or not the underlying input for the swatch should be enabled.
false
accessibleTextstring | nullfalse
A text representation of the color value. Used in the hover tooltip and as a hidden label for accessibility
null
primaryColorstring | nullfalse
The main color of the swatch. Accepts a css color value
transparent
secondaryColorstring | nullfalse
The optional secondary color of the swatch. Accepts a css color value
null
backgroundImagestring | nullfalse
URL for a background image for the swatch.
null
labelPosition"left" | "right" | "bottom" | "top" | nullfalse
Where to position the label tooltip relative to the swatch. Overrides the position setting of the ColorSwatches component.
null
gradient"linear" | "radial" | nullfalse
Configures a gradient between the primary and secondary colors. By default shows the two colors stacked but separate
null
ColorSwatchesMore
This component is implemented using the <span /> as the root element. You can utilize the native attributes supported by <span /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
ColorSwatches
This component is implemented using the <div /> as the root element. You can utilize the native attributes supported by <div /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
proptyperequireddescriptiondefault
size"standard" | "super" | nullfalse
The size of the color swatches
standard
labelPosition"left" | "right" | "bottom" | "top" | nullfalse
Where to position the label tooltips relative to its swatch
top

Related

Was this page useful?

Thanks for your feedback!

Feel free to include your name if you wish to have a follow up conversation.


Published: Jan 25, 2022Last updated: Sep 3, 2024