-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
131 lines (124 loc) · 3.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Defines as extensibility slot for the Settings sidebar
*/
/**
* WordPress dependencies
*/
import { createSlotFill, PanelBody } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withPluginContext } from '@wordpress/plugins';
import { withDispatch, withSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { EnablePluginDocumentSettingPanelOption } from '../../options-modal/options';
export const { Fill, Slot } = createSlotFill( 'PluginDocumentSettingPanel' );
const PluginDocumentSettingFill = ( {
isEnabled,
panelName,
opened,
onToggle,
className,
title,
icon,
children,
} ) => {
return (
<>
<EnablePluginDocumentSettingPanelOption
label={ title }
panelName={ panelName }
/>
<Fill>
{ isEnabled && (
<PanelBody
className={ className }
title={ title }
icon={ icon }
opened={ opened }
onToggle={ onToggle }
>
{ children }
</PanelBody>
) }
</Fill>
</>
);
};
/**
* Renders items below the Status & Availability panel in the Document Sidebar.
*
* @param {Object} props Component properties.
* @param {string} [props.name] The machine-friendly name for the panel.
* @param {string} [props.className] An optional class name added to the row.
* @param {string} [props.title] The title of the panel
* @param {WPBlockTypeIconRender} [props.icon=inherits from the plugin] The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered when the sidebar is pinned to toolbar.
*
* @example
* <caption>ES5</caption>
* ```js
* // Using ES5 syntax
* var el = wp.element.createElement;
* var __ = wp.i18n.__;
* var registerPlugin = wp.plugins.registerPlugin;
* var PluginDocumentSettingPanel = wp.editPost.PluginDocumentSettingPanel;
*
* function MyDocumentSettingPlugin() {
* return el(
* PluginDocumentSettingPanel,
* {
* className: 'my-document-setting-plugin',
* title: 'My Panel',
* },
* __( 'My Document Setting Panel' )
* );
* }
*
* registerPlugin( 'my-document-setting-plugin', {
* render: MyDocumentSettingPlugin
* } );
* ```
*
* @example
* <caption>ESNext</caption>
* ```jsx
* // Using ESNext syntax
* const { registerPlugin } = wp.plugins;
* const { PluginDocumentSettingPanel } = wp.editPost;
*
* const MyDocumentSettingTest = () => (
* <PluginDocumentSettingPanel className="my-document-setting-plugin" title="My Panel">
* <p>My Document Setting Panel</p>
* </PluginDocumentSettingPanel>
* );
*
* registerPlugin( 'document-setting-test', { render: MyDocumentSettingTest } );
* ```
*
* @return {WPComponent} The component to be rendered.
*/
const PluginDocumentSettingPanel = compose(
withPluginContext( ( context, ownProps ) => {
return {
icon: ownProps.icon || context.icon,
panelName: `${ context.name }/${ ownProps.name }`,
};
} ),
withSelect( ( select, { panelName } ) => {
return {
opened: select( 'core/edit-post' ).isEditorPanelOpened( panelName ),
isEnabled: select( 'core/edit-post' ).isEditorPanelEnabled(
panelName
),
};
} ),
withDispatch( ( dispatch, { panelName } ) => ( {
onToggle() {
return dispatch( 'core/edit-post' ).toggleEditorPanelOpened(
panelName
);
},
} ) )
)( PluginDocumentSettingFill );
PluginDocumentSettingPanel.Slot = Slot;
export default PluginDocumentSettingPanel;