Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bfadbda
feat: Card 컴포넌트 type 생성
hustle-dev Mar 23, 2022
0e30a94
feat: Card 폴더 및 간단한 파일 생성 - Issue #15
hustle-dev Mar 23, 2022
389f2ad
feat: Card 스타일링 - Issue #15
hustle-dev Mar 24, 2022
b95f094
feat: Card 스타일드 컴포넌트를 위한 타입 정의 - Issue #15
hustle-dev Mar 24, 2022
2643808
feat: Card 컴포넌트를 위한 utils 생성 - Issue #15
hustle-dev Mar 24, 2022
8e74cf7
feat: Card 컴포넌트 진행중 - Issue #15
hustle-dev Mar 24, 2022
f43ca63
fix: CookingInfo 컴포넌트 오타 수정
hustle-dev Mar 24, 2022
c6accfa
refactor: 스켈레톤 컴포넌트 스타일링 리팩토링
hustle-dev Mar 24, 2022
0b1b5d7
refactor: 스켈레톤 컴포넌트 스타일링 리팩토링 완료
hustle-dev Mar 24, 2022
b60591e
Merge branch 'develop' of https://github.com/TeamCooks/TwoSpoon into …
hustle-dev Mar 24, 2022
87651f5
refactor: 카드 style 리팩토링 - Issue #15
hustle-dev Mar 24, 2022
0a54042
Merge branch 'develop' into feature/generalCard
hustle-dev Mar 24, 2022
4eabf2f
feat: Card 컴포넌트 마이그레이션 - Issue #15
hustle-dev Mar 24, 2022
b52fa37
feat: Card 컴포넌트 1차 완료 - Issue #15
hustle-dev Mar 25, 2022
9251b51
Merge branch 'feature/generalCard' into develop
hustle-dev Mar 25, 2022
fb06c77
Merge branch 'develop' of https://github.com/TeamCooks/TwoSpoon into …
hustle-dev Mar 25, 2022
2659e46
fix: 필요없는 주석 삭제
hustle-dev Mar 25, 2022
9653813
feat: 랜덤 레시피 컴포넌트 초기 세팅 - Issue #12
hustle-dev Mar 25, 2022
fb51ce3
fix: 컨플릭트 해결
hustle-dev Mar 25, 2022
9a8809f
Merge branch 'develop' into feature/randomRecipe
hustle-dev Mar 25, 2022
c957d23
feat: RandomRecipe 스타일링 - Issue #12
hustle-dev Mar 25, 2022
512c6af
feat: RandomRecipe 커스텀 훅 생성 - Issue #12
hustle-dev Mar 25, 2022
60e2477
feat: RandomRecipe 1차 컴포넌트 마이그레이션 완료 - Issue #12
hustle-dev Mar 27, 2022
824e066
Merge branch 'feature/randomRecipe' into develop
hustle-dev Mar 27, 2022
522bd77
feat: HotRecipe 컴포넌트 초기 설정 - Issue #9
hustle-dev Mar 27, 2022
13b16d8
refactor: 쓸모없는 import 삭제
hustle-dev Mar 27, 2022
6ce44da
feat: HotRecipe 컴포넌트 스타일링 - Issue #9
hustle-dev Mar 27, 2022
92ba0fe
fix: Card sumamry 타입 선택적 매개변수로 변경
hustle-dev Mar 27, 2022
262672f
feat: HotRecipe 컴포넌트용 커스텀훅 생성 - Issue #9
hustle-dev Mar 27, 2022
e7a0ad5
feat: HotRecipe 컴포넌트 마이그레이션 1차 완료 - Issue #9
hustle-dev Mar 27, 2022
cb9b6b6
Merge branch 'feature/hotRecipe' into develop
hustle-dev Mar 27, 2022
1312fc8
fix: Card 쓸모없는 로직 제거
hustle-dev Mar 28, 2022
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
2 changes: 2 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const setRootPath = (_path) => path.resolve(process.cwd(), _path);

module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
staticDirs: ['../public'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/addon-a11y',
'storybook-addon-next-router',
],
framework: '@storybook/react',

