-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathSimpleButton.vue
93 lines (83 loc) · 2.6 KB
/
SimpleButton.vue
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
<script setup lang="ts">
import { generateRandomMultiple } from "@/services/utils";
import { onBeforeMount, ref } from "vue";
interface ButtonProps {
label?: string;
icon?: string;
isPrimary?: boolean;
isInline?: boolean;
}
const props = withDefaults(defineProps<ButtonProps>(), { isPrimary: false });
const randomBackgroundOffsetX = ref(0);
const randomBackgroundOffsetY = ref(0);
function randomizeBackground() {
randomBackgroundOffsetX.value = generateRandomMultiple(3, 0, 300);
randomBackgroundOffsetY.value = generateRandomMultiple(3, 0, 300);
}
onBeforeMount(() => {
randomizeBackground();
});
</script>
<template>
<button
class="button"
:class="[props.isPrimary ? 'primary' : 'regular', props.isInline ? 'inline' : '']"
@mouseover="randomizeBackground"
:style="`
--background-offset-x: ${randomBackgroundOffsetX}px;
--background-offset-y: ${randomBackgroundOffsetY}px;
`"
>
<span v-if="props.icon" :class="props.icon" class="icon"></span>
<span v-if="props.label" class="label">
{{ props.label }}
</span>
</button>
</template>
<style scoped>
.button {
display: inline-block;
flex: none;
flex-direction: row;
align-items: center;
justify-content: center;
border-radius: var(--border-radius);
box-shadow:
0 2px 6px rgb(0 0 0 / 9%),
0 2px 4px rgb(0 0 0 / 25%),
inset 0 1px 4.3px rgb(255 226 199 / 84%);
color: var(--button-color);
cursor: pointer;
&.primary {
padding: var(--spacing-padding-small) var(--spacing-padding-normal);
border: solid 1px rgb(from var(--button-background-color) h s calc(l + 10%));
background-color: var(--button-background-color);
background-image: linear-gradient(to bottom, transparent, var(--button-background-color)),
url("../assets/images/button-background.png");
background-position:
var(--background-offset-x) var(--background-offset-y),
0;
font-size: var(--text-size-highlight);
font-weight: var(--text-weight-highlight);
}
&.regular {
padding: calc(var(--spacing-padding-small) * 0.6) var(--spacing-padding-small);
border: var(--border-width-normal) solid var(--border-color-elevated);
border-radius: var(--border-radius);
margin: 0 auto;
background: var(--border-color-lower);
box-shadow: inset 0 0 3.24px 2.4px rgb(var(--text-color-highlight) 0.5);
color: var(--text-color-normal);
font-size: var(--text-size-small);
font-weight: var(--text-weight-normal);
}
&.inline {
border: none;
background: none;
box-shadow: none;
}
.icon:has(+ .label) {
padding-right: var(--spacing-padding-small);
}
}
</style>