Skip to content

Commit c6e354c

Browse files
authored
Merge pull request #161 from Web-Dev-Path/feat/add-styled-components
Added styled-components
2 parents 1aeef12 + 4888c33 commit c6e354c

File tree

10 files changed

+308
-139
lines changed

10 files changed

+308
-139
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
8585

8686
- Blog page which pulls content from dev.to
8787
- Search functionality for blog posts
88+
- Styled components to Title component
8889

8990
### Fixed
9091

components/blog/BlogPostsContainer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ const BlogPostsContainer = ({
3232
<RevealContentContainer>
3333
<div className={styles.blogContainer}>
3434
{heading ? (
35-
<Title customClass='blogTitle' title={heading} />
35+
<Container>
36+
<Title title={heading} />
37+
</Container>
3638
) : tag ? (
37-
<Title customClass='blogTitle' title={tagToHeading[tag]} />
39+
<Container>
40+
<Title title={tagToHeading[tag]} />
41+
</Container>
3842
) : null}
3943
{
4044
// put in rows of 3 if more than 3 posts (for swipable cards)

components/snippets/Title.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import styles from '@/styles/Title.module.scss';
1+
import styled from 'styled-components';
22

3-
const Title = ({ title, customClass }) => {
4-
return (
5-
<h2
6-
className={
7-
customClass ? `${styles.title} ${styles[customClass]}` : styles.title
8-
}
9-
>
10-
{title}
11-
</h2>
12-
);
3+
export const StyledTitle = styled.h2`
4+
align-self: flex-start;
5+
margin: '0 auto 1rem';
6+
`;
7+
8+
const Title = ({ title }) => {
9+
return <StyledTitle>{title}</StyledTitle>;
1310
};
1411

1512
export default Title;

next.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,26 @@ module.exports = withPWA({
1919
},
2020
],
2121
},
22+
compiler: {
23+
// see https://styled-components.com/docs/tooling#babel-plugin for more info on the options.
24+
styledComponents:
25+
true |
26+
{
27+
// Enabled by default in development, disabled in production to reduce file size,
28+
// setting this will override the default for all environments.
29+
displayName: true,
30+
// Enabled by default.
31+
ssr: true,
32+
// Enabled by default.
33+
fileName: true,
34+
// Empty by default.
35+
topLevelImportPaths: '',
36+
// Defaults to ["index"].
37+
meaninglessFileNames: '',
38+
// Enabled by default.
39+
cssProp: true,
40+
// Empty by default.
41+
namespace: '',
42+
},
43+
},
2244
});

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,24 @@
2121
"dependencies": {
2222
"@sendgrid/mail": "^7.7.0",
2323
"html-entities": "^2.3.2",
24-
"next": "^13.0.5",
24+
"next": "^13.1.6",
2525
"next-pwa": "^5.5.4",
2626
"react": "^18.2.0",
2727
"react-dom": "^18.2.0",
2828
"react-google-recaptcha": "^2.1.0",
2929
"react-hook-form": "^7.35.0",
3030
"react-mailchimp-subscribe": "^2.1.3",
3131
"sass": "^1.35.1",
32+
"styled-components": "^5.3.6",
3233
"swiper": "^8.2.2"
3334
},
3435
"devDependencies": {
3536
"husky": "^8.0.0",
3637
"lint-staged": "^13.0.3",
3738
"prettier": "^2.7.1",
3839
"prettylint": "^1.0.0"
40+
},
41+
"resolutions": {
42+
"styled-components": "^5"
3943
}
4044
}

pages/blog/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState } from 'react';
22
import BlogPostsContainer from '@/components/blog/BlogPostsContainer';
3+
import Container from '@/components/containers/Container';
34
import SearchBar from '@/components/blog/SearchBar';
45
import Title from '@/components/snippets/Title';
56
import styles from '@/styles/Blog.module.scss';
@@ -27,10 +28,13 @@ export default function Blog({ posts }) {
2728

2829
return (
2930
<>
30-
<div className={styles.blogSearch}>
31-
<Title customClass='blogTitle' title={!searchTerm && 'Latest Posts'} />
32-
<SearchBar setSearchTerm={setSearchTerm} />
33-
</div>
31+
<Container>
32+
<div className={styles.blogSearch}>
33+
<Title blogTitle title={!searchTerm && 'Latest Posts'} />
34+
<SearchBar setSearchTerm={setSearchTerm} />
35+
</div>
36+
</Container>
37+
3438
<BlogPostsContainer {...filteredData} />
3539
{!searchTerm &&
3640
Object.keys(tagToHeading).map(tag => (

styles/Blog.module.scss

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323

2424
.blogSearch {
2525
display: flex;
26-
align-items: center;
2726
padding-top: 2.5rem;
28-
margin: 0 auto;
29-
width: 90%;
30-
max-width: $large-desktop-breakpoint;
27+
justify-content: space-between;
28+
flex-direction: column-reverse;
29+
align-items: flex-start;
3130

32-
@include mobile {
33-
flex-direction: column-reverse;
34-
align-items: flex-start;
31+
@include desktop {
32+
align-items: center;
33+
flex-direction: row;
3534
}
3635
}
3736

styles/SearchBar.module.scss

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
.searchBar {
55
display: flex;
66
justify-content: space-between;
7-
width: 19rem;
87
height: 2.5rem;
98
border-radius: 0.5rem;
109
border: 0;
1110
box-shadow: 2px 4px 8px 3px rgba(0, 0, 0, 0.08);
1211
font-size: 1.2rem;
12+
width: 100%;
13+
margin-top: 3rem;
1314

14-
@include mobile {
15-
width: 80%;
16-
margin: 3rem auto;
15+
@include desktop {
16+
width: 24rem;
17+
margin: unset;
1718
}
1819

1920
input[type='search'] {

styles/Title.module.scss

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)