refactor(thing): new theme

This commit is contained in:
07akioni 2021-01-08 00:36:40 +08:00
parent a776087be0
commit 9917461d5c
8 changed files with 106 additions and 135 deletions

View File

@ -75,7 +75,7 @@ export { baseDark, baseLight } from './_styles/base'
// export { tableDark, tableLight } from './table/styles' // export { tableDark, tableLight } from './table/styles'
// export { tabsDark, tabsLight } from './tabs/styles' // export { tabsDark, tabsLight } from './tabs/styles'
// export { tagDark, tagLight } from './tag/styles' // export { tagDark, tagLight } from './tag/styles'
export { thingDark, thingLight } from './thing/styles' // export { thingDark, thingLight } from './thing/styles'
export { timeDark, timeLight } from './time/styles' export { timeDark, timeLight } from './time/styles'
export { timePickerDark, timePickerLight } from './time-picker/styles' export { timePickerDark, timePickerLight } from './time-picker/styles'
export { timelineDark, timelineLight } from './timeline/styles' export { timelineDark, timelineLight } from './timeline/styles'

View File

@ -56,6 +56,7 @@ import { switchDark } from './switch/styles'
import { tableDark } from './table/styles' import { tableDark } from './table/styles'
import { tabsDark } from './tabs/styles' import { tabsDark } from './tabs/styles'
import { tagDark } from './tag/styles' import { tagDark } from './tag/styles'
import { thingDark } from './thing/styles'
export const darkTheme = { export const darkTheme = {
common: commonDark, common: commonDark,
@ -115,5 +116,6 @@ export const darkTheme = {
Switch: switchDark, Switch: switchDark,
Table: tableDark, Table: tableDark,
Tabs: tabsDark, Tabs: tabsDark,
Tag: tagDark Tag: tagDark,
Thing: thingDark
} }

View File

@ -1,11 +1,5 @@
<template> <template>
<div <div class="n-thing" :style="cssVars">
class="n-thing"
:class="{
[`n-${mergedTheme}-theme`]: mergedTheme
}"
:style="mergedStyle"
>
<div v-if="$slots.avatar && contentIndented" class="n-thing-avatar"> <div v-if="$slots.avatar && contentIndented" class="n-thing-avatar">
<slot name="avatar" /> <slot name="avatar" />
</div> </div>
@ -97,12 +91,13 @@
</template> </template>
<script> <script>
import { configurable, themeable, withCssr } from '../../_mixins' import { defineComponent, computed } from 'vue'
import styles from './styles' import { useTheme } from '../../_mixins'
import { thingLight } from '../styles'
import style from './styles/index.cssr.js'
export default { export default defineComponent({
name: 'Thing', name: 'Thing',
mixins: [configurable, themeable, withCssr(styles)],
props: { props: {
title: { title: {
type: String, type: String,
@ -124,6 +119,24 @@ export default {
type: Boolean, type: Boolean,
default: false default: false
} }
},
setup (props) {
const themeRef = useTheme('Thing', 'Thing', style, thingLight, props)
return {
cssVars: computed(() => {
const {
self: { titleTextColor, textColor, titleFontWeight, fontSize },
common: { cubicBezierEaseInOut }
} = themeRef.value
return {
'--bezier': cubicBezierEaseInOut,
'--font-size': fontSize,
'--text-color': textColor,
'--title-font-weight': titleFontWeight,
'--title-text-color': titleTextColor
}
})
}
} }
} })
</script> </script>

View File

@ -0,0 +1,64 @@
import { c, cB, cE } from '../../../_utils/cssr'
// vars:
// --bezier
// --font-size
// --text-color
// --title-font-weight
// --title-text-color
export default cB('thing', `
display: flex;
transition: color .3s var(--bezier);
font-size: var(--font-size);
color: var(--text-color);
`, [
cB('thing-avatar', `
margin-right: 12px;
margin-top: 2px;
`),
cB('thing-avatar-header-wrapper', `
display: flex;
flex-wrap: nowrap;
`, [
cB('thing-header-wrapper', `
flex: 1;
`)
]),
cB('thing-main', `
flex-grow: 1;
`, [
cB('thing-header', `
display: flex;
margin-bottom: 4px;
justify-content: space-between;
align-items: center;
`, [
cE('title', `
font-size: 16px;
font-weight: var(--title-font-weight);
transition: color .3s var(--bezier);
color: var(--title-text-color);
`)
]),
cE('description', [
c('&:not(:last-child)', `
margin-bottom: 4px;
`)
]),
cE('content', [
c('&:not(:first-child)', `
margin-top: 12px;
`)
]),
cE('footer', [
c('&:not(:first-child)', `
margin-top: 12px;
`)
]),
cE('action', [
c('&:not(:first-child)', `
margin-top: 12px;
`)
])
])
])

View File

@ -1,9 +0,0 @@
import themedBaseStyle from './themed-base.cssr.js'
export default [
{
key: 'mergedTheme',
watch: ['mergedTheme'],
CNode: themedBaseStyle
}
]

View File

@ -1,95 +0,0 @@
import { c, cTB, cB, cE } from '../../../_utils/cssr'
export default c([
({ props }) => {
const {
$local: {
headerTextColor,
textColor,
headerFontWeight,
fontSize
},
$global: {
cubicBezierEaseInOut
}
} = props
return cTB('thing', {
raw: `
display: flex;
transition: color .3s ${cubicBezierEaseInOut};
font-size: ${fontSize};
`,
color: textColor
}, [
cB('thing-avatar', {
raw: `
margin-right: 12px;
margin-top: 2px;
`
}),
cB('thing-avatar-header-wrapper', {
raw: `
display: flex;
flex-wrap: nowrap;
`
}, [
cB('thing-header-wrapper', {
raw: `
flex: 1;
`
})
]),
cB('thing-main', {
raw: `
flex-grow: 1;
`
}, [
cB('thing-header', {
raw: `
display: flex;
margin-bottom: 4px;
justify-content: space-between;
align-items: center;
`
}, [
cE('title', {
raw: `
font-size: 16px;
font-weight: ${headerFontWeight};
transition: color .3s ${cubicBezierEaseInOut};
`,
color: headerTextColor
})
]),
cE('description', [
c('&:not(:last-child)', {
raw: `
margin-bottom: 4px;
`
})
]),
cE('content', [
c('&:not(:first-child)', {
raw: `
margin-top: 12px;
`
})
]),
cE('footer', [
c('&:not(:first-child)', {
raw: `
margin-top: 12px;
`
})
]),
cE('action', [
c('&:not(:first-child)', {
raw: `
margin-top: 12px;
`
})
])
])
])
}
])

View File

@ -1,11 +1,9 @@
import create from '../../_styles/utils/create-component-base' import { commonDark } from '../../_styles/new-common'
import { baseDark } from '../../_styles/base'
export default create({ export default {
name: 'Thing', name: 'Thing',
theme: 'dark', common: commonDark,
peer: [baseDark], self (vars) {
getLocalVars (vars) {
const { const {
textColor1Overlay, textColor1Overlay,
textColor2Overlay, textColor2Overlay,
@ -14,9 +12,9 @@ export default create({
} = vars } = vars
return { return {
fontSize, fontSize,
headerTextColor: textColor1Overlay, titleTextColor: textColor1Overlay,
textColor: textColor2Overlay, textColor: textColor2Overlay,
headerFontWeight: fontWeightStrong titleFontWeight: fontWeightStrong
} }
} }
}) }

View File

@ -1,17 +1,15 @@
import create from '../../_styles/utils/create-component-base' import { commonLight } from '../../_styles/new-common'
import { baseLight } from '../../_styles/base'
export default create({ export default {
name: 'Thing', name: 'Thing',
theme: 'light', common: commonLight,
peer: [baseLight],
getLocalVars (vars) { getLocalVars (vars) {
const { textColor1, textColor2, fontWeightStrong, fontSize } = vars const { textColor1, textColor2, fontWeightStrong, fontSize } = vars
return { return {
fontSize, fontSize,
headerTextColor: textColor1, titleTextColor: textColor1,
textColor: textColor2, textColor: textColor2,
headerFontWeight: fontWeightStrong titleFontWeight: fontWeightStrong
} }
} }
}) }