import classnames from 'classnames' import React, { MouseEventHandler, ReactNode, useEffect } from 'react' import { __, sprintf } from '@wordpress/i18n' import { useSnippetForm } from '../SnippetForm/context' interface DismissibleNoticeProps { classNames?: classnames.Argument onRemove: MouseEventHandler children?: ReactNode } const DismissibleNotice: React.FC = ({ classNames, onRemove, children }) => { useEffect(() => { if (window.CODE_SNIPPETS_EDIT?.scrollToNotices) { window.scrollTo({ top: 0, behavior: 'smooth' }) } }, []) return (
<>{children}
) } export const Notices: React.FC = () => { const { currentNotice, setCurrentNotice, snippet, setSnippet } = useSnippetForm() return <> {currentNotice ? setCurrentNotice(undefined)}>

{currentNotice[1]}

: null} {snippet.code_error ? setSnippet(previous => ({ ...previous, code_error: null }))} >

{sprintf( // translators: %d: line number. __('Snippet automatically deactivated due to an error on line %d:', 'code-snippets'), snippet.code_error[1] )}

{snippet.code_error[0]}

: null} }