This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create and implement a Stepper component. (#2246)
* Fix duplicate CSS properties. * Create and implement a Stepper component. * Cleanup comment * Further styling of active step text. * Change button to use 'continue' text. * Modify text + refactor stepper. * Use a CSS var to store the default iconSize * Use a CSS var to store the default iconSize * Wording suggestions. * Update src/custom/pages/Claim/InvestmentFlow/index.tsx Co-authored-by: Leandro Boscariol <[email protected]> * Fix code style issues with Prettier * Revert key id to use index instead. Co-authored-by: Leandro Boscariol <[email protected]> Co-authored-by: Lint Action <[email protected]>
- Loading branch information
1 parent
26e7540
commit 56fbeb1
Showing
5 changed files
with
319 additions
and
168 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,128 @@ | ||
import styled from 'styled-components/macro' | ||
import CheckCircle from 'assets/cow-swap/check.svg' | ||
import { transparentize } from 'polished' | ||
|
||
export const Wrapper = styled.div` | ||
width: 100%; | ||
display: flex; | ||
flex-flow: row wrap; | ||
margin: 12px 0 24px; | ||
` | ||
|
||
export const Step = styled.div<{ | ||
totalSteps: number | ||
isActiveStep: boolean | ||
completedStep: boolean | ||
circleSize?: number | ||
}>` | ||
--circleSize: 42px; | ||
display: flex; | ||
flex-flow: column wrap; | ||
align-items: center; | ||
position: relative; | ||
flex: 1 1 ${({ totalSteps }) => `calc(100% / ${totalSteps})`}; | ||
&::before, | ||
&::after { | ||
content: ''; | ||
position: absolute; | ||
top: ${({ circleSize }) => (circleSize ? `calc(${circleSize / 2})px` : 'calc(var(--circleSize) / 2)')}; | ||
height: 1px; | ||
border-top: 1px solid ${({ theme }) => theme.border2}; | ||
} | ||
&::before { | ||
left: 0; | ||
right: 50%; | ||
margin-right: ${({ circleSize }) => (circleSize ? `${circleSize}px` : 'var(--circleSize)')}; | ||
} | ||
&::after { | ||
right: 0; | ||
left: 50%; | ||
margin-left: ${({ circleSize }) => (circleSize ? `${circleSize}px` : 'var(--circleSize)')}; | ||
} | ||
&:first-child::before, | ||
&:last-child::after { | ||
content: none; | ||
display: none; | ||
} | ||
> span { | ||
display: flex; | ||
flex-flow: column wrap; | ||
align-items: center; | ||
justify-content: center; | ||
width: ${({ circleSize }) => (circleSize ? `${circleSize}px` : 'var(--circleSize)')}; | ||
height: ${({ circleSize }) => (circleSize ? `${circleSize}px` : 'var(--circleSize)')}; | ||
margin: 0 auto 12px; | ||
border-radius: ${({ circleSize }) => (circleSize ? `${circleSize}px` : 'var(--circleSize)')}; | ||
text-align: center; | ||
line-height: 1; | ||
font-size: 100%; | ||
position: relative; | ||
color: ${({ isActiveStep, completedStep, theme }) => | ||
completedStep ? theme.black : isActiveStep ? theme.black : transparentize(0.4, theme.text1)}; | ||
background: ${({ isActiveStep, completedStep, theme, circleSize }) => | ||
completedStep | ||
? `url(${CheckCircle}) no-repeat center/${circleSize ? `${circleSize}px` : 'var(--circleSize)'}` | ||
: isActiveStep | ||
? theme.primary1 | ||
: theme.blueShade3}; | ||
> small { | ||
font-size: inherit; | ||
color: inherit; | ||
display: ${({ completedStep }) => (completedStep ? 'none' : 'block')}; | ||
} | ||
} | ||
> b { | ||
color: ${({ isActiveStep, completedStep, theme }) => | ||
completedStep ? theme.text1 : isActiveStep ? theme.text1 : transparentize(0.4, theme.text1)}; | ||
font-weight: ${({ isActiveStep, completedStep }) => (completedStep ? '300' : isActiveStep ? 'bold' : '300')}; | ||
} | ||
> i { | ||
font-style: normal; | ||
color: ${({ isActiveStep, completedStep, theme }) => | ||
completedStep | ||
? transparentize(0.2, theme.text1) | ||
: isActiveStep | ||
? transparentize(0.2, theme.text1) | ||
: transparentize(0.4, theme.text1)}; | ||
font-size: 12px; | ||
margin: 6px 0 0; | ||
padding: 0 24px; | ||
text-align: center; | ||
} | ||
` | ||
|
||
interface StepperProps { | ||
steps: { | ||
title: string | ||
subtitle?: string | ||
}[] | ||
activeStep: number | ||
} | ||
|
||
export function Stepper({ steps, activeStep }: StepperProps) { | ||
return ( | ||
<Wrapper> | ||
{steps.map(({ title, subtitle }, index) => { | ||
const completedStep = activeStep > index | ||
const isActiveStep = activeStep === index | ||
return ( | ||
<Step key={index} totalSteps={steps.length} isActiveStep={isActiveStep} completedStep={completedStep}> | ||
<span> | ||
<small>{index + 1}</small> | ||
</span> | ||
<b>{title}</b> | ||
<i>{subtitle}</i> | ||
</Step> | ||
) | ||
})} | ||
</Wrapper> | ||
) | ||
} |
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
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
Oops, something went wrong.