-
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.
Add more menu to customize widgets (#31970)
* Add basic more menu framework * Hook up top toolbar and contain caret inside blocks preferences to editor settings * Introduce keyboard shortcut modal * Fix modal styles * Add shortcut for modal itself * Tidy up bottom margin when top toolbar is active * Toolbar adjustments * Update package lock
- Loading branch information
Showing
21 changed files
with
786 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
27 changes: 27 additions & 0 deletions
27
packages/customize-widgets/src/components/keyboard-shortcut-help-modal/config.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,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
export const textFormattingShortcuts = [ | ||
{ | ||
keyCombination: { modifier: 'primary', character: 'b' }, | ||
description: __( 'Make the selected text bold.' ), | ||
}, | ||
{ | ||
keyCombination: { modifier: 'primary', character: 'i' }, | ||
description: __( 'Make the selected text italic.' ), | ||
}, | ||
{ | ||
keyCombination: { modifier: 'primary', character: 'k' }, | ||
description: __( 'Convert the selected text into a link.' ), | ||
}, | ||
{ | ||
keyCombination: { modifier: 'primaryShift', character: 'k' }, | ||
description: __( 'Remove a link.' ), | ||
}, | ||
{ | ||
keyCombination: { modifier: 'primary', character: 'u' }, | ||
description: __( 'Underline the selected text.' ), | ||
}, | ||
]; |
40 changes: 40 additions & 0 deletions
40
packages/customize-widgets/src/components/keyboard-shortcut-help-modal/dynamic-shortcut.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,40 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Shortcut from './shortcut'; | ||
|
||
function DynamicShortcut( { name } ) { | ||
const { keyCombination, description, aliases } = useSelect( ( select ) => { | ||
const { | ||
getShortcutKeyCombination, | ||
getShortcutDescription, | ||
getShortcutAliases, | ||
} = select( keyboardShortcutsStore ); | ||
|
||
return { | ||
keyCombination: getShortcutKeyCombination( name ), | ||
aliases: getShortcutAliases( name ), | ||
description: getShortcutDescription( name ), | ||
}; | ||
} ); | ||
|
||
if ( ! keyCombination ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Shortcut | ||
keyCombination={ keyCombination } | ||
description={ description } | ||
aliases={ aliases } | ||
/> | ||
); | ||
} | ||
|
||
export default DynamicShortcut; |
153 changes: 153 additions & 0 deletions
153
packages/customize-widgets/src/components/keyboard-shortcut-help-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,153 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
import { isString } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Modal } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
useShortcut, | ||
store as keyboardShortcutsStore, | ||
} from '@wordpress/keyboard-shortcuts'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { textFormattingShortcuts } from './config'; | ||
import Shortcut from './shortcut'; | ||
import DynamicShortcut from './dynamic-shortcut'; | ||
|
||
const ShortcutList = ( { shortcuts } ) => ( | ||
/* | ||
* Disable reason: The `list` ARIA role is redundant but | ||
* Safari+VoiceOver won't announce the list otherwise. | ||
*/ | ||
/* eslint-disable jsx-a11y/no-redundant-roles */ | ||
<ul | ||
className="customize-widgets-keyboard-shortcut-help-modal__shortcut-list" | ||
role="list" | ||
> | ||
{ shortcuts.map( ( shortcut, index ) => ( | ||
<li | ||
className="customize-widgets-keyboard-shortcut-help-modal__shortcut" | ||
key={ index } | ||
> | ||
{ isString( shortcut ) ? ( | ||
<DynamicShortcut name={ shortcut } /> | ||
) : ( | ||
<Shortcut { ...shortcut } /> | ||
) } | ||
</li> | ||
) ) } | ||
</ul> | ||
/* eslint-enable jsx-a11y/no-redundant-roles */ | ||
); | ||
|
||
const ShortcutSection = ( { title, shortcuts, className } ) => ( | ||
<section | ||
className={ classnames( | ||
'customize-widgets-keyboard-shortcut-help-modal__section', | ||
className | ||
) } | ||
> | ||
{ !! title && ( | ||
<h2 className="customize-widgets-keyboard-shortcut-help-modal__section-title"> | ||
{ title } | ||
</h2> | ||
) } | ||
<ShortcutList shortcuts={ shortcuts } /> | ||
</section> | ||
); | ||
|
||
const ShortcutCategorySection = ( { | ||
title, | ||
categoryName, | ||
additionalShortcuts = [], | ||
} ) => { | ||
const categoryShortcuts = useSelect( | ||
( select ) => { | ||
return select( keyboardShortcutsStore ).getCategoryShortcuts( | ||
categoryName | ||
); | ||
}, | ||
[ categoryName ] | ||
); | ||
|
||
return ( | ||
<ShortcutSection | ||
title={ title } | ||
shortcuts={ categoryShortcuts.concat( additionalShortcuts ) } | ||
/> | ||
); | ||
}; | ||
|
||
export default function KeyboardShortcutHelpModal( { | ||
isModalActive, | ||
toggleModal, | ||
} ) { | ||
const { registerShortcut } = useDispatch( keyboardShortcutsStore ); | ||
registerShortcut( { | ||
name: 'core/customize-widgets/keyboard-shortcuts', | ||
category: 'main', | ||
description: __( 'Display these keyboard shortcuts.' ), | ||
keyCombination: { | ||
modifier: 'access', | ||
character: 'h', | ||
}, | ||
} ); | ||
|
||
useShortcut( 'core/customize-widgets/keyboard-shortcuts', toggleModal, { | ||
bindGlobal: true, | ||
} ); | ||
|
||
if ( ! isModalActive ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Modal | ||
className="customize-widgets-keyboard-shortcut-help-modal" | ||
title={ __( 'Keyboard shortcuts' ) } | ||
closeLabel={ __( 'Close' ) } | ||
onRequestClose={ toggleModal } | ||
> | ||
<ShortcutSection | ||
className="customize-widgets-keyboard-shortcut-help-modal__main-shortcuts" | ||
shortcuts={ [ 'core/customize-widgets/keyboard-shortcuts' ] } | ||
/> | ||
<ShortcutCategorySection | ||
title={ __( 'Global shortcuts' ) } | ||
categoryName="global" | ||
/> | ||
|
||
<ShortcutCategorySection | ||
title={ __( 'Selection shortcuts' ) } | ||
categoryName="selection" | ||
/> | ||
|
||
<ShortcutCategorySection | ||
title={ __( 'Block shortcuts' ) } | ||
categoryName="block" | ||
additionalShortcuts={ [ | ||
{ | ||
keyCombination: { character: '/' }, | ||
description: __( | ||
'Change the block type after adding a new paragraph.' | ||
), | ||
/* translators: The forward-slash character. e.g. '/'. */ | ||
ariaLabel: __( 'Forward-slash' ), | ||
}, | ||
] } | ||
/> | ||
<ShortcutSection | ||
title={ __( 'Text formatting' ) } | ||
shortcuts={ textFormattingShortcuts } | ||
/> | ||
</Modal> | ||
); | ||
} |
Oops, something went wrong.