import React, { useState } from 'react' import styles from './_tile.module.scss' import Button from '../../Button/Button' import { type ButtonProps } from '../../Button/Button.models' import DropdownMenu from '../../DropdownMenu/DropdownMenu' import Icon from '../../Icons/Icon' import Image from '../../Image/Image' import { type MenuProps } from '../../Menu/Menu' type TilePropsBase = { /** The header for the `Tile` is made up of an image, title, and subtitle. */ header: { title: string imgUrl?: string subtitle?: string } /** Unique identifier for the `Tile`. */ id: string /** The tabIndex is used to allow the `Tile` to have a focused state. */ tabIndex?: number /** Optionally show a `Menu`. If this is undefined, then the `Menu` button will be hidden. */ menuProps?: MenuProps /** Optionally show the `FormFooter` component. If this is undefined, then the `FormFooter` button will be hidden. */ buttons?: [ButtonProps] | [ButtonProps, ButtonProps] /** Optionally add a custom class name */ className?: string /** Optional prop to add a test id to the Tile for QA testing */ qaTestId?: string } type WithBody = TilePropsBase & { /** The body that appears in the center of the `Tile`. */ body: React.ReactNode /** Optional subHeader that appears above the body. */ subHeader?: string } type WithoutBody = TilePropsBase & { body?: never subHeader?: never } export type TileProps = WithBody | WithoutBody const Tile = ({ header, subHeader, body, tabIndex, menuProps, buttons, className, qaTestId = 'tile', }: TileProps): React.JSX.Element => { const [reRenderView, setReRenderView] = useState(false) const Header = () => { return (
{header.imgUrl ? ( {header.title} ) : null}
{header.title} {header.subtitle ? ( {header.subtitle} ) : null}
{menuProps ? ( } popoverProps={{ position: 'left' }} reRenderView={() => setReRenderView(!reRenderView)} /> ) : null}
) } const SubHeader = () =>
{subHeader}
const Body = () => (
{subHeader ? SubHeader() : null}
{body}
) const Footer = () => (
{buttons?.map((button, i) => (
) return ( // This is the main container for the `Tile` component.
{Header()} {body ? Body() : null} {buttons ? Footer() : null}
) } export default Tile