Skip to content

Commit

Permalink
feat: update headlines component (#71)
Browse files Browse the repository at this point in the history
- Add news story
- Support cards as config
  • Loading branch information
amalv authored Nov 19, 2019
1 parent 306b723 commit 0e9b130
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 36 deletions.
Binary file added public/displays.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/electronics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/game.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/games.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/mac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/playstation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
62 changes: 61 additions & 1 deletion src/components/Headlines.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,64 @@ export default {
title: "Headlines",
};

export const Default: React.FC = () => <Headlines>Top Categories</Headlines>;
const cardsCategories = {
data: [
{
title: "Tablets",
subtitle: "Subtitle",
image: "./tablets.png",
},
{
title: "Electronics",
subtitle: "Subtitle",
image: "./electronics.png",
},
{
title: "Displays",
subtitle: "Subtitle",
image: "./displays.png",
},
{
title: "Games",
subtitle: "Subtitle",
image: "./games.png",
},
],
};

const cardsNews = {
data: [
{
title: "Mobile",
subtitle: "Subtitle",
image: "./mobile.png",
},
{
title: "New Mac",
subtitle: "Subtitle",
image: "./mac.png",
},
{
title: "New Game",
subtitle: "Subtitle",
image: "./game.png",
},
{
title: "Playstation",
subtitle: "Subtitle",
image: "./playstation.png",
},
],
};

export const Categories: React.FC = () => (
<Headlines
title="Top categories"
linkName="See all categories"
cards={cardsCategories}
/>
);

export const News: React.FC = () => (
<Headlines title="News" linkName="See all news" cards={cardsNews} />
);
8 changes: 6 additions & 2 deletions src/components/Headlines.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export interface PaperStyledProps {
padding?: string | number | undefined;
}

export interface HeadlineCardImageProps {
image: string;
}

export const HeadlineCard = styled(Paper)`
width: 76px;
height: 115px;
Expand Down Expand Up @@ -46,11 +50,11 @@ export const HeadlineCardSubtitle = styled(Typography)`
font-weight: 400;
`;

export const HeadlineCardImage = styled.div`
export const HeadlineCardImage = styled.div<HeadlineCardImageProps>`
margin: auto;
width: 70px;
height: 70px;
background-image: url("./tabletHeadlineCard.png");
background-image: url(${({ image }): string => image});
background-position: center;
background-size: cover;
`;
Expand Down
55 changes: 22 additions & 33 deletions src/components/Headlines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,48 @@ import {
import { Icon } from "./Icon";

export interface HeadlineProps {
children: React.ReactNode;
title: string;
linkName: string;
cards: Record<string, any>;
}

export const Headlines: React.FC<HeadlineProps> = ({
children,
title,
linkName,
cards,
}: HeadlineProps) => {
const theme = useTheme();
return (
<StylesProvider injectFirst>
<Box width="344px" height="207px">
<Box height="207px">
<PaperStyled padding={theme.spacing(1)}>
<Grid spacing={2} container direction="column">
<Grid item>
<Grid justify="space-between" container>
<Title color="primary">{children}</Title>
<Title color="primary">{title}</Title>
<Icon color="rgba(0, 0, 0, 0.6)" icon="share" />
</Grid>
</Grid>
<Grid item>
<Grid spacing={1} justify="center" container>
<Grid item>
<HeadlineCard>
<HeadlineCardImage />
<HeadlineCardTitle>Tablets</HeadlineCardTitle>
<HeadlineCardSubtitle>Subtitle</HeadlineCardSubtitle>
</HeadlineCard>
</Grid>
<Grid item>
<HeadlineCard>
<HeadlineCardImage />
<HeadlineCardTitle>Tablets</HeadlineCardTitle>
<HeadlineCardSubtitle>Subtitle</HeadlineCardSubtitle>
</HeadlineCard>
</Grid>
<Grid item>
<HeadlineCard>
<HeadlineCardImage />
<HeadlineCardTitle>Tablets</HeadlineCardTitle>
<HeadlineCardSubtitle>Subtitle</HeadlineCardSubtitle>
</HeadlineCard>
</Grid>
<Grid item>
<HeadlineCard>
<HeadlineCardImage />
<HeadlineCardTitle>Tablets</HeadlineCardTitle>
<HeadlineCardSubtitle>Subtitle</HeadlineCardSubtitle>
</HeadlineCard>
</Grid>
{cards.data.map((card: any) => (
<React.Fragment key={card.title}>
<Grid item>
<HeadlineCard>
<HeadlineCardImage image={card.image} />
<HeadlineCardTitle>{card.title}</HeadlineCardTitle>
<HeadlineCardSubtitle>
{card.subtitle}
</HeadlineCardSubtitle>
</HeadlineCard>
</Grid>
</React.Fragment>
))}
</Grid>
</Grid>
<Grid item>
<Grid container justify="flex-end">
<HeadlineCardLink>See all categories</HeadlineCardLink>
<HeadlineCardLink>{linkName}</HeadlineCardLink>
</Grid>
</Grid>
</Grid>
Expand Down

1 comment on commit 0e9b130

@vercel
Copy link

@vercel vercel bot commented on 0e9b130 Nov 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.