-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show a draft save button on the block toolbar
- Loading branch information
Showing
4 changed files
with
73 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/block-library/src/navigation/edit/navigation-menu-publish-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { ToolbarButton } from '@wordpress/components'; | ||
import { | ||
useEntityId, | ||
useEntityProp, | ||
store as coreStore, | ||
} from '@wordpress/core-data'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NavigationMenuNameModal from './navigation-menu-name-modal'; | ||
|
||
export default function NavigationMenuPublishButton() { | ||
const [ isNameModalVisible, setIsNameModalVisible ] = useState( false ); | ||
const id = useEntityId( 'postType', 'wp_navigation' ); | ||
const [ navigationMenuTitle ] = useEntityProp( | ||
'postType', | ||
'wp_navigation', | ||
'title' | ||
); | ||
const { editEntityRecord, saveEditedEntityRecord } = useDispatch( | ||
coreStore | ||
); | ||
|
||
return ( | ||
<> | ||
<ToolbarButton onClick={ () => setIsNameModalVisible( true ) }> | ||
{ __( 'Save as' ) } | ||
</ToolbarButton> | ||
{ isNameModalVisible && ( | ||
<NavigationMenuNameModal | ||
title={ __( 'Save your new navigation menu' ) } | ||
value={ navigationMenuTitle } | ||
onRequestClose={ () => setIsNameModalVisible( false ) } | ||
finishButtonText={ __( 'Save' ) } | ||
onFinish={ ( updatedTitle ) => { | ||
editEntityRecord( 'postType', 'wp_navigation', id, { | ||
title: updatedTitle, | ||
status: 'publish', | ||
} ); | ||
saveEditedEntityRecord( | ||
'postType', | ||
'wp_navigation', | ||
id | ||
); | ||
} } | ||
/> | ||
) } | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters