refactor(list): new theme

This commit is contained in:
07akioni 2021-01-05 19:10:43 +08:00
parent 59f1729195
commit 14de3b82ae
9 changed files with 136 additions and 154 deletions

View File

@ -3,9 +3,9 @@
class="n-list" class="n-list"
:class="{ :class="{
'n-list--bordered': bordered, 'n-list--bordered': bordered,
[`n-list--${size}-size`]: size, [`n-list--${size}-size`]: size
[`n-${mergedTheme}-theme`]: mergedTheme
}" }"
:style="cssVars"
> >
<div v-if="$slots.header" class="n-list__header"> <div v-if="$slots.header" class="n-list__header">
<slot name="header" /> <slot name="header" />
@ -18,13 +18,15 @@
</template> </template>
<script> <script>
import { configurable, themeable, withCssr } from '../../_mixins' import { computed, defineComponent } from 'vue'
import styles from './styles' import { useTheme } from '../../_mixins'
import { listLight } from '../styles'
import style from './styles/index.cssr.js'
export default { export default defineComponent({
name: 'List', name: 'List',
mixins: [configurable, themeable, withCssr(styles)],
props: { props: {
...useTheme.props,
size: { size: {
type: String, type: String,
default: 'medium' default: 'medium'
@ -33,6 +35,33 @@ export default {
type: Boolean, type: Boolean,
default: false default: false
} }
},
setup (props) {
const themeRef = useTheme('List', 'List', style, listLight, props)
return {
cssVars: computed(() => {
const {
common: { cubicBezierEaseInOut },
self: {
fontSize,
textColor,
color,
colorModal,
borderColor,
borderRadius
}
} = themeRef.value
return {
'--font-size': fontSize,
'--bezier': cubicBezierEaseInOut,
'--text-color': textColor,
'--color': color,
'--border-radius': borderRadius,
'--border-color': borderColor,
'--color-modal': colorModal
}
})
}
} }
} })
</script> </script>

View File

@ -13,7 +13,9 @@
</template> </template>
<script> <script>
export default { import { defineComponent } from 'vue'
export default defineComponent({
name: 'ListItem' name: 'ListItem'
} })
</script> </script>

View File

@ -0,0 +1,82 @@
import { cB, c, cE, cM, insideModal } from '../../../_utils/cssr'
// vars:
// --font-size
// --bezier
// --text-color
// --color
// --border-radius
// --border-color
// --color-modal
export default c([
cB('list', `
font-size: var(--font-size);
transition:
background-color .3s var(--bezier),
color .3s var(--bezier),
border-color .3s var(--bezier);
padding: 0;
list-style-type: none;
color: var(--text-color);
`, [
cM('bordered', `
background-color: var(--color);
border-radius: var(--border-radius);
border: 1px solid var(--border-color);
`, [
cB('list-item', `
padding: 12px 20px;
`, [
c('&:not(:last-child)', `
border-bottom: 1px solid var(--border-color);
`)
]),
cE('header, footer', `
padding: 12px 20px;
`, [
c('&:not(:last-child)', `
border-bottom: 1px solid var(--border-color);
`)
])
]),
cE('header, footer', `
padding: 12px 0;
box-sizing: border-box;
transition: border-color .3s var(--bezier);
`, [
c('&:not(:last-child)', `
border-bottom: 1px solid var(--border-color);
`)
]),
cB('list-item', `
padding: 12px 0;
box-sizing: border-box;
display: flex;
flex-wrap: nowrap;
align-items: center;
transition: border-color .3s var(--bezier);
`, [
cE('prefix', `
margin-right: 20px;
flex: 0;
`),
cE('suffix', `
margin-left: 20px;
flex: 0;
`),
cE('main', `
flex: 1;
`),
c('&:not(:last-child)', `
border-bottom: 1px solid var(--border-color);
`)
])
]),
insideModal(
cB('list', [
cM('bordered', `
background-color: var(--color-modal);
`)
])
)
])

View File

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

View File

@ -1,120 +0,0 @@
import { cTB, c, cB, cE, cM, insideModal } from '../../../_utils/cssr'
export default c([
({ props }) => {
const {
$global: {
cubicBezierEaseInOut
},
$local
} = props
const {
fontSize,
textColor,
color,
colorModal,
borderColor,
borderRadius
} = $local
return [
cTB('list', {
raw: `
font-size: ${fontSize};
transition:
background-color .3s ${cubicBezierEaseInOut},
color .3s ${cubicBezierEaseInOut},
border-color .3s ${cubicBezierEaseInOut};
padding: 0;
list-style-type: none;
color: ${textColor};
`
}, [
cM('bordered', {
raw: `
background-color: ${color};
border-radius: ${borderRadius};
border: 1px solid ${borderColor};
`
}, [
cB('list-item', {
raw: `
padding: 12px 20px;
`
}, [
c('&:not(:last-child)', {
raw: `
border-bottom: 1px solid ${borderColor};
`
})
]),
cE('header, footer', {
raw: `
padding: 12px 20px;
`
}, [
c('&:not(:last-child)', {
raw: `
border-bottom: 1px solid ${borderColor};
`
})
])
]),
cE('header, footer', {
raw: `
padding: 12px 0;
box-sizing: border-box;
transition: border-color .3s ${cubicBezierEaseInOut};
`
}, [
c('&:not(:last-child)', {
raw: `
border-bottom: 1px solid ${borderColor};
`
})
]),
cB('list-item', {
raw: `
padding: 12px 0;
box-sizing: border-box;
display: flex;
flex-wrap: nowrap;
align-items: center;
transition: border-color .3s ${cubicBezierEaseInOut};
`
}, [
cE('prefix', {
raw: `
margin-right: 20px;
flex: 0;
`
}),
cE('suffix', {
raw: `
margin-left: 20px;
flex: 0;
`
}),
cE('main', {
raw: `
flex: 1;
`
}),
c('&:not(:last-child)', {
raw: `
border-bottom: 1px solid ${borderColor};
`
})
])
]),
insideModal(
cTB('list', [
cM('bordered', {
raw: `
background-color: ${colorModal};
`
})
])
)
]
}
])

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: 'List', name: 'List',
theme: 'dark', common: commonDark,
peer: [baseDark], self (vars) {
getLocalVars (vars) {
const { const {
textColor2Overlay, textColor2Overlay,
cardColor, cardColor,
@ -23,4 +21,4 @@ export default create({
fontSize fontSize
} }
} }
}) }

