bf397bc6ec
* Update the frontend to adhere to the custom eslint rule `twenty/no-spread-props` Co-authored-by: v1b3m <vibenjamin6@gmail.com> * Update the frontend to adhere to the custom eslint rule `twenty/no-spread-props` Co-authored-by: v1b3m <vibenjamin6@gmail.com> * resolve bug with data-testid --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: bosiraphael <raphael.bosi@gmail.com>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import React from 'react';
|
|
import styled from '@emotion/styled';
|
|
|
|
import { MOBILE_VIEWPORT } from '@/ui/theme/constants/theme';
|
|
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
|
|
|
|
import { Step, StepProps } from './Step';
|
|
|
|
const StyledContainer = styled.div`
|
|
display: flex;
|
|
flex: 1;
|
|
justify-content: space-between;
|
|
@media (max-width: ${MOBILE_VIEWPORT}px) {
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
`;
|
|
|
|
export type StepBarProps = React.PropsWithChildren &
|
|
React.ComponentProps<'div'> & {
|
|
activeStep: number;
|
|
};
|
|
|
|
export const StepBar = ({ activeStep, children }: StepBarProps) => {
|
|
const isMobile = useIsMobile();
|
|
|
|
return (
|
|
<StyledContainer>
|
|
{React.Children.map(children, (child, index) => {
|
|
if (!React.isValidElement(child)) {
|
|
return null;
|
|
}
|
|
|
|
// If the child is not a Step, return it as-is
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-expect-error
|
|
if (child.type?.displayName !== Step.displayName) {
|
|
return child;
|
|
}
|
|
|
|
// We should only render the active step, and if activeStep is -1, we should only render the first step only when it's mobile device
|
|
if (
|
|
isMobile &&
|
|
(activeStep === -1 ? index !== 0 : index !== activeStep)
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return React.cloneElement<StepProps>(child as any, {
|
|
index,
|
|
isActive: index <= activeStep,
|
|
isLast: index === React.Children.count(children) - 1,
|
|
});
|
|
})}
|
|
</StyledContainer>
|
|
);
|
|
};
|
|
|
|
StepBar.Step = Step;
|