Skip to content

Commit

Permalink
Add speak messages to the feature toggle component. (#13385)
Browse files Browse the repository at this point in the history
* Add speak messages to the feature toggle component.

* Use plain props.
  • Loading branch information
afercia authored and youknowriad committed Mar 6, 2019
1 parent e1e10fe commit e0a514d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
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

0 comments on commit e0a514d

Please sign in to comment.