File tree Expand file tree Collapse file tree 1 file changed +79
-0
lines changed
Expand file tree Collapse file tree 1 file changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ <script setup>
2+ import { ref , computed , watch } from " vue" ;
3+ import BaseIcon from " ./BaseIcon.vue" ;
4+ import { adaptColorToBackground } from " ../lib" ;
5+
6+ const props = defineProps ({
7+ value: {
8+ type: String ,
9+ default: " #ffffff" ,
10+ },
11+ size: {
12+ type: String ,
13+ default: " 50px" ,
14+ },
15+ });
16+
17+ const emit = defineEmits ([" update:value" ]);
18+
19+ const colorPickerStyle = computed (() => ({
20+ backgroundColor: props .value ,
21+ width: ' 100%' ,
22+ height: ' 100%' ,
23+ cursor: " pointer" ,
24+ }));
25+
26+ const colorInput = ref (null );
27+
28+ const triggerColorPicker = () => {
29+ colorInput .value ? .click ();
30+ };
31+
32+ const updateColor = (event ) => {
33+ const newColor = event .target .value ;
34+ emit (" update:value" , newColor);
35+ };
36+
37+ const iconColor = computed (() => {
38+ return adaptColorToBackground (props .value );
39+ })
40+
41+ watch (
42+ () => props .value ,
43+ (newVal ) => {
44+ colorInput .value .value = newVal;
45+ }
46+ );
47+ < / script>
48+
49+ < template>
50+ < div : style= " colorPickerStyle" class = " color-picker-wrapper" @click= " triggerColorPicker" >
51+ < input ref= " colorInput" type= " color" : value= " value" class = " hidden-input" @input= " updateColor" / >
52+ < div class = " icon" >
53+ < BaseIcon name= " palette" : stroke= " iconColor" : size= " 22" / >
54+ < / div>
55+ < / div>
56+ < / template>
57+
58+ < style scoped>
59+ .hidden - input {
60+ visibility: hidden
61+ }
62+
63+ .color - picker- wrapper {
64+ display: inline- block;
65+ position: relative;
66+ cursor: pointer;
67+ }
68+
69+ .icon {
70+ position: absolute;
71+ top: 0 ;
72+ left: 0 ;
73+ height: 100 % ;
74+ width: 100 % ;
75+ display: flex;
76+ align- items: center;
77+ justify- content: center;
78+ }
79+ < / style>
You can’t perform that action at this time.
0 commit comments