-
Notifications
You must be signed in to change notification settings - Fork 0
feat: ProgressIndicator 컴포넌트 #60
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { HTMLAttributes, PropsWithChildren, forwardRef } from 'react'; | ||
|
|
||
| import { progressIndicatorCss, stepCss } from './styles'; | ||
|
|
||
| export interface ProgressIndicatorProps extends Omit<HTMLAttributes<HTMLDivElement>, 'style'> { | ||
| mode?: 'horizontal' | 'vertical'; | ||
| totalStep: number; | ||
| currentStep: number; | ||
| } | ||
|
|
||
| export const ProgressIndicator = forwardRef<HTMLDivElement, PropsWithChildren<ProgressIndicatorProps>>( | ||
| ({ mode = 'horizontal', totalStep, currentStep, children, ...rest }, ref) => { | ||
| const flexDirection = mode === 'horizontal' ? 'row' : 'column'; | ||
| const currentStepIndex = Math.min(totalStep, currentStep) - 1; | ||
| const basis = 100 / totalStep; | ||
|
|
||
| return ( | ||
| <div ref={ref} {...rest} css={progressIndicatorCss({ flexDirection })}> | ||
| {Array.from({ length: totalStep }).map((_, index) => ( | ||
| <ProgressIndicator.Step key={index} isCurrent={index === currentStepIndex} basis={basis} /> | ||
| ))} | ||
| {children} | ||
| </div> | ||
| ); | ||
| }, | ||
| ) as React.ForwardRefExoticComponent<ProgressIndicatorProps> & { Step: typeof Step }; | ||
|
|
||
| export interface StepProps extends HTMLAttributes<HTMLSpanElement> { | ||
| basis: number; | ||
| isCurrent: boolean; | ||
| } | ||
|
|
||
| const Step = ({ isCurrent, basis, ...rest }: StepProps) => { | ||
| let color = '#E1E1E1'; | ||
|
|
||
| if (isCurrent) { | ||
| color = '#FF7664'; | ||
| } | ||
|
|
||
| return <span {...rest} css={stepCss({ basis, color })} />; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 단순한 궁금증인데 span 태그로 하신 이유가 있을까요?? |
||
| }; | ||
|
|
||
| ProgressIndicator.displayName = 'ProgressIndicator'; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 친구는 무슨 용도인가요?? |
||
| ProgressIndicator.Step = Step; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { css } from '@emotion/react'; | ||
|
|
||
| import { ProgressIndicatorCssArgs, StepCssArgs } from './type'; | ||
|
|
||
| export const progressIndicatorCss = ({ flexDirection }: ProgressIndicatorCssArgs) => | ||
| css({ width: '100%', display: 'flex', flexWrap: 'nowrap', flexDirection }); | ||
|
|
||
| export const stepCss = ({ basis, color }: StepCssArgs) => | ||
| css({ | ||
| boxSizing: 'border-box', | ||
| flex: `${basis}% 1 1`, | ||
| height: '4px', | ||
| backgroundColor: color, | ||
| borderRadius: '8px', | ||
| margin: '2px', | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export type ProgressIndicatorCssArgs = { | ||
| flexDirection: 'row' | 'column'; | ||
| }; | ||
|
|
||
| export type StepCssArgs = { | ||
| color: string; | ||
| basis: number; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export { Button } from './components/Button'; | ||
| export { Card } from './components/Card'; | ||
| export { Code } from './components/Code'; | ||
| export { ProgressIndicator } from './components/ProgressIndicator'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,11 @@ | ||
| 'use client'; | ||
|
|
||
| import { FirstFeatureOfFirstDomainBox } from '../components/FirstFeatureOfFirstDomainTestBox'; | ||
| import { FirstFeatureOfFirstDomainTestButton } from '../components/FirstFeatureOfFirstDomainTestButton'; | ||
| import { useFirstFeatureOfFirstDomainService } from '../services/useFirstFeatureOfFirstDomainTestService'; | ||
| import { ProgressIndicator } from '@sambad/sds'; | ||
|
|
||
| export const FirstFeatureOfFirstDomainTestContainer = () => { | ||
| const { displayText, handleChangeDisplayText, data } = useFirstFeatureOfFirstDomainService(); | ||
|
|
||
| return ( | ||
| <FirstFeatureOfFirstDomainBox displayText={displayText} onClick={handleChangeDisplayText}> | ||
| <FirstFeatureOfFirstDomainTestButton | ||
| onClick={() => { | ||
| alert('Button is Clicked at Container'); | ||
| }} | ||
| /> | ||
| <div css={{ width: '200px', height: '200px', backgroundColor: 'red' }}>{data}</div> | ||
| </FirstFeatureOfFirstDomainBox> | ||
| <div css={{ maxWidth: '600px;', margin: '0 auto' }}> | ||
| <ProgressIndicator totalStep={10} currentStep={7} /> | ||
| </div> | ||
| ); | ||
| }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ForwardRefExoticComponent라는 타입이란걸 처음 알았네요. 최근에 ref 때문에 다형성 컴포넌트 타입 추론 오류를 겪었는데 이게 해결책이 되겠군요.@Doeunnkimm 아래 포스팅 보시면 Txt 다형성 컴포넌트 타입 추론 문제를 해결할 수 있을 것 같습니다.
Polymorphic한 React 컴포넌트 만들기