| 1 |
import { __ } from '@wordpress/i18n' |
| 2 |
import classnames from 'classnames' |
| 3 |
import React from 'react' |
| 4 |
import type { HTMLAttributes, ReactNode } from 'react' |
| 5 |
|
| 6 |
export type NoticeType = 'info' | 'warning' | 'error' | 'success' |
| 7 |
|
| 8 |
export interface NoticeProps extends Omit<HTMLAttributes<HTMLDivElement>, 'className'> { |
| 9 |
className?: classnames.Argument |
| 10 |
children?: ReactNode |
| 11 |
type?: NoticeType |
| 12 |
} |
| 13 |
|
| 14 |
export const Notice: React.FC<NoticeProps> = ({ className, type, children, ...props }) => |
| 15 |
<div className={classnames('notice', { [`notice-${type}`]: type }, className)} {...props}> |
| 16 |
{children} |
| 17 |
</div> |
| 18 |
|
| 19 |
export interface DismissibleNoticeProps extends NoticeProps { |
| 20 |
onDismiss: VoidFunction |
| 21 |
} |
| 22 |
|
| 23 |
export const DismissibleNotice: React.FC<DismissibleNoticeProps> = ({ className, onDismiss, children, ...noticeProps }) => |
| 24 |
<Notice className={classnames('is-dismissible', className)} {...noticeProps}> |
| 25 |
{children} |
| 26 |
|
| 27 |
<button type="button" className="notice-dismiss" onClick={event => { |
| 28 |
event.preventDefault() |
| 29 |
onDismiss() |
| 30 |
}}> |
| 31 |
<span className="screen-reader-text">{__('Dismiss notice.', 'code-snippets')}</span> |
| 32 |
</button> |
| 33 |
</Notice> |
| 34 |
|