Expand Down
26 changes: 24 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import ko from 'axe-core/locales/ko.json';
import React from 'react';
import { RouterContext } from 'next/dist/shared/lib/router-context';
import { GlobalStyle } from 'styles/GlobalStyle';
import { ThemeProvider } from '@emotion/react';
import { theme } from 'theme/theme';
import * as NextImage from 'next/image';
import { StoreProvider } from 'store';

export const decorators = [
(Story) => (
<ThemeProvider theme={theme}>
<GlobalStyle />
<Story />
<StoreProvider>
<GlobalStyle />
<Story />
</StoreProvider>
</ThemeProvider>
),
];

export const parameters = {
nextRouter: {
Provider: RouterContext.Provider,
},
a11y: {
config: { locale: ko },
},
Expand All @@ -25,3 +33,17 @@ export const parameters = {
},
},
};

const OriginalNextImage = NextImage.default;

Object.defineProperty(NextImage, 'default', {
configurable: true,
value: (props) => (
<OriginalNextImage
{...props}
unoptimized
// this is new!
// blurDataURL="/images/no-image.jpg"
/>
),
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"firebase-tools": "^10.3.0",
"prettier": "^2.5.1",
"redux-logger": "^3.0.6",
"storybook-addon-next-router": "^3.1.1",
"typescript": "4.6.2"
}
}
Binary file added public/images/default.jpg
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/images/food-image-temp.jpg
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/images/no-image.jpg
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 src/assets/images/default.jpg
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 src/assets/images/food-image-temp.jpg
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 src/assets/images/no-image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions src/components/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { Card } from './Card';

export default {
title: 'Card',
component: Card,
args: {
id: 1,
type: 'wide',
background: 'white',
hasSummary: true,
headingPosition: 'bottomLeft',
title: 'hi',
},
parameters: {
nextRouter: {
query: {
id: 1,
},
},
},
} as ComponentMeta<typeof Card>;

const Template: ComponentStory<typeof Card> = (args) => <Card {...args} />;

export const Default = Template.bind({});
161 changes: 161 additions & 0 deletions src/components/Card/Card.styled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { media, pxToRem } from 'utils';
import { CardContainerProps, CardFigcaptionProps, CardFigureImgProps } from './Card.types';

const inlineBlock = css`
text-align: center;
width: 100%;
${media.desktop} {
display: inline-block;
}
`;

const typeCss = {
wide: css`
width: 100%;
height: 50vw;
object-fit: cover;

${media.desktop} {
width: 100%;
height: 250px;
}
`,
square: css`
width: 100%;

${media.mobile} {
height: 50vw;
}
${media.desktop} {
height: rem(200px);
@media (max-width: 1547px) {
height: 20vw;
}

@media (max-width: 1100px) {
height: 25vw;
}
}
object-fit: cover;
`,

smallSquare: css`
width: 100%;
aspect-ratio: 1 / 1;
object-fit: cover;
${media.mobile} {
aspect-ratio: 16 / 9;
}

@media (max-width: 1056px) {
aspect-ratio: 16 / 9;
}
`,
};

const headingPositionCss = {
bottomLeft: css`
font-size: ${pxToRem(20)};
left: 0;
`,
bottomCenter: css`
font-size: ${pxToRem(20)};
text-align: center;
`,
topLeft: css`
font-size: ${pxToRem(24)};
color: orange;
order: -1;
`,
};

export const CardLink = styled.a`
width: 100%;
border: none;
background-color: transparent;
text-align: left;
${media.mobile} {
width: 100%;
}
`;

export const CardContainer = styled.div<CardContainerProps>`
height: 100%;
display: flex;
flex-direction: column;
padding: ${pxToRem(16)};
position: relative;
cursor: pointer;

background: ${({ $background }) => ($background === 'white' ? 'white' : 'none')};
box-shadow: ${({ $background }) => $background === 'white' && '0px 4px 4px rgba(0, 0, 0, 0.25);'};

${({ $type }) => $type === 'square' && inlineBlock}
`;

export const CardFigureImgContainer = styled.div<CardFigureImgProps>`
${({ $type }) => typeCss[$type]}
`;

