'use client'; import classnames from 'classnames'; import React from 'react'; import MdIconButton from '../iconButton/MdIconButton'; import MdIconCheckCircle from '../icons-material/MdIconCheckCircle'; import MdIconClose from '../icons-material/MdIconClose'; import MdIconDangerous from '../icons-material/MdIconDangerous'; import MdIconInfo from '../icons-material/MdIconInfo'; import MdIconWarning from '../icons-material/MdIconWarning'; interface Labels { info?: string; confirm?: string; error?: string; warning?: string; closeButton?: string; } export interface MdAlertMessageProps extends React.HTMLAttributes { label?: string | React.ReactNode; labels?: Labels; theme?: 'info' | 'success' | 'warning' | 'error' | 'info-box'; description?: string | React.ReactNode; hideIcon?: boolean; closable?: boolean; fullWidth?: boolean; onClose?(_e: React.MouseEvent): void; customIcon?: React.ReactNode | string; className?: string; alignContent?: 'start' | 'center' | 'end'; } export const MdAlertMessage: React.FC = ({ theme = 'info', label, labels = {}, description, hideIcon = false, closable = false, fullWidth = false, onClose, customIcon, className, alignContent, ...otherProps }: MdAlertMessageProps) => { const defaultLabels: Required = { info: 'Info', confirm: 'Bekreft', error: 'Feil', warning: 'Advarsel', closeButton: 'Lukk', }; const mergedLabels: Required = { ...defaultLabels, ...labels }; const classNames = classnames( 'md-alert-message', { 'md-alert-message--fullWidth': !!fullWidth, 'md-alert-message--success': theme === 'success', 'md-alert-message--warning': theme === 'warning', 'md-alert-message--error': theme === 'error', 'md-alert-message--info-box': theme === 'info-box', }, className, ); const contentClassNames = classnames('md-alert-message__content', { 'md-alert-message__content--center': alignContent === 'center', 'md-alert-message__content--end': alignContent === 'end', }); const renderIcon = () => { let icon = ( ) as React.ReactNode; if (customIcon) { icon = customIcon; } else if (theme === 'success') { icon = ( ); } else if (theme === 'error') { icon = ( ); } else if (theme === 'warning') { icon = ( ); } return icon; }; const clickHandler = (e: React.MouseEvent) => { if (onClose) { onClose(e); } }; return (
{!hideIcon && renderIcon()}
{label &&
{label}
} {description &&
{description}
}
{!!closable && onClose && (
{ return clickHandler(e); }} >
)}
); }; export default MdAlertMessage;