mirror of
https://github.com/antd-tiny-vue/antd-tiny-vue.git
synced 2025-07-07 04:09:07 +08:00
feat: add theme and style
This commit is contained in:
8
components/theme/themes/dark/colorAlgorithm.ts
Normal file
8
components/theme/themes/dark/colorAlgorithm.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { TinyColor } from '@ctrl/tinycolor'
|
||||
|
||||
export const getAlphaColor = (baseColor: string, alpha: number) => new TinyColor(baseColor).setAlpha(alpha).toRgbString()
|
||||
|
||||
export const getSolidColor = (baseColor: string, brightness: number) => {
|
||||
const instance = new TinyColor(baseColor)
|
||||
return instance.lighten(brightness).toHexString()
|
||||
}
|
50
components/theme/themes/dark/colors.ts
Normal file
50
components/theme/themes/dark/colors.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { generate } from '@ant-design/colors'
|
||||
import type { GenerateColorMap, GenerateNeutralColorMap } from '../ColorMap'
|
||||
import { getAlphaColor, getSolidColor } from './colorAlgorithm'
|
||||
|
||||
export const generateColorPalettes: GenerateColorMap = (baseColor: string) => {
|
||||
const colors = generate(baseColor, { theme: 'dark' })
|
||||
return {
|
||||
1: colors[0],
|
||||
2: colors[1],
|
||||
3: colors[2],
|
||||
4: colors[3],
|
||||
5: colors[6],
|
||||
6: colors[5],
|
||||
7: colors[4],
|
||||
8: colors[6],
|
||||
9: colors[5],
|
||||
10: colors[4]
|
||||
// 8: colors[9],
|
||||
// 9: colors[8],
|
||||
// 10: colors[7],
|
||||
}
|
||||
}
|
||||
|
||||
export const generateNeutralColorPalettes: GenerateNeutralColorMap = (bgBaseColor: string, textBaseColor: string) => {
|
||||
const colorBgBase = bgBaseColor || '#000'
|
||||
const colorTextBase = textBaseColor || '#fff'
|
||||
|
||||
return {
|
||||
colorBgBase,
|
||||
colorTextBase,
|
||||
|
||||
colorText: getAlphaColor(colorTextBase, 0.85),
|
||||
colorTextSecondary: getAlphaColor(colorTextBase, 0.65),
|
||||
colorTextTertiary: getAlphaColor(colorTextBase, 0.45),
|
||||
colorTextQuaternary: getAlphaColor(colorTextBase, 0.25),
|
||||
|
||||
colorFill: getAlphaColor(colorTextBase, 0.18),
|
||||
colorFillSecondary: getAlphaColor(colorTextBase, 0.12),
|
||||
colorFillTertiary: getAlphaColor(colorTextBase, 0.08),
|
||||
colorFillQuaternary: getAlphaColor(colorTextBase, 0.04),
|
||||
|
||||
colorBgElevated: getSolidColor(colorBgBase, 12),
|
||||
colorBgContainer: getSolidColor(colorBgBase, 8),
|
||||
colorBgLayout: getSolidColor(colorBgBase, 0),
|
||||
colorBgSpotlight: getSolidColor(colorBgBase, 26),
|
||||
|
||||
colorBorder: getSolidColor(colorBgBase, 26),
|
||||
colorBorderSecondary: getSolidColor(colorBgBase, 19)
|
||||
}
|
||||
}
|
43
components/theme/themes/dark/index.ts
Normal file
43
components/theme/themes/dark/index.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { generate } from '@ant-design/colors'
|
||||
import type { DerivativeFunc } from '@antd-tiny-vue/cssinjs'
|
||||
import type { ColorPalettes, MapToken, PresetColorType, SeedToken } from '../../interface'
|
||||
import { defaultPresetColors } from '../seed'
|
||||
import genColorMapToken from '../shared/genColorMapToken'
|
||||
import defaultAlgorithm from '../default'
|
||||
import { generateColorPalettes, generateNeutralColorPalettes } from './colors'
|
||||
|
||||
const derivative: DerivativeFunc<SeedToken, MapToken> = (token, mapToken) => {
|
||||
const colorPalettes = Object.keys(defaultPresetColors)
|
||||
// @ts-expect-error this is a bug of typescript
|
||||
.map((colorKey: keyof PresetColorType) => {
|
||||
const colors = generate(token[colorKey], { theme: 'dark' })
|
||||
|
||||
return new Array(10).fill(1).reduce((prev, _, i) => {
|
||||
prev[`${colorKey}-${i + 1}`] = colors[i]
|
||||
return prev
|
||||
}, {}) as ColorPalettes
|
||||
})
|
||||
.reduce((prev, cur) => {
|
||||
prev = {
|
||||
...prev,
|
||||
...cur
|
||||
}
|
||||
return prev
|
||||
}, {} as ColorPalettes)
|
||||
|
||||
const mergedMapToken = mapToken ?? defaultAlgorithm(token)
|
||||
|
||||
return {
|
||||
...mergedMapToken,
|
||||
|
||||
// Dark tokens
|
||||
...colorPalettes,
|
||||
// Colors
|
||||
...genColorMapToken(token, {
|
||||
generateColorPalettes,
|
||||
generateNeutralColorPalettes
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default derivative
|
Reference in New Issue
Block a user