Skip to content

Commit

Permalink
refactor(components): refactor result
Browse files Browse the repository at this point in the history
  • Loading branch information
emojiiii authored and sxzz committed Nov 5, 2021
1 parent 3cf03d5 commit c10d0cb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion packages/components/result/__tests__/result.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import makeMount from '@element-plus/test-utils/make-mount'
import Result from '../src/index.vue'
import Result from '../src/result.vue'

const AXIOM = 'Rem is the best girl'

Expand Down
15 changes: 5 additions & 10 deletions packages/components/result/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import Result from './src/index.vue'
import { withInstall } from '@element-plus/utils/with-install'
import Result from './src/result.vue'

import type { App } from 'vue'
import type { SFCWithInstall } from '@element-plus/utils/types'
export const ElResult = withInstall(Result)

Result.install = (app: App): void => {
app.component(Result.name, Result)
}
export default ElResult

const _Result = Result as SFCWithInstall<typeof Result>

export default _Result
export const ElResult = _Result
export * from './src/result'
40 changes: 40 additions & 0 deletions packages/components/result/src/result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { buildProps } from '@element-plus/utils/props'
import {
WarningFilled,
CircleCheckFilled,
CircleCloseFilled,
InfoFilled,
} from '@element-plus/icons'
import type { Indexable } from '@element-plus/utils/types'
import type { Component, ExtractPropTypes } from 'vue'

export const IconMap: Indexable<string> = {
success: 'icon-success',
warning: 'icon-warning',
error: 'icon-error',
info: 'icon-info',
}

export const IconComponentMap: Indexable<Component> = {
[IconMap.success]: CircleCheckFilled,
[IconMap.warning]: WarningFilled,
[IconMap.error]: CircleCloseFilled,
[IconMap.info]: InfoFilled,
}

export const resultProps = buildProps({
title: {
type: String,
default: '',
},
subTitle: {
type: String,
default: '',
},
icon: {
type: String,
default: 'info',
},
} as const)

export type ResultProps = ExtractPropTypes<typeof resultProps>
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,11 @@
</template>
<script lang="ts">
import { computed, defineComponent } from 'vue'
import {
WarningFilled,
CircleCheckFilled,
CircleCloseFilled,
InfoFilled,
} from '@element-plus/icons'
import type { Component } from 'vue'
import type { Indexable } from '@element-plus/utils/types'
const IconMap: Indexable<string> = {
success: 'icon-success',
warning: 'icon-warning',
error: 'icon-error',
info: 'icon-info',
}
const IconComponentMap: Indexable<Component> = {
[IconMap.success]: CircleCheckFilled,
[IconMap.warning]: WarningFilled,
[IconMap.error]: CircleCloseFilled,
[IconMap.info]: InfoFilled,
}
import { resultProps, IconComponentMap, IconMap } from './result'
export default defineComponent({
name: 'ElResult',
props: {
title: {
type: String,
default: '',
},
subTitle: {
type: String,
default: '',
},
icon: {
type: String,
default: 'info',
},
},
props: resultProps,
setup(props) {
const resultIcon = computed(() => {
const icon = props.icon
Expand Down

0 comments on commit c10d0cb

Please sign in to comment.