Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Story] Homepage - add BlogPost component #3

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"lint:auto": "yarn eslint ./src/** --fix --no-color && yarn prettier --write --no-color ."
},
"dependencies": {
"antd": "^4.21.6",
"@chakra-ui/react": "^2.2.4",
"@emotion/react": "^11.9.3",
"@emotion/styled": "^11.9.3",
"framer-motion": "^6.5.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-dom": "^6.3.0"
Expand Down
42 changes: 42 additions & 0 deletions src/components/BlogPost.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import { Box, Center, Heading, Text, Stack, Image } from '@chakra-ui/react';
import { Post } from '../types/types';

// TODO: fix image
IloveNooodles marked this conversation as resolved.
Show resolved Hide resolved
const BlogPost: React.FC<Post> = (props) => {
const { title, date, author, description, imageUrl, link } = props;
return (
<Center className="py-6">
<Box
maxW="450px"
w="full"
overflow="hidden"
className="bg-LightBrown rounded-md shadow-l p-6"
>
<Box h="275px" className="-mt-6 -mx-6 mb-6 relative">
<Image src={imageUrl} h="275px" w="450px" />
</Box>
<Stack>
<Text className="font-Subheading text-caption font-normal">
{date} | Posted by {author}
</Text>
<Heading className="font-Heading text-h6 font-semibold">
{title}
</Heading>
<Text className="font-Body text-body font-normal">
{description}
</Text>
</Stack>
<Stack direction="row" spacing={4} className="mt-6 center">
<Stack direction="column" spacing={0}>
<Text className="font-Caption text-caption font-semibold">
<a href={link}>Read More</a>
</Text>
</Stack>
</Stack>
</Box>
</Center>
);
};

export default BlogPost;
45 changes: 26 additions & 19 deletions src/pages/Homepage/Homepage.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import React from 'react';
import { HomepageProps } from '../../types/interface';
import { useToggle } from '../../hooks/useToggle';
import BlogPost from '../../components/BlogPost';
import Post from '../../types/types';

const Homepage: React.FC<HomepageProps> = (props) => {
const { text } = props;
const [isOn, toggle] = useToggle();

return (
<div
style={
isOn ? { backgroundColor: 'green' } : { backgroundColor: 'red' }
}
>
<p>Halo semuanya ini homepage</p>
<p>{text}</p>
<button onClick={toggle} type="button">
Click me
</button>
</div>
);
const listOfPosts: Post[] = [
{
title: 'Post Title',
date: '19 Jul 2022',
author: 'Mamet KAT ITB',
imageUrl:
'https://images.unsplash.com/photo-1515378791036-0648a3ef77b2?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80',
link: '#',
description:
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.',
},
];
const Homepage: React.FC<{}> = () => {
const blogPostElements = listOfPosts.map((item: Post) => (
<BlogPost
title={item.title}
date={item.date}
author={item.author}
description={item.description}
imageUrl={item.imageUrl}
link={item.link}
/>
));
return <>{blogPostElements}</>;
};

export default Homepage;
15 changes: 12 additions & 3 deletions src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// export type Post = {
// name: string;
// detail: string;
// link: string;
// };

export type Post = {
name: string;
detail: string;
link: string;
title: string;
date: string;
author: string;
description: string;
imageUrl: string;
link: string; // link to detail post
};
2 changes: 2 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module.exports = {
Orange: '#FFA06E',
LightOrange: '#F9D7AA',
Brown: '#66402C',
LightBrown: '#FFECD0',
MediumOrange: '#FFB965',
},
fontFamily: {
Heading: 'Magilio',
Expand Down
Loading