import { clsx } from 'clsx'; import { Size, Breakpoint, SizeSmall, SizeMedium } from '../common'; import { useScreenSize } from '../common/hooks/useScreenSize'; import NavigationOption from '../navigationOption'; import Tile from '../tile'; interface DecisionOption { 'aria-label'?: string; description?: React.ReactNode; disabled?: boolean; href?: string; target?: React.HTMLAttributeAnchorTarget; media: { block: React.ReactNode; list: React.ReactNode; }; onClick?: (event?: React.MouseEvent) => void; title: React.ReactNode; } export enum DecisionPresentation { LIST = 'LIST', LIST_BLOCK = 'LIST_BLOCK', LIST_BLOCK_GRID = 'LIST_BLOCK_GRID', } export enum DecisionType { NAVIGATION = 'NAVIGATION', } export interface DecisionProps { /** A list of elements to be rendered */ options: readonly DecisionOption[]; /** Handles the display mode of the component */ presentation?: `${DecisionPresentation}`; /** Size currently affects only Tile dimension */ size?: SizeSmall | SizeMedium; /** Decide which kind of element type needs to be rendered ex: Navigation Options or in the future Radio or Checkbox Options */ type?: `${DecisionType}`; /** Display media in a circle in list presentation */ showMediaCircleInList?: boolean; /** Sets navigation options to be aligned with the parent container */ isContainerAligned?: boolean; } const Decision = ({ options, presentation = DecisionPresentation.LIST, size = Size.MEDIUM, type = DecisionType.NAVIGATION, showMediaCircleInList = true, isContainerAligned = false, }: DecisionProps) => { const screenXs = useScreenSize(Breakpoint.EXTRA_SMALL); const screenSm = useScreenSize(Breakpoint.SMALL); if (type === DecisionType.NAVIGATION) { const renderedOptions = options.map( ( { 'aria-label': ariaLabel, title, description, disabled, href, target, media: { list }, onClick, }, key, ) => ( ), ); if ( presentation === DecisionPresentation.LIST_BLOCK || presentation === DecisionPresentation.LIST_BLOCK_GRID ) { const isSmall = size === Size.SMALL; const breakpoint = isSmall ? screenXs : screenSm; const isGrid = presentation === DecisionPresentation.LIST_BLOCK_GRID; return (
{breakpoint ? options.map( ( { 'aria-label': ariaLabel, description, disabled, href, target, media: { block }, onClick, title, }, key, ) => ( ), ) : renderedOptions}
); } // LIST return <>{renderedOptions}; } return null; }; export default Decision;