-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
723143a
commit 24f0dd5
Showing
18 changed files
with
250 additions
and
244 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
42 changes: 0 additions & 42 deletions
42
...es/edit-post/src/components/header/plugin-more-menu-item/test/__snapshots__/index.js.snap
This file was deleted.
Oops, something went wrong.
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
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
12 changes: 12 additions & 0 deletions
12
packages/interface/src/components/complementary-area-context/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,12 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withPluginContext } from '@wordpress/plugins'; | ||
|
||
export default withPluginContext( ( context, ownProps ) => { | ||
return { | ||
icon: ownProps.icon || context.icon, | ||
identifier: | ||
ownProps.identifier || `${ context.name }/${ ownProps.name }`, | ||
}; | ||
} ); |
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
44 changes: 44 additions & 0 deletions
44
packages/interface/src/components/complementary-area-more-menu-item/README.md
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,44 @@ | ||
ComplementaryAreaMoreMenuItem | ||
============================= | ||
|
||
Renders an item in the more menu that allows toggling a complementary area. | ||
Props not referenced here are passed to the component used to render the menu item. | ||
|
||
### scope | ||
|
||
The scope of the complementary area e.g: "core/edit-post", "core/edit-site", "myplugin/custom-screen-a", | ||
|
||
- Type: `String` | ||
- Required: Yes | ||
|
||
### identifier | ||
|
||
Identifier of the complementary area. The string is saved on the store and allows to identify which of the sidebars is active. | ||
|
||
- Type: `String` | ||
- Required: No | ||
- Default: Concatenation of `name` of the plugin extracted from the context (when available) with the `targe` of the sidebar passed as a property. | ||
|
||
### target | ||
|
||
Name of the complementary area. The name of the complementarity area is concatenated with the name of the plugin to form the identifier of the complementary area. The name of the plugin is extracted from the plugin context where the sidebar is rendered. If there is no plugin context available or there is a need to specify a custom identifier, please use the `identifier` property instead. | ||
|
||
- Type: `String` | ||
- Required: No | ||
|
||
### selectedIcon | ||
|
||
An icon to use when the complementary area is open e.g: a check mark. | ||
If the prop is not passed the icon of the complementary area or of the plugin is used. | ||
|
||
|
||
- Type: `Element` | ||
- Required: no | ||
|
||
### as | ||
|
||
A component used to render the item. | ||
Defaults to what was specified in the slot for menu items but specific component can be used. | ||
|
||
- Type: `Component` | ||
- Required: no |
33 changes: 33 additions & 0 deletions
33
packages/interface/src/components/complementary-area-more-menu-item/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,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { check } from '@wordpress/icons'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import ComplementaryAreaToggle from '../complementary-area-toggle'; | ||
import ActionItem from '../action-item'; | ||
|
||
export default function ComplementaryAreaMoreMenuItem( { | ||
scope, | ||
target, | ||
...props | ||
} ) { | ||
return ( | ||
<ComplementaryAreaToggle | ||
as={ ( toggleProps ) => { | ||
return ( | ||
<ActionItem | ||
name={ `${ scope }/plugin-more-menu` } | ||
{ ...toggleProps } | ||
/> | ||
); | ||
} } | ||
role="menuitemcheckbox" | ||
selectedIcon={ check } | ||
name={ target } | ||
scope={ scope } | ||
{ ...props } | ||
/> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/interface/src/components/complementary-area-toggle/README.md
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,46 @@ | ||
ComplementaryAreaToggle | ||
============================= | ||
|
||
`ComplementaryArea.Toggle` is a component used to render a UI allowing the toggle (open/close) a complementary area. | ||
|
||
## Props | ||
|
||
### scope | ||
|
||
The scope of the complementary area e.g: "core/edit-post", "core/edit-site", "myplugin/custom-screen-a", | ||
|
||
- Type: `String` | ||
- Required: Yes | ||
|
||
### identifier | ||
|
||
Identifier of the complementary area. | ||
|
||
- Type: `String` | ||
- Required: No | ||
- Default: Concatenation of `name` of the plugin extracted from the context (when available) with the "name" of the sidebar passed as a property. | ||
|
||
### name | ||
|
||
Name of the complementary area. The name of the complementarity area is concatenated with the name of the plugin to form the identifier of the complementary area. The name of the plugin is extracted from the plugin context where the sidebar is rendered. If there is no plugin context available or there is a need to specify a custom identifier, please use the `identifier` property instead. | ||
|
||
- Type: `String` | ||
- Required: No | ||
|
||
|
||
### selectedIcon | ||
|
||
An icon to use when the complementary area is open e.g: a check mark. | ||
If the prop is not passed the icon of the complementary area or of the plugin is used. | ||
|
||
|
||
- Type: `Element` | ||
- Required: no | ||
|
||
### as | ||
|
||
A component used to render the toggle. | ||
Defaults to and `Button` can be changed to `MenuItem`or a custom component for example. | ||
|
||
- Type: `Component` | ||
- Required: no |
51 changes: 51 additions & 0 deletions
51
packages/interface/src/components/complementary-area-toggle/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,51 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { omit } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button } from '@wordpress/components'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import complementaryAreaContext from '../complementary-area-context'; | ||
|
||
function ComplementaryAreaToggle( { | ||
as = Button, | ||
scope, | ||
identifier, | ||
icon, | ||
selectedIcon, | ||
...props | ||
} ) { | ||
const ComponentToUse = as; | ||
const isSelected = useSelect( | ||
( select ) => | ||
select( 'core/interface' ).getActiveComplementaryArea( scope ) === | ||
identifier, | ||
[ identifier ] | ||
); | ||
const { enableComplementaryArea, disableComplementaryArea } = useDispatch( | ||
'core/interface' | ||
); | ||
return ( | ||
<ComponentToUse | ||
icon={ selectedIcon && isSelected ? selectedIcon : icon } | ||
isSelected={ isSelected } | ||
onClick={ () => { | ||
if ( isSelected ) { | ||
disableComplementaryArea( scope ); | ||
} else { | ||
enableComplementaryArea( scope, identifier ); | ||
} | ||
} } | ||
{ ...omit( props, [ 'name' ] ) } | ||
/> | ||
); | ||
} | ||
|
||
export default complementaryAreaContext( ComplementaryAreaToggle ); |
Oops, something went wrong.