mand-mobile/components/button/index.vue

206 lines
4.3 KiB
Vue
Raw Normal View History

2018-03-26 16:04:04 +08:00
<template>
<button
2018-03-26 16:04:04 +08:00
class="md-button"
:class="[
type,
inactive ? 'inactive' : 'active',
inline ? 'inline' : 'block',
round ? 'round' : '',
2018-08-09 11:04:04 +08:00
plain ? 'plain' : '',
size === 'small' ? 'small' : ''
]"
2018-03-26 16:04:04 +08:00
@click="$_onBtnClick"
>
<div class="md-button-inner">
<template v-if="icon">
2018-10-15 15:52:00 +08:00
<md-icon :name="icon" :svg="iconSvg"></md-icon>
2018-03-26 16:04:04 +08:00
</template>
<p class="md-button-content">
<slot></slot>
</p>
2018-03-26 16:04:04 +08:00
</div>
</button>
2018-03-26 16:04:04 +08:00
</template>
<script> import Icon from '../icon'
export default {
name: 'md-button',
components: {
[Icon.name]: Icon,
},
props: {
type: {
type: String,
2018-08-29 14:47:54 +08:00
default: 'default', // default, primary, warning, disabled, link
2018-03-26 16:04:04 +08:00
},
icon: {
type: String,
default: '',
},
2018-10-15 15:52:00 +08:00
iconSvg: {
type: Boolean,
default: false,
},
2018-08-09 11:04:04 +08:00
size: {
type: String,
default: 'large', // large, small
},
plain: {
type: Boolean,
default: false,
},
round: {
type: Boolean,
default: false,
},
inline: {
type: Boolean,
default: false,
},
inactive: {
2018-03-26 16:04:04 +08:00
type: Boolean,
default: false,
},
},
methods: {
$_onBtnClick(event) {
if (this.inactive || this.type === 'disabled') {
2018-03-26 16:04:04 +08:00
event.stopImmediatePropagation()
} else {
this.$emit('click', event)
2018-03-26 16:04:04 +08:00
}
},
},
}
</script>
<style lang="stylus">
.md-button
position relative
2018-08-09 11:04:04 +08:00
display block
height button-height
line-height button-height
font-size button-font-size
font-weight button-font-weight
2018-03-26 16:04:04 +08:00
text-align center
border none
border-radius button-radius
2018-03-26 16:04:04 +08:00
box-sizing border-box
outline none
transition all .3s
-webkit-appearance none
2018-08-09 11:04:04 +08:00
-webkit-user-select none
-webkit-tap-highlight-color transparent
2018-03-26 16:04:04 +08:00
overflow visible
2018-09-03 17:28:32 +08:00
.md-button-inner
display flex
align-items center
justify-content center
width 100%
height 100%
overflow hidden
text-overflow ellipsis
word-break break-word
white-space nowrap
.md-button-content
display flex
align-items center
padding 0 6px
.md-icon
padding 0
.md-button
2018-09-26 20:10:47 +08:00
position relative
2018-09-03 17:28:32 +08:00
.md-icon
display flex
align-items center
justify-content center
2018-09-03 17:28:32 +08:00
padding 0 6px
2018-03-26 16:04:04 +08:00
// type
&.default
background-color button-default-fill
color button-default-color
hairline(all, color-border-element, button-radius)
&.active:active
background-color button-default-active-fill
2018-03-26 16:04:04 +08:00
&.primary
background-color button-primary-fill
color button-primary-color
hairline(all, button-primary-fill, button-radius)
&.active:active
background-color button-primary-active-fill
&.warning
background-color button-warning-fill
color button-warning-color
hairline(all, button-warning-fill, button-radius)
&.active:active
background-color button-warning-active-fill
&.disabled
background-color button-disabled-fill
color button-disabled-color
hairline(all, button-disabled-fill, button-radius)
2018-09-03 17:28:32 +08:00
&.plain
background transparent
2018-03-26 16:04:04 +08:00
&.default
color button-default-color
hairline(all, color-border-element, button-radius)
&.active:active
background-color button-default-plain-active-fill
&.primary
color button-primary-fill
hairline(all, button-primary-fill, button-radius)
&.active:active
background-color button-primary-plain-active-fill
&.warning
color button-warning-fill
hairline(all, button-warning-fill, button-radius)
&.active:active
background-color button-warning-plain-active-fill
2018-03-26 16:04:04 +08:00
&.disabled
color button-disabled-fill
hairline(all, button-disabled-fill, button-radius)
&.round
border-radius button-height
&:after
2018-08-09 11:04:04 +08:00
border-radius button-height
&.inline
2018-08-09 11:04:04 +08:00
display inline-block
padding 0 h-gap-md
&.block
width 100%
2018-08-09 11:04:04 +08:00
&.small
height button-small-height
font-size button-small-font-size
&.round
2018-08-09 11:04:04 +08:00
border-radius button-small-height
&:after
2018-08-09 11:04:04 +08:00
border-radius button-small-height
2018-04-23 17:33:32 +08:00
2018-03-26 16:04:04 +08:00
&.link
display inline
width auto
height auto
line-height 1
2018-08-09 11:04:04 +08:00
font-size button-small-font-size
font-weight font-weight-normal
color button-primary-fill
&.inactive
color color-text-disabled
opacity 1
2018-03-26 16:04:04 +08:00
&.inactive
opacity opacity-disabled
&.disabled
opacity 1
2018-03-26 16:04:04 +08:00
</style>