-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a5573e
commit fc4ab6d
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
.../src/relay-question/features/select-relay-question/components/ProgressIndicator/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })} />; | ||
}; | ||
|
||
ProgressIndicator.displayName = 'ProgressIndicator'; | ||
ProgressIndicator.Step = Step; |
16 changes: 16 additions & 0 deletions
16
.../src/relay-question/features/select-relay-question/components/ProgressIndicator/styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); |
8 changes: 8 additions & 0 deletions
8
...ns/src/relay-question/features/select-relay-question/components/ProgressIndicator/type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |