Element Plus Colors
English | 中文
This project for build color utils for theme customization
The mixing algorithm referenced from dart-sass's mixColor algorithm
Formula for calculating the primary color:
mix('#FFF', primary, i * 10)
Formula for calculating the secondary color:
mix('#FFF', color, '0')
mix('#FFF', color, '80%')
mix('#FFF', color, '90%')
Install
yarn
yarn add @element-plus/colors
npm
npm install @element-plus/colors
Usage
Basic
import { generateColors } from '@element-plus/colors'
const { primary, success, warning, danger, error, info } = generateColors('#409eff')
console.log(primary)
console.log(success)
console.log(warning)
console.log(danger)
console.log(error)
console.log(info)
Preset colors
We provide preset colors, you can import them by presetPalettes
or paletteName
, all paletteName
are listed below
import { presetPalettes } from '@element-plus/colors'
import { chalk } from '@element-plus/colors'
console.log(presetPalettes)
console.log(chalk)
chalk
chalk is the default theme of element-plus
{
"primary": "#409EFF",
"success": "#67C23A",
"warning": "#E6A23C",
"danger": "#F56C6C",
"error": "#F56C6C",
"info": "#909399"
}
API
generateColors(options: string | object)
options
options can be a string or an object, if options is a string then it means it is a primary color.
if options is an object, the following configuration:
interface ColorOptions {
primary?: string
success?: string
warning?: string
danger?: string
error: string[]
info?: string
}
If you not provide any valid options, then the function will return the default colors
return
interface OutputColors {
primary: string[]
success: string[]
warning: string[]
danger: string[]
error: string[]
info: string[]
}
Development
yarn dev
for coverage
yarn dev:coverage