mand-mobile/components/button/index.vue

236 lines
5.7 KiB
Vue
Raw Permalink Normal View History

2018-03-26 16:04:04 +08:00
<template>
<button
2018-11-11 12:17:35 +08:00
:type="nativeType"
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' : ''
]"
:disabled="inactive || type === 'disabled'"
v-on="$listeners"
2018-03-26 16:04:04 +08:00
>
<div class="md-button-inner">
<template v-if="loading">
<md-activity-indicator-rolling class="md-button-loading"></md-activity-indicator-rolling>
</template>
<template v-else-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>
<div class="md-button-content">
<slot></slot>
</div>
2018-03-26 16:04:04 +08:00
</div>
</button>
2018-03-26 16:04:04 +08:00
</template>
<script> import ActivityIndicatorRolling from '../activity-indicator/roller'
import Icon from '../icon'
2018-03-26 16:04:04 +08:00
export default {
name: 'md-button',
components: {
[ActivityIndicatorRolling.name]: ActivityIndicatorRolling,
2018-03-26 16:04:04 +08:00
[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
},
2018-11-11 12:17:35 +08:00
nativeType: {
type: String,
default: 'button',
},
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,
},
loading: {
type: Boolean,
default: false,
},
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
font-family font-family-normal
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-loading
.md-activity-indicator-svg
width 35px !important
height 35px !important
margin-right 10px
2018-09-03 17:28:32 +08:00
.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 button-default-fill
color button-default-color
hairline(all, color-border-element, button-radius, 3px)
&.active:active
background button-default-active-fill
.md-button-loading .md-activity-indicator-svg .circle circle
stroke button-default-color !important
2018-03-26 16:04:04 +08:00
&.primary
background button-primary-fill
color button-primary-color
hairline(all, button-primary-fill, button-radius, 3px)
&.active:active
background button-primary-active-fill
.md-button-loading .md-activity-indicator-svg .circle circle
stroke button-primary-color !important
&.warning
background button-warning-fill
color button-warning-color
hairline(all, button-warning-fill, button-radius, 3px)
&.active:active
background button-warning-active-fill
.md-button-loading .md-activity-indicator-svg .circle circle
stroke button-warning-color !important
&.disabled
background button-disabled-fill
color button-disabled-color
hairline(all, button-disabled-fill, button-radius, 3px)
.md-button-loading .md-activity-indicator-svg .circle circle
stroke button-disabled-color !important
2018-09-03 17:28:32 +08:00
&.plain
background transparent
2018-03-26 16:04:04 +08:00
&.default
color button-default-plain-color
hairline(all, color-border-element, button-radius, 3px)
&.active:active
background button-default-plain-active-fill
.md-button-loading .md-activity-indicator-svg .circle circle
stroke button-default-plain-color !important
&.primary
color button-primary-plain-color
hairline(all, button-primary-fill, button-radius, 3px)
&.active:active
background button-primary-plain-active-fill
.md-button-loading .md-activity-indicator-svg .circle circle
stroke button-primary-plain-color !important
&.warning
color button-warning-plain-color
hairline(all, button-warning-fill, button-radius, 3px)
&.active:active
background button-warning-plain-active-fill
.md-button-loading .md-activity-indicator-svg .circle circle
stroke button-warning-plain-color !important
2018-03-26 16:04:04 +08:00
&.disabled
color button-disabled-plain-color
hairline(all, color-border-element, button-radius, 3px)
.md-button-loading .md-activity-indicator-svg .circle circle
stroke button-disabled-plain-color !important
&.round
border-radius button-height
&:after
border-radius button-height !important
&.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
line-height button-small-height
2018-08-09 11:04:04 +08:00
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 normal
2018-08-09 11:04:04 +08:00
font-size button-small-font-size
font-weight font-weight-normal
color button-primary-fill
background transparent
&.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>