import React from 'react' import styled from 'styled-components' import { SpaceProps, space } from 'styled-system' import Icon from '../../atoms/icon' import Text from '../../atoms/text' import Box from '../../atoms/box/box' import { cssClass } from '../../utils/css-class' /** * Handler which is invoked when user clicks given step * * @alias OnStepClickHandler * @memberof Step */ export type OnStepClickHandler = ( /** * The same number what was passed to a {@link Step} */ number?: number | string ) => boolean | void /** * @alias StepProps * @memberof Step */ export type StepProps = { /** number presented in a circle */ number?: number | string; /** indicates if given step is done */ completed?: boolean; /** indicates if given step is active */ active?: boolean; /** turn off any */ disabled?: boolean; /** handler which passes a number of the step in an argument */ onClick?: OnStepClickHandler; /** Optional className */ className?: string; } const Circle = styled(Box)` border-width: 1px; border-style: solid; border-radius: 9999px; text-align: center; ` Circle.defaultProps = { py: 'default', px: 'default', minWidth: '34px', height: '34px', } type StyledStepProps = SpaceProps & Pick const StyledStep = styled.div` flex: 1 1 0px; display: flex; flex-direction: row; & > ${Box} { ${({ disabled }): string => (!disabled ? 'cursor: pointer' : '')}; border-bottom: 2px solid ${({ active, theme }): string => (active ? theme.colors.primary100 : 'transparent')}; } ${space}; ` /** * @classdesc * * * * Step represents one of the tab in placed inside {@link Stepper} component. * You can use it alone or with before-mentioned {@link Stepper}. * * ### Usage * * ```javascript * import { Step, StepProps } from '@admin-bro/design-system' * ``` * * * @hideconstructor * @see Stepper * @see StepProps * @see OnStepClickHandler * @subcategory Molecules * @component * @example Regular step * return ( * * Normal Step * * ) * * @example Active steps * return ( * * I am active * * ) * * @example Active steps * return ( * * This was done !!! * * ) * * @example Clickable step * const onClick = () => alert('Why did you click me?') * * return ( * * Click me if you dare * * ) * @section design-system */ const Step: React.FC = (props) => { const { number, completed, children, active, disabled, onClick, className } = props return ( !disabled && onClick && onClick(number)} > {completed ? ( ) : number} {children} ) } export { Step } export default Step