mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-18 12:34:25 +08:00
refactor: stronger theme props
This commit is contained in:
parent
06e78b19bd
commit
7bf705c5a5
@ -17,7 +17,11 @@ export interface Theme<T = {}, R = any> {
|
||||
self?: (vars: ThemeCommonVars) => T
|
||||
}
|
||||
|
||||
export type ExtractThemeVars<T> = T extends Theme<infer U, unknown> ? U : {}
|
||||
export type ExtractThemeVars<T> = T extends Theme<infer U, unknown>
|
||||
? unknown extends U
|
||||
? {}
|
||||
: U
|
||||
: {}
|
||||
|
||||
export type ExtractPeerOverrides<T> = T extends Theme<unknown, infer V>
|
||||
? {
|
||||
@ -27,6 +31,12 @@ export type ExtractPeerOverrides<T> = T extends Theme<unknown, infer V>
|
||||
}
|
||||
: T
|
||||
|
||||
export type ExtractMergedPeerOverrides<T> = T extends Theme<unknown, infer V>
|
||||
? {
|
||||
[k in keyof V]?: ExtractThemeVars<V[k]>
|
||||
}
|
||||
: T
|
||||
|
||||
export type ExtractThemeOverrides<T> = Partial<ExtractThemeVars<T>> &
|
||||
ExtractPeerOverrides<T> & { common?: ThemeCommonVars }
|
||||
|
||||
@ -45,7 +55,7 @@ export type MergedTheme<T> = T extends Theme<infer V, infer W>
|
||||
common: ThemeCommonVars
|
||||
self: V
|
||||
peers: W
|
||||
overrides: any
|
||||
overrides: ExtractMergedPeerOverrides<T>
|
||||
}
|
||||
: T
|
||||
|
||||
@ -114,7 +124,7 @@ function useTheme<T, R> (
|
||||
common: mergedCommon,
|
||||
self: mergedSelf,
|
||||
peers: merge({}, defaultTheme.peers, peers, injectedPeers),
|
||||
overrides: merge(peersOverrides, injectedPeersOverrides)
|
||||
overrides: merge({}, peersOverrides, injectedPeersOverrides)
|
||||
}
|
||||
})
|
||||
return mergedThemeRef
|
||||
|
@ -2,7 +2,7 @@ import { changeColor } from 'seemly'
|
||||
import { checkboxLight } from '../../checkbox/styles'
|
||||
import { commonLight } from '../../_styles/new-common'
|
||||
import type { ThemeCommonVars } from '../../_styles/new-common'
|
||||
import { Theme } from '../../_mixins/use-theme'
|
||||
import { createTheme } from '../../_mixins/use-theme'
|
||||
|
||||
const self = (vars: ThemeCommonVars) => {
|
||||
const {
|
||||
@ -30,14 +30,14 @@ const self = (vars: ThemeCommonVars) => {
|
||||
|
||||
export type TreeThemeVars = ReturnType<typeof self>
|
||||
|
||||
const treeLight: Theme<TreeThemeVars> = {
|
||||
const treeLight = createTheme({
|
||||
name: 'Tree',
|
||||
common: commonLight,
|
||||
peers: {
|
||||
Checkbox: checkboxLight
|
||||
},
|
||||
self
|
||||
}
|
||||
})
|
||||
|
||||
export default treeLight
|
||||
export type TreeTheme = typeof treeLight
|
||||
|
Loading…
Reference in New Issue
Block a user