Files
grafana/public/app/features/admin/ServerStatsCard.tsx
Ashley Harrison 47f8717149 React: Use new JSX transform (#88802)
* update eslint, tsconfig + esbuild to handle new jsx transform

* remove thing that breaks the new jsx transform

* remove react imports

* adjust grafana-icons build

* is this the correct syntax?

* try this

* well this was much easier than expected...

* change grafana-plugin-configs webpack config

* fixes

* fix lockfile

* fix 2 more violations

* use path.resolve instead of require.resolve

* remove react import

* fix react imports

* more fixes

* remove React import

* remove import React from docs

* remove another react import
2024-06-25 12:43:47 +01:00

68 lines
1.8 KiB
TypeScript

import { css, cx } from '@emotion/css';
import Skeleton from 'react-loading-skeleton';
import { GrafanaTheme2 } from '@grafana/data';
import { Card, Stack, useStyles2, Tooltip, Icon } from '@grafana/ui';
interface StatItem {
name: string;
value: string | number | undefined;
tooltip?: string;
highlight?: boolean;
indent?: boolean;
}
export interface Props {
content: StatItem[];
isLoading?: boolean;
footer?: JSX.Element | boolean;
}
export const ServerStatsCard = ({ content, footer, isLoading }: Props) => {
const styles = useStyles2(getStyles);
return (
<Card className={styles.container}>
{content.map((item, index) => (
<Stack key={index} justifyContent="space-between" alignItems="center">
<Stack alignItems={'center'}>
<span className={cx({ [styles.indent]: !!item.indent })}>{item.name}</span>
{item.tooltip && (
<Tooltip content={String(item.tooltip)} placement="auto-start">
<Icon name="info-circle" className={styles.tooltip} />
</Tooltip>
)}
</Stack>
{isLoading ? (
<Skeleton width={60} />
) : (
<span className={item.highlight ? styles.highlight : ''}>{item.value}</span>
)}
</Stack>
))}
{footer && <div>{footer}</div>}
</Card>
);
};
const getStyles = (theme: GrafanaTheme2) => {
return {
container: css({
display: 'flex',
flexDirection: 'column',
gap: theme.spacing(2),
padding: theme.spacing(2),
}),
indent: css({
marginLeft: theme.spacing(2),
}),
tooltip: css({
color: theme.colors.secondary.text,
}),
highlight: css({
color: theme.colors.warning.text,
padding: `${theme.spacing(0.5)} ${theme.spacing(1)}`,
marginRight: `-${theme.spacing(1)}`,
}),
};
};