Stats grid
A grid of numbers, each with an icon and the change since last month.
A grid of numbers, each with an icon and the change since last month.
npm install @mantine/core @tabler/icons-react
First time with Mantine UI? Set it up once.
/**
* Component from Mantine UI, https://ui.mantine.dev
* MIT License, Copyright (c) 2022 Vitaly Rtischev. Full text: https://github.com/mantinedev/ui.mantine.dev/blob/master/LICENCE
*/
import {
IconArrowDownRight,
IconArrowUpRight,
IconCoin,
IconDiscount2,
IconReceipt2,
IconUserPlus,
} from '@tabler/icons-react';
import { Group, Paper, SimpleGrid, Text } from '@mantine/core';
import classes from './StatsGrid.module.css';
const icons = {
user: IconUserPlus,
discount: IconDiscount2,
receipt: IconReceipt2,
coin: IconCoin,
};
const data = [
{ title: 'Revenue', icon: 'receipt', value: '13,456', diff: 34 },
{ title: 'Profit', icon: 'coin', value: '4,145', diff: -13 },
{ title: 'Coupons usage', icon: 'discount', value: '745', diff: 18 },
{ title: 'New customers', icon: 'user', value: '188', diff: -30 },
] as const;
export function StatsGrid() {
const stats = data.map((stat) => {
const Icon = icons[stat.icon];
const DiffIcon = stat.diff > 0 ? IconArrowUpRight : IconArrowDownRight;
return (
<Paper withBorder p="md" radius="md" key={stat.title}>
<Group justify="space-between">
<Text size="xs" c="dimmed" className={classes.title}>
{stat.title}
</Text>
<Icon className={classes.icon} size={22} stroke={1.5} />
</Group>
<Group align="flex-end" gap="xs" mt={25}>
<Text className={classes.value}>{stat.value}</Text>
<Text c={stat.diff > 0 ? 'teal' : 'red'} fz="sm" fw={500} className={classes.diff}>
<span>{stat.diff}%</span>
<DiffIcon size={16} stroke={1.5} />
</Text>
</Group>
<Text fz="xs" c="dimmed" mt={7}>
Compared to previous month
</Text>
</Paper>
);
});
return (
<div className={classes.root}>
<SimpleGrid cols={{ base: 1, xs: 2, md: 4 }}>{stats}</SimpleGrid>
</div>
);
}
/**
* Component from Mantine UI, https://ui.mantine.dev
* MIT License, Copyright (c) 2022 Vitaly Rtischev. Full text: https://github.com/mantinedev/ui.mantine.dev/blob/master/LICENCE
*/
.root {
padding: calc(var(--mantine-spacing-xl) * 1.5);
}
.value {
font-size: 24px;
font-weight: 700;
line-height: 1;
}
.diff {
line-height: 1;
display: flex;
align-items: center;
}
.icon {
color: light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-3));
}
.title {
font-weight: 700;
text-transform: uppercase;
}