-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adds a basic Options modal to the More menu. - Moves the 'Enable Pre-publish Checks' and 'Show Tips' toggles to the new modal. - Allows the user to turn Document panels on or off.
- Loading branch information
1 parent
6990448
commit 7fcbf7c
Showing
22 changed files
with
518 additions
and
88 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
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,33 @@ | ||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { withDispatch } from '@wordpress/data'; | ||
|
||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { MenuItem } from '@wordpress/components'; | ||
|
||
export function OptionsMenuItem( { openModal, onSelect } ) { | ||
return ( | ||
<MenuItem | ||
onClick={ () => { | ||
onSelect(); | ||
openModal( 'edit-post/options' ); | ||
} } | ||
> | ||
{ __( 'Options' ) } | ||
</MenuItem> | ||
); | ||
} | ||
|
||
export default withDispatch( ( dispatch, ) => { | ||
const { | ||
openModal, | ||
} = dispatch( 'core/edit-post' ); | ||
|
||
return { | ||
openModal, | ||
}; | ||
} )( OptionsMenuItem ); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Modal, CheckboxControl } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { compose } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
|
||
const MODAL_NAME = 'edit-post/options'; | ||
|
||
const Section = ( { title, children } ) => ( | ||
<section className="edit-post-options__section"> | ||
<h2 className="edit-post-options__section-title"> | ||
{ title } | ||
</h2> | ||
{ children } | ||
</section> | ||
); | ||
|
||
export function OptionsModal( { | ||
isModalActive, | ||
toggleModal, | ||
isPublishSidebarEnabled, | ||
setIsPublishSidebarEnabled, | ||
areTipsEnabled, | ||
setAreTipsEnabled, | ||
isStatusPanelEnabled, | ||
setIsStatusPanelEnabled, | ||
isCategoriesPanelEnabled, | ||
setIsCategoriesPanelEnabled, | ||
isTagsPanelEnabled, | ||
setIsTagsPanelEnabled, | ||
isFeaturedImagePanelEnabled, | ||
setIsFeaturedImagePanelEnabled, | ||
isExcerptPanelEnabled, | ||
setIsExcerptPanelEnabled, | ||
isDiscussionPanelEnabled, | ||
setIsDiscussionPanelEnabled, | ||
} ) { | ||
if ( ! isModalActive ) { | ||
return null; | ||
} | ||
|
||
const title = ( | ||
<span className="edit-post-options__title"> | ||
{ __( 'Options' ) } | ||
</span> | ||
); | ||
|
||
return ( | ||
<Modal | ||
className="edit-post-options" | ||
title={ title } | ||
closeLabel={ __( 'Close' ) } | ||
onRequestClose={ toggleModal } | ||
> | ||
<Section title={ __( 'General' ) }> | ||
<CheckboxControl | ||
className="edit-post-options__option" | ||
label={ __( 'Enable Pre-publish Checks' ) } | ||
checked={ isPublishSidebarEnabled } | ||
onChange={ setIsPublishSidebarEnabled } | ||
/> | ||
<CheckboxControl | ||
className="edit-post-options__option" | ||
label={ __( 'Enable Tips' ) } | ||
checked={ areTipsEnabled } | ||
onChange={ setAreTipsEnabled } | ||
/> | ||
</Section> | ||
<Section title={ __( 'Document Panels' ) }> | ||
<CheckboxControl | ||
className="edit-post-options__option" | ||
label={ __( 'Status & Visibility' ) } | ||
checked={ isStatusPanelEnabled } | ||
onChange={ setIsStatusPanelEnabled } | ||
/> | ||
<CheckboxControl | ||
className="edit-post-options__option" | ||
label={ __( 'Categories' ) } | ||
checked={ isCategoriesPanelEnabled } | ||
onChange={ setIsCategoriesPanelEnabled } | ||
/> | ||
<CheckboxControl | ||
className="edit-post-options__option" | ||
label={ __( 'Tags' ) } | ||
checked={ isTagsPanelEnabled } | ||
onChange={ setIsTagsPanelEnabled } | ||
/> | ||
<CheckboxControl | ||
className="edit-post-options__option" | ||
label={ __( 'Featured Image' ) } | ||
checked={ isFeaturedImagePanelEnabled } | ||
onChange={ setIsFeaturedImagePanelEnabled } | ||
/> | ||
<CheckboxControl | ||
className="edit-post-options__option" | ||
label={ __( 'Excerpt' ) } | ||
checked={ isExcerptPanelEnabled } | ||
onChange={ setIsExcerptPanelEnabled } | ||
/> | ||
<CheckboxControl | ||
className="edit-post-options__option" | ||
label={ __( 'Discussion' ) } | ||
checked={ isDiscussionPanelEnabled } | ||
onChange={ setIsDiscussionPanelEnabled } | ||
/> | ||
</Section> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select ) => { | ||
const { isModalActive, isEditorSidebarPanelEnabled } = select( 'core/edit-post' ); | ||
const { isPublishSidebarEnabled } = select( 'core/editor' ); | ||
const { areTipsEnabled } = select( 'core/nux' ); | ||
|
||
return { | ||
isModalActive: isModalActive( MODAL_NAME ), | ||
isPublishSidebarEnabled: isPublishSidebarEnabled(), | ||
areTipsEnabled: areTipsEnabled(), | ||
isStatusPanelEnabled: isEditorSidebarPanelEnabled( 'post-status' ), | ||
isCategoriesPanelEnabled: isEditorSidebarPanelEnabled( 'taxonomy-panel-category' ), | ||
isTagsPanelEnabled: isEditorSidebarPanelEnabled( 'taxonomy-panel-post_tag' ), | ||
isFeaturedImagePanelEnabled: isEditorSidebarPanelEnabled( 'featured-image' ), | ||
isExcerptPanelEnabled: isEditorSidebarPanelEnabled( 'post-excerpt' ), | ||
isDiscussionPanelEnabled: isEditorSidebarPanelEnabled( 'discussion-panel' ), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, { isModalActive } ) => { | ||
const { openModal, closeModal, enablePanel, disablePanel } = dispatch( 'core/edit-post' ); | ||
const { enablePublishSidebar, disablePublishSidebar } = dispatch( 'core/editor' ); | ||
const { enableTips, disableTips } = dispatch( 'core/nux' ); | ||
|
||
const buildSetIsPanelEnabled = ( panel ) => ( isEnabled ) => { | ||
if ( isEnabled ) { | ||
enablePanel( panel ); | ||
} else { | ||
disablePanel( panel ); | ||
} | ||
}; | ||
|
||
return { | ||
toggleModal() { | ||
if ( isModalActive ) { | ||
closeModal(); | ||
} else { | ||
openModal( MODAL_NAME ); | ||
} | ||
}, | ||
setIsPublishSidebarEnabled( isEnabled ) { | ||
if ( isEnabled ) { | ||
enablePublishSidebar(); | ||
} else { | ||
disablePublishSidebar(); | ||
} | ||
}, | ||
setAreTipsEnabled( isEnabled ) { | ||
if ( isEnabled ) { | ||
enableTips(); | ||
} else { | ||
disableTips(); | ||
} | ||
}, | ||
setIsStatusPanelEnabled: buildSetIsPanelEnabled( 'post-status' ), | ||
setIsCategoriesPanelEnabled: buildSetIsPanelEnabled( 'taxonomy-panel-category' ), | ||
setIsTagsPanelEnabled: buildSetIsPanelEnabled( 'taxonomy-panel-post_tag' ), | ||
setIsFeaturedImagePanelEnabled: buildSetIsPanelEnabled( 'featured-image' ), | ||
setIsExcerptPanelEnabled: buildSetIsPanelEnabled( 'post-excerpt' ), | ||
setIsDiscussionPanelEnabled: buildSetIsPanelEnabled( 'discussion-panel' ), | ||
}; | ||
} ), | ||
] )( OptionsModal ); |
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,36 @@ | ||
.edit-post-options { | ||
min-width: 450px; | ||
|
||
&__title { | ||
font-size: 1rem; | ||
font-weight: bold; | ||
} | ||
|
||
&__section { | ||
margin: 0 0 2rem 0; | ||
} | ||
|
||
&__section-title { | ||
font-size: 0.9rem; | ||
font-weight: bold; | ||
} | ||
|
||
&__option { | ||
display: flex; | ||
align-items: center; | ||
padding: 0.6rem 0; | ||
border-top: 1px solid $light-gray-500; | ||
|
||
&:last-child { | ||
border-bottom: 1px solid $light-gray-500; | ||
} | ||
|
||
.components-base-control__field { | ||
margin: 0; | ||
} | ||
|
||
.components-checkbox-control__input { | ||
margin-right: 10px; | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
edit-post/components/options-modal/test/__snapshots__/index.js.snap
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,58 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`OptionsModal should match snapshot when the modal is active 1`] = ` | ||
<WithInstanceId(Modal) | ||
className="edit-post-options" | ||
closeLabel="Close" | ||
title={ | ||
<span | ||
className="edit-post-options__title" | ||
> | ||
Options | ||
</span> | ||
} | ||
> | ||
<Section | ||
title="General" | ||
> | ||
<WithInstanceId(CheckboxControl) | ||
className="edit-post-options__option" | ||
label="Enable Pre-publish Checks" | ||
/> | ||
<WithInstanceId(CheckboxControl) | ||
className="edit-post-options__option" | ||
label="Enable Tips" | ||
/> | ||
</Section> | ||
<Section | ||
title="Document Panels" | ||
> | ||
<WithInstanceId(CheckboxControl) | ||
className="edit-post-options__option" | ||
label="Status & Visibility" | ||
/> | ||
<WithInstanceId(CheckboxControl) | ||
className="edit-post-options__option" | ||
label="Categories" | ||
/> | ||
<WithInstanceId(CheckboxControl) | ||
className="edit-post-options__option" | ||
label="Tags" | ||
/> | ||
<WithInstanceId(CheckboxControl) | ||
className="edit-post-options__option" | ||
label="Featured Image" | ||
/> | ||
<WithInstanceId(CheckboxControl) | ||
className="edit-post-options__option" | ||
label="Excerpt" | ||
/> | ||
<WithInstanceId(CheckboxControl) | ||
className="edit-post-options__option" | ||
label="Discussion" | ||
/> | ||
</Section> | ||
</WithInstanceId(Modal)> | ||
`; | ||
|
||
exports[`OptionsModal should match snapshot when the modal is not active 1`] = `""`; |
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,31 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { OptionsModal } from '../'; | ||
|
||
describe( 'OptionsModal', () => { | ||
it( 'should match snapshot when the modal is active', () => { | ||
const wrapper = shallow( | ||
<OptionsModal | ||
isModalActive={ true } | ||
/> | ||
); | ||
|
||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should match snapshot when the modal is not active', () => { | ||
const wrapper = shallow( | ||
<OptionsModal | ||
isModalActive={ false } | ||
/> | ||
); | ||
|
||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
} ); |
Oops, something went wrong.