export const CardFigcaption = styled.figcaption<CardFigcaptionProps>`
font-size: ${pxToRem(18)};
font-weight: bold;
padding: ${pxToRem(16)} 0;
width: 100%;

${({ $headingPosition }) => headingPositionCss[$headingPosition]}
`;

export const CardSummary = styled.div`
line-height: ${pxToRem(24)};
${media.desktop} {
display: -webkit-box;
word-wrap: break-word;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
&:after {
content: '';
color: black;
position: absolute;
display: block;
width: 100%;
height: 30%;
bottom: 0;
left: 0;
background: linear-gradient(to top, #fff 50%, transparent);
}
}
${media.mobile} {
display: -webkit-box;
-webkit-line-clamp: 1;
word-wrap: break-word;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
`;

export const CardSummaryText = styled.p`
margin-top: 0;
margin-bottom: ${pxToRem(8)};
`;

export const CardButton = styled.button`
${media.mobile} {
display: none;
}

padding: ${pxToRem(8)} 0;
font-size: ${pxToRem(24)};
z-index: 1;
margin: 0;

display: flex;
gap: 10px;
border: none;
background: none;
justify-content: center;
`;
58 changes: 58 additions & 0 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import Image from 'next/image';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { useState } from 'react';
import { HiCursorClick } from 'react-icons/hi';
import { excludeTags } from 'utils';
import {
CardButton,
CardContainer,
CardFigcaption,
CardFigureImgContainer,
CardLink,
CardSummary,
CardSummaryText,
} from './Card.styled';
import { CardProps } from './Card.types';

export const Card = ({
id = 0,
type,
background,
hasSummary,
headingPosition,
// image,
imgSrc = '/images/no-image.jpg',
title,
summary = '',
}: CardProps): JSX.Element => {
return (
<Link href={`/recipe/${id}`}>
<CardLink>
<CardContainer $type={type} $background={background}>
<figure>
<CardFigureImgContainer $type={type}>
<Image src={imgSrc} title={title} layout="fill" priority />
</CardFigureImgContainer>
<CardFigcaption $headingPosition={headingPosition}>{title}</CardFigcaption>
</figure>
{hasSummary && (
<>
<CardSummary>
{excludeTags(summary)
.split('. ')
.map((text, index, texts) => (
<CardSummaryText key={text + index}>{text + (index < texts.length - 1 ? '.' : '')}</CardSummaryText>
))}
</CardSummary>
<CardButton>
Click for more
<HiCursorClick />
</CardButton>
</>
)}
</CardContainer>
</CardLink>
</Link>
);
};
27 changes: 27 additions & 0 deletions src/components/Card/Card.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type CardType = 'wide' | 'square' | 'smallSquare';
type CardBackgroundType = 'white' | 'none';
type CardHeadingPositionType = 'bottomLeft' | 'bottomCenter' | 'topLeft';

export interface CardProps {
id: string | number;
type: CardType;
background: CardBackgroundType;
hasSummary: boolean;
headingPosition: CardHeadingPositionType;
imgSrc: string;
title: string;
summary?: string;
}

export interface CardContainerProps {
$type: CardType;
$background: CardBackgroundType;
}

export interface CardFigureImgProps {
$type: CardType;
}

export interface CardFigcaptionProps {
$headingPosition: CardHeadingPositionType;
}
2 changes: 1 addition & 1 deletion src/components/CookingInfo/CookingInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const CookingInfo = ({ time = 0, count = 0 }: CookingInfoProps): JSX.Elem
<StyledTimer title="time" />
Cooking Time
</dt>
<StyledDD>{time} miuntes</StyledDD>
<StyledDD>{time} minutes</StyledDD>
</StyledDiv>
<StyledDiv>
<dt>
Expand Down
11 changes: 11 additions & 0 deletions src/components/HotRecipes/HotRecipes.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { HotRecipes } from './HotRecipes';

export default {
title: 'HotRecipes',
component: HotRecipes,
} as ComponentMeta<typeof HotRecipes>;

const Template: ComponentStory<typeof HotRecipes> = () => <HotRecipes />;

export const Default = Template.bind({});
Loading