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

feat: Spacing, Divider 컴포넌트 추가 #171

Open
wants to merge 4 commits into
base: feat/v2
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions src/components/Common/Divider/Divider.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Meta, StoryObj } from '@storybook/react';

import Divider from './Divider';

const meta: Meta<typeof Divider> = {
title: 'common/Divider',
component: Divider,
};

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
variant: 'default',
},
};

export const Light: Story = {
args: {
variant: 'light',
},
};
28 changes: 28 additions & 0 deletions src/components/Common/Divider/Divider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import cx from 'classnames';
import type { ComponentPropsWithoutRef } from 'react';

import { divider, dividerHeight, dividerWidth } from './divider.css';

import { assignInlineVars } from '@vanilla-extract/dynamic';

export interface DividerProps extends ComponentPropsWithoutRef<'hr'> {
variant?: 'default' | 'light' | 'navigation';
width?: string;
height?: string;
}

const Divider = ({ variant = 'default', width = '100%', height = '1px', ...props }: DividerProps) => {
return (
<hr
aria-hidden
className={cx(divider({ variant }))}
style={assignInlineVars({
[dividerWidth]: width ?? '100%',
[dividerHeight]: height ?? '1px',
})}
{...props}
/>
);
};

export default Divider;
23 changes: 23 additions & 0 deletions src/components/Common/Divider/divider.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { vars } from '@/styles/theme.css';
import { createVar, style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';

export const dividerWidth = createVar();
export const dividerHeight = createVar();

export const dividerBase = style({
width: dividerWidth,
height: dividerHeight,
border: 0,
});

export const divider = recipe({
base: dividerBase,
variants: {
variant: {
default: { backgroundColor: vars.colors.border.default },
light: { backgroundColor: vars.colors.border.light },
navigation: { backgroundColor: vars.colors.border.navigation },
},
},
});
7 changes: 4 additions & 3 deletions src/components/Common/ErrorComponent/ErrorComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { container } from './errorComponent.css';
import Spacing from '../Spacing/Spacing';
import Text from '../Typography/Text/Text';

import Error from '@/assets/error.png';

const ErrorComponent = () => {
return (
<div className={container}>
<div style={{ height: 30 }} />
<Spacing size={30} />
<img src={Error} alt="404 캐릭터" width={92} height={58} />
<div style={{ height: 12 }} />
<Spacing size={12} />
<Text size="headline" weight="semiBold" color="sub">
에러가 발생했습니다
</Text>
<div style={{ height: 32 }} />
<Spacing size={32} />
</div>
);
};
Expand Down
81 changes: 81 additions & 0 deletions src/components/Common/Spacing/Spacing.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type { Meta, StoryObj } from '@storybook/react';
import type { PropsWithChildren } from 'react';

import Spacing from './Spacing';

import { vars } from '@/styles/theme.css';

const meta: Meta<typeof Spacing> = {
title: 'common/Spacing',
component: Spacing,
};

export default meta;
type Story = StoryObj<typeof Spacing>;

const Container = ({ children, vertical }: PropsWithChildren<{ vertical?: boolean }>) => {
return (
<div
style={{
display: 'flex',
flexDirection: `${vertical ? 'column' : 'row'}`,
}}
>
{children}
</div>
);
};

const Box = () => {
return (
<div
style={{
width: '100px',
height: '50px',
backgroundColor: `${vars.colors.primary}`,
}}
/>
);
};

export const Default: Story = {
render: ({ direction = 'vertical', size }) => (
<Container vertical={direction === 'vertical'}>
<Box />
<Spacing direction={direction} size={size} />
<Box />
<Spacing direction={direction} size={size} />
<Box />
<Spacing direction={direction} size={size} />
<Box />
</Container>
),
};

export const Vertical: Story = {
render: ({ size }) => (
<Container vertical>
<Box />
<Spacing direction="vertical" size={size} />
<Box />
<Spacing direction="vertical" size={size} />
<Box />
<Spacing direction="vertical" size={size} />
<Box />
</Container>
),
};

export const Horizontal: Story = {
render: ({ size }) => (
<Container>
<Box />
<Spacing direction="horizontal" size={size} />
<Box />
<Spacing direction="horizontal" size={size} />
<Box />
<Spacing direction="horizontal" size={size} />
<Box />
</Container>
),
};
27 changes: 27 additions & 0 deletions src/components/Common/Spacing/Spacing.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { ComponentPropsWithoutRef } from 'react';

import { spacing, spacingSize } from './spacing.css';

import { assignInlineVars } from '@vanilla-extract/dynamic';

type SpacingDirections = 'vertical' | 'horizontal';

export interface SpacingProps extends ComponentPropsWithoutRef<'div'> {
direction?: SpacingDirections;
size: number;
}

const Spacing = ({ direction = 'vertical', size, ...props }: SpacingProps) => {
return (
<div
aria-hidden="true"
className={direction === 'vertical' ? spacing['vertical'] : spacing['horizontal']}
style={assignInlineVars({
[spacingSize]: `${size}px`,
})}
{...props}
/>
);
};

export default Spacing;
8 changes: 8 additions & 0 deletions src/components/Common/Spacing/spacing.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createVar, styleVariants } from '@vanilla-extract/css';

