import React from 'react'; import { DynamicConfigValue, FieldConfigOptionsRegistry, FieldOverrideContext, GrafanaTheme } from '@grafana/data'; import { FieldConfigItemHeaderTitle, selectThemeVariant, stylesFactory, useTheme } from '@grafana/ui'; import { css } from 'emotion'; interface DynamicConfigValueEditorProps { property: DynamicConfigValue; registry: FieldConfigOptionsRegistry; onChange: (value: DynamicConfigValue) => void; context: FieldOverrideContext; onRemove: () => void; } export const DynamicConfigValueEditor: React.FC = ({ property, context, registry, onChange, onRemove, }) => { const theme = useTheme(); const styles = getStyles(theme); const item = registry?.getIfExists(property.id); if (!item) { return null; } return (
{ onChange(value); }} item={item} context={context} />
); }; const getStyles = stylesFactory((theme: GrafanaTheme) => { const borderColor = selectThemeVariant( { light: theme.palette.gray85, dark: theme.palette.dark9, }, theme.type ); const highlightColor = selectThemeVariant( { light: theme.palette.blue95, dark: theme.palette.blue77, }, theme.type ); return { wrapper: css` border-top: 1px dashed ${borderColor}; position: relative; &:hover { &:before { background: ${highlightColor}; } } &:before { content: ''; position: absolute; top: 0; z-index: 1; left: -1px; width: 2px; height: 100%; transition: background 0.5s cubic-bezier(0.19, 1, 0.22, 1); } `, property: css` padding: ${theme.spacing.xs} ${theme.spacing.sm} ${theme.spacing.sm} ${theme.spacing.sm}; `, }; });