refactor(grid): new theme

This commit is contained in:
07akioni 2021-01-03 23:42:04 +08:00
parent febf840217
commit 0147b34f87
9 changed files with 100 additions and 118 deletions

View File

@ -3,8 +3,8 @@
class="n-col" class="n-col"
:class="{ :class="{
[`n-col--${span}-span`]: true, [`n-col--${span}-span`]: true,
[`n-col--${computedPush}-push`]: computedPush > 0, [`n-col--${mergedPush}-push`]: mergedPush > 0,
[`n-col--${-computedPush}-pull`]: computedPush < 0, [`n-col--${-mergedPush}-pull`]: mergedPush < 0,
[`n-col--${offset}-offset`]: offset [`n-col--${offset}-offset`]: offset
}" }"
:style="{ :style="{
@ -21,15 +21,13 @@
</template> </template>
<script> <script>
import { computed, defineComponent, inject } from 'vue'
import { formatLength } from '../../_utils' import { formatLength } from '../../_utils'
import { useTheme } from '../../_mixins'
import style from './styles/index.cssr.js'
export default { export default defineComponent({
name: 'Col', name: 'Col',
inject: {
NRow: {
default: null
}
},
props: { props: {
span: { span: {
type: [String, Number], type: [String, Number],
@ -48,18 +46,19 @@ export default {
default: 0 default: 0
} }
}, },
computed: { setup (props) {
gutter () { useTheme('Grid', 'Grid', style, null, null)
return this.NRow.gutter const NRow = inject('NRow')
}, return {
stylePadding () { gutter: computed(() => NRow.gutter),
return `${formatLength(this.NRow.verticalGutter, { stylePadding: computed(
() =>
`${formatLength(NRow.verticalGutter, {
c: 0.5 c: 0.5
})} ${formatLength(this.NRow.horizontalGutter, { c: 0.5 })}` })} ${formatLength(NRow.horizontalGutter, { c: 0.5 })}`
}, ),
computedPush () { mergedPush: computed(() => props.push - props.pull)
return this.push - this.pull
}
} }
} }
})
</script> </script>

View File

@ -16,14 +16,14 @@
</template> </template>
<script> <script>
import { defineComponent } from 'vue'
import { useMemo } from 'vooks'
import { formatLength } from '../../_utils' import { formatLength } from '../../_utils'
import { configurable, themeable, withCssr } from '../../_mixins' import { useTheme } from '../../_mixins'
import styles from './styles' import style from './styles/index.cssr.js'
export default { export default defineComponent({
name: 'Row', name: 'Row',
cssrName: 'Grid',
mixins: [configurable, themeable, withCssr(styles)],
provide () { provide () {
return { return {
NRow: this NRow: this
@ -47,27 +47,32 @@ export default {
default: undefined default: undefined
} }
}, },
computed: { setup (props) {
verticalGutter () { useTheme('Grid', 'Grid', style, null, null)
const gutter = this.gutter const verticalGutterRef = useMemo(() => {
const { gutter } = props
if (Array.isArray(gutter)) { if (Array.isArray(gutter)) {
return gutter[1] || 0 return gutter[1] || 0
} }
return 0 return 0
}, })
horizontalGutter () { const horizontalGutterRef = useMemo(() => {
const gutter = this.gutter const { gutter } = props
if (Array.isArray(gutter)) { if (Array.isArray(gutter)) {
return gutter[0] return gutter[0]
} }
return gutter return gutter
}, })
styleMargin () { return {
return `0px -${formatLength(this.horizontalGutter, { c: 0.5 })}` verticalGutter: verticalGutterRef,
}, horizontalGutter: horizontalGutterRef,
styleWidth () { styleMargin: useMemo(
return `calc(100% + ${formatLength(this.horizontalGutter)})` () => `0px -${formatLength(horizontalGutterRef.value, { c: 0.5 })}`
} ),
styleWidth: useMemo(
() => `calc(100% + ${formatLength(horizontalGutterRef.value)})`
)
} }
} }
})
</script> </script>

View File

@ -1,51 +0,0 @@
import { c, cB, cM, cE } from '../../../_utils/cssr'
export default c([
() => {
return cB('row', {
width: '100%'
},
[
cM('flex', {
display: 'flex'
})
])
},
() => {
const positionStyles = Array
.apply(null, { length: 24 })
.map((_, index) => {
const prefixIndex = index + 1
const percent = (1 / 24 * prefixIndex * 100).toFixed(2) + '%'
return [
cM(`${prefixIndex}-span`, {
width: percent
}),
cM(`${prefixIndex}-offset`, {
marginLeft: percent
}),
cM(`${prefixIndex}-push`, {
left: percent
}),
cM(`${prefixIndex}-pull`, {
right: percent
})
]
})
return cB('col', {
verticalAlign: 'top',
boxSizing: 'border-box',
display: 'inline-block',
position: 'relative',
zIndex: 'auto'
}, [
cE('box', {
position: 'relative',
zIndex: 'auto',
width: '100%',
height: '100%'
}),
positionStyles
])
}
])

View File

@ -0,0 +1,48 @@
import { c, cB, cM, cE } from '../../../_utils/cssr'
const positionStyles = Array
.apply(null, { length: 24 })
.map((_, index) => {
const prefixIndex = index + 1
const percent = (1 / 24 * prefixIndex * 100).toFixed(2) + '%'
return [
cM(`${prefixIndex}-span`, {
width: percent
}),
cM(`${prefixIndex}-offset`, {
marginLeft: percent
}),
cM(`${prefixIndex}-push`, {
left: percent
}),
cM(`${prefixIndex}-pull`, {
right: percent
})
]
})
export default c([
cB('row', {
width: '100%'
},
[
cM('flex', {
display: 'flex'
})
]),
cB('col', {
verticalAlign: 'top',
boxSizing: 'border-box',
display: 'inline-block',
position: 'relative',
zIndex: 'auto'
}, [
cE('box', {
position: 'relative',
zIndex: 'auto',
width: '100%',
height: '100%'
}),
positionStyles
])
])

View File

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

View File

@ -1,9 +1,3 @@
import create from '../../_styles/utils/create-component-base' export default {
name: 'Grid'
export default create({
theme: 'dark',
name: 'Grid',
getLocalVars (vars) {
return {}
} }
})

View File

@ -1,9 +1,3 @@
import create from '../../_styles/utils/create-component-base' export default {
name: 'Grid'
export default create({
theme: 'light',
name: 'Grid',
getLocalVars (vars) {
return {}
} }
})

View File

@ -44,7 +44,7 @@ export { baseDark, baseLight } from './_styles/base'
// export { emptyDark, emptyLight } from './empty/styles' // export { emptyDark, emptyLight } from './empty/styles'
// export { formDark, formLight } from './form/styles' // export { formDark, formLight } from './form/styles'
// export { gradientTextDark, gradientTextLight } from './gradient-text/styles' // export { gradientTextDark, gradientTextLight } from './gradient-text/styles'
export { gridDark, gridLight } from './grid/styles' // export { gridDark, gridLight } from './grid/styles'
export { iconDark, iconLight } from './icon/styles' export { iconDark, iconLight } from './icon/styles'
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'

View File

@ -26,6 +26,7 @@ import { elementDark } from './element/styles'
import { emptyDark } from './empty/styles' import { emptyDark } from './empty/styles'
import { formDark } from './form/styles' import { formDark } from './form/styles'
import { gradientTextDark } from './gradient-text/styles' import { gradientTextDark } from './gradient-text/styles'
import { gridDark } from './grid/styles'
export const darkTheme = { export const darkTheme = {
common: commonDark, common: commonDark,
@ -55,5 +56,6 @@ export const darkTheme = {
Element: elementDark, Element: elementDark,
Empty: emptyDark, Empty: emptyDark,
Form: formDark, Form: formDark,
GradientText: gradientTextDark GradientText: gradientTextDark,
Grid: gridDark
} }