export const spacingSize = createVar();

export const spacing = styleVariants({
vertical: [{ height: spacingSize }],
horizontal: [{ width: spacingSize }],
});
2 changes: 2 additions & 0 deletions src/components/Common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export { default as StarRating } from './StarRating/StarRating';
export { default as ShowAllButton } from './ShowAllButton/ShowAllButton';
export { default as FormTextarea } from './FormTextarea/FormTextarea';
export { default as Stepper } from './Stepper/Stepper';
export { default as Spacing } from './Spacing/Spacing';
export { default as Divider } from './Divider/Divider';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ChangeEventHandler } from 'react';

import { container, inputWrapper, letterCount } from './memberModifyInput.css';

import { Text } from '@/components/Common';
import { Spacing, Text } from '@/components/Common';

const MIN_LENGTH = 1;
const MAX_LENGTH = 10;
Expand All @@ -18,7 +18,7 @@ const MemberModifyInput = ({ nickname, modifyNickname }: MemberModifyInputProps)
<Text size="caption2" weight="semiBold">
닉네임
</Text>
<div style={{ height: 8 }} />
<Spacing size={8} />
<div className={container}>
<Text className={letterCount} as="span" size="caption4" weight="medium" color="disabled">
{nickname.length} / {MAX_LENGTH}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Members/MemberReviewItem/MemberReviewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link } from 'react-router-dom';

import { titleWrapper } from './memberReviewItem.css';

import { SvgIcon, Text } from '@/components/Common';
import { Spacing, SvgIcon, Text } from '@/components/Common';
import { ReviewItemInfo } from '@/components/Review';
import { PATH } from '@/constants/path';
import { useDeleteReview } from '@/hooks/queries/members';
Expand Down Expand Up @@ -60,7 +60,7 @@ const MemberReviewItem = ({ review }: MemberReviewItemProps) => {
</Text>
</button>
</div>
<div style={{ height: '11px' }} />
<Spacing size={11} />

<ReviewItemInfo rating={rating} createdAt={createdAt} image={image} content={content} tags={tags} />
</>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Members/MemberReviewList/MemberReviewList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { notFound, notFoundContainer } from './memberReviewList.css';
import MemberReviewItem from '../MemberReviewItem/MemberReviewItem';

import ReviewNotFoundImage from '@/assets/review-notfound.png';
import { Text } from '@/components/Common';
import { Spacing, Text } from '@/components/Common';
import { useIntersectionObserver } from '@/hooks/common';
import { useInfiniteMemberReviewQuery } from '@/hooks/queries/members';
import displaySlice from '@/utils/displaySlice';
Expand Down Expand Up @@ -47,7 +47,7 @@ const MemberReviewList = ({ isPreview = false }: MemberReviewListProps) => {
<li key={review.reviewId}>
<MemberReviewItem review={review} />
</li>
<div style={{ height: '40px' }} />
<Spacing size={40} />
</>
))}
</ul>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Members/MembersInfo/MembersInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { container, logoutButton, modifyButton, wrapper } from './memberInfo.css
import MemberImage from '../MemberImage/MemberImage';
import PostCounterBox from '../PostCounterBox/PostCounterBox';

