Color
Color design tokens, keeping a consistent color scheme around the application.
Colors
Colors in Kaleidoscope are designed to be functional — if you're styling a border, use tokens.color.border
rather than reaching for the raw underlying palette color. This means we can apply theming without any extra effort if all colors are using these functional tokens. They also help to maintain the consistent application of colors — because we have a token for borders all of our borders will use the same color.
To use colors, import tokens
from @qwilr/kaleidoscope/tokens
and pick your color from the object.
import { tokens } from "@qwilr/kaleidoscope/tokens";export const example = style({background: tokens.color.surface,});
tokens.color.primary
tokens.color.primaryBorder
tokens.color.critical
tokens.color.criticalBorder
tokens.color.text
tokens.color.textSecondary
tokens.color.textPrimary
tokens.color.textSuccess
tokens.color.textCaution
tokens.color.textCritical
tokens.color.textOnPrimary
tokens.color.textPlaceholder
tokens.color.textOnCritical
tokens.color.textDisabled
tokens.color.heading
tokens.color.headingSecondary
tokens.color.surface
tokens.color.surfacePrimary
tokens.color.surfaceSecondary
tokens.color.surfaceTertiary
tokens.color.surfaceSuccess
tokens.color.surfaceCaution
tokens.color.surfaceCritical
tokens.color.surfaceHover
tokens.color.surfaceActive
tokens.color.icon
tokens.color.iconHover
tokens.color.iconActive
tokens.color.iconPrimary
tokens.color.iconSuccess
tokens.color.iconCaution
tokens.color.iconCritical
tokens.color.iconDisabled
tokens.color.iconOnControlAccent
tokens.color.iconOnControlAccentDisabled
tokens.color.background
tokens.color.border
tokens.color.controlBorder
tokens.color.controlBorderHover
tokens.color.controlBorderFocus
tokens.color.controlBorderDisabled
tokens.color.controlAccent
tokens.color.controlAccentHover
tokens.color.controlAccentDisabled
Naming and usage
There are a few naming conventions within the set of functional color tokens:
Name | Usage |
---|---|
text | Text and typography |
textOn... | Text when placed on another color |
surface | Surfaces such as cards and panels as well as anything that layers directly on a surface |
background | The lowest level layer on top of which surfaces sit |
icon | Any interface icon |
control | Interactive elements like buttons and inputs |
border | An outer stroke or line |
primary | Elements to be given emphasis, this is typically also the primary brand color |
secondary | A level of hierarchy down from primary, or from a base color |
tertiary | A level of hierarchy down from secondary |
active | Indicates an active nav item or pressed state |
hover | The hover state color |
focus | The focus state color |
disabled | The disabled state color |
success | Indicates a positive state or message |
caution | Indicates a warning state or message |
critical | Indicates an error or destructive action |
accent | A highlight color for controls |
Theming
Kaleidoscope's functional colors come with light/dark theming out of the box. By default, everything in the application is light themed. To apply a dark theme, use the darkTheme
className from tokens
.
import { darkTheme } from "@qwilr/kaleidoscope/tokens";// Both the card and its children will now be dark themedconst Example = () => (<Card className={darkTheme}><Stack padding="m"><Text size="l">Some text</Text><Button>Do the thing</Button></Stack></Card>);
Palette
This is the fundamental base of all colors in Kaleidoscope. Before reaching for a palette color always check if there is a functional color to pick first, as choosing from the palette means any theming must be handled manually because the colors are fixed and do not adapt to the theme.
To use a palette color, import palette
from @qwilr/kaleidoscope/tokens
and pick your color from the object.
import { palette } from "@qwilr/kaleidoscope/tokens";export const example = style({background: palette.purple400,});
You can also access the raw RGB values for palette colors, which is useful if you need to change the opacity of a color. RGB colors are specified in the CSS Color Module Level 4 syntax, so the opacity is separated with a slash instead of a comma.
import { rgb } from "@qwilr/kaleidoscope/tokens";export const example = style({background: `rgb(${rgb.purple400} / 0.5)`,});
Purple
Blue
Green
Yellow
Orange
Red
Grey
Eggplant
Slate
Midnight
Black
White
Figma
To get the right color from Figma, hop into dev mode and select a layer.
Any color tokens in your selection will show up under colors, and styles for the selected layer will appear in the CSS custom properties syntax. So in this example, the color token in Figma is names textPrimary
, and the style shows var(--textPrimary)
. In Vanilla Extract you can grab the same color from tokens
as tokens.color.textPrimary
.
Accessibility
The functional color tokens are designed to have AA contrast between surfaces and text/icons. If you use any colors directly from the palette you will need to manually check the contrast for text and icons.