File size: 1,674 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import './style.scss';
import clsx from 'clsx';
import { translate } from 'i18n-calypso';
import closeIcon from './images/close.svg';
import errorIcon from './images/error.svg';
import successIcon from './images/success.svg';
import warningIcon from './images/warning.svg';
export enum NoticeType {
Success = 'success',
Warning = 'warning',
Error = 'error',
}
export type NoticeState = {
type: NoticeType;
message: string | React.ReactNode;
onClose?: () => void;
action?: React.ReactNode;
};
type NoticeProps = {
children: React.ReactNode;
className?: string;
action?: React.ReactNode;
type?: NoticeType;
onClose?: () => void;
visible?: boolean;
};
const Notice = ( {
children,
className,
action,
type = NoticeType.Success,
onClose,
visible = true,
}: NoticeProps ) => {
return visible ? (
<div
className={ clsx(
'subscription-management__notice',
`subscription-management__notice--${ type }`,
className
) }
>
{ onClose && (
<a
className="subscription-management__notice-close"
href="#close"
onClick={ ( e ) => {
e.preventDefault();
onClose?.();
} }
>
<img
src={ closeIcon }
alt={ translate( 'Close', { context: 'Hide the notice' } ) as string }
/>
</a>
) }
<div className="subscription-management__notice-icon">
<img
src={ { success: successIcon, warning: warningIcon, error: errorIcon }[ type ] }
alt=""
/>
</div>
<div className="subscription-management__notice-content">{ children }</div>
{ action && <div className="subscription-management__notice-action">{ action }</div> }
</div>
) : null;
};
export default Notice;
|