UNPKG

@wordpress/block-library

Version:
51 lines (50 loc) 1.87 kB
import { createElement, Fragment } from "@wordpress/element"; /** * WordPress dependencies */ import { Button, Flex, FlexItem, Modal } from '@wordpress/components'; import { store as coreStore, useEntityId, useEntityProp } from '@wordpress/core-data'; import { useDispatch } from '@wordpress/data'; import { useState } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; export default function NavigationMenuDeleteControl(_ref) { let { onDelete } = _ref; const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); const id = useEntityId('postType', 'wp_navigation'); const [title] = useEntityProp('postType', 'wp_navigation', 'title'); const { deleteEntityRecord } = useDispatch(coreStore); return createElement(Fragment, null, createElement(Button, { className: "wp-block-navigation-delete-menu-button", variant: "secondary", isDestructive: true, onClick: () => { setIsConfirmModalVisible(true); } }, __('Delete menu')), isConfirmModalVisible && createElement(Modal, { title: sprintf( /* translators: %s: the name of a menu to delete */ __('Delete %s'), title), closeLabel: __('Cancel'), onRequestClose: () => setIsConfirmModalVisible(false) }, createElement("p", null, __('Are you sure you want to delete this navigation menu?')), createElement(Flex, { justify: "flex-end" }, createElement(FlexItem, null, createElement(Button, { variant: "secondary", onClick: () => { setIsConfirmModalVisible(false); } }, __('Cancel'))), createElement(FlexItem, null, createElement(Button, { variant: "primary", onClick: () => { deleteEntityRecord('postType', 'wp_navigation', id, { force: true }); onDelete(title); } }, __('Confirm')))))); } //# sourceMappingURL=navigation-menu-delete-control.js.map