@grafana/ui
Version:
Grafana Components Library
55 lines (50 loc) • 1.96 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var i18n = require('@grafana/i18n');
var ColorPicker = require('../ColorPicker/ColorPicker.cjs');
require('../PanelChrome/index.cjs');
var SeriesIcon = require('./SeriesIcon.cjs');
var PanelContext = require('../PanelChrome/PanelContext.cjs');
;
const VizLegendSeriesIcon = React.memo(({ seriesName, color, gradient, readonly, lineStyle }) => {
const { onSeriesColorChange } = PanelContext.usePanelContext();
const onChange = React.useCallback(
(color2) => {
return onSeriesColorChange(seriesName, color2);
},
[seriesName, onSeriesColorChange]
);
if (seriesName && onSeriesColorChange && color && !readonly) {
return /* @__PURE__ */ jsxRuntime.jsx(ColorPicker.SeriesColorPicker, { color, onChange, enableNamedColors: true, children: ({ ref, showColorPicker, hideColorPicker, isOpen }) => {
function handleKeyDown(e) {
if (e.key === " " || e.key === "Enter") {
e.preventDefault();
showColorPicker();
}
}
return /* @__PURE__ */ jsxRuntime.jsx(
SeriesIcon.SeriesIcon,
{
tabIndex: 0,
role: "button",
"aria-label": i18n.t("grafana-ui.viz-legend.color-picker", "Edit color for {{seriesName}}", { seriesName }),
"aria-haspopup": "menu",
"aria-expanded": isOpen,
color,
className: "pointer",
ref,
onClick: showColorPicker,
onKeyDown: handleKeyDown,
onMouseLeave: hideColorPicker,
lineStyle
}
);
} });
}
return /* @__PURE__ */ jsxRuntime.jsx(SeriesIcon.SeriesIcon, { color, gradient, lineStyle });
});
VizLegendSeriesIcon.displayName = "VizLegendSeriesIcon";
exports.VizLegendSeriesIcon = VizLegendSeriesIcon;
//# sourceMappingURL=VizLegendSeriesIcon.cjs.map