all files / src/button/ button.vue

66.67% Statements 2/3
50% Branches 2/4
100% Functions 1/1
66.67% Lines 2/3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116                                                                                                                                                                                                                                   
<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>