import { SvgIcon, Text } from '@/components/Common';
import { Spacing, SvgIcon, Text } from '@/components/Common';
import { PATH } from '@/constants/path';
import { useLogoutMutation, useMemberQuery } from '@/hooks/queries/members';
import { vars } from '@/styles/theme.css';
Expand Down Expand Up @@ -41,15 +41,15 @@ const MembersInfo = () => {
objectFit: `cover`,
}}
/>
<div style={{ width: '10px' }} />
<Spacing direction="horizontal" size={10} />
<Text size="display1" weight="semiBold">
{nickname}
</Text>
<Link to={`${PATH.MEMBER}/modify`} className={modifyButton}>
<SvgIcon variant="pencil" width={12} height={12} fill={vars.colors.white} />
</Link>
</div>
<div style={{ height: '24px' }} />
<Spacing size={24} />

<PostCounterBox recipeCount={recipeCount} reviewCount={reviewCount} />
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Product/ProductItem/ProductItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { memo, useState } from 'react';

import { container, imageWrapper, previewWrapper, productImage, summaryWrapper } from './productItem.css';

import { SvgIcon, Text } from '@/components/Common';
import { Spacing, SvgIcon, Text } from '@/components/Common';
import { ellipsis } from '@/styles/common.css';
import { vars } from '@/styles/theme.css';
import type { Product } from '@/types/product';
Expand Down Expand Up @@ -33,16 +33,16 @@ const ProductItem = ({ product }: ProductItemProps) => {
</div>
)}
</div>
<div style={{ height: '8px' }} />
<Spacing size={8} />
<Text className={ellipsis} size="caption3" weight="semiBold" color="sub">
{name}
</Text>
<div style={{ height: '2px' }} />
<Spacing size={2} />
{/* 추후 bold로 변경 */}
<Text size="caption2" weight="semiBold" color="sub">
{price.toLocaleString('ko-KR')}원
</Text>
<div style={{ height: '8px' }} />
<Spacing size={8} />
<div className={summaryWrapper}>
<div className={previewWrapper}>
<SvgIcon variant="star2" width={11} height={11} fill={vars.colors.gray2} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { container, priceRate, priceRateWrapper, rateWrapper, wrapper } from './productOverviewItem.css';

import { SvgIcon } from '@/components/Common';
import { Spacing, SvgIcon } from '@/components/Common';
import {
PRODUCT_OVERVIEW_DEFAULT_IMAGE_URL_1,
PRODUCT_OVERVIEW_DEFAULT_IMAGE_URL_2,
Expand Down Expand Up @@ -34,7 +34,7 @@ const ProductOverviewItem = ({ product }: ProductOverviewItemProps) => {
<img src={image ?? defaultImage} width={60} height={60} alt={name} />
<div>
<p>{name}</p>
<div style={{ height: '6px' }} />
<Spacing size={6} />
<div className={priceRateWrapper}>
<span className={priceRate}>{price}원</span>
<div className={rateWrapper}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link } from 'react-router-dom';
import { container } from './productOverviewList.css';
import ProductOverviewItem from '../ProductOverviewItem/ProductOverviewItem';

import { Divider, Spacing } from '@/components/Common';
import { UsedProductOverviewItem } from '@/components/Recipe';
import { PATH } from '@/constants/path';
import type { Product } from '@/types/product';
Expand All @@ -27,8 +28,8 @@ const ProductOverviewList = ({ products, hasBorder = false, hasRemoved = false }
)}
{hasBorder && (
<>
<div style={{ height: '20px' }} />
<hr style={{ border: '0.5px solid #e6e6e6' }} />
<Spacing size={20} />
<Divider variant="default" />
Copy link
Contributor

Choose a reason for hiding this comment

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

궁금한게 Divider variant의 기본값이 default던데 따로 명시해야 하는건가용?!?!

</>
)}
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Link } from 'react-router-dom';
import { container, moreItem, notFound, recipeLink } from './productRecipeList.css';

import SearchNotFoundImage from '@/assets/search-notfound.png';
import { Text, ShowAllButton } from '@/components/Common';
import { Text, ShowAllButton, Spacing } from '@/components/Common';
import { DefaultRecipeItem } from '@/components/Recipe';
import { PATH } from '@/constants/path';
import { useInfiniteProductRecipesQuery } from '@/hooks/queries/product';
Expand All @@ -28,7 +28,7 @@ const ProductRecipeList = ({ productId, productName }: ProductRecipeListProps) =
<Text color="disabled" size="caption4">
아직 작성된 꿀조합이 없어요
</Text>
<div style={{ height: '6px' }} />
<Spacing size={6} />
<Link to={PATH.RECIPE} className={recipeLink}>
<Text as="span" color="sub" weight="semiBold" size="caption2">
꿀조합 작성하러 가기
Expand Down
Loading
Loading