import React, { FC } from 'react' import { BorderRadius, borderRadius, Colors, flexFlow, getColor, Sizes, } from '@monorail/helpers/exports' import styled, { css } from '@monorail/helpers/styled-components' import { isBoolean } from '@monorail/sharedHelpers/typeGuards' import { CommonComponentType, CssOverridesType } from '@monorail/types' import { Icon } from '@monorail/visualComponents/icon/Icon' import { IconType } from '@monorail/visualComponents/icon/IconType' import { ListItem, ListItemPrimaryText, ListItemSecondaryText, ListItemText, } from '@monorail/visualComponents/list/List' import { Status } from '@monorail/visualComponents/status/Status' import { Step as StepType } from '@monorail/visualComponents/stepper/types' const Container = styled.div` ${flexFlow('column')}; ` export type StepperProps = CommonComponentType & { steps: Array onStepClick: (index: number) => void activeStepIndex: number isNumbered?: boolean } export type VerticalStepperProps = CommonComponentType & { children: React.ReactNode isNumbered?: boolean value: number onChange: (index: number) => void } export type InjectedStepProps = { /* Even though these are marked as optional, they will always be applied to by AR - 2020/03/25 */ index?: number isActive?: boolean isNumbered?: boolean key?: string onClick?: () => void } export type StepProps = { cssOverrides?: CssOverridesType iconLeft?: IconType iconLeftColor?: Colors iconLeftActiveColor?: Colors iconRight?: IconType iconRightColor?: Colors iconRightActiveColor?: Colors iconColor?: Colors isDisabled?: boolean label: string statusIconName?: IconType statusIconColor?: Colors subtitle?: string } export const Step: FC = ({ cssOverrides, iconColor = Colors.Gray54, iconLeft, iconLeftColor, iconLeftActiveColor, iconRight, iconRightColor, iconRightActiveColor, index = 0, isActive = false, isDisabled, isNumbered = true, label, onClick = () => {}, statusIconName, statusIconColor, subtitle, }) => { const textStyles = css` color: ${isActive ? getColor(Colors.BrandLightBlue) : 'inherit'}; margin-left: ${isNumbered || iconLeft ? `12px;` : `0`}; ` return ( {isNumbered ? ( {index + 1} ) : iconLeft ? ( ) : null} {subtitle ? ( {label} {subtitle} ) : ( {label} )} {statusIconName && statusIconColor ? ( ) : iconRight ? ( ) : null} ) } export const Stepper = (props: VerticalStepperProps) => { const { isNumbered = true, children, ...domProps } = props return ( {React.Children.map(children, (child, idx) => { return React.isValidElement(child) ? React.cloneElement(child, { key: `${idx}-vertical-stepper`, isNumbered, index: idx, // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment isActive: isBoolean(child.props?.isActive) ? child.props?.isActive : props.value === idx, onClick: () => { props.onChange?.(idx) // eslint-disable-next-line @typescript-eslint/no-unsafe-call child.props?.onClick?.() }, }) : null })} ) }