import React, { FunctionComponent, ReactElement } from "react"; import classNames from "classnames"; import Icon from "react-oui-icons"; import Button from "../Button"; import OverlayWrapper from "../OverlayWrapper"; import Popover from "../Popover"; import Poptip from "../Poptip"; import Dropdown from "../Dropdown"; import ButtonIcon from "../ButtonIcon"; import Link from "../Link"; import { greyDark, redBase } from "../../tokens/forimport/index.es"; const renderDropdownActivator = ( { onClick, buttonRef } // eslint-disable-line ): ReactElement => ; export type TileProps = { /** CSS class names. */ className?: string; /** * Description of the item for this reference Tile */ description?: string | React.ReactNode; /** * Optional properties to include when using Tile * in DragAndDrop component */ dragHandleProps?: Record; /** * Optional dropdown items to add to right side of Tile * Should be an array of Dropdown.ListItem items */ dropdownItems?: React.ReactNode[]; /** * Whether or not this Tile has margin on the ends * True by default */ hasSpacing?: boolean; /** * Whether or not this Tile includes a drag handle */ isDraggable?: boolean; /** * Whether or not this Tile is currently selected/active */ isSelected?: boolean; /** * Function to call when copy button is clicked * Supplying this function adds a copy button * to the tile */ onCopy?: (...args: any[]) => any; /** * Function to call when delete button is clicked * Supplying this function adds a delete button * to the tile */ onDismiss?: (...args: any[]) => any; /** * Function to call when edit button is clicked * Supplying this function adds an edit button * to the tile */ onEdit?: (...args: any[]) => any; /** * Function to call when the main area of the Tile is clicked * If function is not supplied, main content of the Tile * will not be clickable (div instead of a button) */ onTileClick?: (...args: any[]) => any; /** * Optional number used to indicate the order of Tiles */ order?: number; /** * Link to open in a new tab when results button is clicked * Supplying this link adds a results button to the tile */ resultsLink?: string; /** * Optional string used to indicate status before action items */ status?: string; /** * String to use for testing */ testSection?: string; /** * Title of the Tile, required */ name: string | React.ReactNode; /** * Whether or not the title of this Tile displays in monospace font */ usesMonospaceName?: boolean; /** * Text to show in unsaved status indicator. If empty or left out no status indicator will be shown */ unsavedChangesText?: string; /** * The title and body content to show in the warning icon and popover */ warningTitleAndBodyContent?: [] | [string, React.ReactNode]; }; const Tile: FunctionComponent = ({ className, description, dragHandleProps, dropdownItems, hasSpacing = true, isDraggable = false, isSelected = false, name, onCopy, onDismiss, onEdit, onTileClick, order, resultsLink, status, testSection, usesMonospaceName = false, unsavedChangesText = "", warningTitleAndBodyContent = [], ...props }: TileProps)=> { const tileContent = (

{name}

{description}

); const hasExtraContent = status || onCopy || onEdit || onDismiss || resultsLink || dropdownItems; const hasWarning = !!warningTitleAndBodyContent.length; return (
{order && {order}} {isDraggable && (
)} {unsavedChangesText && !hasWarning && (
)} {hasWarning && (
{warningTitleAndBodyContent[1] || <>} } shouldHideOnClick={true} verticalAttachment="bottom" >
)} {onTileClick ? (
) : (
{tileContent}
)} {hasExtraContent && (
{status &&

{status}

} {onCopy && ( )} {onEdit && ( )} {onDismiss && ( )} {resultsLink && ( )} {dropdownItems && ( {dropdownItems} )}
)}
); }; export default Tile;