-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathIconGridRow.vue
More file actions
100 lines (90 loc) · 1.99 KB
/
IconGridRow.vue
File metadata and controls
100 lines (90 loc) · 1.99 KB
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
<script setup>
import { computed, onMounted } from 'vue';
import { toolbarIcons } from './toolbarIcons.js';
const emit = defineEmits(['select']);
const props = defineProps({
icons: {
type: Array,
required: true,
},
activeColor: {
type: Object,
required: false,
},
});
const isActive = computed(() => (option) => {
if (!props.activeColor.value) return false;
return props.activeColor.value.toUpperCase() === option.value;
});
const getCheckStyle = (color, optionIndex) => {
const lightColors = ['#FFFFFF', '#FAFF09'];
if (optionIndex === 5 || lightColors.includes(color)) return { color: '#000' };
return { color: '#FFF' };
};
const handleClick = (option) => {
emit('select', option.value);
};
onMounted(() => {
const isMatrix = props.icons.every((row) => Array.isArray(row));
if (!isMatrix) throw new Error('icon props must be 2d array');
});
</script>
<template>
<div
class="option-row"
v-for="(row, rowIndex) in icons"
:key="rowIndex"
role="group"
>
<div
class="option"
v-for="(option, optionIndex) in row"
:key="optionIndex"
:aria-label="option.label"
role="menuitem"
@click.stop.prevent="handleClick(option)"
>
<div
class="option__icon"
v-html="option.icon"
:style="option.style">
</div>
<div
v-if="isActive(option)"
class="option__check"
v-html="toolbarIcons.colorOptionCheck"
:style="getCheckStyle(option.value, optionIndex)">
</div>
</div>
</div>
</template>
<style scoped>
.option-row {
display: flex;
flex-direction: row;
}
.option {
border-radius: 50%;
cursor: pointer;
padding: 3px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-sizing: border-box;
}
.option:hover {
background-color: #dbdbdb;
}
.option__icon {
width: 20px;
height: 20px;
flex-shrink: 0;
}
.option__check {
width: 14px;
height: 14px;
flex-shrink: 0;
position: absolute;
}
</style>