Colors config #
You can personalize colors that are used in your app. The colors used by Vuestic components may be redefined dynamically. You can also add your own colors that you intend to use frequently in your app.
For example, you can change the primary
color that is used by almost all Vuestic components.
Pick a different primary color below and notice how the colors are changing all over the page.
Reactivity #
Methods like getColors
return a computed reactives that can also be accessed by variable colors
. The advantage is allow to change properties, instead of rewriting whole colors variable. For example, you can change primary
color by writing colors.primary = "#ff0"
. Multiple properties changes are also supported, you can write setColors({'{ primary: "#00f", secondary: "#0ff" }'})
.
Adding new colors #
You can add new colors and use your custom colors in Components config.
import { createVuestic } from "vuestic-ui";
createApp(App)
.use(
createVuestic({
config: {
colors: {
variables: {
primary: "#ff00ff",
button: "#000",
},
},
components: {
VaButton: {
color: "button",
},
},
},
})
)
.mount("#app");
The same works for Icons config.
import { createVuestic, createIconsConfig } from 'vuestic-ui'
createApp(App)
.use(createVuestic({
config: {
colors: {
variables: {
success: '#0fb',
'player-icon': '#aaa',
}
},
icons: createIconsConfig({
aliases: [
{
name: 'prev',
to: 'fa4-prev',
color: 'player-icon',
},
{
name: 'play',
to: 'fa4-play',
color: 'success',
}
],
fonts: [...],
})
}
}))
.mount('#app')
Getting typings for custom colors #
Color config is fully typed and provides type safety and autocompletion for all instances where color is specified. Color typings could be extended with your custom colors to rip the same benefits via Typescript Module augmentation.
declare module 'vuestic-ui' {
interface CustomColorVariables {
newColor: string
}
}
Colors config service API #
Types #
name | type | description |
---|---|---|
CssColor |
| A valid CSS color. |
EssentialVariables |
| An object where the keys are the color names and values are valid CSS colors. |
ColorVariables |
| An object where the keys are the color names and values are valid CSS colors. |
ColorConfig |
| Configuration object where is defined color variables, threshold, presets and current preset name. |
useColors hook methods. #
method | type | description |
---|---|---|
applyPreset |
| Applies preset by its name to the colors config. |
setColors |
| Used to merge new colors into config or update existing colors. |
getColors |
| Returns current color config. |
getColor |
| Return color by name. |
getComputedColor |
| Returns compute color from colors variables. |
getBoxShadowColor |
| Return a color that is appropriate to be used for the |
getBoxShadowColorFromBg |
| Return a color that is appropriate to be used for the |
getHoverColor |
| Return a color that you can use as a |
getFocusColor |
| Return a color that you can use as a |
getGradientBackground |
| Return a gradient-color that you can use as a |
getTextColor |
| Returns a color depending on the background lightness. |
shiftHSLAColor |
| Returns shifted HSLA color. |
setHSLAColor |
| Sets HSLA color. |
colorsToCSSVariable |
| Converts object of colors to the object of named css variables. |
colorToRgba |
| Converts named color to the |
getStateMaskGradientBackground |
| Returns a CSS linear-background value for the |
useColors hook variables. #
variable | type | description |
---|---|---|
colors |
| A computed reactive where the keys are color names and values are valid CSS colors. |
currentPresetName |
| A computed reactive where the keys are color names and values are valid CSS colors. |
presets |
| A computed reactive where the keys are color names and values are valid CSS colors. |