-
Notifications
You must be signed in to change notification settings - Fork 483
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
Safe creation stepper #992
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3cf8bcf
feat: new creation design + step 1
iamacook ddaf0d9
fix: widget width
iamacook 4997dc0
refactor: combine components
iamacook 40dfd11
fix: rename folder + remove CSS module
iamacook abe288e
fix: missing padding
iamacook c7cb075
fix: Reuse NetworkSelector component
usame-algan a9a798e
feat: basic step 2 implementation
iamacook b04c40d
change: design and add functionality to owner step
schmanu 532c0c0
fix: divider above threshold
schmanu dd0f446
revert unwanted change to old owner row
schmanu dc2a327
add comment in copied component
schmanu cc34faf
remove unused css module
schmanu 62c4f4d
fix: small design issues
schmanu 57add59
add new safe creation stepper to wrap each step
schmanu e5b0ef5
fix: adjust linear progress color
schmanu d9ec223
fix: Spread data when updating
usame-algan 996429e
fix: update stepper state
schmanu 11a307c
[Safe Creation] Owner step (#989)
schmanu 7ca3c46
improve responsiveness & small fixes
schmanu c163a1d
Merge remote-tracking branch 'origin/creation' into safe-creation-ste…
schmanu 07394e0
change: route of new create safe to /create-safe
schmanu 5c66dae
Merge remote-tracking branch 'origin/creation' into safe-creation-ste…
schmanu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,30 @@ | ||
import css from './styles.module.css' | ||
import { Card, LinearProgress, CardHeader, Avatar, Typography, CardContent } from '@mui/material' | ||
import type { TxStepperProps } from './useCardStepper' | ||
import { useCardStepper } from './useCardStepper' | ||
|
||
export function CardStepper<StepperData>(props: TxStepperProps<StepperData>) { | ||
const { activeStep, onSubmit, onBack, stepData, setStep } = useCardStepper<StepperData>(props) | ||
const { steps } = props | ||
const currentStep = steps[activeStep] | ||
const progress = (activeStep + 1 / steps.length) * 100 | ||
|
||
return ( | ||
<Card className={css.card}> | ||
<LinearProgress color="secondary" variant="determinate" value={Math.min(progress, 100)} /> | ||
<CardHeader | ||
title={currentStep.title} | ||
subheader={currentStep.subtitle} | ||
titleTypographyProps={{ variant: 'h4' }} | ||
subheaderTypographyProps={{ variant: 'body2' }} | ||
avatar={ | ||
<Avatar className={css.step}> | ||
<Typography variant="body2">{activeStep + 1}</Typography> | ||
</Avatar> | ||
} | ||
className={css.header} | ||
/> | ||
<CardContent className={css.content}>{currentStep.render(stepData, onSubmit, onBack, setStep)}</CardContent> | ||
</Card> | ||
) | ||
} |
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,31 @@ | ||
.card { | ||
border: none; | ||
} | ||
|
||
.header { | ||
padding: var(--space-3) var(--space-2); | ||
} | ||
|
||
.header :global .MuiCardHeader-title { | ||
font-weight: 700; | ||
} | ||
|
||
.header :global .MuiCardHeader-subheader { | ||
color: var(--color-text-primary); | ||
} | ||
|
||
.step { | ||
background-color: var(--color-primary-main); | ||
height: 20px; | ||
width: 20px; | ||
} | ||
|
||
.content { | ||
padding: var(--space-3) 52px; | ||
border-top: 1px solid var(--color-border-light); | ||
border-bottom: 1px solid var(--color-border-light); | ||
} | ||
|
||
.actions { | ||
padding: var(--space-3) 52px; | ||
} |
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,81 @@ | ||
import type { ReactElement } from 'react' | ||
import { useState } from 'react' | ||
import { trackEvent, MODALS_CATEGORY } from '@/services/analytics' | ||
|
||
export type StepRenderProps<TData> = { | ||
data: TData | ||
onSubmit: (data: Partial<TData>) => void | ||
onBack: (data?: Partial<TData>) => void | ||
setStep: (step: number) => void | ||
} | ||
|
||
export type Step<TData> = { | ||
title: string | ||
subtitle: string | ||
render: ( | ||
data: StepRenderProps<TData>['data'], | ||
onSubmit: StepRenderProps<TData>['onSubmit'], | ||
onBack: StepRenderProps<TData>['onBack'], | ||
setStep: StepRenderProps<TData>['setStep'], | ||
) => ReactElement | ||
} | ||
|
||
export type TxStepperProps<TData> = { | ||
steps: Array<Step<TData>> | ||
initialData: TData | ||
initialStep?: number | ||
eventCategory?: string | ||
onClose: () => void | ||
} | ||
|
||
export const useCardStepper = <TData>({ | ||
steps, | ||
initialData, | ||
initialStep, | ||
eventCategory = MODALS_CATEGORY, | ||
onClose, | ||
}: TxStepperProps<TData>) => { | ||
const [activeStep, setActiveStep] = useState<number>(initialStep || 0) | ||
const [stepData, setStepData] = useState(initialData) | ||
|
||
const handleNext = () => { | ||
setActiveStep((prevActiveStep) => prevActiveStep + 1) | ||
trackEvent({ category: eventCategory, action: lastStep ? 'Submit' : 'Next' }) | ||
} | ||
|
||
const handleBack = (data?: Partial<TData>) => { | ||
setActiveStep((prevActiveStep) => prevActiveStep - 1) | ||
iamacook marked this conversation as resolved.
Show resolved
Hide resolved
|
||
trackEvent({ category: eventCategory, action: firstStep ? 'Cancel' : 'Back' }) | ||
|
||
if (data) { | ||
setStepData((previous) => ({ ...previous, ...data })) | ||
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. What was the decision made on separating data across steps? This could overrite nested values from other steps (although we do not use such a data structure atm). |
||
} | ||
} | ||
|
||
const setStep = (step: number) => { | ||
setActiveStep(step) | ||
} | ||
|
||
const firstStep = activeStep === 0 | ||
const lastStep = activeStep === steps.length - 1 | ||
|
||
const onBack = firstStep ? onClose : handleBack | ||
|
||
const onSubmit = (data: Partial<TData>) => { | ||
if (lastStep) { | ||
onClose() | ||
return | ||
} | ||
setStepData((previous) => ({ ...previous, ...data })) | ||
handleNext() | ||
} | ||
|
||
return { | ||
onBack, | ||
onSubmit, | ||
setStep, | ||
activeStep, | ||
stepData, | ||
firstStep, | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are we preferring this syntax over targeting MUI classes in the sx property?
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.
Good question. I just copied it from the styles which were previously in the removed
StepCard
componentThere 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.
Ok. Non-blocker though 👍