PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
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.2, at js/components/common/Notice.tsx

41 lines 1.3 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 const isAssertive = (type?: NoticeType): boolean => 'error' === type || 'warning' === type
15
16 export const Notice: React.FC<NoticeProps> = ({ className, type, children, ...props }) =>
17 <div
18 className={classnames('notice', 'code-snippets-notice', { [`notice-${type}`]: type }, className)}
19 role={isAssertive(type) ? 'alert' : 'status'}
20 aria-live={isAssertive(type) ? 'assertive' : 'polite'}
21 {...props}
22 >
23 {children}
24 </div>
25
26 export interface DismissibleNoticeProps extends NoticeProps {
27 onDismiss: VoidFunction
28 }
29
30 export const DismissibleNotice: React.FC<DismissibleNoticeProps> = ({ className, onDismiss, children, ...noticeProps }) =>
31 <Notice className={classnames('is-dismissible', className)} {...noticeProps}>
32 {children}
33
34 <button type="button" className="notice-dismiss" onClick={event => {
35 event.preventDefault()
36 onDismiss()
37 }}>
38 <span className="screen-reader-text">{__('Dismiss notice.', 'code-snippets')}</span>
39 </button>
40 </Notice>
41