-
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
Add an API to add a plugin sidebar #4109
Changes from 1 commit
f3d3daf
2864974
b4fa154
ba05cd8
506fd15
9caaf8e
53579b3
9428aa9
7241609
8870121
cc0b124
b3aa610
c7b36b3
e4b9df3
693e5a8
04d6e2b
aa3c84b
ed6ea39
3af2240
10529c8
fd057e8
af1cc84
c7daa63
a5ffe6c
ec870c3
b34991d
06950bd
fce3ddd
02cc074
0072e66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { compose } from '@wordpress/element'; | ||
import { Panel, PanelBody, IconButton, withFocusReturn } from '@wordpress/components'; | ||
import { getActivePlugin } from '../../store/selectors'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import './style.scss'; | ||
import { getSidebar } from '../../api/sidebar'; | ||
|
||
/** | ||
* Returns the sidebar that should be rendered in the sidebar registered by | ||
* plugins. | ||
* | ||
* @param {string} plugin The currently active plugin. | ||
* | ||
* @returns {Object} The React element to render as a panel. | ||
*/ | ||
function getPluginSidebar( plugin ) { | ||
const pluginSidebar = getSidebar( plugin ); | ||
|
||
if ( ! pluginSidebar ) { | ||
return () => { | ||
return <Panel> | ||
<PanelBody> | ||
{ sprintf( __( 'No matching plugin sidebar found for plugin "%s"' ), plugin ) } | ||
</PanelBody> | ||
</Panel>; | ||
}; | ||
} | ||
|
||
return pluginSidebar.render; | ||
} | ||
|
||
function PluginsPanel( { onClose, plugin } ) { | ||
return ( | ||
<div | ||
className="editor-sidebar" | ||
role="region" | ||
aria-label={ __( 'Editor plugins' ) } | ||
tabIndex="-1"> | ||
<div className="components-panel__header editor-sidebar__panel-tabs"> | ||
<IconButton | ||
onClick={ onClose } | ||
icon="no-alt" | ||
label={ __( 'Close settings' ) } | ||
/> | ||
</div> | ||
<div className="editor-plugins-panel__content"> | ||
{ getPluginSidebar( plugin )() } | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default connect( | ||
( state ) => { | ||
return { | ||
plugin: getActivePlugin( state ), | ||
}; | ||
} | ||
)( withFocusReturn( PluginsPanel ) ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.editor-plugins-panel { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
width: $sidebar-width; | ||
border-left: 1px solid $light-gray-500; | ||
background: $light-gray-300; | ||
color: $dark-gray-500; | ||
height: 100vh; | ||
overflow: hidden; | ||
|
||
@include break-small() { | ||
top: $admin-bar-height-big + $header-height; | ||
z-index: auto; | ||
height: auto; | ||
overflow: auto; | ||
-webkit-overflow-scrolling: touch; | ||
} | ||
|
||
@include break-medium() { | ||
top: $admin-bar-height + $header-height; | ||
} | ||
|
||
> .components-panel .components-panel__header { | ||
position: fixed; | ||
z-index: z-index( '.components-panel__header' ); | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
height: $panel-header-height; | ||
|
||
@include break-small() { | ||
position: inherit; | ||
top: auto; | ||
left: auto; | ||
right: auto; | ||
} | ||
} | ||
} | ||
|
||
.editor-plugins-panel__header { | ||
padding-left: 16px; | ||
height: $header-height; | ||
border-bottom: 1px solid $light-gray-500; | ||
display: flex; | ||
align-items: center; | ||
align-content: space-between; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,7 +334,7 @@ export function stopTyping() { | |
/** | ||
* Returns an action object used in signalling that the user toggled the sidebar | ||
* | ||
* @param {String} sidebar Name of the sidebar to toggle (desktop, mobile or publish) | ||
* @param {String} sidebar Name of the sidebar to toggle (desktop, mobile, plugins or publish) | ||
* @param {Boolean?} force Force a sidebar state | ||
* @return {Object} Action object | ||
*/ | ||
|
@@ -359,6 +359,19 @@ export function setActivePanel( panel ) { | |
}; | ||
} | ||
|
||
/** | ||
* Returns an action object usid in signalling that the user switched the active plugin. | ||
* | ||
* @param {String} plugin The plugin name | ||
* @return {Object} Action object | ||
*/ | ||
export function setActivePlugin( plugin ) { | ||
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. setActive(Plugin)Sidebar might be a better name, because a plugin can have multiple sidebars. |
||
return { | ||
type: 'SET_ACTIVE_PLUGIN', | ||
plugin, | ||
}; | ||
} | ||
|
||
/** | ||
* Returns an action object used in signalling that the user toggled a sidebar panel | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,16 @@ export function getActivePanel( state ) { | |
return state.panel; | ||
} | ||
|
||
/** | ||
* Returns the current active plugin for the plugin sidebar. | ||
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. See above: a plugin can have multiple sidebars |
||
* | ||
* @param {Object} state Global application state | ||
* @return {String} Active plugin sidebar plugin | ||
*/ | ||
export function getActivePlugin( state ) { | ||
return state.plugin; | ||
} | ||
|
||
/** | ||
* Returns the preferences (these preferences are persisted locally) | ||
* | ||
|
@@ -145,8 +155,8 @@ export function isSidebarOpened( state, sidebar ) { | |
export function hasOpenSidebar( state ) { | ||
const sidebars = getPreference( state, 'sidebars' ); | ||
return isMobile( state ) ? | ||
sidebars.mobile || sidebars.publish : | ||
sidebars.desktop || sidebars.publish; | ||
sidebars.mobile || sidebars.publish || sidebars.plugins : | ||
sidebars.desktop || sidebars.publish || sidebars.plugins ; | ||
} | ||
|
||
/** | ||
|
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.
Please add translator comment