palette - Shade Palette Generation
Generate design system shade palettes from any color. Supports Ant Design HSV curves, linear interpolation, and custom generator functions.
An invalid base color throws, including empty shade requests and custom generators. Parser fallback black is never promoted into a valid palette.
Built-in algorithms retain the base alpha and instance useDecimal option. Shade 500 is an independent copy of the base. Later global configuration does not override the source instance's options. Custom generators control their output opacity and precision.
Install
import xcolor from '@xpyjs/color'
import palettePlugin from '@xpyjs/color/plugins/palette'
xcolor.use(palettePlugin)Instance Methods
palette(options?)
Generate a design system shade palette from the current color. The base color maps to shade 500, with lighter shades below and darker shades above.
Dark shades can reach pure black. A black base remains black in subsequent dark shades instead of being artificially brightened.
linear uses fixed anchors: white at 50, the base at 500, and black at 950. Intermediate colors interpolate by shade value. Subsets, ordering and duplicates do not change a shade's color. This corrects the previous request-relative interpolation, so intermediate colors may differ from older versions.
| Parameter | Type | Default | Description |
|---|---|---|---|
options.type | PaletteType | 'antd' | Palette generation type |
options.shades | Shade[] | [50,...,950] | Shade levels |
Return value: XColor[]
xcolor('#1890ff').palette()
// → XColor[], 11 shades (50–950)
xcolor('#1890ff').palette({ type: 'linear' })
// → linear interpolation palette
xcolor('#ff0000').palette({ shades: [100, 500, 900] })
// → 3 shadesPalette Type (PaletteType)
| Value | Description |
|---|---|
'antd' | Ant Design HSV curve algorithm. Non-linear hue rotation + saturation/value adjustment for perceptually uniform palettes |
'linear' | Linear RGB interpolation. Even transition from white through base color to black |
(baseColor, shades) => XColor[] | Custom function. Receives the base color and shade levels, returns corresponding XColor[] |
// Custom function example
const result = xcolor('#1890ff').palette({
type: (baseColor, shades) => {
return shades.map((s) => {
const factor = (s - 500) / 500
return factor < 0
? xcolor(baseColor.toHex()).lighten(Math.abs(factor) * 50)
: xcolor(baseColor.toHex()).darken(factor * 50)
})
}
})Shade Levels (Shade)
By default, 11 shade levels are generated: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950.
The base color maps to 500. Shades below 500 are lighter; shades above 500 are darker.
