'use client'; import classnames from 'classnames'; import React from 'react'; import MdIconChevronForward from '../icons-material/MdIconChevronForward'; import MdLoadingSpinner from '../loadingSpinner/MdLoadingSpinner'; export type MdTileProps = { heading?: string; description?: string; href?: string; theme?: 'primary' | 'secondary'; fullWidth?: boolean; disabled?: boolean; mode?: 'large' | 'medium' | 'small'; icon?: React.ReactNode; preventDefault?: boolean; loading?: boolean; asChild?: boolean; asChildContent?: React.ReactNode; onClick?(_e: React.MouseEvent): void; } & React.AnchorHTMLAttributes & React.ButtonHTMLAttributes; export const MdTile: React.FC = ({ heading, description, href, theme = 'primary', fullWidth = false, mode = 'large', disabled = false, icon = null, preventDefault = false, loading = false, asChild, asChildContent, onClick, ...otherProps }: MdTileProps) => { const classNames = classnames( 'md-tile', { 'md-tile--disabled': !!disabled, 'md-tile--secondary': theme && theme === 'secondary', 'md-tile--medium': mode === 'medium', 'md-tile--small': mode === 'small', 'md-tile--fullWidth': !!fullWidth, }, otherProps.className, ); const handleClick = (e: React.MouseEvent) => { if (preventDefault || disabled) { e.preventDefault(); } if (onClick) { onClick(e); } }; const content = ( <>
{(icon || loading) && ( )}
{heading}
{description && description !== '' &&
{description}
}
); if (asChild && asChildContent) { const childElement = asChildContent as React.ReactElement; const childClassName = childElement.props?.className || ''; return React.cloneElement( childElement, { ...otherProps, className: classnames(classNames, childClassName), }, content, ); } return href ? ( {content} ) : ( ); }; export default MdTile;