fix/typescripting-button-component

- Adding type definition for button component
This commit is contained in:
JeremyWuuuuu 2020-07-21 22:27:30 +08:00
parent 5da603bffb
commit 393830f946

View File

@ -22,9 +22,19 @@
<span v-if="$slots.default"><slot></slot></span>
</button>
</template>
<script>
<script lang='ts'>
import { computed, inject } from 'vue'
const ELEMENT = {}
const ELEMENT: {
size?: number;
} = {}
// TODOS: replace these interface definition with actual ElForm interface
interface ElForm {
disabled: boolean;
}
interface ElFormItem {
elFormItemSize: number;
}
export default {
name: 'ElButton',
@ -49,27 +59,21 @@ export default {
round: Boolean,
circle: Boolean
},
methods: {
handleClick(evt) {
this.$emit('click', evt);
}
},
setup(props,ctx) {
// inject
const elForm = inject('elForm', '')
const elFormItem = inject('elFormItem', '')
const elForm = inject<ElForm>('elForm')
const elFormItem = inject<ElFormItem>('elFormItem')
// computed
const _elFormItemSize = computed(() => {
return (elFormItem || {}).elFormItemSize
return elFormItem.elFormItemSize || undefined
})
const buttonSize = computed(() => {
// todo ELEMENT
return props.size || _elFormItemSize.value || (ELEMENT || {}).size
return props.size || _elFormItemSize.value || ELEMENT.size || undefined
})
const buttonDisabled = computed(() => {
return props.disabled || (elForm || {}).disabled
return props.disabled || elForm.disabled
})
//methods