-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Chrome: Replace the publish dropdown by a sidebar panel #4119
Changes from 1 commit
6c8ddf2
131ab94
100e210
ae83845
a8c3906
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import { connect } from 'react-redux'; | |
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { IconButton } from '@wordpress/components'; | ||
import { Component } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -18,77 +17,49 @@ import { | |
PostPreviewButton, | ||
PostSavedState, | ||
PostPublishPanelToggle, | ||
PostPublishPanel, | ||
} from '../../components'; | ||
import EllipsisMenu from './ellipsis-menu'; | ||
import HeaderToolbar from './header-toolbar'; | ||
import { isEditorSidebarOpened } from '../../store/selectors'; | ||
import { isSidebarOpened } from '../../store/selectors'; | ||
import { toggleSidebar } from '../../store/actions'; | ||
|
||
class Header extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
this.state = { | ||
isPublishPanelOpened: false, | ||
}; | ||
this.togglePublishPanel = this.togglePublishPanel.bind( this ); | ||
this.closePublishPanel = this.closePublishPanel.bind( this ); | ||
} | ||
|
||
togglePublishPanel() { | ||
this.setState( ( state ) => ( { | ||
isPublishPanelOpened: ! state.isPublishPanelOpened, | ||
} ) ); | ||
} | ||
|
||
closePublishPanel() { | ||
this.setState( { | ||
isPublishPanelOpened: false, | ||
} ); | ||
} | ||
|
||
render() { | ||
const { onToggleSidebar, isSidebarOpened } = this.props; | ||
return ( | ||
<div | ||
role="region" | ||
aria-label={ __( 'Editor toolbar' ) } | ||
className="editor-header" | ||
tabIndex="-1" | ||
> | ||
<HeaderToolbar /> | ||
function Header( { onToggleSidebar, isDefaultSidebarOpened, isPublishSidebarOpened } ) { | ||
return ( | ||
<div | ||
role="region" | ||
aria-label={ __( 'Editor toolbar' ) } | ||
className="editor-header" | ||
tabIndex="-1" | ||
> | ||
<HeaderToolbar /> | ||
{ ! isPublishSidebarOpened && ( | ||
<div className="editor-header__settings"> | ||
{ ! this.state.isPublishPanelOpened && [ | ||
<PostSavedState key="saved-state" />, | ||
<PostPreviewButton key="preview-button" />, | ||
<PostPublishPanelToggle | ||
key="publish-button" | ||
isOpen={ this.state.isPublishPanelOpened } | ||
onToggle={ this.togglePublishPanel } | ||
/>, | ||
<IconButton | ||
key="sidebar-toggle" | ||
icon="admin-generic" | ||
onClick={ onToggleSidebar } | ||
isToggled={ isSidebarOpened } | ||
label={ __( 'Settings' ) } | ||
aria-expanded={ isSidebarOpened } | ||
/>, | ||
<EllipsisMenu key="ellipsis-menu" />, | ||
] } | ||
|
||
{ this.state.isPublishPanelOpened && <PostPublishPanel onClose={ this.closePublishPanel } /> } | ||
<PostSavedState /> | ||
<PostPreviewButton /> | ||
<PostPublishPanelToggle | ||
isOpen={ isPublishSidebarOpened } | ||
onToggle={ () => onToggleSidebar( 'publish' ) } | ||
/> | ||
<IconButton | ||
icon="admin-generic" | ||
onClick={ () => onToggleSidebar() } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the function need to be bound? Perhaps this is an artefact of something else? I'd expect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It needs to be to avoid passing the event as argument to the action creator :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. facepalm — obviously. I mean, you could just do some insane stuff in |
||
isToggled={ isDefaultSidebarOpened } | ||
label={ __( 'Settings' ) } | ||
aria-expanded={ isDefaultSidebarOpened } | ||
/> | ||
<EllipsisMenu key="ellipsis-menu" /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
) } | ||
</div> | ||
); | ||
} | ||
|
||
export default connect( | ||
( state ) => ( { | ||
isSidebarOpened: isEditorSidebarOpened( state ), | ||
isDefaultSidebarOpened: isSidebarOpened( state ), | ||
isPublishSidebarOpened: isSidebarOpened( state, 'publish' ), | ||
} ), | ||
( dispatch ) => ( { | ||
onToggleSidebar: () => dispatch( toggleSidebar() ), | ||
} ) | ||
{ | ||
onToggleSidebar: toggleSidebar, | ||
} | ||
)( Header ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,18 +19,34 @@ import Sidebar from '../sidebar'; | |
import TextEditor from '../modes/text-editor'; | ||
import VisualEditor from '../modes/visual-editor'; | ||
import DocumentTitle from '../document-title'; | ||
import { MetaBoxes, AutosaveMonitor, UnsavedChangesWarning, EditorNotices } from '../../components'; | ||
import { | ||
MetaBoxes, | ||
AutosaveMonitor, | ||
UnsavedChangesWarning, | ||
EditorNotices, | ||
PostPublishPanel, | ||
} from '../../components'; | ||
import { | ||
getEditorMode, | ||
isEditorSidebarOpened, | ||
hasOpenSidebar, | ||
isSidebarOpened, | ||
isFeatureActive, | ||
} from '../../store/selectors'; | ||
import { toggleSidebar } from '../../store/actions'; | ||
|
||
function Layout( { mode, isSidebarOpened, hasFixedToolbar } ) { | ||
function Layout( { | ||
mode, | ||
layoutHasOpenSidebar, | ||
isDefaultSidebarOpened, | ||
isPublishSidebarOpened, | ||
hasFixedToolbar, | ||
onToggleSidebar, | ||
} ) { | ||
const className = classnames( 'editor-layout', { | ||
'is-sidebar-opened': isSidebarOpened, | ||
'is-sidebar-opened': layoutHasOpenSidebar, | ||
'has-fixed-toolbar': hasFixedToolbar, | ||
} ); | ||
const closePublishPanel = () => onToggleSidebar( 'publish', false ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor, similar comment as the previous one. Since these bound action creators don't depend on component data, I'd place them in |
||
|
||
return ( | ||
<div className={ className }> | ||
|
@@ -51,7 +67,8 @@ function Layout( { mode, isSidebarOpened, hasFixedToolbar } ) { | |
<MetaBoxes location="advanced" /> | ||
</div> | ||
</div> | ||
{ isSidebarOpened && <Sidebar /> } | ||
{ isDefaultSidebarOpened && <Sidebar /> } | ||
{ isPublishSidebarOpened && <PostPublishPanel onClose={ closePublishPanel } /> } | ||
<Popover.Slot /> | ||
</div> | ||
); | ||
|
@@ -60,7 +77,10 @@ function Layout( { mode, isSidebarOpened, hasFixedToolbar } ) { | |
export default connect( | ||
( state ) => ( { | ||
mode: getEditorMode( state ), | ||
isSidebarOpened: isEditorSidebarOpened( state ), | ||
layoutHasOpenSidebar: hasOpenSidebar( state ), | ||
isDefaultSidebarOpened: isSidebarOpened( state ), | ||
isPublishSidebarOpened: isSidebarOpened( state, 'publish' ), | ||
hasFixedToolbar: isFeatureActive( state, 'fixedToolbar' ), | ||
} ), | ||
{ onToggleSidebar: toggleSidebar } | ||
)( navigateRegions( Layout ) ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -348,13 +348,15 @@ export function stopTyping() { | |
/** | ||
* Returns an action object used in signalling that the user toggled the sidebar | ||
* | ||
* @param {Boolean} isMobile Flag indicating if we are in mobile context | ||
* @return {Object} Action object | ||
* @param {String} sidebar Name of the sidebar to toggle (desktop, mobile or publish) | ||
* @param {Boolean?} force Force a sidebar state | ||
* @return {Object} Action object | ||
*/ | ||
export function toggleSidebar( isMobile ) { | ||
export function toggleSidebar( sidebar, force ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also minor, but both arguments are nouns, yet they express different things, IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
return { | ||
type: 'TOGGLE_SIDEBAR', | ||
isMobile, | ||
sidebar, | ||
force, | ||
}; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but we could extend
mapDispatchToProps
:and replace the prop here with
onToggle={ onTogglePublishSidebar }
.