|
1 | 1 | <script setup lang="ts"> |
| 2 | + import { computed } from 'vue'; |
| 3 | +
|
2 | 4 | interface Props { |
3 | 5 | modelValue: boolean; |
4 | 6 | editable?: boolean; |
| 7 | + changeable?: boolean; |
5 | 8 | infoText?: string; |
6 | 9 | label?: string; |
| 10 | + enabledIcon: string; |
| 11 | + disabledIcon: string; |
7 | 12 | } |
8 | 13 |
|
9 | 14 | const props = withDefaults(defineProps<Props>(), { |
10 | 15 | editable: true, |
| 16 | + changeable: true, |
11 | 17 | infoText: '', |
12 | 18 | label: undefined, |
13 | 19 | }); |
14 | 20 |
|
| 21 | + const isInteractive = computed(() => props.editable && props.changeable); |
| 22 | +
|
15 | 23 | const emit = defineEmits<{ |
16 | 24 | (e: 'update:modelValue', value: boolean): void; |
17 | 25 | }>(); |
18 | 26 |
|
19 | | - function toggleReminder(): void { |
20 | | - if (props.editable) { |
| 27 | + function toggleValue(): void { |
| 28 | + if (isInteractive.value) { |
21 | 29 | emit('update:modelValue', !props.modelValue); |
22 | 30 | } |
23 | 31 | } |
|
26 | 34 | <template> |
27 | 35 | <div |
28 | 36 | class="info-box relative flex cursor-pointer flex-row items-center" |
29 | | - :class="{ 'cursor-not-allowed': !editable }" |
| 37 | + :class="{ 'cursor-not-allowed': !isInteractive }" |
30 | 38 | > |
31 | | - <div v-if="editable" class="flex items-center" @click="toggleReminder"> |
| 39 | + <div v-if="isInteractive" class="flex items-center" @click="toggleValue"> |
32 | 40 | <div class="icon-box reminder"> |
33 | 41 | <span |
34 | 42 | class="pi cursor-pointer" |
35 | | - :class="modelValue ? 'pi-bell' : 'pi-bell-slash'" |
| 43 | + :class="modelValue ? `${enabledIcon}` : `${disabledIcon}`" |
36 | 44 | /> |
37 | 45 | </div> |
38 | 46 | </div> |
|
41 | 49 | class="pi" |
42 | 50 | :class=" |
43 | 51 | modelValue |
44 | | - ? 'pi-bell color-approved' |
45 | | - : 'pi-bell-slash color-important' |
| 52 | + ? `${enabledIcon} color-approved` |
| 53 | + : `${disabledIcon} color-important` |
46 | 54 | " |
47 | 55 | /> |
48 | 56 | </div> |
49 | | - <div v-if="infoText" class="inline"> |
50 | | - <div |
51 | | - class="info-box-hidden pointer-events-none absolute bottom-full right-0 bg-white p-5 text-center opacity-0" |
52 | | - > |
53 | | - {{ infoText }} |
54 | | - </div> |
55 | | - </div> |
56 | 57 | <span v-if="label" class="ml-2 inline"> |
57 | 58 | <slot name="label"> |
58 | 59 | {{ label }} |
59 | 60 | </slot> |
60 | 61 | </span> |
61 | 62 | <i |
62 | 63 | class="pi pi-info-circle color-primary mx-1" |
63 | | - :class="{ 'me-2': editable }" |
| 64 | + :class="{ 'me-2': isInteractive }" |
64 | 65 | /> |
| 66 | + <div |
| 67 | + v-if="infoText" |
| 68 | + class="info-box-hidden pointer-events-none absolute bottom-full bg-white p-5 text-center opacity-0" |
| 69 | + > |
| 70 | + {{ infoText }} |
| 71 | + </div> |
65 | 72 | </div> |
66 | 73 | </template> |
67 | 74 |
|
68 | 75 | <style scoped lang="postcss"> |
69 | 76 | .info-box { |
70 | 77 | &-hidden { |
71 | | - width: 20vw; |
| 78 | + width: max-content; |
| 79 | + max-width: 300px; |
72 | 80 | border: 1px solid var(--bluegray-200); |
73 | 81 | transition: ease-in-out opacity 0.25s; |
74 | 82 | box-shadow: 1px 1px 5px var(--bluegray-200); |
| 83 | + left: 0; |
| 84 | + white-space: normal; |
| 85 | + z-index: 100000; |
| 86 | + margin-bottom: 0.5rem; |
75 | 87 | } |
76 | 88 |
|
77 | 89 | &:hover { |
|
0 commit comments