UNPKG

@wordpress/block-library

Version:
61 lines (54 loc) 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = NavigationMenuDeleteControl; var _element = require("@wordpress/element"); var _components = require("@wordpress/components"); var _coreData = require("@wordpress/core-data"); var _data = require("@wordpress/data"); var _i18n = require("@wordpress/i18n"); /** * WordPress dependencies */ function NavigationMenuDeleteControl(_ref) { let { onDelete } = _ref; const [isConfirmModalVisible, setIsConfirmModalVisible] = (0, _element.useState)(false); const id = (0, _coreData.useEntityId)('postType', 'wp_navigation'); const [title] = (0, _coreData.useEntityProp)('postType', 'wp_navigation', 'title'); const { deleteEntityRecord } = (0, _data.useDispatch)(_coreData.store); return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.Button, { className: "wp-block-navigation-delete-menu-button", variant: "secondary", isDestructive: true, onClick: () => { setIsConfirmModalVisible(true); } }, (0, _i18n.__)('Delete menu')), isConfirmModalVisible && (0, _element.createElement)(_components.Modal, { title: (0, _i18n.sprintf)( /* translators: %s: the name of a menu to delete */ (0, _i18n.__)('Delete %s'), title), closeLabel: (0, _i18n.__)('Cancel'), onRequestClose: () => setIsConfirmModalVisible(false) }, (0, _element.createElement)("p", null, (0, _i18n.__)('Are you sure you want to delete this navigation menu?')), (0, _element.createElement)(_components.Flex, { justify: "flex-end" }, (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, { variant: "secondary", onClick: () => { setIsConfirmModalVisible(false); } }, (0, _i18n.__)('Cancel'))), (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, { variant: "primary", onClick: () => { deleteEntityRecord('postType', 'wp_navigation', id, { force: true }); onDelete(title); } }, (0, _i18n.__)('Confirm')))))); } //# sourceMappingURL=navigation-menu-delete-control.js.map