Color functions
@mantine/core package exports several functions that can be used to manipulate colors
or extract information before using them as CSS value.
darken and lighten
darken and lighten functions can be used to manipulate color brightness,
they accept color in any format as first argument and the amount of lightness to add/remove as second argument.
alpha
alpha function converts color to rgba format with a given alpha channel,
it is usually used to make colors more transparent. If it is not possible to convert color to rgba
format (for example if color is a CSS variable), the function will use color-mix.
Note that color-mix is not supported in some older browsers, you can check caniuse
for more information.
parseThemeColor
parseThemeColor function returns information about a given color in the following format:
parseThemeColor function can be used everywhere theme object is available,
for example in CSS variables resolver, variant color resolver
or component body:
getThemeColor
getThemeColor is a simpler version of parseThemeColor function, it accepts a color string
as first argument and theme object as second argument. It returns parsed color value or CSS variable:
getGradient
getGradient function transforms given MantineGradient object to CSS gradient string:
isLightColor
isLightColor function can be used to achieve better contrast between text and background:
luminance
luminance function returns color luminance, it can be used to check colors contrast: