Skip to content

Commit 1cffb92

Browse files
committed
add tags to card
1 parent 8a304d9 commit 1cffb92

File tree

6 files changed

+38
-3
lines changed

6 files changed

+38
-3
lines changed

components/blog/BlogPostsContainer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Title from '@/components/snippets/Title';
44
import Link from 'next/link';
55
import styles from '@/styles/Blog.module.scss';
66
import RevealContentContainer from '@/components/containers/RevealContentContainer';
7+
import { tagToHeading } from '@/utils/blogCategories';
78

89
function* splitPosts(arr, n) {
910
for (let i = 0; i < arr.length; i += n) {
@@ -23,7 +24,11 @@ const BlogPostsContainer = ({ posts, heading, tag, swipe = true }) => {
2324
return (
2425
<RevealContentContainer>
2526
<div className={styles.blogContainer}>
26-
{heading ? <Title customClass='blogTitle' title={heading} /> : null}
27+
{heading ? (
28+
<Title customClass='blogTitle' title={heading} />
29+
) : tag ? (
30+
<Title customClass='blogTitle' title={tagToHeading[tag]} />
31+
) : null}
2732
{
2833
// put in rows of 3 if more than 3 posts (for swipable cards)
2934
swipe ? (

components/blog/Tag.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import styles from '@/styles/Blog.module.scss';
2+
3+
const Tag = ({ text }) => {
4+
return <div className={styles.tag}>{text}</div>;
5+
};
6+
7+
export default Tag;

components/containers/Card.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import Image from 'next/image';
22
import Link from 'next/link';
33
import styles from '@/styles/Card.module.scss';
4+
import Tag from '@/components/blog/Tag';
45

56
export default function Card({
6-
card: { image, altTag, title, content, link, linkText },
7+
card: { image, altTag, title, content, link, linkText, tagList },
78
customClass,
89
}) {
910
const LinkComponent = link?.startsWith('http') ? (
@@ -28,6 +29,13 @@ export default function Card({
2829
<h2 className={styles.title} title={title}>
2930
{title}
3031
</h2>
32+
{tagList && tagList.length > 0 ? (
33+
<div className={styles.tagListContainer}>
34+
{tagList.map((tag, i) => (
35+
<Tag key={i} text={tag} />
36+
))}
37+
</div>
38+
) : null}
3139
<div className={styles.content}>
3240
<p>
3341
{content} {link && LinkComponent}

styles/Blog.module.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@
5050
.postContainer > div:last-child:nth-child(3n + 1) {
5151
margin: 1.5rem auto 0 16%;
5252
}
53+
54+
.tag {
55+
background-color: $light-bg-color;
56+
padding: 0.5rem 1rem;
57+
border-radius: 2rem;
58+
font-weight: bold;
59+
}

styles/Card.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,10 @@
131131
overflow: hidden;
132132
}
133133
}
134+
135+
.tagListContainer {
136+
display: flex;
137+
gap: 0.5rem;
138+
margin-bottom: -1rem;
139+
}
134140
}

styles/SearchBar.module.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.searchBar {
55
display: flex;
66
justify-content: space-between;
7-
width: 15rem;
7+
width: 19rem;
88
height: 2.5rem;
99
border-radius: 0.5rem;
1010
border: 0;
@@ -32,6 +32,7 @@
3232
height: 100%;
3333
border: 0;
3434
padding-left: 1rem;
35+
width: 16rem;
3536
}
3637

3738
button[type='submit'] {
@@ -43,5 +44,6 @@
4344
background-size: cover;
4445
background-repeat: no-repeat;
4546
margin: 0.5rem 1rem 0.5rem 0;
47+
cursor: pointer;
4648
}
4749
}

0 commit comments

Comments
 (0)