import React, { MouseEvent, ReactNode } from 'react' import { ElevationRange, flexFlow, FontSizes, getElevationShadow, typographyFont, } from '@monorail/helpers/exports' import styled, { css, StyledProps } from '@monorail/helpers/styled-components' import { isNotNil } from '@monorail/sharedHelpers/typeGuards' import { IconButton, IconButtonProps, } from '@monorail/v2/core/IconButton/IconButton' import { MODAL_SIZE, ModalSize } from '@monorail/v2/core/Modal/modalTypes' import * as Icons from '@monorail/v2/icons/Icons' export type ModalHeaderProps = { title: string TitleProps?: Partial size?: ModalSize startAdornment?: ReactNode endAdornment?: ReactNode closeButton?: ReactNode onClose?: (event: MouseEvent) => void } type HeaderTitleProps = Pick // #region CSS export const ModalHeaderContainer = styled.div>( ({ size, theme }) => css` ${flexFlow('row')}; ${getElevationShadow(ElevationRange.Elevation2)}; align-items: center; height: ${size === MODAL_SIZE.Mini || size === MODAL_SIZE.Small ? 48 : 56}px; padding: 0 16px; width: 100%; overflow: hidden; background: ${theme.v2.Accent1}; flex-shrink: 0; user-select: none; box-sizing: border-box; color: ${theme.v2.FoundationPlate}; `, ) // TODO: [kp 2020-10] use the Header component that Dan is working on instead? /** * WCAG note: This heading uses an `h1`. * Since it is displayed in a modal, it does not affect other headings on the page. */ export const ModalHeaderTitle = styled.h1.attrs(_ => ({ 'data-test-id': 'modal-header-title', }))( ({ size }) => css` ${size === MODAL_SIZE.Mini || size === MODAL_SIZE.Small ? typographyFont(700, FontSizes.Title4) : typographyFont(700, FontSizes.Title3)}; white-space: nowrap; margin: 0; `, ) // #endregion CSS const CLOSE_BUTTON_TEXT = 'Close' export type CloseButtonProps = Pick & Pick export const CloseButton = ({ display = 'chromelessContrast', size = 'default', onClose, }: CloseButtonProps) => ( ) /** * Top banner of the modal dialog */ export const ModalHeader = (props: ModalHeaderProps) => { const { closeButton, size = MODAL_SIZE.Medium, title, startAdornment, endAdornment, onClose, TitleProps, ...rest } = props return ( {startAdornment} {title} {endAdornment} {isNotNil(closeButton) ? closeButton : } ) }