From 6b40fb8045af50deddcdb0e4d7dcf42fbaf91d6b Mon Sep 17 00:00:00 2001 From: Monalisha Mishra Date: Mon, 26 Aug 2024 22:30:17 +0530 Subject: [PATCH] fixed the stepper ui --- src/common/components/Stepper.tsx | 32 +++++++++++++++++++++---- src/modules/addNewChain/AddNewChain.tsx | 16 ++++++++----- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/common/components/Stepper.tsx b/src/common/components/Stepper.tsx index 1d8cd7e9b7..16b828f6cd 100644 --- a/src/common/components/Stepper.tsx +++ b/src/common/components/Stepper.tsx @@ -1,5 +1,5 @@ // React + web3 essentials -import { FC } from 'react'; +import { FC, useCallback, useEffect, useRef, useState } from 'react'; // Components import { Box, Text } from 'blocks'; @@ -12,17 +12,39 @@ type StepperProps = { }; const Stepper: FC = ({ steps, setActiveStepKey, completedSteps }) => { + const [stepWidth, setStepWidth] = useState(0); + const parentRef = useRef(null); + const stepLength = steps?.length; const handleChangeActiveStep = (step: string) => { if (completedSteps?.includes(step)) { setActiveStepKey(step); } }; + const updateStepWidth = useCallback(() => { + if (parentRef.current) { + setStepWidth((parentRef.current.offsetWidth - 32 * (stepLength - 1)) / stepLength); + } + }, []); + + useEffect(() => { + updateStepWidth(); + window.addEventListener('resize', updateStepWidth); + + return () => { + window.removeEventListener('resize', updateStepWidth); + }; + }, [updateStepWidth]); + return ( {steps.map((step, index) => ( = ({ steps, setActiveStepKey, completedSteps }) display="flex" flexDirection="column" gap="spacing-xs" - css={css` - flex: 1; - `} + width={`${stepWidth}px`} cursor="pointer" onClick={() => handleChangeActiveStep(step.value)} > @@ -40,12 +60,14 @@ const Stepper: FC = ({ steps, setActiveStepKey, completedSteps }) textAlign="center" color={completedSteps.includes(step.value) ? 'text-brand-medium' : 'text-tertiary'} variant="h5-semibold" + ellipsis display={{ ml: 'none', dp: 'block' }} > {step.label} { alignItems="center" > { )} - - Tip: Please do not exit the process before the address is verified. If you leave, you will need to start over. - + + + Tip: Please do not exit the process before the address is verified. If you leave, you will need to start + over. + + );