Skip to content

Commit

Permalink
Add additional dismissal mouse handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
turner committed Nov 6, 2024
1 parent e673730 commit 341e895
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions js/ui/components/genericColorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ function createAndPresentMoreColorsPicker(parent, colorHandler) {
editor: false,
editorFormat: 'rgb',
alpha: false,
// color: parent.style.backgroundColor,
color: parent.style.backgroundColor,
}

picker = new Picker(config)

// picker.onChange = (color) => {
// console.log(`color changes: hex ${ color.hex } rgba ${ color.rgba }`)
// };
picker.onChange = (color) => {
// console.log(`color changes: hex ${ color.hex } rgba ${ color.rgba }`)
parent.style.backgroundColor = color.rgba
};

picker.onDone = (color) => {

Expand All @@ -134,6 +135,20 @@ function createAndPresentMoreColorsPicker(parent, colorHandler) {
colorPickerContainer.remove()
}

function dismissPicker() {
picker.destroy()
colorPickerContainer.remove()
document.removeEventListener('click', onOutsideClick);
}

function onOutsideClick(event) {
if (!colorPickerContainer.contains(event.target) && parent !== event.target) {
dismissPicker();
}
}

document.addEventListener('click', onOutsideClick);

picker.show()
}

Expand Down

0 comments on commit 341e895

Please sign in to comment.