Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Controls

ColorSwatches

A palette of colours to choose from: brand colours, presets or recent colours.

Aradio group of colours

When to useLink to "When to use"

  • A short list of colours people pick from, alone or next to a full picker.

Use something else when:

  • any colour is allowed: ColorField, which shows swatches in its picker with its swatches prop

UsageLink to "Usage"

tsx
Copy
import { ColorSwatches } from "@arshad-shah/cynosure";

<ColorSwatches label="Brand colours" swatches={brand} value={colour} onChange={setColour} />

Swatches are any CSS colours, as strings or { value, label }. Give brand colours a label so screen readers say "Ember" rather than "rgb(194 65 12)". Keep recent colours in your own state or storage and pass them in.

The chosen colour is matched by colour, not spelling, so #1D1B18 selects an rgb(29 27 24) swatch.

Matches by colour not spelling

PropsLink to "Props"

Every prop of ColorSwatches
PropWhat it doesTypeDefault
labelRequired
Accessible name of the group, e.g. "Recent colours".string
swatchesRequired
The colours to offer: a CSS colour, or { value, label } to give it a spoken name.(string | ColorSwatch)[]
onChangeRequired
Called when a swatch is chosen (pressed, or reached with the arrow keys), with that swatch's value.(value: string) => void
value
The chosen colour, matched by colour (so "#FFF" and "white" are the same swatch).string
disabled
No swatch can be chosen.boolean
size
Size of each swatch. Default "md".Size"md"
className
Added to the root element, for layout.string
style
Layout only. Restyle through --cy-color-swatches-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

  • Role: a radio group named by label; each swatch is a radio named by its label or value.
  • Keyboard: one tab stop; arrow keys move and choose (once a colour is chosen), Home and End jump.
  • Visibility: each swatch has a hairline so pale colours stand out from the page; transparent colours sit over a checkerboard; the chosen one has a ring and a tick that contrasts with it.
  • Touch: 44px hit areas on touch screens (24px with a mouse).
Tick shows on light and dark

ThemingLink to "Theming"

Tokens: --cy-color-swatches-size and --cy-color-swatches-radius.

ColorField · SegmentedControl

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog