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] 프로그래스바 컴포넌트 #58

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions src/components/common/progressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Icon from '@assets/svgs';
import React from 'react';

import * as ProgressBarStyle from './progressBar.css';

interface ProgressBarProps {
currentStep: number;
totalSteps: number;
onBackClick: () => void;
}

const ProgressBar = ({ currentStep, totalSteps, onBackClick }: ProgressBarProps) => {
const progressPercentage = (currentStep / totalSteps) * 100;

return (
<div className={ProgressBarStyle.container}>
<button className={ProgressBarStyle.backButton} onClick={onBackClick}>
<Icon.IcnArrowBlackLeft />
</button>
<div className={ProgressBarStyle.barContainer}>
<div
className={ProgressBarStyle.barStyle}
style={{ width: `${progressPercentage}%` }}></div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

컨벤션에서 인라인 스타일은 사용하지 않기로 했으니 recipe를 사용해서 currentStep에 맞게 width를 설정하는 방법은 어떨까요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

현재 단계의 진행도를 계산해서 퍼센트로 width를 채우는 방식 넘 좋네요! inline스타일을 사용하지 않고 적용할 수 있는 방법이 있는지에 대해서 고민하는 시간을 가져봐도 좋을 것 같아요! 물론 지금 progressPercentage를 통해 inline으로 width를 적용하는 것도 좋은 것 같아요!!

</div>
</div>
);
};

export default ProgressBar;
30 changes: 30 additions & 0 deletions src/components/common/progressBar/progressBar.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import theme from '@styles/theme.css';
import { style } from '@vanilla-extract/css';

export const container = style({
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
alignItems: 'start',
width: '37.5rem',
height: '6.4rem',
paddingTop: '1.2rem',
});

export const backButton = style({
width: '4rem',
height: '4rem',
marginLeft: '1.2rem',
});

export const barContainer = style({
width: '100%',
height: '0.2rem',
backgroundColor: theme.COLORS.gray1,
overflow: 'hidden',
});

export const barStyle = style({
height: '100%',
backgroundColor: theme.COLORS.primary400,
bykbyk0401 marked this conversation as resolved.
Show resolved Hide resolved
});
bykbyk0401 marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 26 additions & 0 deletions src/stories/ProgressBar.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ProgressBar from '@components/common/progressBar/ProgressBar';
import type { Meta, StoryObj } from '@storybook/react';

const meta = {
title: 'Common/ProgressBar',
component: ProgressBar,
bykbyk0401 marked this conversation as resolved.
Show resolved Hide resolved
bykbyk0401 marked this conversation as resolved.
Show resolved Hide resolved
args: {
currentStep: 1,
totalSteps: 4,
onBackClick: () => alert('clicked'),
},
argTypes: {
currentStep: {
control: { type: 'number', min: 1 },
},
totalSteps: {
control: { type: 'number', min: 1 },
},
},
} satisfies Meta<typeof ProgressBar>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {};
Loading