refactor(components): [card] add namespace & instance type (#5445)

This commit is contained in:
三咲智子
2022-01-18 14:45:04 +08:00
committed by GitHub
parent 6107740866
commit cc4cebf465
2 changed files with 13 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import { buildProps, definePropType } from '@element-plus/utils/props'
import type Card from './card.vue'
import type { ExtractPropTypes } from 'vue'
import type { StyleValue } from '@element-plus/utils/types'
@@ -17,3 +18,4 @@ export const cardProps = buildProps({
},
} as const)
export type CardProps = ExtractPropTypes<typeof cardProps>
export type CardInstance = InstanceType<typeof Card>

View File

@@ -1,22 +1,27 @@
<template>
<div
class="el-card"
:class="shadow ? 'is-' + shadow + '-shadow' : 'is-always-shadow'"
>
<div v-if="$slots.header || header" class="el-card__header">
<div :class="[ns.b(), shadow ? `is-${shadow}-shadow` : 'is-always-shadow']">
<div v-if="$slots.header || header" :class="ns.e('header')">
<slot name="header">{{ header }}</slot>
</div>
<div class="el-card__body" :style="bodyStyle">
<div :class="ns.e('body')" :style="bodyStyle">
<slot></slot>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { useNamespace } from '@element-plus/hooks'
import { cardProps } from './card'
export default defineComponent({
name: 'ElCard',
props: cardProps,
setup() {
const ns = useNamespace('card')
return {
ns,
}
},
})
</script>