ColorPicker: Remove deprecated onColorChange prop (#49923)
This commit is contained in:
@@ -8,7 +8,7 @@ import { closePopover } from '../../utils/closePopover';
|
|||||||
import { Popover } from '../Tooltip/Popover';
|
import { Popover } from '../Tooltip/Popover';
|
||||||
import { PopoverController } from '../Tooltip/PopoverController';
|
import { PopoverController } from '../Tooltip/PopoverController';
|
||||||
|
|
||||||
import { ColorPickerPopover, ColorPickerProps, ColorPickerChangeHandler } from './ColorPickerPopover';
|
import { ColorPickerPopover, ColorPickerProps } from './ColorPickerPopover';
|
||||||
import { ColorSwatch } from './ColorSwatch';
|
import { ColorSwatch } from './ColorSwatch';
|
||||||
import { SeriesColorPickerPopover } from './SeriesColorPickerPopover';
|
import { SeriesColorPickerPopover } from './SeriesColorPickerPopover';
|
||||||
|
|
||||||
@@ -34,19 +34,12 @@ export const colorPickerFactory = <T extends ColorPickerProps>(
|
|||||||
static displayName = displayName;
|
static displayName = displayName;
|
||||||
pickerTriggerRef = createRef<any>();
|
pickerTriggerRef = createRef<any>();
|
||||||
|
|
||||||
onColorChange = (color: string) => {
|
|
||||||
const { onColorChange, onChange } = this.props;
|
|
||||||
const changeHandler = (onColorChange || onChange) as ColorPickerChangeHandler;
|
|
||||||
|
|
||||||
return changeHandler(color);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { theme, children } = this.props;
|
const { theme, children, onChange } = this.props;
|
||||||
const styles = getStyles(theme);
|
const styles = getStyles(theme);
|
||||||
const popoverElement = React.createElement(popover, {
|
const popoverElement = React.createElement(popover, {
|
||||||
...{ ...this.props, children: null },
|
...{ ...this.props, children: null },
|
||||||
onChange: this.onColorChange,
|
onChange,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { PopoverContentProps } from '../Tooltip';
|
|||||||
|
|
||||||
import { NamedColorsPalette } from './NamedColorsPalette';
|
import { NamedColorsPalette } from './NamedColorsPalette';
|
||||||
import SpectrumPalette from './SpectrumPalette';
|
import SpectrumPalette from './SpectrumPalette';
|
||||||
import { warnAboutColorPickerPropsDeprecation } from './warnAboutColorPickerPropsDeprecation';
|
|
||||||
|
|
||||||
export type ColorPickerChangeHandler = (color: string) => void;
|
export type ColorPickerChangeHandler = (color: string) => void;
|
||||||
|
|
||||||
@@ -18,10 +17,6 @@ export interface ColorPickerProps extends Themeable2 {
|
|||||||
color: string;
|
color: string;
|
||||||
onChange: ColorPickerChangeHandler;
|
onChange: ColorPickerChangeHandler;
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use onChange instead
|
|
||||||
*/
|
|
||||||
onColorChange?: ColorPickerChangeHandler;
|
|
||||||
enableNamedColors?: boolean;
|
enableNamedColors?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +43,6 @@ class UnThemedColorPickerPopover<T extends CustomPickersDescriptor> extends Reac
|
|||||||
this.state = {
|
this.state = {
|
||||||
activePicker: 'palette',
|
activePicker: 'palette',
|
||||||
};
|
};
|
||||||
warnAboutColorPickerPropsDeprecation('ColorPickerPopover', props);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getTabClassName = (tabName: PickerType | keyof T) => {
|
getTabClassName = (tabName: PickerType | keyof T) => {
|
||||||
@@ -57,12 +51,11 @@ class UnThemedColorPickerPopover<T extends CustomPickersDescriptor> extends Reac
|
|||||||
};
|
};
|
||||||
|
|
||||||
handleChange = (color: any) => {
|
handleChange = (color: any) => {
|
||||||
const { onColorChange, onChange, enableNamedColors, theme } = this.props;
|
const { onChange, enableNamedColors, theme } = this.props;
|
||||||
const changeHandler = onColorChange || onChange;
|
|
||||||
if (enableNamedColors) {
|
if (enableNamedColors) {
|
||||||
return changeHandler(color);
|
return onChange(color);
|
||||||
}
|
}
|
||||||
changeHandler(colorManipulator.asHexString(theme.visualization.getColorByName(color)));
|
onChange(colorManipulator.asHexString(theme.visualization.getColorByName(color)));
|
||||||
};
|
};
|
||||||
|
|
||||||
onTabChange = (tab: PickerType | keyof T) => {
|
onTabChange = (tab: PickerType | keyof T) => {
|
||||||
|
|||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
import { deprecationWarning } from '@grafana/data';
|
|
||||||
|
|
||||||
import { ColorPickerProps } from './ColorPickerPopover';
|
|
||||||
|
|
||||||
export const warnAboutColorPickerPropsDeprecation = (componentName: string, props: ColorPickerProps) => {
|
|
||||||
const { onColorChange } = props;
|
|
||||||
if (onColorChange) {
|
|
||||||
deprecationWarning(componentName, 'onColorChange', 'onChange');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user