import { createStyles } from '@mantine/core';
import dayjs from 'dayjs';
import { DataTable, uniqBy } from 'mantine-datatable';
import { employees } from '~/data';
const records = employees.slice(0, 10);
const useStyles = createStyles((theme) => ({
idColumnCells: { fontWeight: 700 },
birthdayColumnTitle: { '&&': { color: theme.colors.blue[6] } },
color: theme.colors.blue[6],
background: theme.fn.rgba(theme.colors.yellow[6], 0.25),
'&&': { color: theme.colors.red[6] },
background: theme.fn.rgba(theme.colors.yellow[6], 0.25),
export default function ColumnPropertiesExampleStyling() {
const { classes, cx } = useStyles();
cellsClassName: classes.idColumnCells,
render: (record) => records.indexOf(record) + 1,
cellsStyle: { fontStyle: 'italic' },
render: ({ firstName, lastName }) => `${firstName} ${lastName}`,
footer: `${records.length} employees`,
footerStyle: { fontStyle: 'italic' },
accessor: 'department.name',
titleSx: (theme) => ({ '&&': { color: theme.colors.green[6] } }),
color: theme.colors.green[8],
background: theme.fn.rgba(theme.colors.orange[6], 0.25),
accessor: 'department.company.name',
footer: `${uniqBy(records, (record) => record.department.company.name).length} companies`,
footerSx: (theme) => ({ '&&': { color: theme.colors.blue[6] } }),
titleClassName: classes.birthdayColumnTitle,
cellsClassName: ({ birthDate }) => cx({ [classes.birthdayInApril]: dayjs(birthDate).format('MM') === '04' }),
render: ({ birthDate }) => dayjs(birthDate).format('MMM D'),
titleStyle: { fontStyle: 'italic' },
cellsStyle: ({ birthDate }) =>
dayjs().diff(birthDate, 'years') <= 40
render: ({ birthDate }) => dayjs().diff(birthDate, 'years'),
footer: `Avg: ${Math.round(
records.map((record) => dayjs().diff(record.birthDate, 'years')).reduce((a, b) => a + b, 0) / records.length
footerClassName: classes.ageFooter,