Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add speak messages to the feature toggle component. #13385

Merged
merged 2 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions packages/edit-post/src/components/header/feature-toggle/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
/**
* External dependencies
*/
import { flow } from 'lodash';

/**
* WordPress Dependencies
*/
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { MenuItem } from '@wordpress/components';
import { MenuItem, withSpokenMessages } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

function FeatureToggle( { onToggle, isActive, label, info, messageActivated, messageDeactivated, speak } ) {
const speakMessage = () => {
if ( isActive ) {
speak( messageDeactivated || __( 'Feature deactivated' ) );
} else {
speak( messageActivated || __( 'Feature activated' ) );
}
};

function FeatureToggle( { onToggle, isActive, label, info } ) {
return (
<MenuItem
icon={ isActive && 'yes' }
isSelected={ isActive }
onClick={ onToggle }
onClick={ flow( onToggle, speakMessage ) }
role="menuitemcheckbox"
label={ label }
info={ info }
Expand All @@ -30,4 +44,5 @@ export default compose( [
ownProps.onToggle();
},
} ) ),
withSpokenMessages,
] )( FeatureToggle );
15 changes: 12 additions & 3 deletions packages/edit-post/src/components/header/writing-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,26 @@ function WritingMenu( { onClose } ) {
feature="fixedToolbar"
label={ __( 'Top Toolbar' ) }
info={ __( 'Access all block and document tools in a single place' ) }
onToggle={ onClose } />
onToggle={ onClose }
messageActivated={ __( 'Top toolbar activated' ) }
messageDeactivated={ __( 'Top toolbar deactivated' ) }
/>
<FeatureToggle
feature="focusMode"
label={ __( 'Spotlight Mode' ) }
info={ __( 'Focus on one block at a time' ) }
onToggle={ onClose } />
onToggle={ onClose }
messageActivated={ __( 'Spotlight mode activated' ) }
messageDeactivated={ __( 'Spotlight mode deactivated' ) }
/>
<FeatureToggle
feature="fullscreenMode"
label={ __( 'Fullscreen Mode' ) }
info={ __( 'Work without distraction' ) }
onToggle={ onClose } />
onToggle={ onClose }
messageActivated={ __( 'Fullscreen mode activated' ) }
messageDeactivated={ __( 'Fullscreen mode deactivated' ) }
/>
</MenuGroup>
);
}
Expand Down