|
| 1 | +<script lang="ts" setup> |
| 2 | +interface Props { |
| 3 | + loading?: boolean |
| 4 | +} |
| 5 | +interface Emits { |
| 6 | + (name: 'click', event: MouseEvent): void |
| 7 | +} |
| 8 | +
|
| 9 | +const props = withDefaults(defineProps<Props>(), { |
| 10 | + loading: false, |
| 11 | +}) |
| 12 | +const emit = defineEmits<Emits>() |
| 13 | +
|
| 14 | +function handleClick(e: MouseEvent) { |
| 15 | + if (props.loading) |
| 16 | + return |
| 17 | +
|
| 18 | + emit('click', e) |
| 19 | +} |
| 20 | +</script> |
| 21 | + |
1 | 22 | <template> |
2 | | - <button class="button"> |
3 | | - <slot /> |
| 23 | + <button |
| 24 | + :disabled="loading || undefined" |
| 25 | + class="button" |
| 26 | + :class="{ 'button-loading': loading }" |
| 27 | + @click="handleClick" |
| 28 | + > |
| 29 | + <div |
| 30 | + v-if="loading" |
| 31 | + class="button-loading-indicator" |
| 32 | + > |
| 33 | + <div class="button-loading-indicator-outer" /> |
| 34 | + <div class="button-loading-indicator-inner" /> |
| 35 | + </div> |
| 36 | + |
| 37 | + <div class="button-content"> |
| 38 | + <slot /> |
| 39 | + </div> |
4 | 40 | </button> |
5 | 41 | </template> |
6 | 42 |
|
7 | 43 | <style lang="scss" scoped> |
8 | 44 | .button { |
| 45 | + height: 35px; |
9 | 46 | font-size: 14px; |
10 | 47 | padding: 8px 12px; |
11 | 48 | border: 1px solid var(--item-border-color); |
12 | 49 | outline: none; |
13 | 50 | background-color: var(--item-bg); |
| 51 | + position: relative; |
| 52 | + overflow: hidden; |
14 | 53 | color: var(--white); |
15 | 54 | border-radius: 8px; |
16 | | - @include focus-visible; |
17 | 55 | @include text-outline(); |
18 | 56 |
|
19 | | - &:active { |
20 | | - background-color: var(--item-hover-bg); |
| 57 | + &-loading { |
| 58 | + .button-content { |
| 59 | + opacity: 0; |
| 60 | + } |
| 61 | + } |
| 62 | +
|
| 63 | + &:not(.button-loading) { |
| 64 | + @include focus-visible; |
| 65 | +
|
| 66 | + &:active { |
| 67 | + background-color: var(--item-hover-bg); |
| 68 | + } |
| 69 | +
|
| 70 | + &:hover { |
| 71 | + border-color: var(--item-hover-bg);; |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | +
|
| 76 | +.button-loading-indicator { |
| 77 | + left: 0; |
| 78 | + top: 0; |
| 79 | + width: 100%; |
| 80 | + height: 100%; |
| 81 | + display: flex; |
| 82 | + align-items: center; |
| 83 | + justify-content: center; |
| 84 | + position: absolute; |
| 85 | +
|
| 86 | + $animation-cubic-bezier: cubic-bezier(.57,-0.66,.48,1.66); |
| 87 | +
|
| 88 | + &-inner { |
| 89 | + animation: .75s button-loading-inner-anim $animation-cubic-bezier infinite alternate-reverse; |
| 90 | + width: 10px; |
| 91 | + height: 10px; |
| 92 | + border-radius: 50%; |
| 93 | + background-color: var(--white); |
| 94 | + position: relative; |
| 95 | + } |
| 96 | +
|
| 97 | + &-outer { |
| 98 | + animation: 1.5s button-loading-outer-anim $animation-cubic-bezier infinite; |
| 99 | + position: absolute; |
| 100 | + left: 0; |
| 101 | + top: 0; |
| 102 | + right: 0; |
| 103 | + bottom: 0; |
| 104 | + margin: auto; |
| 105 | + width: 25px; |
| 106 | + height: 25px; |
| 107 | + border-radius: 50%; |
| 108 | + border: 2px solid var(--app-border); |
| 109 | + } |
| 110 | +} |
| 111 | +
|
| 112 | +@keyframes button-loading-outer-anim { |
| 113 | + 0% { |
| 114 | + transform: scale(0.25); |
| 115 | + opacity: 1; |
| 116 | + } |
| 117 | +
|
| 118 | + 25% { |
| 119 | + opacity: 1; |
| 120 | + } |
| 121 | +
|
| 122 | + 50%, |
| 123 | + 100% { |
| 124 | + opacity: 0; |
| 125 | + transform: scale(1); |
| 126 | + } |
| 127 | +} |
| 128 | +
|
| 129 | +@keyframes button-loading-inner-anim { |
| 130 | + 0% { |
| 131 | + transform: scale(1); |
21 | 132 | } |
22 | 133 |
|
23 | | - &:hover { |
24 | | - border-color: var(--item-hover-bg);; |
| 134 | + 100% { |
| 135 | + transform: scale(0.5); |
25 | 136 | } |
26 | 137 | } |
27 | 138 | </style> |
0 commit comments