Skip to content

颜色(Color)

使用指引(做什么、何时用)

  • 主题色体系:用 lighten/darken 生成按钮/卡片的亮暗层级
  • 文本可读性:用 contrastColor(bg) 自动选择黑/白文本色
  • 颜色转换:hexToRgb/rgbToHex 用于颜色处理与跨格式

转换

  • ColorUtils.hexToRgb(hex){ r,g,b }
  • ColorUtils.rgbToHex(r,g,b)#rrggbb

亮/暗

  • ColorUtils.lighten(hex, ratio)
  • ColorUtils.darken(hex, ratio)

对比色

  • ColorUtils.contrastColor(hex)#000000#ffffff
ts
import { ColorUtils } from 'nex-lib'
ColorUtils.hexToRgb('#ffcc00')
ColorUtils.rgbToHex(255, 204, 0)
ColorUtils.lighten('#333333', 0.5)
ColorUtils.darken('#cccccc', 0.5)
ColorUtils.contrastColor('#ffcc00')
text
{ "r": 255, "g": 204, "b": 0 }
#ffcc00
#999999
#666666
#000000

Released under the ISC License.