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 (
);
}
export function DisallowOverridesModal( {
onClose,
onSave,
}: DisallowOverridesModalProps ) {
const descriptionId = useId();
return (
);
}