-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pattern title in create modal in post editor (#59550)
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: jameskoster <jameskoster@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
- Loading branch information
Showing
4 changed files
with
121 additions
and
100 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
packages/edit-post/src/components/init-pattern-modal/index.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,117 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { | ||
Modal, | ||
Button, | ||
__experimentalHStack as HStack, | ||
__experimentalVStack as VStack, | ||
ToggleControl, | ||
TextControl, | ||
} from '@wordpress/components'; | ||
import { useEffect, useState } from '@wordpress/element'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { ReusableBlocksRenameHint } = unlock( blockEditorPrivateApis ); | ||
|
||
export default function InitPatternModal() { | ||
const { editPost } = useDispatch( editorStore ); | ||
const [ isModalOpen, setIsModalOpen ] = useState( false ); | ||
const [ syncType, setSyncType ] = useState( undefined ); | ||
const [ title, setTitle ] = useState( '' ); | ||
|
||
const { postType, isNewPost } = useSelect( ( select ) => { | ||
const { getEditedPostAttribute, isCleanNewPost } = | ||
select( editorStore ); | ||
return { | ||
postType: getEditedPostAttribute( 'type' ), | ||
isNewPost: isCleanNewPost(), | ||
}; | ||
}, [] ); | ||
|
||
useEffect( () => { | ||
if ( isNewPost && postType === 'wp_block' ) { | ||
setIsModalOpen( true ); | ||
} | ||
// We only want the modal to open when the page is first loaded. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [] ); | ||
|
||
if ( postType !== 'wp_block' || ! isNewPost ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
{ isModalOpen && ( | ||
<Modal | ||
title={ __( 'Create pattern' ) } | ||
onRequestClose={ () => { | ||
setIsModalOpen( false ); | ||
} } | ||
overlayClassName="reusable-blocks-menu-items__convert-modal" | ||
> | ||
<form | ||
onSubmit={ ( event ) => { | ||
event.preventDefault(); | ||
setIsModalOpen( false ); | ||
editPost( { | ||
title, | ||
meta: { | ||
wp_pattern_sync_status: syncType, | ||
}, | ||
} ); | ||
} } | ||
> | ||
<VStack spacing="5"> | ||
<TextControl | ||
label={ __( 'Name' ) } | ||
value={ title } | ||
onChange={ setTitle } | ||
placeholder={ __( 'My pattern' ) } | ||
className="patterns-create-modal__name-input" | ||
__nextHasNoMarginBottom | ||
__next40pxDefaultSize | ||
/> | ||
<ReusableBlocksRenameHint /> | ||
<ToggleControl | ||
label={ _x( | ||
'Synced', | ||
'Option that makes an individual pattern synchronized' | ||
) } | ||
help={ __( | ||
'Sync this pattern across multiple locations.' | ||
) } | ||
checked={ ! syncType } | ||
onChange={ () => { | ||
setSyncType( | ||
! syncType ? 'unsynced' : undefined | ||
); | ||
} } | ||
/> | ||
<HStack justify="right"> | ||
<Button | ||
variant="primary" | ||
type="submit" | ||
disabled={ ! title } | ||
__experimentalIsFocusable | ||
> | ||
{ __( 'Create' ) } | ||
</Button> | ||
</HStack> | ||
</VStack> | ||
</form> | ||
</Modal> | ||
) } | ||
</> | ||
); | ||
} |
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
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