mirror of https://github.com/grafana/grafana
VizLegend: move onSeriesColorChanged to PanelContext (breaking change) (#33611)
parent
578283078b
commit
6b0417207d
@ -1,32 +1,41 @@ |
|||||||
import React from 'react'; |
import React, { useCallback } from 'react'; |
||||||
import { SeriesColorPicker } from '../ColorPicker/ColorPicker'; |
import { SeriesColorPicker } from '../ColorPicker/ColorPicker'; |
||||||
|
import { usePanelContext } from '../PanelChrome'; |
||||||
import { SeriesIcon } from './SeriesIcon'; |
import { SeriesIcon } from './SeriesIcon'; |
||||||
|
|
||||||
interface Props { |
interface Props { |
||||||
disabled: boolean; |
seriesName: string; |
||||||
color: string; |
color: string; |
||||||
onColorChange: (color: string) => void; |
|
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* @internal |
* @internal |
||||||
*/ |
*/ |
||||||
export const VizLegendSeriesIcon: React.FunctionComponent<Props> = ({ disabled, color, onColorChange }) => { |
export const VizLegendSeriesIcon: React.FunctionComponent<Props> = ({ seriesName, color }) => { |
||||||
return disabled ? ( |
const { onSeriesColorChange } = usePanelContext(); |
||||||
<SeriesIcon color={color} /> |
const onChange = useCallback( |
||||||
) : ( |
(color: string) => { |
||||||
<SeriesColorPicker color={color} onChange={onColorChange} enableNamedColors> |
return onSeriesColorChange!(seriesName, color); |
||||||
{({ ref, showColorPicker, hideColorPicker }) => ( |
}, |
||||||
<SeriesIcon |
[seriesName, onSeriesColorChange] |
||||||
color={color} |
|
||||||
className="pointer" |
|
||||||
ref={ref} |
|
||||||
onClick={showColorPicker} |
|
||||||
onMouseLeave={hideColorPicker} |
|
||||||
/> |
|
||||||
)} |
|
||||||
</SeriesColorPicker> |
|
||||||
); |
); |
||||||
|
|
||||||
|
if (seriesName && onSeriesColorChange) { |
||||||
|
return ( |
||||||
|
<SeriesColorPicker color={color} onChange={onChange} enableNamedColors> |
||||||
|
{({ ref, showColorPicker, hideColorPicker }) => ( |
||||||
|
<SeriesIcon |
||||||
|
color={color} |
||||||
|
className="pointer" |
||||||
|
ref={ref} |
||||||
|
onClick={showColorPicker} |
||||||
|
onMouseLeave={hideColorPicker} |
||||||
|
/> |
||||||
|
)} |
||||||
|
</SeriesColorPicker> |
||||||
|
); |
||||||
|
} |
||||||
|
return <SeriesIcon color={color} />; |
||||||
}; |
}; |
||||||
|
|
||||||
VizLegendSeriesIcon.displayName = 'VizLegendSeriesIcon'; |
VizLegendSeriesIcon.displayName = 'VizLegendSeriesIcon'; |
||||||
|
Loading…
Reference in new issue