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

71 lines
1.8 KiB
TypeScript
Raw Normal View History

import React, { memo } from 'react';
import { css } from '@emotion/css';
import { GrafanaTheme2 } from '@grafana/data';
import { useStyles2 } from '@grafana/ui';
2020-01-20 06:32:28 -06:00
const getStyles = (theme: GrafanaTheme2) => ({
2020-01-20 06:32:28 -06:00
metaContainer: css`
flex: 1;
color: ${theme.colors.text.secondary};
margin-bottom: ${theme.spacing(2)};
2020-01-20 06:32:28 -06:00
min-width: 30%;
display: flex;
flex-wrap: wrap;
2020-01-20 06:32:28 -06:00
`,
metaItem: css`
margin-right: ${theme.spacing(2)};
margin-top: ${theme.spacing(0.5)};
2020-01-20 06:32:28 -06:00
display: flex;
align-items: baseline;
.logs-meta-item__error {
color: ${theme.colors.error.text};
}
2020-01-20 06:32:28 -06:00
`,
metaLabel: css`
margin-right: calc(${theme.spacing(2)} / 2);
font-size: ${theme.typography.bodySmall.fontSize};
font-weight: ${theme.typography.fontWeightMedium};
2020-01-20 06:32:28 -06:00
`,
metaValue: css`
font-family: ${theme.typography.fontFamilyMonospace};
font-size: ${theme.typography.bodySmall.fontSize};
2020-01-20 06:32:28 -06:00
`,
});
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
}
export 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 className={style.metaItem}>
{label && <span className={style.metaLabel}>{label}:</span>}
<span className={style.metaValue}>{value}</span>
</div>
);
});
export interface MetaInfoTextProps {
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}>
{metaItems.map((item, index) => (
<MetaInfoItem key={`${index}-${item.label}`} label={item.label} value={item.value} />
))}
</div>
);
});
export default MetaInfoText;