@grafana/ui
Version:
Grafana Components Library
76 lines (73 loc) • 2.46 kB
JavaScript
import { jsxs, jsx } from 'react/jsx-runtime';
import { identityOverrideProcessor, FieldType } from '@grafana/data';
import { t } from '@grafana/i18n';
import { StackingMode } from '@grafana/schema';
import { RadioButtonGroup } from '../../components/Forms/RadioButtonGroup/RadioButtonGroup.mjs';
import { IconButton } from '../../components/IconButton/IconButton.mjs';
import { Input } from '../../components/Input/Input.mjs';
import { Stack } from '../../components/Layout/Stack/Stack.mjs';
import { getGraphFieldOptions } from '../../components/uPlot/config.mjs';
const StackingEditor = ({
value,
context,
onChange,
item
}) => {
var _a, _b;
return /* @__PURE__ */ jsxs(Stack, { children: [
/* @__PURE__ */ jsx(
RadioButtonGroup,
{
value: (value == null ? void 0 : value.mode) || StackingMode.None,
options: (_b = (_a = item.settings) == null ? void 0 : _a.options) != null ? _b : [],
onChange: (v) => {
onChange({
...value,
mode: v
});
}
}
),
context.isOverride && (value == null ? void 0 : value.mode) && (value == null ? void 0 : value.mode) !== StackingMode.None && /* @__PURE__ */ jsx(
Input,
{
type: "text",
placeholder: t("grafana-ui.stacking-builder.group", "Group"),
suffix: /* @__PURE__ */ jsx(
IconButton,
{
name: "question-circle",
tooltip: t("grafana-ui.stacking-builder.group-tooltip", "Name of the stacking group"),
tooltipPlacement: "top"
}
),
defaultValue: value == null ? void 0 : value.group,
onChange: (v) => {
onChange({
...value,
group: v.currentTarget.value.trim()
});
}
}
)
] });
};
function addStackingConfig(builder, defaultConfig, category = ["Graph styles"]) {
const graphFieldOptions = getGraphFieldOptions();
builder.addCustomEditor({
id: "stacking",
path: "stacking",
name: t("grafana-ui.builder.stacking.name-stack-series", "Stack series"),
category,
defaultValue: defaultConfig,
editor: StackingEditor,
override: StackingEditor,
settings: {
options: graphFieldOptions.stacking
},
process: identityOverrideProcessor,
shouldApply: (f) => f.type === FieldType.number
});
}
export { StackingEditor, addStackingConfig };
//# sourceMappingURL=stacking.mjs.map