mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-12 12:25:16 +08:00
feat(element): expose css variables
This commit is contained in:
parent
8e395cfe8b
commit
7172519089
@ -1,16 +1,19 @@
|
||||
import { h } from 'vue'
|
||||
import {
|
||||
configurable,
|
||||
themeable
|
||||
themeable,
|
||||
withCssr
|
||||
} from '../../_mixins'
|
||||
import styleScheme from '../../_deprecated/style-scheme'
|
||||
import style from './styles'
|
||||
import { warn } from '../../_utils/naive/warn'
|
||||
|
||||
export default {
|
||||
name: 'Element',
|
||||
mixins: [
|
||||
configurable,
|
||||
themeable
|
||||
themeable,
|
||||
withCssr(style)
|
||||
],
|
||||
props: {
|
||||
tag: {
|
||||
@ -49,6 +52,7 @@ export default {
|
||||
} = this
|
||||
return h(as || tag, {
|
||||
class: {
|
||||
'n-element': true,
|
||||
[`n-${mergedTheme}-theme`]: mergedTheme
|
||||
}
|
||||
}, ($slots.default && $slots.default({
|
||||
|
11
src/element/src/styles/index.js
Normal file
11
src/element/src/styles/index.js
Normal file
@ -0,0 +1,11 @@
|
||||
import themedBaseStyle from './themed-base.cssr.js'
|
||||
|
||||
export default [
|
||||
{
|
||||
key: 'mergedTheme',
|
||||
watch: [
|
||||
'mergedTheme'
|
||||
],
|
||||
CNode: themedBaseStyle
|
||||
}
|
||||
]
|
14
src/element/src/styles/themed-base.cssr.js
Normal file
14
src/element/src/styles/themed-base.cssr.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { kebabCase } from 'lodash-es'
|
||||
import { c, cTB } from '../../../_utils/cssr'
|
||||
|
||||
export default c([
|
||||
({ props }) => {
|
||||
const { $local } = props
|
||||
return cTB('element',
|
||||
Object.keys($local).reduce((vars, key) => {
|
||||
vars[`--${kebabCase(key)}`] = $local[key]
|
||||
return vars
|
||||
}, {})
|
||||
)
|
||||
}
|
||||
])
|
12
src/element/styles/dark.js
Normal file
12
src/element/styles/dark.js
Normal file
@ -0,0 +1,12 @@
|
||||
import create from '../../_styles/utils/create-component-base'
|
||||
|
||||
export default create({
|
||||
theme: 'dark',
|
||||
name: 'Element',
|
||||
getDerivedVariables ({ base, derived }) {
|
||||
return {
|
||||
...base,
|
||||
...derived
|
||||
}
|
||||
}
|
||||
})
|
2
src/element/styles/index.js
Normal file
2
src/element/styles/index.js
Normal file
@ -0,0 +1,2 @@
|
||||
export { default as elementDark } from './dark'
|
||||
export { default as elementLight } from './light'
|
12
src/element/styles/light.js
Normal file
12
src/element/styles/light.js
Normal file
@ -0,0 +1,12 @@
|
||||
import create from '../../_styles/utils/create-component-base'
|
||||
|
||||
export default create({
|
||||
theme: 'light',
|
||||
name: 'Element',
|
||||
getDerivedVariables ({ base, derived }) {
|
||||
return {
|
||||
...base,
|
||||
...derived
|
||||
}
|
||||
}
|
||||
})
|
@ -52,6 +52,10 @@ export {
|
||||
tabsDark,
|
||||
tabsLight
|
||||
} from './tabs/styles'
|
||||
export {
|
||||
elementDark,
|
||||
elementLight
|
||||
} from './element/styles'
|
||||
export {
|
||||
treeDark,
|
||||
treeLight
|
||||
|
Loading…
Reference in New Issue
Block a user