Your IP : 216.73.216.215


Current Path : /home/flapst5/ekmtoronto.com/wp-content/plugins/code-snippets/js/components/common/
Upload File :
Current File : /home/flapst5/ekmtoronto.com/wp-content/plugins/code-snippets/js/components/common/Notice.tsx

import { __ } from '@wordpress/i18n'
import classnames from 'classnames'
import React from 'react'
import type { HTMLAttributes, ReactNode } from 'react'

export type NoticeType = 'info' | 'warning' | 'error' | 'success'

export interface NoticeProps extends Omit<HTMLAttributes<HTMLDivElement>, 'className'> {
	className?: classnames.Argument
	children?: ReactNode
	type?: NoticeType
}

const isAssertive = (type?: NoticeType): boolean => 'error' === type || 'warning' === type

export const Notice: React.FC<NoticeProps> = ({ className, type, children, ...props }) =>
	<div
		className={classnames('notice', 'code-snippets-notice', { [`notice-${type}`]: type }, className)}
		role={isAssertive(type) ? 'alert' : 'status'}
		aria-live={isAssertive(type) ? 'assertive' : 'polite'}
		{...props}
	>
		{children}
	</div>

export interface DismissibleNoticeProps extends NoticeProps {
	onDismiss: VoidFunction
}

export const DismissibleNotice: React.FC<DismissibleNoticeProps> = ({ className, onDismiss, children, ...noticeProps }) =>
	<Notice className={classnames('is-dismissible', className)} {...noticeProps}>
		{children}

		<button type="button" className="notice-dismiss" onClick={event => {
			event.preventDefault()
			onDismiss()
		}}>
			<span className="screen-reader-text">{__('Dismiss notice.', 'code-snippets')}</span>
		</button>
	</Notice>