Canvas: Fix duplicated option editors functionality (#53184)

Co-authored-by: nmarrs <nathanielmarrs@gmail.com>
This commit is contained in:
Adela Almasan
2022-08-03 14:49:35 -05:00
committed by GitHub
parent 4c02d072e3
commit d54e55ea9a
2 changed files with 49 additions and 12 deletions

View File

@@ -0,0 +1,34 @@
import React, { FC, useCallback } from 'react';
import { SelectableValue, StandardEditorProps } from '@grafana/data';
import { InlineField, InlineFieldRow, RadioButtonGroup } from '@grafana/ui/src';
import { BackgroundImageSize } from 'app/features/canvas';
const options: Array<SelectableValue<BackgroundImageSize>> = [
{ value: BackgroundImageSize.Original, label: 'Original' },
{ value: BackgroundImageSize.Contain, label: 'Contain' },
{ value: BackgroundImageSize.Cover, label: 'Cover' },
{ value: BackgroundImageSize.Fill, label: 'Fill' },
{ value: BackgroundImageSize.Tile, label: 'Tile' },
];
export const BackgroundSizeEditor: FC<StandardEditorProps<string, undefined, undefined>> = (props) => {
const { value, onChange } = props;
const imageSize = value ?? BackgroundImageSize.Cover;
const onImageSizeChange = useCallback(
(size) => {
onChange(size);
},
[onChange]
);
return (
<InlineFieldRow>
<InlineField grow={true}>
<RadioButtonGroup value={imageSize} options={options} onChange={onImageSizeChange} fullWidth />
</InlineField>
</InlineFieldRow>
);
};