diff --git a/public/app/features/dimensions/editors/BackgroundSizeEditor.tsx b/public/app/features/dimensions/editors/BackgroundSizeEditor.tsx new file mode 100644 index 00000000000..27d12646d5d --- /dev/null +++ b/public/app/features/dimensions/editors/BackgroundSizeEditor.tsx @@ -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> = [ + { 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> = (props) => { + const { value, onChange } = props; + + const imageSize = value ?? BackgroundImageSize.Cover; + + const onImageSizeChange = useCallback( + (size) => { + onChange(size); + }, + [onChange] + ); + + return ( + + + + + + ); +}; diff --git a/public/app/plugins/panel/canvas/editor/options.ts b/public/app/plugins/panel/canvas/editor/options.ts index 53180363b96..2e81e17b821 100644 --- a/public/app/plugins/panel/canvas/editor/options.ts +++ b/public/app/plugins/panel/canvas/editor/options.ts @@ -1,15 +1,23 @@ import { PanelOptionsSupplier } from '@grafana/data/src/panel/PanelPlugin'; -import { BackgroundImageSize, CanvasElementOptions } from 'app/features/canvas'; +import { CanvasElementOptions } from 'app/features/canvas'; import { ColorDimensionEditor, ResourceDimensionEditor } from 'app/features/dimensions/editors'; +import { BackgroundSizeEditor } from 'app/features/dimensions/editors/BackgroundSizeEditor'; interface OptionSuppliers { addBackground: PanelOptionsSupplier; addBorder: PanelOptionsSupplier; } +const getCategoryName = (str: string, type: string | undefined) => { + if (type !== 'frame' && type !== undefined) { + return [str + ` (${type})`]; + } + return [str]; +}; + export const optionBuilder: OptionSuppliers = { addBackground: (builder, context) => { - const category = ['Background']; + const category = getCategoryName('Background', context.options?.type); builder .addCustomEditor({ category, @@ -33,25 +41,20 @@ export const optionBuilder: OptionSuppliers = { resourceType: 'image', }, }) - .addRadio({ + .addCustomEditor({ category, + id: 'background.size', path: 'background.size', name: 'Image size', + editor: BackgroundSizeEditor, settings: { - options: [ - { 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' }, - ], + resourceType: 'image', }, - defaultValue: BackgroundImageSize.Cover, }); }, addBorder: (builder, context) => { - const category = ['Border']; + const category = getCategoryName('Border', context.options?.type); builder.addSliderInput({ category, path: 'border.width',