From 341e89533064bea903cf87e3224a9a45a577c126 Mon Sep 17 00:00:00 2001 From: turner Date: Wed, 6 Nov 2024 17:29:09 -0500 Subject: [PATCH] Add additional dismissal mouse handlers --- js/ui/components/genericColorPicker.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/js/ui/components/genericColorPicker.js b/js/ui/components/genericColorPicker.js index f0a024c5f..b851f85c6 100644 --- a/js/ui/components/genericColorPicker.js +++ b/js/ui/components/genericColorPicker.js @@ -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) => { @@ -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() }