<template>
<button
class="g-button"
:class="{[position]:position,disabled:disabled || loading}"
@click="$emit('click')"
>
<g-icon v-if="icon && !loading" :icon="icon"></g-icon>
<g-icon v-if="loading" class="loading icon" icon="loading"></g-icon>
<div class="content">
<slot></slot>
</div>
</button>
</template>
<script>
import Icon from '../icon'
export default {
name: 'g-button',
components: {
'g-icon': Icon
},
props: {
icon: {
default: '',
type: String
},
loading: {
default: false,
type: Boolean
},
disabled: {
default: false,
type: Boolean
},
position: {
position: '',
type: String,
validator(value) {
Eif (value === 'right' || value === 'left') {
return true
} else {
return false
}
}
}
}
}
</script>
<style scoped lang="scss">
@import "../var";
.box-shadow {
box-shadow: 0 0 5px rgba(0, 0, 0, 0.25);
}
* {
box-sizing: border-box;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.g-button {
font-size: $font-size;
height: $button-height;
padding: 0 1em;
border-radius: $border-radius;
border: 1px solid $border-color;
background: $button-bg;
vertical-align: middle;
display: inline-flex;
justify-content: center;
align-items: center;
&:focus {
outline: none;
}
&:active {
background-color: $button-active-bg;
}
&:hover {
border-color: $border-color-hover;
}
> .icon {
order: 1;
margin-right: 0.3em;
&.loading {
animation: spin 2s infinite linear;
}
}
> .content {
order: 2;
}
&.right {
> .icon {
order: 2;
margin: 0;
margin-left: 0.3em;
}
> .content {
order: 1;
}
}
&.disabled {
// pointer-events: none;
cursor: not-allowed;
opacity: 0.6;
&:active {
background-color: #fff;
}
}
}
</style> |