refactor(components): refactor empty (#3522)

* refactor(components): refactor empty

* fix: tests
This commit is contained in:
三咲智子 2021-09-22 01:41:44 +08:00 committed by GitHub
parent 9575d111c2
commit 426a1814d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 28 deletions

View File

@ -1,5 +1,5 @@
import makeMount from '@element-plus/test-utils/make-mount'
import Empty from '../src/index.vue'
import Empty from '../src/empty.vue'
const AXIOM = 'Rem is the best girl'

View File

@ -1,13 +1,8 @@
import Empty from './src/index.vue'
import { withInstall } from '@element-plus/utils/with-install'
import type { App } from 'vue'
import type { SFCWithInstall } from '@element-plus/utils/types'
import Empty from './src/empty.vue'
Empty.install = (app: App): void => {
app.component(Empty.name, Empty)
}
export const ElEmpty = withInstall(Empty)
export default ElEmpty
const _Empty = Empty as SFCWithInstall<typeof Empty>
export default _Empty
export const ElEmpty = _Empty
export * from './src/empty'

View File

@ -0,0 +1,14 @@
import type { ExtractPropTypes } from 'vue'
export const emptyProps = {
image: {
type: String,
default: '',
},
imageSize: Number,
description: {
type: String,
default: '',
},
} as const
export type EmptyProps = ExtractPropTypes<typeof emptyProps>

View File

@ -20,33 +20,26 @@
import { computed, defineComponent } from 'vue'
import { useLocaleInject } from '@element-plus/hooks'
import ImgEmpty from './img-empty.vue'
import { emptyProps } from './empty'
import type { CSSProperties } from 'vue'
export default defineComponent({
name: 'ElEmpty',
components: {
[ImgEmpty.name]: ImgEmpty,
},
props: {
image: {
type: String,
default: '',
},
imageSize: Number,
description: {
type: String,
default: '',
},
ImgEmpty,
},
props: emptyProps,
setup(props) {
const { t } = useLocaleInject()
const emptyDescription = computed(
() => props.description || t('el.table.emptyText')
)
const imageStyle = computed(() => {
return {
width: props.imageSize ? `${props.imageSize}px` : '',
}
})
const imageStyle = computed<CSSProperties>(() => ({
width: props.imageSize ? `${props.imageSize}px` : '',
}))
return {
emptyDescription,