aboutsummaryrefslogtreecommitdiffstats
path: root/components/base/TrueFalseSwitch.vue
blob: 46a9d9a48f10e5f632b6a28fb729e8ca33a835ed (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
<script setup lang="ts">
import { ref } from 'vue';

const props = defineProps<{
  value: boolean;
}>();
const emit = defineEmits(['update']);

const value = ref(props.value);

const invert = () => {
  value.value = !value.value;
  emit('update', value.value);
};
</script>

<template>
  <div class="switch" @click="invert">
    <span v-if="value" class="true"><font-awesome-icon :icon="['fas', 'check']" /> True</span>
    <span v-else class="false"><font-awesome-icon :icon="['fas', 'xmark']" /> False</span>
  </div>
</template>

<style scoped>
.switch {
  display: flex;
  width: 100%;
  height: 100%;
  cursor: pointer;
  align-items: center;
  padding: 0.5rem;
  user-select: none;
  transition: background-color 0.3s;
  background-color: var(--color-background-soft);

  span {
    font-family: monospace;
    font-size: 0.8rem;
  }

  .true {
    color: var(--color-text-primary);
  }

  .false {
    color: var(--color-false);
  }

  &:hover {
    background-color: var(--color-hover);
  }
}
</style>