grafana/public/app/features/explore/MetaInfoText.tsx

69 lines
1.8 KiB
TypeScript
Raw Normal View History

import { css } from '@emotion/css';
import React, { memo } from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { useStyles2 } from '@grafana/ui';
2020-01-20 06:32:28 -06:00
const getStyles = (theme: GrafanaTheme2) => ({
metaContainer: css({
flex: 1,
color: theme.colors.text.secondary,
marginBottom: theme.spacing(2),
minWidth: '30%',
display: 'flex',
flexWrap: 'wrap',
}),
metaItem: css({
marginRight: theme.spacing(2),
marginTop: theme.spacing(0.5),
display: 'flex',
alignItems: 'center',
['.logs-meta-item__error']: {
color: theme.colors.error.text,
},
}),
metaLabel: css({
marginRight: `calc(${theme.spacing(2)} / 2)`,
fontSize: theme.typography.bodySmall.fontSize,
fontWeight: theme.typography.fontWeightMedium,
}),
metaValue: css({
fontFamily: theme.typography.fontFamilyMonospace,
fontSize: theme.typography.bodySmall.fontSize,
}),
});
2020-01-20 06:32:28 -06:00
export interface MetaItemProps {
2020-01-20 06:32:28 -06:00
label?: string;
value: string | JSX.Element;
2020-01-20 06:32:28 -06:00
}
const MetaInfoItem = memo(function MetaInfoItem(props: MetaItemProps) {
const style = useStyles2(getStyles);
2020-01-20 06:32:28 -06:00
const { label, value } = props;
return (
<div data-testid="meta-info-text-item" className={style.metaItem}>
2020-01-20 06:32:28 -06:00
{label && <span className={style.metaLabel}>{label}:</span>}
<span className={style.metaValue}>{value}</span>
</div>
);
});
interface MetaInfoTextProps {
2020-01-20 06:32:28 -06:00
metaItems: MetaItemProps[];
}
export const MetaInfoText = memo(function MetaInfoText(props: MetaInfoTextProps) {
const style = useStyles2(getStyles);
2020-01-20 06:32:28 -06:00
const { metaItems } = props;
return (
<div className={style.metaContainer} data-testid="meta-info-text">
2020-01-20 06:32:28 -06:00
{metaItems.map((item, index) => (
<MetaInfoItem key={`${index}-${item.label}`} label={item.label} value={item.value} />
))}
</div>
);
});