feat: added a steps indicator in the wizard component

This commit is contained in:
Liordino Neto 2020-04-03 19:59:31 -03:00 committed by Josh Harvey
parent 8c35ffc2ed
commit fdac1602c6
2 changed files with 84 additions and 4 deletions

View file

@ -262,7 +262,7 @@ const SelectTriggerRequirements = () => {
)
}
const Wizard = ({ finish, children }) => {
const Wizard = ({ nextStepText, finalStepText, finish, children }) => {
const [currentStepIndex, setCurrentStepIndex] = useState(0)
const classes = useStyles()
@ -278,14 +278,42 @@ const Wizard = ({ finish, children }) => {
}
const currentStep = children[currentStepIndex]
const finalStepIndex = children.length - 1
const isFinalStep = currentStepIndex === finalStepIndex
return (
<>
<div className={classes.topLeftAligned}>{currentStep}</div>
<div className={classes.topLeftAligned}>
<div className={classes.wizardStepsWrapper}>
{children.map((e, i) => {
const elementToRender = []
if (i < currentStepIndex)
elementToRender.push(
<div className={classes.completedStepCircle}>
<div className={classes.completedStepCheck} />
</div>
)
else if (i === currentStepIndex)
elementToRender.push(<div className={classes.currentStep} />)
else elementToRender.push(<div className={classes.unreachedStep} />)
if (i < currentStepIndex)
elementToRender.push(<div className={classes.reachedStepLine} />)
else if (i < finalStepIndex)
elementToRender.push(
<div className={classes.unreachedStepLine} />
)
return elementToRender
})}
</div>
{currentStep}
</div>
<div className={classes.bottomRightAligned}>
<div className={classes.button}>
<Button onClick={() => handleMoveToNextStep(currentStepIndex + 1)}>
Next
{isFinalStep ? finalStepText : nextStepText}
</Button>
</div>
</div>
@ -334,7 +362,10 @@ const NewTriggerWizard = ({ finish }) => {
</div>
</div>
<div className={classes.modalBody}>
<Wizard finish={finish}>
<Wizard
nextStepText={'Next'}
finalStepText={'Add Trigger'}
finish={finish}>
<SelectTriggerDirection />
<SelectTriggerRequirements />
<SelectTriggerType />

View file

@ -1,5 +1,6 @@
import baseStyles from 'src/pages/Logs.styles'
import { booleanPropertiesTableStyles } from 'src/components/booleanPropertiesTable/BooleanPropertiesTable.styles'
import { disabledColor, secondaryColor } from 'src/styling/variables'
const {
titleWrapper,
@ -89,6 +90,54 @@ const mainStyles = {
width: 96,
height: 40,
marginRight: 8
},
wizardStepsWrapper: {
display: 'flex',
alignItems: 'center',
position: 'relative',
flex: 'wrap',
marginTop: 8,
marginBottom: 10
},
unreachedStep: {
width: 24,
height: 24,
border: `solid 2px ${disabledColor}`,
borderRadius: '50%'
},
currentStep: {
display: 'block',
width: 24,
height: 24,
borderRadius: '100%',
backgroundColor: secondaryColor,
border: `2px solid ${secondaryColor}`,
backgroundClip: 'content-box',
padding: 4
},
completedStepCircle: {
width: 24,
height: 24,
border: `solid 2px ${secondaryColor}`,
borderRadius: '50%'
},
completedStepCheck: {
width: 6,
height: 10,
margin: '4px 7px',
borderBottom: `3px solid ${secondaryColor}`,
borderRight: `3px solid ${secondaryColor}`,
transform: 'rotate(45deg)'
},
unreachedStepLine: {
width: 24,
height: 2,
border: `solid 1px ${disabledColor}`
},
reachedStepLine: {
width: 24,
height: 2,
border: `solid 1px ${secondaryColor}`
}
}