-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidebar-sample.js
249 lines (218 loc) · 8.2 KB
/
sidebar-sample.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/**
* Sample Sidebar
*
* Requires the 'WP Sides' plugin to be activated.
* Tested with 'WP Sides' version: 0.3
*/
(async () => {
const { wpSides } = await import(wpSidesPlugin.load); // Import the WP Sides controls
const { extras } = await import('./extras.js'); // Import extra options for the sidebar controls
const { __ } = wp.i18n;
const el = wp.element.createElement;
const { Fragment } = wp.element;
const { PanelBody } = wp.components;
const { groupControl, icons, utils } = wpSides;
const sidebar = () => {
/**
* Sidebar details
*/
const details = {
title: __('WPSides - Sample Sidebar'),
name: 'wpsides-sample-sidebar',
metaKey: '_page_sidebar_meta'
};
/**
* Get the sidebar meta data, post type and page template of the current page
*/
const get = {
meta: utils.get.groupMeta(details.metaKey),
postType: utils.get.postType(),
pageTemplate: utils.get.pageTemplate()
};
/**
* Restrict to specific post types
*/
/*
const allowedPostTypes = [ 'page' ];
if( !allowedPostTypes.includes(get.postType) ){
return null;
}
*/
/**
* Restrict to specific page templates
*/
/*
const allowedPageTemplates = [ 'some-template' ];
if( !allowedPageTemplates.includes(get.pageTemplate) ){
return null;
}
*/
/**
* Render the sidebar
*/
return (
el(Fragment, {},
// Adds the sidebar to the 'Plugins' section
el(wpSides.AddSidebar,
{ target: details.name }, details.title
),
// Create the sidebar
el(wpSides.Sidebar,
{ name: details.name, title: details.title },
// ------------------ Add your options below ------------------
/**
* Group 1
*/
el(PanelBody, { title: "Group 1" },
// Text field
el(
groupControl('text'),
{
id: 'text_1',
title: __('Sample Text Field'),
metaKey: details.metaKey,
}
),
// Checkbox
el(
groupControl('checkbox'),
{
id: 'checkbox',
title: __('Checkbox test'),
metaKey: details.metaKey,
}
),
// Toggle button
el(
groupControl('toggle'),
{
id: 'toggle',
title: __('Boolean test'),
metaKey: details.metaKey,
}
),
// Date field
el(
groupControl('date'),
{
id: 'date',
title: __('Date test'),
metaKey: details.metaKey,
}
),
),
/**
* Group 2
*/
el(PanelBody, { title: "Group 2", initialOpen: false },
// Color select
el(
groupControl('colour'),
{
id: 'colour',
title: __('Colour test'),
metaKey: details.metaKey,
}
),
// Font size
el(
groupControl('fontSize', {
fontSizes: [
{
name: __('Small'),
slug: 'small',
size: 12,
},
{
name: __('Large'),
slug: 'large',
size: 32,
},
]
}),
{
id: 'font_size',
title: __('Font size test'),
metaKey: details.metaKey,
}
),
// Radio buttons
el(
groupControl('radio', {
options: [
{ label: 'Author', value: 'author' },
{ label: 'Editor', value: 'editor' },
]
}),
{
id: 'radio',
title: __('Radio test'),
metaKey: details.metaKey,
}
),
// Range field
el(
groupControl('range', { min: 0, max: 100 }),
{
id: 'range',
title: __('Range test'),
metaKey: details.metaKey,
}
),
// Time field
el(
groupControl('time'),
{
id: 'time',
title: __('Time test'),
metaKey: details.metaKey,
}
),
// Select field
el(
groupControl('select', {
options: [
{ label: 'Big', value: '100%' },
{ label: 'Medium', value: '50%' },
{ label: 'Small', value: '25%' },
]
}),
{
id: 'select',
title: __('Select test'),
metaKey: details.metaKey,
}
),
// Select field (displaying all pages)
el(
groupControl('select', {
options: extras.selectAllPages()
}),
{
id: 'select',
title: __('Page select test'),
metaKey: details.metaKey,
}
),
// Media field
el(
groupControl('media'),
{
id: 'media',
title: __('Media test'),
metaKey: details.metaKey,
}
),
)
)
)
)
}
/**
* Register the sidebar
*/
wp.plugins.registerPlugin('wpsides-sample-sidebar', {
render: sidebar,
icon: icons.sliders // Icon to be associated with
});
})();