itmar-block-packages 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
package/img/grid.png ADDED
Binary file
Binary file
package/img/pseudo.png ADDED
Binary file
package/img/shadow.png ADDED
Binary file
Binary file
package/package.json CHANGED
@@ -1,17 +1,29 @@
1
1
  {
2
2
  "name": "itmar-block-packages",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "We have put together a package of common React components used for WordPress custom blocks.",
5
- "main": "src/index.js",
5
+ "main": "build/index.js",
6
6
  "scripts": {
7
7
  "build": "wp-scripts build",
8
8
  "start": "wp-scripts start",
9
9
  "test": "echo \"Error: no test specified\" && exit 1"
10
10
  },
11
11
  "author": "Web Creator ITmaroon",
12
- "license": "ISC",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/itmaroon/itmar-block-packages.git"
15
+ },
16
+ "keywords": [
17
+ "WordPress",
18
+ "Plugin",
19
+ "Block",
20
+ "Gutenberg"
21
+ ],
22
+ "license": "MIT",
13
23
  "dependencies": {
24
+ "@wordpress/icons": "^9.47.0",
14
25
  "lodash": "^4.17.21",
26
+ "react-select": "^5.8.0",
15
27
  "styled-components": "^6.1.8"
16
28
  },
17
29
  "devDependencies": {
@@ -0,0 +1,112 @@
1
+ import { __ } from "@wordpress/i18n";
2
+ import { css, keyframes } from "styled-components";
3
+
4
+ import {
5
+ PanelBody,
6
+ ToggleControl,
7
+ RadioControl,
8
+ RangeControl,
9
+ } from "@wordpress/components";
10
+
11
+ export const anime_comp = (attributes) => {
12
+ return css`
13
+ &.fadeTrigger {
14
+ opacity: 0;
15
+ }
16
+ &.${attributes.pattern} {
17
+ animation-name: ${attributes.pattern};
18
+ animation-delay: ${attributes.delay}s;
19
+ animation-duration: ${attributes.duration}s;
20
+ animation-fill-mode: forwards;
21
+ opacity: 0;
22
+ }
23
+ `;
24
+ };
25
+
26
+ export default function AnimationBlock(props) {
27
+ const { is_anime, anime_prm } = props.attributes;
28
+
29
+ return (
30
+ <>
31
+ <PanelBody
32
+ title={__("Animation Setting", "block-collections")}
33
+ initialOpen={true}
34
+ >
35
+ <ToggleControl
36
+ label={__("Is Animation", "block-collections")}
37
+ checked={is_anime}
38
+ onChange={(newVal) => {
39
+ props.onChange({ is_anime: newVal });
40
+ }}
41
+ />
42
+ {is_anime && (
43
+ <>
44
+ <div className="itmar_link_type">
45
+ <RadioControl
46
+ label={__("Animation Pattern", "block-collections")}
47
+ selected={anime_prm.pattern}
48
+ options={[
49
+ { label: "flipDown", value: "flipDown" },
50
+ { label: "fadeUp", value: "fadeUp" },
51
+ { label: "fadeLeft", value: "fadeLeft" },
52
+ { label: "fadeRight", value: "fadeRight" },
53
+ ]}
54
+ onChange={(changeOption) => {
55
+ props.onChange({
56
+ anime_prm: { ...anime_prm, pattern: changeOption },
57
+ });
58
+ }}
59
+ />
60
+ </div>
61
+
62
+ <RangeControl
63
+ value={anime_prm.duration}
64
+ label={__("Animation duration time", "block-collections")}
65
+ max={5}
66
+ min={0}
67
+ onChange={(val) => {
68
+ props.onChange({ anime_prm: { ...anime_prm, duration: val } });
69
+ }}
70
+ step={0.1}
71
+ withInputField={true}
72
+ />
73
+
74
+ <RangeControl
75
+ value={anime_prm.delay}
76
+ label={__("Animation delay time", "block-collections")}
77
+ max={3}
78
+ min={0}
79
+ onChange={(val) => {
80
+ props.onChange({ anime_prm: { ...anime_prm, delay: val } });
81
+ }}
82
+ step={0.1}
83
+ withInputField={true}
84
+ />
85
+
86
+ <div className="itmar_link_type">
87
+ <RadioControl
88
+ label={__("Animation Trigger", "block-collections")}
89
+ selected={anime_prm.trigger}
90
+ options={[
91
+ {
92
+ label: __("Page Opend", "block-collections"),
93
+ value: "opend",
94
+ },
95
+ {
96
+ label: __("Enter Visible", "block-collections"),
97
+ value: "visible",
98
+ },
99
+ ]}
100
+ onChange={(changeOption) => {
101
+ props.onChange({
102
+ anime_prm: { ...anime_prm, trigger: changeOption },
103
+ });
104
+ }}
105
+ />
106
+ </div>
107
+ </>
108
+ )}
109
+ </PanelBody>
110
+ </>
111
+ );
112
+ }
@@ -0,0 +1,518 @@
1
+ import { __ } from '@wordpress/i18n';
2
+ import { useState, useEffect } from '@wordpress/element';
3
+
4
+ import {
5
+ Button,
6
+ PanelBody,
7
+ PanelRow,
8
+ __experimentalUnitControl as UnitControl,
9
+ ComboboxControl,
10
+ Icon,
11
+ ToolbarGroup,
12
+ ToolbarItem,
13
+ RangeControl,
14
+ RadioControl,
15
+ Modal
16
+ } from '@wordpress/components';
17
+ import { group, stack, layout, justifyCenter, justifyLeft, justifyRight, justifySpaceBetween, justifyStretch, stretchWide, positionCenter } from '@wordpress/icons';
18
+ import GridControls from "./GridControls";
19
+
20
+
21
+ //横並びのアイコン
22
+ const flex = <Icon icon={stack} className="rotate-icon" />
23
+ //上よせアイコン
24
+ const upper = <Icon icon={justifyLeft} className="rotate-icon" />
25
+ //中央よせのアイコン
26
+ const middle = <Icon icon={justifyCenter} className="rotate-icon" />
27
+ //下よせのアイコン
28
+ const lower = <Icon icon={justifyRight} className="rotate-icon" />
29
+ //上下一杯に伸ばすアイコン
30
+ const vert_between = <Icon icon={justifyStretch} className="rotate-icon" />
31
+ //上下均等に伸ばすアイコン
32
+ const vert_around = <Icon icon={justifySpaceBetween} className="rotate-icon" />
33
+
34
+ export default function BlockPlace(props) {
35
+
36
+ const {
37
+ attributes,
38
+ clientId,
39
+ blockRef,
40
+ isMobile,
41
+ isSubmenu
42
+ } = props;
43
+ const {
44
+ positionType,
45
+ heightValue,
46
+ default_pos,
47
+ mobile_pos
48
+ } = attributes;
49
+
50
+ //モバイルかデスクトップか
51
+ const sel_pos = isMobile ? mobile_pos : default_pos
52
+
53
+ //配置アイコンの選択
54
+ const start_icon = sel_pos.direction === 'vertical' ? upper : justifyLeft;
55
+ const center_icon = sel_pos.direction === 'vertical' ? middle : justifyCenter;
56
+ const end_icon = sel_pos.direction === 'vertical' ? lower : justifyRight;
57
+ const between_icon = sel_pos.direction === 'vertical' ? vert_between : justifyStretch;
58
+ const around_icon = sel_pos.direction === 'vertical' ? vert_around : justifySpaceBetween;
59
+ //ツールチップの選択
60
+ const start_tip = sel_pos.direction === 'vertical' ? __('upper alignment', 'block-collections') : __('left alignment', 'block-collections');
61
+ const end_tip = sel_pos.direction === 'vertical' ? __('lower alignment', 'block-collections') : __('right alignment', 'block-collections');
62
+
63
+ const [isContainer, setIsContainer] = useState(false);
64
+ const [direction, setDirection] = useState('row');
65
+ useEffect(() => {
66
+ if (blockRef.current) {
67
+ const element = blockRef.current;
68
+ const parentElement = element.parentElement;
69
+ const grandparentElement = parentElement?.parentElement;
70
+ const computedStyle = getComputedStyle(grandparentElement);
71
+ //親要素がFlex又はGridコンテナか
72
+ if (computedStyle.display === "flex" || computedStyle.display === "inline-flex" || computedStyle.display === "grid" || computedStyle.display === "inline-grid") {
73
+ setIsContainer(true)
74
+ }
75
+ //flexの時その方向
76
+ if (computedStyle.display === "flex" || computedStyle.display === "inline-flex") {
77
+ if (computedStyle.flexDirection === "row") {
78
+ setDirection('row');
79
+ } else {
80
+ setDirection('column');
81
+ }
82
+
83
+ }
84
+ }
85
+ }, []);
86
+
87
+
88
+
89
+ //GridModalを開く
90
+ const [isGridModalOpen, setIsGridModalOpen] = useState(false);
91
+ const openGridModal = () => setIsGridModalOpen(true);
92
+ const closeGridModal = () => setIsGridModalOpen(false);
93
+
94
+ // 翻訳が必要な文字列を直接指定
95
+ const blockMaxWidthMobile = __('Block Max Width(Mobile)', 'block-collections');
96
+ const blockWidthMobile = __('Block Width(Mobile)', 'block-collections');
97
+ const blockMaxWidthDesktop = __('Block Max Width(DeskTop)', 'block-collections');
98
+ const blockWidthDesktop = __('Block Width(DeskTop)', 'block-collections');
99
+
100
+ // 条件に応じて選択
101
+ const blockWidthLabel = isMobile
102
+ ? (isSubmenu ? blockWidthMobile : blockMaxWidthMobile)
103
+ : (isSubmenu ? blockWidthDesktop : blockMaxWidthDesktop);
104
+
105
+
106
+ return (
107
+ <>
108
+ <PanelBody
109
+ title={__("Block placement", 'block-collections')}
110
+ initialOpen={false}
111
+ className='itmar_group_direction'
112
+ >
113
+ {isMobile ?
114
+ <p>{__('InnerBlock direction(Mobile)', 'block-collections')}</p>
115
+ :
116
+ <p>{__('InnerBlock direction(DeskTop)', 'block-collections')}</p>
117
+ }
118
+
119
+ <ToolbarGroup>
120
+ <ToolbarItem>
121
+ {(itemProps) => (
122
+ <Button {...itemProps}
123
+ isPressed={sel_pos.direction === 'block'}
124
+ onClick={() => props.onDirectionChange('block')}
125
+ icon={group}
126
+ label={__('block', 'block-collections')}
127
+ />
128
+
129
+ )}
130
+ </ToolbarItem>
131
+ <ToolbarItem>
132
+ {(itemProps) => (
133
+ <Button {...itemProps}
134
+ isPressed={sel_pos.direction === 'vertical'}
135
+ onClick={() => props.onDirectionChange('vertical')}
136
+ icon={stack}
137
+ label={__('virtical', 'block-collections')}
138
+ />
139
+ )}
140
+ </ToolbarItem>
141
+ <ToolbarItem>
142
+ {(itemProps) => (
143
+ <Button {...itemProps}
144
+ isPressed={sel_pos.direction === 'horizen'}
145
+ onClick={() => props.onDirectionChange('horizen')}
146
+ icon={flex}
147
+ label={__('horizen', 'block-collections')}
148
+ />
149
+ )}
150
+ </ToolbarItem>
151
+ <ToolbarItem>
152
+ {(itemProps) => (
153
+ <Button {...itemProps}
154
+ isPressed={sel_pos.direction === 'grid'}
155
+ onClick={() => props.onDirectionChange('grid')}
156
+ icon={layout}
157
+ label={__('grid', 'block-collections')}
158
+ />
159
+ )}
160
+ </ToolbarItem>
161
+ </ToolbarGroup>
162
+ {(sel_pos.direction !== 'block' && sel_pos.direction !== 'grid') &&
163
+ <>
164
+ {isMobile ?
165
+ <p>{__('InnerBlock alignment(Mobile)', 'block-collections')}</p>
166
+ :
167
+ <p>{__('InnerBlock alignment(DeskTop)', 'block-collections')}</p>
168
+ }
169
+ <ToolbarGroup>
170
+ <ToolbarItem>
171
+ {(itemProps) => (
172
+ <Button {...itemProps}
173
+ isPressed={sel_pos.inner_align === 'flex-start'}
174
+ onClick={() => props.onFlexChange('flex-start')}//親コンポーネントに通知
175
+ icon={start_icon}
176
+ label={start_tip}
177
+ />
178
+
179
+ )}
180
+ </ToolbarItem>
181
+ <ToolbarItem>
182
+ {(itemProps) => (
183
+ <Button {...itemProps}
184
+ isPressed={sel_pos.inner_align === 'center'}
185
+ onClick={() => props.onFlexChange('center')}//親コンポーネントに通知
186
+ icon={center_icon}
187
+ label={__('center alignment', 'block-collections')}
188
+ />
189
+ )}
190
+ </ToolbarItem>
191
+ <ToolbarItem>
192
+ {(itemProps) => (
193
+ <Button {...itemProps}
194
+ isPressed={sel_pos.inner_align === 'flex-end'}
195
+ onClick={() => props.onFlexChange('flex-end')}//親コンポーネントに通知
196
+ icon={end_icon}
197
+ label={end_tip}
198
+ />
199
+ )}
200
+ </ToolbarItem>
201
+ <ToolbarItem>
202
+ {(itemProps) => (
203
+ <Button {...itemProps}
204
+ isPressed={sel_pos.inner_align === 'space-between'}
205
+ onClick={() => props.onFlexChange('space-between')}//親コンポーネントに通知
206
+ icon={between_icon}
207
+ label={__('beteen stretch', 'block-collections')}
208
+ />
209
+
210
+ )}
211
+ </ToolbarItem>
212
+ <ToolbarItem>
213
+ {(itemProps) => (
214
+ <Button {...itemProps}
215
+ isPressed={sel_pos.inner_align === 'space-around'}
216
+ onClick={() => props.onFlexChange('space-around')}//親コンポーネントに通知
217
+ icon={around_icon}
218
+ label={__('around stretch', 'block-collections')}
219
+ />
220
+
221
+ )}
222
+ </ToolbarItem>
223
+ </ToolbarGroup>
224
+ </>
225
+ }
226
+
227
+ {(!isContainer && !isSubmenu) && (
228
+ isMobile ?
229
+ <p>{__('Block alignment(Mobile)', 'block-collections')}</p>
230
+ :
231
+ <p>{__('Block alignment(DeskTop)', 'block-collections')}</p>
232
+ )}
233
+
234
+ {(!isContainer && !isSubmenu) &&
235
+ <ToolbarGroup>
236
+ <ToolbarItem>
237
+ {(itemProps) => (
238
+ <Button {...itemProps}
239
+ isPressed={sel_pos.outer_align === 'left'}
240
+ onClick={() => props.onAlignChange('left')}
241
+ icon={justifyLeft}
242
+ label={__('left alignment', 'block-collections')}
243
+ />
244
+
245
+ )}
246
+ </ToolbarItem>
247
+ <ToolbarItem>
248
+ {(itemProps) => (
249
+ <Button {...itemProps}
250
+ isPressed={sel_pos.outer_align === 'center'}
251
+ onClick={() => props.onAlignChange('center')}
252
+ icon={justifyCenter}
253
+ label={__('center alignment', 'block-collections')}
254
+ />
255
+ )}
256
+ </ToolbarItem>
257
+ <ToolbarItem>
258
+ {(itemProps) => (
259
+ <Button {...itemProps}
260
+ isPressed={sel_pos.outer_align === 'right'}
261
+ onClick={() => props.onAlignChange('right')}
262
+ icon={justifyRight}
263
+ label={__('right alignment', 'block-collections')}
264
+ />
265
+ )}
266
+ </ToolbarItem>
267
+
268
+ </ToolbarGroup>
269
+ }
270
+ {isContainer &&
271
+ <>
272
+ {isMobile ?
273
+ <p>{__('Block alignment(Mobile)', 'block-collections')}</p>
274
+ :
275
+ <p>{__('Block alignment(DeskTop)', 'block-collections')}</p>
276
+ }
277
+
278
+ <ToolbarGroup>
279
+ <ToolbarItem>
280
+ {(itemProps) => (
281
+ <Button {...itemProps}
282
+ isPressed={sel_pos.outer_vertical === 'self-start'}
283
+ onClick={() => props.onVerticalChange('self-start')}
284
+ icon={direction === 'row' ? upper : justifyLeft}
285
+ label={__('upper alignment', 'block-collections')}
286
+ />
287
+
288
+ )}
289
+ </ToolbarItem>
290
+ <ToolbarItem>
291
+ {(itemProps) => (
292
+ <Button {...itemProps}
293
+ isPressed={sel_pos.outer_vertical === 'center'}
294
+ onClick={() => props.onVerticalChange('center')}
295
+ icon={direction === 'row' ? middle : justifyCenter}
296
+ label={__('center alignment', 'block-collections')}
297
+ />
298
+ )}
299
+ </ToolbarItem>
300
+ <ToolbarItem>
301
+ {(itemProps) => (
302
+ <Button {...itemProps}
303
+ isPressed={sel_pos.outer_vertical === 'self-end'}
304
+ onClick={() => props.onVerticalChange('self-end')}
305
+ icon={direction === 'row' ? lower : justifyRight}
306
+ label={__('lower alignment', 'block-collections')}
307
+ />
308
+ )}
309
+ </ToolbarItem>
310
+
311
+ </ToolbarGroup>
312
+ </>
313
+ }
314
+
315
+ <p>{blockWidthLabel}</p>
316
+ <ToolbarGroup>
317
+ <ToolbarItem>
318
+ {(itemProps) => (
319
+ <Button {...itemProps}
320
+ isPressed={sel_pos.width_val === 'full'}
321
+ onClick={() => props.onWidthChange('full')}
322
+ text='full'
323
+ />
324
+
325
+ )}
326
+ </ToolbarItem>
327
+ <ToolbarItem>
328
+ {(itemProps) => (
329
+ <Button {...itemProps}
330
+ isPressed={sel_pos.width_val === 'fit'}
331
+ onClick={() => props.onWidthChange('fit')}
332
+ text='fit'
333
+ />
334
+
335
+ )}
336
+ </ToolbarItem>
337
+ <ToolbarItem>
338
+ {(itemProps) => (
339
+ <Button {...itemProps}
340
+ isPressed={sel_pos.width_val === 'wideSize'}
341
+ onClick={() => props.onWidthChange('wideSize')}
342
+ icon={stretchWide}
343
+ label={__('Wide Size', 'block-collections')}
344
+ />
345
+
346
+ )}
347
+ </ToolbarItem>
348
+ <ToolbarItem>
349
+ {(itemProps) => (
350
+ <Button {...itemProps}
351
+ isPressed={sel_pos.width_val === 'contentSize'}
352
+ onClick={() => props.onWidthChange('contentSize')}
353
+ icon={positionCenter}
354
+ label={__('Content Size', 'block-collections')}
355
+ />
356
+
357
+ )}
358
+ </ToolbarItem>
359
+ <ToolbarItem>
360
+ {(itemProps) => (
361
+ <Button {...itemProps}
362
+ isPressed={sel_pos.width_val === 'free'}
363
+ onClick={() => props.onWidthChange('free')}
364
+ text='free'
365
+ />
366
+
367
+ )}
368
+ </ToolbarItem>
369
+
370
+ </ToolbarGroup>
371
+
372
+ {sel_pos.width_val === 'free' &&
373
+ <RangeControl
374
+ value={sel_pos.free_val}
375
+ label={__("Max width", 'block-collections')}
376
+ max={1800}
377
+ min={300}
378
+ step={10}
379
+ onChange={(newValue) => {
380
+ props.onFreevalChange(newValue)
381
+ }}
382
+ withInputField={true}
383
+ />
384
+ }
385
+
386
+ <p>{__('Block Height', 'block-collections')}</p>
387
+ <ToolbarGroup>
388
+ <ToolbarItem>
389
+ {(itemProps) => (
390
+ <Button {...itemProps}
391
+ isPressed={heightValue === 'full'}
392
+ onClick={() => props.onHeightChange('full')}
393
+ text='full'
394
+ />
395
+
396
+ )}
397
+ </ToolbarItem>
398
+ <ToolbarItem>
399
+ {(itemProps) => (
400
+ <Button {...itemProps}
401
+ isPressed={heightValue === 'fit'}
402
+ onClick={() => props.onHeightChange('fit')}
403
+ text='fit'
404
+ />
405
+
406
+ )}
407
+ </ToolbarItem>
408
+ </ToolbarGroup>
409
+
410
+ {sel_pos.direction === 'grid' &&
411
+ <>
412
+ {isMobile ?
413
+ <p>{__('Grid Info settings(Mobile)', 'block-collections')}</p>
414
+ :
415
+ <p>{__('Grid Info settings(DeskTop)', 'block-collections')}</p>
416
+ }
417
+ <Button variant="primary" onClick={openGridModal}>
418
+ {__("Open Setting Modal", 'block-collections')}
419
+ </Button>
420
+ {isGridModalOpen && (
421
+ <Modal title="Grid Info settings" onRequestClose={closeGridModal}>
422
+ <GridControls
423
+ attributes={sel_pos.grid_info}
424
+ clientId={clientId}
425
+ onChange={(newValue) => {
426
+ props.onGridChange(newValue)
427
+ }}
428
+ />
429
+ </Modal>
430
+ )}
431
+ </>
432
+ }
433
+ <div className='itmar_title_type'>
434
+ <RadioControl
435
+ label={__("Position Type", 'block-collections')}
436
+ selected={positionType}
437
+ options={[
438
+ { label: __("Static", 'block-collections'), value: 'staic' },
439
+ { label: __("Relative", 'block-collections'), value: 'relative' },
440
+ { label: __("Absolute", 'block-collections'), value: 'absolute' },
441
+ { label: __("Fix", 'block-collections'), value: 'fixed' },
442
+ { label: __("Sticky", 'block-collections'), value: 'sticky' }
443
+ ]}
444
+ onChange={(newVal) => {
445
+ props.onPositionChange(newVal)
446
+ }}
447
+ />
448
+ </div>
449
+ {(positionType === 'absolute' || positionType === 'fixed' || positionType === 'sticky') &&
450
+ <>
451
+ {isMobile ?
452
+ <p>{__('Block Position(Mobile)', 'block-collections')}</p>
453
+ :
454
+ <p>{__('Block Position(DeskTop)', 'block-collections')}</p>
455
+ }
456
+ <PanelRow className='position_row'>
457
+ <ComboboxControl
458
+ label={__("Vertical", 'block-collections')}
459
+ options={[
460
+ { value: 'top', label: 'Top' },
461
+ { value: 'bottom', label: 'Bottom' }
462
+ ]}
463
+ value={sel_pos.posValue?.vertBase || 'top'}
464
+ onChange={
465
+ (newValue) => {
466
+ const newValObj = { ...(sel_pos.posValue || {}), vertBase: newValue }
467
+ props.onPosValueChange(newValObj)
468
+ }
469
+ }
470
+ />
471
+ <UnitControl
472
+ dragDirection="e"
473
+ onChange={
474
+ (newValue) => {
475
+ const newValObj = { ...(sel_pos.posValue || {}), vertValue: newValue }
476
+ props.onPosValueChange(newValObj)
477
+ }
478
+ }
479
+ value={sel_pos.posValue?.vertValue || '3em'}
480
+ />
481
+
482
+ </PanelRow>
483
+ <PanelRow className='position_row'>
484
+ <ComboboxControl
485
+ label={__("Horizon", 'block-collections')}
486
+ options={[
487
+ { value: 'left', label: 'Left' },
488
+ { value: 'right', label: 'Right' }
489
+ ]}
490
+ value={sel_pos.posValue?.horBase || 'left'}
491
+ onChange={
492
+ (newValue) => {
493
+ const newValObj = { ...(sel_pos.posValue || {}), horBase: newValue }
494
+ props.onPosValueChange(newValObj)
495
+ }
496
+ }
497
+ />
498
+ <UnitControl
499
+ dragDirection="e"
500
+ onChange={
501
+ (newValue) => {
502
+ const newValObj = { ...(sel_pos.posValue || {}), horValue: newValue }
503
+ props.onPosValueChange(newValObj)
504
+ }
505
+ }
506
+ value={sel_pos.posValue?.horValue || '3em'}
507
+ />
508
+
509
+ </PanelRow>
510
+
511
+ </>
512
+
513
+ }
514
+ </PanelBody >
515
+
516
+ </>
517
+ );
518
+ }