diff --git a/public/app/core/components/OptionsUI/color.tsx b/public/app/core/components/OptionsUI/color.tsx index dcbb9137d48..8494e5f32a7 100644 --- a/public/app/core/components/OptionsUI/color.tsx +++ b/public/app/core/components/OptionsUI/color.tsx @@ -2,26 +2,35 @@ import { css } from '@emotion/css'; import React from 'react'; import { GrafanaTheme2 } from '@grafana/data'; -import { useTheme2, useStyles2, ColorPicker } from '@grafana/ui'; +import { useTheme2, useStyles2, ColorPicker, IconButton } from '@grafana/ui'; import { ColorSwatch } from '@grafana/ui/src/components/ColorPicker/ColorSwatch'; -/** - * @alpha - * */ -export interface ColorValueEditorProps { +export interface ColorValueEditorSettings { + placeholder?: string; + /** defaults to true */ + enableNamedColors?: boolean; + /** defaults to false */ + isClearable?: boolean; +} + +interface Props { value?: string; - onChange: (value: string) => void; + onChange: (value: string | undefined) => void; + settings?: ColorValueEditorSettings; + + // Will show placeholder or details + details?: boolean; } /** * @alpha * */ -export const ColorValueEditor: React.FC = ({ value, onChange }) => { +export const ColorValueEditor = ({ value, settings, onChange, details }: Props) => { const theme = useTheme2(); const styles = useStyles2(getStyles); return ( - + {({ ref, showColorPicker, hideColorPicker }) => { return (
@@ -33,6 +42,20 @@ export const ColorValueEditor: React.FC = ({ value, onCha color={value ? theme.visualization.getColorByName(value) : theme.components.input.borderColor} />
+ {details && ( + <> + {value ? ( + + {value} + + ) : ( + + {settings?.placeholder ?? 'Select color'} + + )} + {settings?.isClearable && value && onChange(undefined)} />} + + )} ); }} @@ -43,6 +66,7 @@ export const ColorValueEditor: React.FC = ({ value, onCha const getStyles = (theme: GrafanaTheme2) => { return { spot: css` + cursor: pointer; color: ${theme.colors.text}; background: ${theme.components.input.background}; padding: 3px; @@ -51,6 +75,7 @@ const getStyles = (theme: GrafanaTheme2) => { display: flex; flex-direction: row; align-items: center; + align-content: flex-end; &:hover { border: 1px solid ${theme.components.input.borderHover}; } @@ -59,15 +84,11 @@ const getStyles = (theme: GrafanaTheme2) => { padding: 0 ${theme.spacing(1)}; `, colorText: css` - cursor: pointer; - flex-grow: 1; + flex-grow: 2; `, - trashIcon: css` - cursor: pointer; + placeholderText: css` + flex-grow: 2; color: ${theme.colors.text.secondary}; - &:hover { - color: ${theme.colors.text}; - } `, }; }; diff --git a/public/app/core/components/OptionsUI/registry.tsx b/public/app/core/components/OptionsUI/registry.tsx index 99fb0ea55d1..3f6fea77291 100644 --- a/public/app/core/components/OptionsUI/registry.tsx +++ b/public/app/core/components/OptionsUI/registry.tsx @@ -33,7 +33,7 @@ import { ThresholdsValueEditor } from 'app/features/dimensions/editors/Threshold import { ValueMappingsEditor } from 'app/features/dimensions/editors/ValueMappingsEditor/ValueMappingsEditor'; import { DashboardPicker, DashboardPickerOptions } from './DashboardPicker'; -import { ColorValueEditor } from './color'; +import { ColorValueEditor, ColorValueEditorSettings } from './color'; import { FieldColorEditor } from './fieldColor'; import { DataLinksValueEditor } from './links'; import { MultiSelectValueEditor } from './multiSelect'; @@ -117,12 +117,14 @@ export const getAllOptionEditors = () => { editor: UnitValueEditor as any, }; - const color: StandardEditorsRegistryItem = { + const color: StandardEditorsRegistryItem = { id: 'color', name: 'Color', description: 'Allows color selection', editor(props) { - return ; + return ( + + ); }, }; diff --git a/public/app/features/dashboard/components/AnnotationSettings/AnnotationSettingsEdit.tsx b/public/app/features/dashboard/components/AnnotationSettings/AnnotationSettingsEdit.tsx index a38024b58c6..03593b13562 100644 --- a/public/app/features/dashboard/components/AnnotationSettings/AnnotationSettingsEdit.tsx +++ b/public/app/features/dashboard/components/AnnotationSettings/AnnotationSettingsEdit.tsx @@ -58,10 +58,10 @@ export const AnnotationSettingsEdit = ({ editIdx, dashboard }: Props) => { }); }; - const onColorChange = (color: string) => { + const onColorChange = (color?: string) => { onUpdate({ ...annotation, - iconColor: color, + iconColor: color!, }); };