aboutsummaryrefslogtreecommitdiffstats
path: root/components/Button.vue
blob: ce9eefc3127d1a82f7a58b4acde3b8de3af3e26f (plain)
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
117
118
119
120
<script setup lang="ts">
import { Loader2Icon } from 'lucide-vue-next'
import { defineProps, type FunctionalComponent } from 'vue';

defineProps({
  isLoading: {
    type: Boolean,
    default: false,
  },
  disabled: {
    type: Boolean,
    default: false
  },
  loading: {
    type: Boolean,
    default: false
  },
  type: {
    type: String as PropType<"button" | "submit" | "reset">,
    default: "",
  },
  kind: {
    type: String as PropType<"primary" | "secondary" | "danger">,
    default: "primary",
  },
  icon: {
    type: Object as PropType<FunctionalComponent>,
    default: null
  }
});
</script>

<template>
  <button :type="type" :disabled="disabled || loading" :class="kind">
    <Loader2Icon v-if="loading" class="icon-loader" />
    <component :is="icon" v-else-if="icon" />
    <span>
      <slot />
    </span>
  </button>
</template>

<style scoped>
button {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  font-size: var(--text-small);
  font-family: var(--font-family);
  font-weight: 500;
  color: white;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

button svg {
  height: var(--text-small);
  width: var(--text-small);
}

button:hover {
  background-color: var(--color-primary-dark);
}

button:focus {
  outline: none;
  border-color: var(--color-accent);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.icon-loader {
  animation: spin 1s linear infinite;
}
  
button.primary {
  background-color: var(--color-primary);
}

button.primary:hover {
  background-color: var(--color-primary-dark);
}
  
button.secondary {
  background-color: unset;
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
}
  
button.secondary:hover {
  background-color: var(--color-background-muted);
  border: 1px solid var(--color-primary-dark);
  color: var(--color-primary-dark);
}
  
button.danger {
  background-color: var(--color-error);
}

button.danger:hover {
  background-color: var(--color-error-dark);
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}
</style>