import { Button, TextControl, Modal } from '@wordpress/components'; import { Stack, Text } from '@wordpress/ui'; import { __, sprintf } from '@wordpress/i18n'; import { useState, useId } from '@wordpress/element'; import { speak } from '@wordpress/a11y'; import type { AllowOverridesModalProps, DisallowOverridesModalProps, } from './types'; export function AllowOverridesModal( { placeholder, initialName = '', onClose, onSave, }: AllowOverridesModalProps ) { const [ editedBlockName, setEditedBlockName ] = useState( initialName ); const descriptionId = useId(); const isNameValid = !! editedBlockName.trim(); const handleSubmit = () => { if ( editedBlockName !== initialName ) { const message = sprintf( /* translators: %s: new name/label for the block */ __( 'Block name changed to: "%s".' ), editedBlockName ); // Must be assertive to immediately announce change. speak( message, 'assertive' ); } onSave( editedBlockName ); // Immediate close avoids ability to hit save multiple times. onClose(); }; return (
{ event.preventDefault(); if ( ! isNameValid ) { return; } handleSubmit(); } } > { __( 'Overrides are changes you make to a block within a synced pattern instance. Use overrides to customize a synced pattern instance to suit its new context. Name this block to specify an override.' ) }
); } export function DisallowOverridesModal( { onClose, onSave, }: DisallowOverridesModalProps ) { const descriptionId = useId(); return (
{ event.preventDefault(); onSave(); onClose(); } } > { __( 'Are you sure you want to disable overrides? Disabling overrides will revert all applied overrides for this block throughout instances of this pattern.' ) }
); }