Article card
A card with a picture space, a badge, a title, a short preview and the author.
A card with a picture space, a badge, a title, a short preview and the author.
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
* Changed for Tastebud: the photo is a plain block, the author photo is initials, the badge gradient is
* blue to cyan, and the sample copy is new.
*/
import { IconBookmarkFilled, IconHeartFilled, IconShare2 } from '@tabler/icons-react';
import { ActionIcon, Avatar, Badge, Box, Card, Group, Text } from '@mantine/core';
import classes from './ArticleCard.module.css';
interface ArticleCardData {
title: string;
description: string;
authorName: string;
rating: string;
link: string;
}
const data: ArticleCardData = {
title: 'A week of drawing on paper first',
description:
'I sketched every screen on paper for a week before opening a design tool. The ideas came faster, I threw more of them away, and the ones I kept were clearer. Here is what I learned and what I will keep doing.',
authorName: 'Bill Wormeater',
rating: 'outstanding',
link: '#',
};
export function ArticleCard() {
return (
<Card withBorder radius="md" className={classes.card}>
<Card.Section component="a" href={data.link} target="_blank" rel="noreferrer">
<Box h={180} bg="gray.2" className={classes.image} aria-hidden />
</Card.Section>
<Badge
className={classes.rating}
variant="gradient"
gradient={{ from: 'blue', to: 'cyan', deg: 145 }}
>
{data.rating}
</Badge>
<Text
className={classes.title}
component="a"
href={data.link}
target="_blank"
rel="noreferrer"
>
{data.title}
</Text>
<Text fz="sm" lineClamp={4} opacity={0.9}>
{data.description}
</Text>
<Group justify="space-between" className={classes.footer}>
<Group gap="xs">
<Avatar name={data.authorName} size={24} alt={data.authorName} />
<Text fz="sm">{data.authorName}</Text>
</Group>
<Group gap={8}>
<ActionIcon className={classes.action} aria-label="Like">
<IconHeartFilled size={16} color="var(--mantine-color-red-6)" />
</ActionIcon>
<ActionIcon className={classes.action} aria-label="Bookmark">
<IconBookmarkFilled size={16} color="var(--mantine-color-yellow-7)" />
</ActionIcon>
<ActionIcon className={classes.action} aria-label="Share">
<IconShare2 size={16} color="var(--mantine-color-cyan-6)" />
</ActionIcon>
</Group>
</Group>
</Card>
);
}
/**
* 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
* Changed for Tastebud: Mantine's PostCSS shorthands (@mixin, $mantine-breakpoint-*) are written out as
* plain CSS, so it runs without postcss-preset-mantine; headings use the theme font instead of Outfit.
*/
.card {
position: relative;
background-color: var(--mantine-color-body);
overflow: visible;
}
.rating {
position: absolute;
top: var(--mantine-spacing-xs);
right: 12px;
pointer-events: none;
}
.title {
display: block;
font-family: var(--mantine-font-family);
margin-top: var(--mantine-spacing-md);
margin-bottom: 7px;
color: var(--mantine-color-bright);
font-weight: 500;
}
.image {
border-top-left-radius: var(--mantine-radius-md);
border-top-right-radius: var(--mantine-radius-md);
margin-left: -1px;
margin-right: -1px;
margin-top: -1px;
width: calc(100% + 2px);
}
.action {
background-color: light-dark(var(--mantine-color-gray-0), var(--mantine-color-dark-5));
&:hover {
background-color: light-dark(var(--mantine-color-gray-1), var(--mantine-color-dark-6));
}
}
.footer {
margin-top: var(--mantine-spacing-md);
}
Changed for this site: The photo is a plain block, the author photo is initials, the badge gradient is blue to cyan, and the sample copy is new. Mantine's PostCSS shorthands (@mixin, $mantine-breakpoint-*) are written out as plain CSS, so it runs without postcss-preset-mantine; headings use the theme font instead of Outfit.