Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add spotlight feature
  • Loading branch information
tellthemachines committed Mar 17, 2022
commit f55c01c3b834dbff1ef600796798f0af0153d26b
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { ___unstablePreferencesModalBaseOption as BaseOption } from '@wordpress/interface';
import { store as preferencesStore } from '@wordpress/preferences';

export default function EnableFeature( props ) {
const { featureName, ...remainingProps } = props;
const isChecked = useSelect( ( select ) =>
select( preferencesStore ).get( 'core/edit-site', featureName )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd maybe just coerce this into a bool to be on the safe side 😄

Suggested change
select( preferencesStore ).get( 'core/edit-site', featureName )
!! select( preferencesStore ).get( 'core/edit-site', featureName )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
select( preferencesStore ).get( 'core/edit-site', featureName )
( select ) =>
select( preferencesStore ).get( 'core/edit-site', featureName ),
[ featureName ]

Missing dependency.

);
const { toggle } = useDispatch( preferencesStore );
const onChange = () => toggle( 'core/edit-site', featureName );
return (
<BaseOption
onChange={ onChange }
isChecked={ isChecked }
{ ...remainingProps }
/>
);
}
15 changes: 14 additions & 1 deletion packages/edit-site/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import {
import { useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import EnableFeature from './enable-feature';

export default function EditSitePreferencesModal( {
isModalActive,
toggleModal,
Expand All @@ -23,7 +28,15 @@ export default function EditSitePreferencesModal( {
description={ __(
'Customize options related to the block editor interface and editing flow.'
) }
></PreferencesModalSection>
>
<EnableFeature
featureName="focusMode"
help={ __(
'Highlights the current block and fades other content.'
) }
label={ __( 'Spotlight mode' ) }
/>
</PreferencesModalSection>
),
},
] );
Expand Down