import * as React from "react"; import { Card as AntCard } from "antd"; import Loader from "../loader/Loader"; import Spacing from "../spacing/Spacing"; import Text from '../text/Text'; import Image from '../image/Image'; import Link from '../link/Link'; import CheckCircleIcon from "../icon/CheckCircleIcon"; import WarningIcon from "../icon/WarningIcon"; import IIconProps from "../icon/IIconProps"; import WarningCircleIcon from "../icon/WarningCircleIcon"; export interface ICardProps { /** Card title */ title?: React.ReactNode; /** Title icon */ icon?: React.ReactElement; /** Card type. Default is "normal." "success", "attention", and "error" override the icon prop */ type?: "normal" | "success" | "error" | "attention"; /** Card description below the title */ description?: string; /** Content to the right of the card title */ extra?: React.ReactNode; /** Cover image src. Cannot be used with title */ image?: string; /** Card footer. Requires children to be set */ footer?: React.ReactNode; /** Remove body padding */ removeBodyPadding?: boolean; /** Min height of the card, excluding the height of the title or image */ height?: number | string; /** Trigger an action on card click. Cannot be used with href */ onClick?: () => void; /** Trigger a link on card click. Cannot be used with onClick */ href?: string; /** Show loading mask */ loading?: boolean; /** Add selected style */ selected?: boolean; } /** Cards structure content like text, forms, and tables. */ const Card: React.FC = (props) => { const { removeBodyPadding, loading, selected, type, image, description, height, onClick, href, ...validProps } = props; let className = "tempo-card"; if (removeBodyPadding || !validProps.children) { className += " tempo-card--body-no-padding"; } if (selected) { className += " tempo-card--selected" } let title = validProps.title; if (title) { title = {title}; if (description) { title = ( {title} {description} ); } let icon: React.ReactElement | null = null; if (props.icon) { icon = React.cloneElement(props.icon, { size: props.icon.props.size || 20, }); } if (type === "success") { icon = } else if (type === "error") { icon = ; } else if (type === "attention") { icon = ; } if (icon != null) { title = ( {icon} {title} ); } } let extra = validProps.extra; let cover; if (!title && image) { cover = ; } let contents = validProps.children; if (contents) { contents =
{contents}
; if (validProps.footer) { contents = (
{validProps.children}
{validProps.footer}
); } } let tabIndex, onKeyPress; if (onClick && !loading) { tabIndex = 0; onKeyPress = (e: React.KeyboardEvent) => { e.key === 'Enter' && onClick(); } } Object.assign(validProps, { hoverable: props.onClick || href }); const card = {contents}; return ( {href ? {card} : card} ); } export default Card;