import * as React from 'react'; import classnames from 'classnames'; import IReactComponentProps from '../../../common/structures/IReactComponentProps'; import styles from './Card.sass'; import Truncate from '../../text/Truncate/Truncate'; import { Title } from '../../text/Title/Title'; import { FunctionGeneric } from '../../../common/structures/Generics'; interface IProps extends IReactComponentProps { childrenClassName?: string; content?: React.ReactNode; contentClassName?: string; contentDescription?: React.ReactNode; contentDescriptionClassName?: string; contentDescriptionTruncate?: boolean; contentDescriptionTruncateEllipsis?: React.ReactNode; contentDescriptionTruncateLines?: number; contentSub?: React.ReactNode; contentSubClassName?: string; contentSubTruncate?: boolean; contentSubTruncateEllipsis?: React.ReactNode; contentSubTruncateLines?: number; contentTitle?: React.ReactNode; contentTitleClassName?: string; contentTitleOnClick?: FunctionGeneric; contentTitleTruncate?: boolean; contentTitleTruncateEllipsis?: React.ReactNode; contentTitleTruncateLines?: number; footer?: React.ReactNode; footerClassName?: string; header?: React.ReactNode; headerBackgroundColor?: string; headerClassName?: string; headerIconClassName?: string; headerIconContainerClassName?: string; headerIconMaxHeight?: string; headerIconPath?: string; headerOnClick?: FunctionGeneric; overflow?: string; tag?: string; truncateDefaultEllipsis?: string; truncateDefaultLines?: number; } const Card = ({ children, childrenClassName, className, content, contentClassName, contentDescription, contentDescriptionClassName, contentDescriptionTruncate, contentDescriptionTruncateEllipsis, contentDescriptionTruncateLines, contentSub, contentSubClassName, contentSubTruncate, contentSubTruncateEllipsis, contentSubTruncateLines, contentTitle, contentTitleClassName, contentTitleOnClick, contentTitleTruncate, contentTitleTruncateEllipsis, contentTitleTruncateLines, footer, footerClassName, header, headerBackgroundColor, headerClassName, headerIconClassName, headerIconContainerClassName, headerIconMaxHeight, headerIconPath, headerOnClick, id, onClick, overflow = 'hidden', style, tag = 'article', truncateDefaultEllipsis = '...', truncateDefaultLines = 1, }: IProps) => { const hasHeader = () => { return header || headerIconPath || headerBackgroundColor; }; const renderHeader = () => { return (
{(headerIconPath || headerBackgroundColor) && (
{headerIconPath && ( )}
)} {header}
); }; const hasContent = () => { return content || children || contentTitle || contentSub || contentDescription; }; const renderContent = () => { return (
{contentTitle && ( {contentTitleTruncate ? ( // this adds a bunch of nested spans, so only use if this feature is enabled <Truncate lines={contentTitleTruncateLines || truncateDefaultLines} ellipsis={contentTitleTruncateEllipsis || truncateDefaultEllipsis} > {contentTitle} </Truncate> ) : contentTitleOnClick ? ( <a>{contentTitle}</a> ) : ( contentTitle )} )} {contentSub && (
{contentSubTruncate ? ( // this adds a bunch of nested spans, so only use if this feature is enabled {contentSub} ) : ( contentSub )}
)} {contentDescription && (
{contentDescriptionTruncate ? ( // this adds a bunch of nested spans, so only use if this feature is enabled {contentDescription} ) : ( contentDescription )}
)} {(content || children) && ( // note this needs to be wrapped in a div for sibling :last-child styles to work
{content} {children}
)}
); }; const hasFooter = () => { return footer; }; const renderFooter = () => { return
{footer}
; }; const Tag: any = tag; return ( {hasHeader() && renderHeader()} {hasContent() && renderContent()} {hasFooter() && renderFooter()} ); }; export default Card;