View File

@ -1,11 +1,9 @@
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: 'List', name: 'List',
theme: 'light', common: commonLight,
peer: [baseLight], self (vars) {
getLocalVars (vars) {
const { const {
textColor2, textColor2,
cardColor, cardColor,
@ -23,4 +21,4 @@ export default create({
fontSize fontSize
} }
} }
}) }

View File

@ -49,7 +49,7 @@ export { baseDark, baseLight } from './_styles/base'
// export { inputDark, inputLight } from './input/styles' // export { inputDark, inputLight } from './input/styles'
// export { inputNumberDark, inputNumberLight } from './input-number/styles' // export { inputNumberDark, inputNumberLight } from './input-number/styles'
// export { layoutDark, layoutLight } from './layout/styles' // export { layoutDark, layoutLight } from './layout/styles'
export { listDark, listLight } from './list/styles' // export { listDark, listLight } from './list/styles'
export { loadingBarDark, loadingBarLight } from './loading-bar/styles' export { loadingBarDark, loadingBarLight } from './loading-bar/styles'
export { logDark, logLight } from './log/styles' export { logDark, logLight } from './log/styles'
export { menuDark, menuLight } from './menu/styles' export { menuDark, menuLight } from './menu/styles'

View File

@ -31,6 +31,7 @@ import { iconDark } from './icon/styles'
import { inputDark } from './input/styles' import { inputDark } from './input/styles'
import { inputNumberDark } from './input-number/styles' import { inputNumberDark } from './input-number/styles'
import { layoutDark } from './layout/styles' import { layoutDark } from './layout/styles'
import { listDark } from './list/styles'
export const darkTheme = { export const darkTheme = {
common: commonDark, common: commonDark,
@ -65,5 +66,6 @@ export const darkTheme = {
Icon: iconDark, Icon: iconDark,
Input: inputDark, Input: inputDark,
InputNumber: inputNumberDark, InputNumber: inputNumberDark,
Layout: layoutDark Layout: layoutDark,
List: listDark
} }