mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
FieldConfig: implement color picker (#24833)
This commit is contained in:
parent
b703f21622
commit
57a9e422b0
@ -109,5 +109,7 @@ export const booleanOverrideProcessor = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface ColorFieldConfigSettings {
|
export interface ColorFieldConfigSettings {
|
||||||
enableNamedColors?: boolean;
|
allowUndefined?: boolean;
|
||||||
|
textWhenUndefined?: string; // Pick Color
|
||||||
|
disableNamedColors?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,80 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FieldConfigEditorProps, ColorFieldConfigSettings } from '@grafana/data';
|
import {
|
||||||
/* import { ColorPicker } from '../ColorPicker/ColorPicker'; */
|
FieldConfigEditorProps,
|
||||||
|
ColorFieldConfigSettings,
|
||||||
|
GrafanaTheme,
|
||||||
|
getColorFromHexRgbOrName,
|
||||||
|
} from '@grafana/data';
|
||||||
|
import { ColorPicker } from '../ColorPicker/ColorPicker';
|
||||||
|
import { getTheme, stylesFactory } from '../../themes';
|
||||||
|
import { Icon } from '../Icon/Icon';
|
||||||
|
import { css } from 'emotion';
|
||||||
|
import { ColorPickerTrigger } from '../ColorPicker/ColorPickerTrigger';
|
||||||
|
|
||||||
export const ColorValueEditor: React.FC<FieldConfigEditorProps<string, ColorFieldConfigSettings>> = ({
|
export const ColorValueEditor: React.FC<FieldConfigEditorProps<string, ColorFieldConfigSettings>> = ({
|
||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
item,
|
item,
|
||||||
}) => {
|
}) => {
|
||||||
return <div>todo</div>;
|
const { settings } = item;
|
||||||
|
const theme = getTheme();
|
||||||
|
const styles = getStyles(theme);
|
||||||
|
|
||||||
|
const color = value || (item.defaultValue as string) || theme.colors.panelBg;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ColorPicker color={color} onChange={onChange} enableNamedColors={!settings.disableNamedColors}>
|
||||||
|
{({ ref, showColorPicker, hideColorPicker }) => {
|
||||||
|
return (
|
||||||
|
<div className={styles.spot} onBlur={hideColorPicker}>
|
||||||
|
<div className={styles.colorPicker}>
|
||||||
|
<ColorPickerTrigger
|
||||||
|
ref={ref}
|
||||||
|
onClick={showColorPicker}
|
||||||
|
onMouseLeave={hideColorPicker}
|
||||||
|
color={getColorFromHexRgbOrName(color, theme.type)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className={styles.colorText} onClick={showColorPicker}>
|
||||||
|
{value ?? settings.textWhenUndefined ?? 'Pick Color'}
|
||||||
|
</div>
|
||||||
|
{value && settings.allowUndefined && (
|
||||||
|
<Icon className={styles.trashIcon} name="trash-alt" onClick={() => onChange(undefined)} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</ColorPicker>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getStyles = stylesFactory((theme: GrafanaTheme) => {
|
||||||
|
return {
|
||||||
|
spot: css`
|
||||||
|
color: ${theme.colors.text};
|
||||||
|
background: ${theme.colors.formInputBg};
|
||||||
|
padding: 3px;
|
||||||
|
border: 1px solid ${theme.colors.formInputBorder};
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
&:hover {
|
||||||
|
border: 1px solid ${theme.colors.formInputBorderHover};
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
colorPicker: css`
|
||||||
|
padding: 0 ${theme.spacing.sm};
|
||||||
|
`,
|
||||||
|
colorText: css`
|
||||||
|
cursor: pointer;
|
||||||
|
flex-grow: 1;
|
||||||
|
`,
|
||||||
|
trashIcon: css`
|
||||||
|
cursor: pointer;
|
||||||
|
color: ${theme.colors.textWeak};
|
||||||
|
&:hover {
|
||||||
|
color: ${theme.colors.text};
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user