-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor-column.js
More file actions
90 lines (82 loc) · 2.83 KB
/
Copy pathcolor-column.js
File metadata and controls
90 lines (82 loc) · 2.83 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
const ColorColumn = {
props: ['color'],
emits: ['update:color', 'delete'],
setup(props, { emit }) {
const hexInput = ref(props.color);
const errorMessage = ref('');
const copyButtonText = ref('Copy to Clipboard');
const colorInput = ref(null);
// Computed property for color picker value
const colorInputValue = computed(() => expandShortHex(hexInput.value));
// Sync hexInput with prop changes
watch(() => props.color, (newColor) => {
hexInput.value = newColor;
errorMessage.value = '';
});
// Handle hex input changes
const handleHexInput = () => {
const hex = hexInput.value.trim();
if (isValidHex(hex)) {
emit('update:color', hex);
errorMessage.value = '';
} else if (hex === '') {
errorMessage.value = '';
} else {
errorMessage.value = 'Invalid hex color';
}
};
// Handle color picker changes
const handleColorPicker = (event) => {
const newColor = event.target.value;
hexInput.value = newColor;
emit('update:color', newColor);
errorMessage.value = '';
};
// Copy hex value to clipboard
const copyToClipboard = () => {
navigator.clipboard.writeText(hexInput.value)
.then(() => {
copyButtonText.value = 'Copied!';
setTimeout(() => {
copyButtonText.value = 'Copy to Clipboard';
}, 1000);
})
.catch(err => {
console.error('Failed to copy: ', err);
});
};
// Open color picker
const openColorPicker = () => {
colorInput.value.click();
};
return {
hexInput,
errorMessage,
copyButtonText,
colorInput,
colorInputValue,
handleHexInput,
handleColorPicker,
copyToClipboard,
openColorPicker,
deleteColumn: () => emit('delete')
};
},
template: `
<div class="column">
<div class="color-square">
<div class="color-fill" :style="{ backgroundColor: color }"></div>
</div>
<div class="controls">
<div class="button-group">
<button @click="openColorPicker">Change Colour</button>
<button @click="copyToClipboard">{{ copyButtonText }}</button>
</div>
<input v-model="hexInput" @input="handleHexInput" />
<div class="error-message" v-if="errorMessage">{{ errorMessage }}</div>
<button @click="deleteColumn">Delete Column</button>
<input type="color" :value="colorInputValue" ref="colorInput" @change="handleColorPicker" style="display: none;" />
</div>
</div>
`
};