2020-02-14 20:46:08 +08:00
|
|
|
import React from 'react';
|
|
|
|
|
import { DynamicConfigValue, FieldConfigEditorRegistry, FieldOverrideContext, GrafanaTheme } from '@grafana/data';
|
2020-03-19 19:28:05 +08:00
|
|
|
import { FieldConfigItemHeaderTitle, selectThemeVariant, stylesFactory, useTheme } from '@grafana/ui';
|
2020-02-14 20:46:08 +08:00
|
|
|
|
|
|
|
|
import { css } from 'emotion';
|
|
|
|
|
interface DynamicConfigValueEditorProps {
|
|
|
|
|
property: DynamicConfigValue;
|
|
|
|
|
editorsRegistry: FieldConfigEditorRegistry;
|
|
|
|
|
onChange: (value: DynamicConfigValue) => void;
|
|
|
|
|
context: FieldOverrideContext;
|
|
|
|
|
onRemove: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const DynamicConfigValueEditor: React.FC<DynamicConfigValueEditorProps> = ({
|
|
|
|
|
property,
|
|
|
|
|
context,
|
|
|
|
|
editorsRegistry,
|
|
|
|
|
onChange,
|
|
|
|
|
onRemove,
|
|
|
|
|
}) => {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const styles = getStyles(theme);
|
|
|
|
|
const item = editorsRegistry?.getIfExists(property.prop);
|
2020-03-16 21:26:03 +08:00
|
|
|
|
|
|
|
|
if (!item) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-14 20:46:08 +08:00
|
|
|
return (
|
|
|
|
|
<div className={styles.wrapper}>
|
2020-03-19 19:28:05 +08:00
|
|
|
<FieldConfigItemHeaderTitle onRemove={onRemove} title={item.name} description={item.description} transparent>
|
|
|
|
|
<div className={styles.property}>
|
|
|
|
|
<item.override
|
|
|
|
|
value={property.value}
|
|
|
|
|
onChange={value => {
|
|
|
|
|
onChange(value);
|
|
|
|
|
}}
|
|
|
|
|
item={item}
|
|
|
|
|
context={context}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</FieldConfigItemHeaderTitle>
|
2020-02-14 20:46:08 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => {
|
|
|
|
|
const borderColor = selectThemeVariant(
|
|
|
|
|
{
|
|
|
|
|
light: theme.colors.gray85,
|
|
|
|
|
dark: theme.colors.dark9,
|
|
|
|
|
},
|
|
|
|
|
theme.type
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const highlightColor = selectThemeVariant(
|
|
|
|
|
{
|
|
|
|
|
light: theme.colors.blueLight,
|
|
|
|
|
dark: theme.colors.blueShade,
|
|
|
|
|
},
|
|
|
|
|
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};
|
|
|
|
|
`,
|
|
|
|
|
};
|
|
|
|
|
});
|