mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-03-19 14:00:50 +08:00
refactor(divider): ts
This commit is contained in:
parent
fd0d70f0bf
commit
d6dc8e6ef6
79
src/divider/src/Divider.tsx
Normal file
79
src/divider/src/Divider.tsx
Normal file
@ -0,0 +1,79 @@
|
||||
import {
|
||||
h,
|
||||
computed,
|
||||
defineComponent,
|
||||
CSSProperties,
|
||||
PropType,
|
||||
Fragment,
|
||||
renderSlot
|
||||
} from 'vue'
|
||||
import { useConfig, useTheme } from '../../_mixins'
|
||||
import type { ThemeProps } from '../../_mixins'
|
||||
import { dividerLight } from '../styles'
|
||||
import type { DividerTheme } from '../styles'
|
||||
import style from './styles/index.cssr'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Divider',
|
||||
props: {
|
||||
...(useTheme.props as ThemeProps<DividerTheme>),
|
||||
titlePlacement: {
|
||||
type: String as PropType<'left' | 'center' | 'right'>,
|
||||
default: 'center'
|
||||
},
|
||||
dashed: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
vertical: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
setup (props) {
|
||||
const themeRef = useTheme('Divider', 'Divider', style, dividerLight, props)
|
||||
return {
|
||||
...useConfig(props),
|
||||
cssVars: computed(() => {
|
||||
const {
|
||||
common: { cubicBezierEaseInOut },
|
||||
self: { color, textColor, fontWeight }
|
||||
} = themeRef.value
|
||||
return {
|
||||
'--bezier': cubicBezierEaseInOut,
|
||||
'--color': color,
|
||||
'--text-color': textColor,
|
||||
'--font-weight': fontWeight
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
render () {
|
||||
const { $slots, titlePlacement, vertical, dashed, cssVars } = this
|
||||
return (
|
||||
<div
|
||||
class={[
|
||||
'n-divider',
|
||||
{
|
||||
'n-divider--vertical': vertical,
|
||||
'n-divider--no-title': !$slots.default,
|
||||
'n-divider--dashed': dashed,
|
||||
[`n-divider--title-position-${titlePlacement}`]:
|
||||
$slots.default && titlePlacement
|
||||
}
|
||||
]}
|
||||
style={cssVars as CSSProperties}
|
||||
>
|
||||
{!vertical ? (
|
||||
<hr class="n-divider__line n-divider__line--left" />
|
||||
) : null}
|
||||
{!vertical && $slots.default ? (
|
||||
<>
|
||||
<div class="n-divider__title">{renderSlot($slots, 'default')}</div>
|
||||
<div class="n-divider__line n-divider__line--right" />
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
})
|
@ -1,66 +0,0 @@
|
||||
<template>
|
||||
<div
|
||||
class="n-divider"
|
||||
:class="{
|
||||
'n-divider--vertical': vertical,
|
||||
'n-divider--no-title': !$slots.default,
|
||||
'n-divider--dashed': dashed,
|
||||
[`n-divider--title-position-${titlePlacement}`]:
|
||||
$slots.default && titlePlacement
|
||||
}"
|
||||
:style="cssVars"
|
||||
>
|
||||
<hr v-if="!vertical" class="n-divider__line n-divider__line--left">
|
||||
<div v-if="!vertical && $slots.default" class="n-divider__title">
|
||||
<slot />
|
||||
</div>
|
||||
<div
|
||||
v-if="!vertical && $slots.default"
|
||||
class="n-divider__line n-divider__line--right"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { computed, defineComponent } from 'vue'
|
||||
import { useConfig, useTheme } from '../../_mixins'
|
||||
import { dividerLight } from '../styles'
|
||||
import style from './styles/index.cssr'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Divider',
|
||||
props: {
|
||||
...useTheme.props,
|
||||
titlePlacement: {
|
||||
type: String,
|
||||
default: 'center'
|
||||
},
|
||||
dashed: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
vertical: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
setup (props) {
|
||||
const themeRef = useTheme('Divider', 'Divider', style, dividerLight, props)
|
||||
return {
|
||||
...useConfig(props),
|
||||
cssVars: computed(() => {
|
||||
const {
|
||||
common: { cubicBezierEaseInOut },
|
||||
self: { color, textColor, fontWeight }
|
||||
} = themeRef.value
|
||||
return {
|
||||
'--bezier': cubicBezierEaseInOut,
|
||||
'--color': color,
|
||||
'--text-color': textColor,
|
||||
'--font-weight': fontWeight
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
@ -1,6 +1,7 @@
|
||||
import { commonDark } from '../../_styles/new-common'
|
||||
import type { DividerTheme } from './light'
|
||||
|
||||
export default {
|
||||
const dividerDark: DividerTheme = {
|
||||
name: 'Divider',
|
||||
common: commonDark,
|
||||
self (vars) {
|
||||
@ -12,3 +13,5 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default dividerDark
|
@ -1,2 +0,0 @@
|
||||
export { default as dividerDark } from './dark.js'
|
||||
export { default as dividerLight } from './light.js'
|
3
src/divider/styles/index.ts
Normal file
3
src/divider/styles/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export { default as dividerDark } from './dark'
|
||||
export { default as dividerLight } from './light'
|
||||
export type { DividerThemeVars, DividerTheme } from './light'
|
@ -1,14 +0,0 @@
|
||||
import { commonLight } from '../../_styles/new-common'
|
||||
|
||||
export default {
|
||||
name: 'Divider',
|
||||
common: commonLight,
|
||||
self (vars) {
|
||||
const { textColor1, dividerColorOverlay, fontWeightStrong } = vars
|
||||
return {
|
||||
textColor: textColor1,
|
||||
color: dividerColorOverlay,
|
||||
fontWeight: fontWeightStrong
|
||||
}
|
||||
}
|
||||
}
|
23
src/divider/styles/light.ts
Normal file
23
src/divider/styles/light.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { commonLight } from '../../_styles/new-common'
|
||||
import type { ThemeCommonVars } from '../../_styles/new-common'
|
||||
import type { Theme } from '../../_mixins'
|
||||
|
||||
const self = (vars: ThemeCommonVars) => {
|
||||
const { textColor1, dividerColorOverlay, fontWeightStrong } = vars
|
||||
return {
|
||||
textColor: textColor1,
|
||||
color: dividerColorOverlay,
|
||||
fontWeight: fontWeightStrong
|
||||
}
|
||||
}
|
||||
|
||||
export type DividerThemeVars = ReturnType<typeof self>
|
||||
|
||||
const dividerLight: Theme<DividerThemeVars> = {
|
||||
name: 'Divider',
|
||||
common: commonLight,
|
||||
self
|
||||
}
|
||||
|
||||
export default dividerLight
|
||||
export type DividerTheme = typeof dividerLight
|
Loading…
x
Reference in New Issue
Block a user