mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
This commit is contained in:
parent
3c52139ce5
commit
ae82a4b279
@ -29,9 +29,11 @@ export function withColorPicker(Component) {
|
|||||||
};
|
};
|
||||||
const eleRef = useRef();
|
const eleRef = useRef();
|
||||||
const pickrObj = useRef();
|
const pickrObj = useRef();
|
||||||
|
const onChangeRef = useRef(onChange);
|
||||||
|
const onSaveRef = useRef(onSave);
|
||||||
|
|
||||||
const setColor = (newVal) => {
|
const setColor = (newVal, silent) => {
|
||||||
pickrObj.current?.setColor((_.isUndefined(newVal) || newVal == '') ? pickrOptions.defaultColor : newVal);
|
pickrObj.current?.setColor((_.isUndefined(newVal) || newVal == '') ? pickrOptions.defaultColor : newVal, silent);
|
||||||
};
|
};
|
||||||
|
|
||||||
const destroyPickr = () => {
|
const destroyPickr = () => {
|
||||||
@ -95,9 +97,9 @@ export function withColorPicker(Component) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).on('clear', () => {
|
}).on('clear', () => {
|
||||||
onChange?.('');
|
onChangeRef.current?.('');
|
||||||
}).on('change', (color) => {
|
}).on('change', (color) => {
|
||||||
onChange?.(color.toHEXA().toString());
|
onChangeRef.current?.(color.toHEXA().toString());
|
||||||
}).on('show', (color, instance) => {
|
}).on('show', (color, instance) => {
|
||||||
const { palette } = instance.getRoot().palette;
|
const { palette } = instance.getRoot().palette;
|
||||||
palette.focus();
|
palette.focus();
|
||||||
@ -106,10 +108,10 @@ export function withColorPicker(Component) {
|
|||||||
button.focus();
|
button.focus();
|
||||||
}).on('save', (color, instance) => {
|
}).on('save', (color, instance) => {
|
||||||
if(color) {
|
if(color) {
|
||||||
color.toHEXA().toString() != fullHexColor(value) && onSave?.(color.toHEXA().toString());
|
color.toHEXA().toString() != fullHexColor(value) && onSaveRef.current?.(color.toHEXA().toString());
|
||||||
instance?.hide();
|
instance?.hide();
|
||||||
} else {
|
} else {
|
||||||
onSave?.('');
|
onSaveRef.current?.('');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -126,10 +128,10 @@ export function withColorPicker(Component) {
|
|||||||
}, [...Object.values(pickrOptions)]);
|
}, [...Object.values(pickrOptions)]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (pickrObj.current && !pickrOptions.allowSave) {
|
if (pickrObj.current) {
|
||||||
setColor(value);
|
setColor(value, true);
|
||||||
}
|
}
|
||||||
}, [value, pickrOptions.allowSave]);
|
}, [value]);
|
||||||
|
|
||||||
return <Component ref={eleRef} {...props}/>;
|
return <Component ref={eleRef} {...props}/>;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user