-
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.
Patterns: add a hint about the rename of reusable blocks to menu and …
…inserter (#51771) Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
- Loading branch information
1 parent
f060b18
commit 14bb146
Showing
10 changed files
with
103 additions
and
10 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
52 changes: 52 additions & 0 deletions
52
packages/block-editor/src/components/inserter/reusable-block-rename-hint.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,52 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button } from '@wordpress/components'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { focus } from '@wordpress/dom'; | ||
import { useRef } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { close } from '@wordpress/icons'; | ||
import { store as preferencesStore } from '@wordpress/preferences'; | ||
|
||
const PREFERENCE_NAME = 'isResuableBlocksrRenameHintVisible'; | ||
|
||
export default function ReusableBlocksRenameHint() { | ||
const isReusableBlocksRenameHint = useSelect( | ||
( select ) => | ||
select( preferencesStore ).get( 'core', PREFERENCE_NAME ) ?? true, | ||
[] | ||
); | ||
|
||
const ref = useRef(); | ||
|
||
const { set: setPreference } = useDispatch( preferencesStore ); | ||
if ( ! isReusableBlocksRenameHint ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div ref={ ref } className="reusable-blocks-menu-items__rename-hint"> | ||
<div className="reusable-blocks-menu-items__rename-hint-content"> | ||
{ __( | ||
'Reusable blocks are now called patterns. A synced pattern will behave in exactly the same way as a reusable block.' | ||
) } | ||
</div> | ||
<Button | ||
className="reusable-blocks-menu-items__rename-hint-dismiss" | ||
icon={ close } | ||
iconSize="16" | ||
label={ __( 'Dismiss hint' ) } | ||
onClick={ () => { | ||
// Retain focus when dismissing the element. | ||
const previousElement = focus.tabbable.findPrevious( | ||
ref.current | ||
); | ||
previousElement?.focus(); | ||
setPreference( 'core', PREFERENCE_NAME, false ); | ||
} } | ||
showTooltip={ false } | ||
/> | ||
</div> | ||
); | ||
} |
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
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
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