Skip to content

Commit 6c0c8dd

Browse files
Covert Tag into a styted-component
1 parent 6c5da54 commit 6c0c8dd

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

components/blog/Tag.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
import styles from '@/styles/Blog.module.scss';
21
import Link from 'next/link';
2+
import styled from 'styled-components';
33

4-
const Tag = ({ text }) => {
5-
return (
6-
<Link className={styles.tag} href={`/blog/category/${text}`}>
7-
{text}
8-
</Link>
9-
);
10-
};
4+
export const TagContainer = styled.div`
5+
display: flex;
6+
flex-wrap: wrap;
7+
max-height: 12rem;
8+
overflow: hidden;
9+
gap: 0.5rem;
10+
margin-bottom: -1rem;
11+
a {
12+
text-decoration: none;
13+
}
14+
`;
15+
16+
const TagLink = styled(Link)`
17+
background-color: #8cd5e8;
18+
padding: 0.5rem 1rem;
19+
border-radius: 2rem;
20+
font-weight: bold;
21+
`;
1122

12-
export default Tag;
23+
export const Tag = ({ text }) => {
24+
return <TagLink href={`/blog/category/${text}`}>{text}</TagLink>;
25+
};

components/containers/Card.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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';
4+
import { Tag, TagContainer } from '@/components/blog/Tag';
55

66
export default function Card({
77
card: { image, altTag, title, content, link, linkText, tagList },
@@ -30,11 +30,11 @@ export default function Card({
3030
{title}
3131
</h2>
3232
{tagList && tagList.length > 0 ? (
33-
<div className={styles.tagListContainer}>
33+
<TagContainer>
3434
{tagList.slice(0, 8).map((tag, i) => (
3535
<Tag key={i} text={tag} />
3636
))}
37-
</div>
37+
</TagContainer>
3838
) : null}
3939
<div className={styles.content}>
4040
<p>

styles/Blog.module.scss

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,18 @@
5151
justify-content: center;
5252
margin-bottom: 3rem;
5353

54-
@include mobile {
55-
justify-content: center;
56-
}
57-
5854
@include tablet {
59-
justify-content: space-between;
60-
}
61-
62-
@include desktop {
6355
justify-content: flex-start;
6456
}
6557
}
6658

6759
.postContainer > div {
68-
@include mobile {
69-
flex-basis: 100%;
70-
}
71-
72-
@include tablet {
73-
flex-basis: 43%;
60+
@include desktop {
61+
flex-basis: 48%;
7462
}
7563

76-
@include desktop {
64+
@include large-desktop {
7765
flex-basis: 32%;
78-
max-width: 200px;
7966
}
8067
}
8168

@@ -89,11 +76,3 @@
8976
content: unset;
9077
}
9178
}
92-
93-
.tag {
94-
background-color: $light-bg-color;
95-
padding: 0.5rem 1rem;
96-
border-radius: 2rem;
97-
font-weight: bold;
98-
text-decoration: none !important;
99-
}

0 commit comments

Comments
 (0)