refactor(components): refactor icon (#3528)

This commit is contained in:
三咲智子 2021-09-22 00:46:23 +08:00 committed by GitHub
parent d71c87344a
commit 6a57d547d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 20 deletions

View File

@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils'
import Icon from '../src/index.vue'
import Icon from '../src/icon.vue'
describe('Icon.vue', () => {
test('render', () => {

View File

@ -1,13 +1,8 @@
import Icon 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 Icon from './src/icon.vue'
Icon.install = (app: App): void => {
app.component(Icon.name, Icon)
}
export const ElIcon = withInstall(Icon)
export default ElIcon
const _Icon = Icon as SFCWithInstall<typeof Icon>
export default _Icon
export const ElIcon = _Icon
export * from './src/icon'

View File

@ -0,0 +1,11 @@
import type { ExtractPropTypes } from 'vue'
export const iconProps = {
size: {
type: Number,
},
color: {
type: String,
},
} as const
export type IconProps = ExtractPropTypes<typeof iconProps>

View File

@ -6,21 +6,19 @@
<script lang="ts">
import { defineComponent, computed } from 'vue'
import { iconProps } from './icon'
import type { CSSProperties } from 'vue'
export default defineComponent({
name: 'ElIcon',
inheritAttrs: false,
props: {
size: {
type: Number,
},
color: {
type: String,
},
},
props: iconProps,
setup(props) {
return {
style: computed(() => {
style: computed<CSSProperties>(() => {
if (!props.size && !props.color) {
return {}
}