PluginProbe
Code Snippets / 4.0.0-beta.1
Code Snippets v4.0.0-beta.1
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / js / components / common / Notice.tsx

Notice.tsx in Code Snippets 4.0.0-beta.1, at js/components/common/Notice.tsx

34 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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