import * as React from 'react'; import classnames from 'classnames'; import IReactComponentProps from '../../../common/structures/IReactComponentProps'; import styles from './Banner.scss'; import Close from '../../buttons/Close/Close'; import { FunctionGeneric } from '../../../common/structures/Generics'; import { Button } from '../../buttons/Button/Button'; import { CircleInfoIcon, SuccessIcon, YieldIcon } from '../../icons/Icons'; export interface BannerProps extends IReactComponentProps { /** Text displayed in inline button. Depends on `buttonOnClick`. */ buttonText?: string; /** Function called when clicking inline button. Depends on `buttonText`. */ buttonOnClick?: FunctionGeneric; /** Function called when dismissing banner. Dismiss button will not show if `onDimiss` is `undefined`. */ onDismiss?: FunctionGeneric; /** Color/icon used in general banner styling. */ variant?: 'warning' | 'neutral' | 'success' | 'error'; /** Size of the close icon. */ closeSize?: 's' | 'm' | 'l'; } const Banner = (props: BannerProps) => { const { 'aria-label': ariaLabel, variant = 'neutral', closeSize = 'm', className, id, style, children, buttonText, buttonOnClick, onDismiss, } = props; const renderIcon = () => { switch (variant) { case 'error': return ; case 'warning': return ; case 'success': return ; case 'neutral': default: return ; } }; const renderLabel = { error: 'Error', warning: 'Warning', success: 'Success', neutral: 'Information', }[variant] ?? 'Information'; const renderButton = () => { return !buttonText || !buttonOnClick ? null : ( ); }; const renderDismiss = () => { return onDismiss ? ( ) : null; }; return (
{renderIcon()}
{children}
{renderButton()} {renderDismiss()}
); }; export default Banner;