Files
element-plus/packages/button/src/button.vue
zazzaz 355a778a2c Feat/datepicker && datetimepicker (#326)
* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update

* Feat/form (#342)

* feat(form): add form component

fix #125

* test(form): add test code

* docs(form): add form doc

* feat: add uitls merge

* fix(form): fix style

* test(form): add form test code

* refactor(form): review changes

* test(form): use idiomatic vue-test-util methods

* feat(core): bump vue version

* feat(form): rewrite label wrap

* feat(form): fix tons of bugs

* fix(form): reuse ts extension

* refactor(form): move out label width computation

* fix(form): fix tons of bugs

* fix(form): test

Co-authored-by: 286506460 <286506460@qq.com>

* Feat/select (#381)

* fix: resove conflict

* feat: select basic usage

* feat: select basic usage

* feat: select feature create item

* fix: fix option data insert

* refactor: select

* fix: fix parse error

* feat: select test

* fix: select add popper

* fix: update select option

* fix: add select dependency

* fix: add index.ts file

* fix(select): clean up

* fix(select): some refactor

* fix(select): some update

* fix(select): fix all test cases

Co-authored-by: helen <yinhelen.hlj@qq.com>

Co-authored-by: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com>
Co-authored-by: 286506460 <286506460@qq.com>
Co-authored-by: helen <yinhelen.hlj@qq.com>
2020-10-03 20:13:19 +08:00

141 lines
3.1 KiB
Vue

<template>
<button
:class="[
'el-button',
type ? 'el-button--' + type : '',
buttonSize ? 'el-button--' + buttonSize : '',
{
'is-disabled': buttonDisabled,
'is-loading': loading,
'is-plain': plain,
'is-round': round,
'is-circle': circle
}
]"
:disabled="buttonDisabled || loading"
:autofocus="autofocus"
:type="nativeType"
@click="handleClick"
>
<i v-if="loading" class="el-icon-loading"></i>
<i v-if="icon && !loading" :class="icon"></i>
<span v-if="$slots.default"><slot></slot></span>
</button>
</template>
<script lang='ts'>
import { computed, inject, defineComponent, PropType } from 'vue'
type IButtonType = PropType<'primary' | 'success' | 'warning' | 'danger' | 'info' | 'text' | 'default'>
type IButtonSize = PropType<'medium' | 'small' | 'mini'>
type IButtonNativeType = PropType<'button' | 'submit' | 'reset'>
const ELEMENT: {
size?: number
} = {}
// TODOS: replace these interface definition with actual ElForm interface
interface ElForm {
disabled: boolean
}
interface ElFormItem {
elFormItemSize: number
}
interface IButtonProps {
type: string
size: string
icon: string
nativeType: string
loading: boolean
disabled: boolean
plain: boolean
autofocus: boolean
round: boolean
circle: boolean
}
type EmitFn = (evt: Event) => void
interface IButtonSetups {
elFormItemSize_: number
buttonSize: string
buttonDisabled: boolean
handleClick: EmitFn
}
export default defineComponent({
name: 'ElButton',
props: {
type: {
type: String as IButtonType,
default: 'default',
validator: (val: string) => {
return [
'default',
'primary',
'success',
'warning',
'info',
'danger',
'text',
].includes(val)
},
},
size: {
type: String as IButtonType,
validator: (val: string) => {
return ['medium', 'small', 'mini'].includes(val)
},
},
icon: {
type: String,
default: '',
},
nativeType: {
type: String as IButtonNativeType,
default: 'button',
validator: (val: string) => {
return ['button', 'submit', 'reset'].includes(val)
},
},
loading: Boolean,
disabled: Boolean,
plain: Boolean,
autofocus: Boolean,
round: Boolean,
circle: Boolean,
},
emits: ['click'],
setup(props, ctx) {
// inject
const elForm = inject<ElForm>('elForm', {} as any)
const elFormItem = inject<ElFormItem>('elFormItem', {} as any)
// computed
const elFormItemSize_ = computed(() => {
return (elFormItem || {}).elFormItemSize
})
const buttonSize = computed(() => {
// todo ELEMENT
return props.size || elFormItemSize_.value || (ELEMENT || {}).size
})
const buttonDisabled = computed(() => {
return props.disabled || (elForm || {}).disabled
})
//methods
const handleClick = evt => {
ctx.emit('click', evt)
}
return {
elFormItemSize_,
buttonSize,
buttonDisabled,
handleClick,
}
},
})
</script>