From 178e7e1dd672767d168866af04758b6adc9e3da3 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Mon, 29 May 2023 11:40:31 +0300 Subject: [PATCH] Template actions with DropDownMenuV2 --- .../index.js | 2 +- .../src/components/template-actions/index.js | 87 +++++++++++-------- .../template-actions/rename-menu-item.js | 10 ++- 3 files changed, 57 insertions(+), 42 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js index 03cc7ecbec75bf..4ee8d7d3449cbf 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js @@ -74,7 +74,7 @@ function useTemplateTitleAndDescription( postType, postId ) { ); - return { title, description }; + return { title, description, template: record }; } export default function SidebarNavigationScreenTemplate() { diff --git a/packages/edit-site/src/components/template-actions/index.js b/packages/edit-site/src/components/template-actions/index.js index 0b54d6ef3ea716..5613213bfaa3c2 100644 --- a/packages/edit-site/src/components/template-actions/index.js +++ b/packages/edit-site/src/components/template-actions/index.js @@ -4,8 +4,8 @@ import { useDispatch, useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { __, sprintf } from '@wordpress/i18n'; -import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components'; -import { moreVertical } from '@wordpress/icons'; +import { privateApis as componentsPrivateApis } from '@wordpress/components'; +// import { Icon, moreVertical } from '@wordpress/icons'; import { store as noticesStore } from '@wordpress/notices'; /** @@ -16,6 +16,21 @@ import isTemplateRemovable from '../../utils/is-template-removable'; import isTemplateRevertable from '../../utils/is-template-revertable'; import RenameMenuItem from './rename-menu-item'; +import { unlock } from '../../private-apis'; + +const { + DropdownMenuV2, + // DropdownMenuCheckboxItemV2, + DropdownMenuGroupV2, + DropdownMenuItemV2, + // DropdownMenuLabelV2, + // DropdownMenuRadioGroupV2, + // DropdownMenuRadioItemV2, + // DropdownMenuSeparatorV2, + // DropdownSubMenuV2, + // DropdownSubMenuTriggerV2, +} = unlock( componentsPrivateApis ); + export default function TemplateActions( { postType, postId, @@ -70,48 +85,44 @@ export default function TemplateActions( { } return ( - } + trigger={ } > - { ( { onClose } ) => ( - - { isRemovable && ( - <> - - { - removeTemplate( template ); - onRemove?.(); - onClose(); - } } - > - { __( 'Delete' ) } - - - ) } - { isRevertable && ( - + { isRemovable && ( + <> + + { - revertAndSaveTemplate(); - onClose(); + removeTemplate( template ); + onRemove?.(); } } > - { __( 'Clear customizations' ) } - - ) } - - ) } - + { __( 'Delete' ) } + + + ) } + { isRevertable && ( + { + revertAndSaveTemplate(); + // onClose(); + } } + > + { __( 'Clear customizations' ) } + + ) } + + ); } diff --git a/packages/edit-site/src/components/template-actions/rename-menu-item.js b/packages/edit-site/src/components/template-actions/rename-menu-item.js index dec7f0bc8bf7dd..c857480623437c 100644 --- a/packages/edit-site/src/components/template-actions/rename-menu-item.js +++ b/packages/edit-site/src/components/template-actions/rename-menu-item.js @@ -15,7 +15,11 @@ import { import { store as coreStore } from '@wordpress/core-data'; import { store as noticesStore } from '@wordpress/notices'; -export default function RenameMenuItem( { template, onClose } ) { +export default function RenameMenuItem( { + template, + onClose, + as: UsedComponent = MenuItem, +} ) { const [ title, setTitle ] = useState( () => template.title.rendered ); const [ isModalOpen, setIsModalOpen ] = useState( false ); @@ -64,14 +68,14 @@ export default function RenameMenuItem( { template, onClose } ) { return ( <> - { setIsModalOpen( true ); setTitle( template.title.rendered ); } } > { __( 'Rename' ) } - + { isModalOpen && (