Skip to content

Commit d169683

Browse files
author
Amir Ghezelbash
committed
3: Styling React Components
1 parent 1c1af22 commit d169683

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

src/components/App/App.module.css

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.wrapper {
2+
display: flex;
3+
align-items: center;
4+
flex-direction: column;
5+
}
6+
7+
.title {
8+
color: #294e80;
9+
}
10+
11+
.postsWrapper {
12+
width: 270px;
13+
}

src/components/App/App.tsx

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import React from "react";
22

3-
interface Post {
4-
title: string;
5-
description: string;
6-
author: string;
7-
isPublished: boolean;
8-
}
3+
import Post, { PostProps } from "../post/Post";
4+
import classNames from "./App.module.css";
95

10-
const posts: Post[] = [
6+
const posts: PostProps[] = [
117
{
128
title: "example post",
139
description: "some text",
@@ -30,17 +26,11 @@ const posts: Post[] = [
3026

3127
const App: React.FC = () => {
3228
return (
33-
<div>
34-
<h1>Hello typescript tv!</h1>
35-
<div>
29+
<div className={classNames.wrapper}>
30+
<h1 className={classNames.title}>Hello typescript tv!</h1>
31+
<div className={classNames.postsWrapper}>
3632
{posts.map((post) => (
37-
<div key={post.title}>
38-
<p>title: {post.title}</p>
39-
<p>description: {post.description}</p>
40-
<p>author: {post.author}</p>
41-
<p>isPublished: {post.isPublished ? "True" : "False"}</p>
42-
<hr />
43-
</div>
33+
<Post key={post.title} {...post} />
4434
))}
4535
</div>
4636
</div>

src/components/post/Post.module.css

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.title {
2+
color: red;
3+
}
4+
5+
.description {
6+
color: purple;
7+
}
8+
9+
.author {
10+
color: orange;
11+
}
12+
13+
.isPublished {
14+
color: blue;
15+
}

src/components/post/Post.tsx

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from "react";
2+
import classNames from "./Post.module.css";
3+
4+
export interface PostProps {
5+
title: string;
6+
description: string;
7+
author: string;
8+
isPublished: boolean;
9+
}
10+
11+
const Post: React.FC<PostProps> = ({
12+
title,
13+
description,
14+
author,
15+
isPublished,
16+
}) => {
17+
return (
18+
<div key={title}>
19+
<p className={classNames.title}>title: {title}</p>
20+
<p className={classNames.description}>description: {description}</p>
21+
<p className={classNames.author}>author: {author}</p>
22+
<p className={classNames.isPublished}>
23+
isPublished: {isPublished ? "True" : "False"}
24+
</p>
25+
<hr />
26+
</div>
27+
);
28+
};
29+
30+
export default Post;

0 commit comments

Comments
 (0)