forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preferences modal to site editor (WordPress#39485)
* Add preferences modal to site editor * Add spotlight feature * Add caret inside block setting * Improvements to enable feature selector.
- Loading branch information
1 parent
145d320
commit 366cef1
Showing
6 changed files
with
118 additions
and
0 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
24 changes: 24 additions & 0 deletions
24
packages/edit-site/src/components/preferences-modal/enable-feature.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,24 @@ | ||
/** | ||
* 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 ), | ||
[ featureName ] | ||
); | ||
const { toggle } = useDispatch( preferencesStore ); | ||
const onChange = () => toggle( 'core/edit-site', featureName ); | ||
return ( | ||
<BaseOption | ||
onChange={ onChange } | ||
isChecked={ isChecked } | ||
{ ...remainingProps } | ||
/> | ||
); | ||
} |
71 changes: 71 additions & 0 deletions
71
packages/edit-site/src/components/preferences-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,71 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
PreferencesModal, | ||
PreferencesModalTabs, | ||
PreferencesModalSection, | ||
} from '@wordpress/interface'; | ||
import { useMemo } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import EnableFeature from './enable-feature'; | ||
|
||
export default function EditSitePreferencesModal( { | ||
isModalActive, | ||
toggleModal, | ||
} ) { | ||
const sections = useMemo( () => [ | ||
{ | ||
name: 'general', | ||
tabLabel: __( 'General' ), | ||
content: ( | ||
<PreferencesModalSection | ||
title={ __( 'Appearance' ) } | ||
description={ __( | ||
'Customize options related to the block editor interface and editing flow.' | ||
) } | ||
> | ||
<EnableFeature | ||
featureName="focusMode" | ||
help={ __( | ||
'Highlights the current block and fades other content.' | ||
) } | ||
label={ __( 'Spotlight mode' ) } | ||
/> | ||
</PreferencesModalSection> | ||
), | ||
}, | ||
{ | ||
name: 'blocks', | ||
tabLabel: __( 'Blocks' ), | ||
content: ( | ||
<PreferencesModalSection | ||
title={ __( 'Block interactions' ) } | ||
description={ __( | ||
'Customize how you interact with blocks in the block library and editing canvas.' | ||
) } | ||
> | ||
<EnableFeature | ||
featureName="keepCaretInsideBlock" | ||
help={ __( | ||
'Aids screen readers by stopping text caret from leaving blocks.' | ||
) } | ||
label={ __( 'Contain text cursor inside block' ) } | ||
/> | ||
</PreferencesModalSection> | ||
), | ||
}, | ||
] ); | ||
if ( ! isModalActive ) { | ||
return null; | ||
} | ||
return ( | ||
<PreferencesModal closeModal={ toggleModal }> | ||
<PreferencesModalTabs sections={ sections } /> | ||
</PreferencesModal> | ||
); | ||
} |
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