mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Canvas: Add support for selecting the button variant (#74782)
This commit is contained in:
@@ -91,7 +91,7 @@ const contentTypeOptions: SelectableValue[] = [
|
||||
];
|
||||
|
||||
export function APIEditor({ value, context, onChange }: Props) {
|
||||
const LABEL_WIDTH = 9;
|
||||
const LABEL_WIDTH = 13;
|
||||
|
||||
if (!value) {
|
||||
value = defaultApiConfig;
|
||||
@@ -185,16 +185,17 @@ export function APIEditor({ value, context, onChange }: Props) {
|
||||
</InlineFieldRow>
|
||||
{value?.method === HttpRequestMethod.POST && (
|
||||
<>
|
||||
<Field label="Content-Type">
|
||||
<Select
|
||||
minMenuHeight={200}
|
||||
options={contentTypeOptions}
|
||||
allowCustomValue={true}
|
||||
formatCreateLabel={formatCreateLabel}
|
||||
value={value?.contentType}
|
||||
onChange={onContentTypeChange}
|
||||
/>
|
||||
</Field>
|
||||
<InlineFieldRow>
|
||||
<InlineField label="Content-Type" labelWidth={LABEL_WIDTH} grow={true}>
|
||||
<Select
|
||||
options={contentTypeOptions}
|
||||
allowCustomValue={true}
|
||||
formatCreateLabel={formatCreateLabel}
|
||||
value={value?.contentType}
|
||||
onChange={onContentTypeChange}
|
||||
/>
|
||||
</InlineField>
|
||||
</InlineFieldRow>
|
||||
{value?.contentType && (
|
||||
<Field label="Payload">
|
||||
<StringValueEditor
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import React, { useCallback } from 'react';
|
||||
|
||||
import { SelectableValue, StandardEditorProps } from '@grafana/data';
|
||||
import { ButtonVariant, InlineField, InlineFieldRow, Select } from '@grafana/ui';
|
||||
import { defaultStyleConfig } from 'app/features/canvas/elements/button';
|
||||
|
||||
export interface ButtonStyleConfig {
|
||||
variant: ButtonVariant;
|
||||
}
|
||||
|
||||
type Props = StandardEditorProps<ButtonStyleConfig>;
|
||||
|
||||
const variantOptions: SelectableValue[] = [
|
||||
{ label: 'primary', value: 'primary' },
|
||||
{ label: 'secondary', value: 'secondary' },
|
||||
{ label: 'success', value: 'success' },
|
||||
{ label: 'destructive', value: 'destructive' },
|
||||
];
|
||||
|
||||
export const ButtonStyleEditor = ({ value, onChange }: Props) => {
|
||||
if (!value) {
|
||||
value = defaultStyleConfig;
|
||||
}
|
||||
|
||||
const onVariantChange = useCallback(
|
||||
(variant: SelectableValue<ButtonVariant>) => {
|
||||
onChange({
|
||||
...value,
|
||||
variant: variant?.value ?? defaultStyleConfig.variant,
|
||||
});
|
||||
},
|
||||
[onChange, value]
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<InlineFieldRow>
|
||||
<InlineField label="Variant" grow={true}>
|
||||
<Select options={variantOptions} value={value?.variant} onChange={onVariantChange} />
|
||||
</InlineField>
|
||||
</InlineFieldRow>
|
||||
</>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user