getColorClass()function

getColorClass({ color }: ColorVariants): string | undefined
ParamType
variantsColorVariants
Variant props for colouring an element, e.g. color="purple". required
    .colorColorVariant
Colour of the element.
Return
string | undefined
The combined tint + colour class string, or undefined when no color is set.

CSS class that applies color tinting to an element.

  • Sets the key .tint-50 color for an element (e.g. --color-purple or --color-primary) based on color="purple" or color="primary"
  • Full set of shades e.g. --tint-20 and --tint-95 are created for the selected color.
  • Element can now compose these shades to style itself using the selected color.

The color variant prop moves the tint ladder anchor to a named palette colour — <Card color="red">, <Tag color="primary">. It's an override for one-off recolouring of a component in a page; for an app-wide look, override the palette variables below in a theme file instead.

getColorClass({ color }) returns getClass(TINT_CLASS, "<colour>") — it moves --tint-50 to the chosen colour and recomposes the ladder, so the whole subtree retints. See TINT_CLASS for how the ladder works.

Theme variables

The following :root variables are defined by this module and can be overridden in a theme file to adjust default styling across the whole app. Override a palette colour to re-aim every variant and status that maps to it.

Palette

VariableDefaultNotes
--color-grayoklch(60% 0.01 240)Neutral anchor — also the default tint when nothing moves it.
--color-redoklch(62% 0.2 30)
--color-orangeoklch(74% 0.157 60)
--color-yellowoklch(86% 0.16 92)
--color-greenoklch(72% 0.185 130)
--color-aquaoklch(72% 0.121 185)
--color-blueoklch(57% 0.216 260)
--color-purpleoklch(58% 0.25 300)
--color-pinkoklch(68% 0.239 350)

Semantic

VariableDefaultUsed for
--color-linkvar(--color-blue)Link colour.
--color-focusvar(--color-blue)Focus outlines.
--color-successvar(--color-green)status="success".
--color-warningvar(--color-orange)status="warning".
--color-failurevar(--color-red)status="error" / status="danger".

Brand

VariableDefaultUsed for
--color-primaryvar(--color-blue)color="primary".
--color-secondaryvar(--color-purple)color="secondary".
--color-tertiaryvar(--color-pink)color="tertiary".

Examples

getColorClass({ color: "purple" }) // "tint color-purple"