itmar-block-packages 1.3.10 → 1.3.12

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itmar-block-packages",
3
- "version": "1.3.10",
3
+ "version": "1.3.12",
4
4
  "description": "We have put together a package of common React components used for WordPress custom blocks.",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/BlockPlace.js CHANGED
@@ -44,7 +44,7 @@ const vert_around = <Icon icon={justifySpaceBetween} className="rotate-icon" />;
44
44
 
45
45
  export default function BlockPlace(props) {
46
46
  const { attributes, clientId, blockRef, isMobile, isSubmenu } = props;
47
- const { positionType, default_pos, mobile_pos } = attributes;
47
+ const { positionType, isPosCenter, default_pos, mobile_pos } = attributes;
48
48
 
49
49
  //モバイルかデスクトップか
50
50
  const sel_pos = isMobile ? mobile_pos : default_pos;
@@ -441,16 +441,10 @@ export default function BlockPlace(props) {
441
441
  </ToolbarGroup>
442
442
 
443
443
  {sel_pos.width_val === "free" && (
444
- <RangeControl
444
+ <UnitControl
445
+ dragDirection="e"
446
+ onChange={(newValue) => props.onFreeWidthChange(newValue)}
445
447
  value={sel_pos.free_width}
446
- label={__("Max width", "block-collections")}
447
- max={1800}
448
- min={300}
449
- step={10}
450
- onChange={(newValue) => {
451
- props.onFreeWidthChange(newValue);
452
- }}
453
- withInputField={true}
454
448
  />
455
449
  )}
456
450
 
@@ -492,16 +486,10 @@ export default function BlockPlace(props) {
492
486
  </ToolbarItem>
493
487
  </ToolbarGroup>
494
488
  {sel_pos.height_val === "free" && (
495
- <RangeControl
489
+ <UnitControl
490
+ dragDirection="e"
491
+ onChange={(newValue) => props.onFreeHeightChange(newValue)}
496
492
  value={sel_pos.free_height}
497
- label={__("Height", "block-collections")}
498
- max={1800}
499
- min={300}
500
- step={10}
501
- onChange={(newValue) => {
502
- props.onFreeHeightChange(newValue);
503
- }}
504
- withInputField={true}
505
493
  />
506
494
  )}
507
495
 
@@ -544,7 +532,19 @@ export default function BlockPlace(props) {
544
532
  }}
545
533
  />
546
534
  </div>
547
- {(positionType === "absolute" ||
535
+ {positionType === "absolute" && (
536
+ <ToggleControl
537
+ label={__(
538
+ "Center Vertically and Horizontally",
539
+ "block-collections"
540
+ )}
541
+ checked={isPosCenter}
542
+ onChange={(newVal) => {
543
+ props.onIsPosCenterChange(newVal);
544
+ }}
545
+ />
546
+ )}
547
+ {((positionType === "absolute" && !isPosCenter) ||
548
548
  positionType === "fixed" ||
549
549
  positionType === "sticky") && (
550
550
  <>
@@ -553,62 +553,97 @@ export default function BlockPlace(props) {
553
553
  ) : (
554
554
  <p>{__("Block Position(DeskTop)", "block-collections")}</p>
555
555
  )}
556
- <PanelRow className="position_row">
557
- <ComboboxControl
558
- label={__("Vertical", "block-collections")}
559
- options={[
560
- { value: "top", label: "Top" },
561
- { value: "bottom", label: "Bottom" },
562
- ]}
563
- value={sel_pos.posValue?.vertBase || "top"}
564
- onChange={(newValue) => {
565
- const newValObj = {
566
- ...(sel_pos.posValue || {}),
567
- vertBase: newValue,
568
- };
569
- props.onPosValueChange(newValObj);
570
- }}
571
- />
572
- <UnitControl
573
- dragDirection="e"
574
- onChange={(newValue) => {
575
- const newValObj = {
576
- ...(sel_pos.posValue || {}),
577
- vertValue: newValue,
578
- };
579
- props.onPosValueChange(newValObj);
580
- }}
581
- value={sel_pos.posValue?.vertValue || "3em"}
582
- />
583
- </PanelRow>
584
- <PanelRow className="position_row">
585
- <ComboboxControl
586
- label={__("Horizon", "block-collections")}
587
- options={[
588
- { value: "left", label: "Left" },
589
- { value: "right", label: "Right" },
590
- ]}
591
- value={sel_pos.posValue?.horBase || "left"}
556
+ <PanelBody
557
+ title={__("Vertical", "block-collections")}
558
+ initialOpen={true}
559
+ >
560
+ {!sel_pos.posValue?.isVertCenter && (
561
+ <PanelRow className="position_row">
562
+ <ComboboxControl
563
+ options={[
564
+ { value: "top", label: "Top" },
565
+ { value: "bottom", label: "Bottom" },
566
+ ]}
567
+ value={sel_pos.posValue?.vertBase || "top"}
568
+ onChange={(newValue) => {
569
+ const newValObj = {
570
+ ...(sel_pos.posValue || {}),
571
+ vertBase: newValue,
572
+ };
573
+ props.onPosValueChange(newValObj);
574
+ }}
575
+ />
576
+ <UnitControl
577
+ dragDirection="e"
578
+ onChange={(newValue) => {
579
+ const newValObj = {
580
+ ...(sel_pos.posValue || {}),
581
+ vertValue: newValue,
582
+ };
583
+ props.onPosValueChange(newValObj);
584
+ }}
585
+ value={sel_pos.posValue?.vertValue || "3em"}
586
+ />
587
+ </PanelRow>
588
+ )}
589
+ <ToggleControl
590
+ label={__("Is Center", "block-collections")}
591
+ checked={sel_pos.posValue?.isVertCenter}
592
592
  onChange={(newValue) => {
593
593
  const newValObj = {
594
594
  ...(sel_pos.posValue || {}),
595
- horBase: newValue,
595
+ isVertCenter: newValue,
596
596
  };
597
597
  props.onPosValueChange(newValObj);
598
598
  }}
599
599
  />
600
- <UnitControl
601
- dragDirection="e"
600
+ </PanelBody>
601
+
602
+ <PanelBody
603
+ title={__("Horizon", "block-collections")}
604
+ initialOpen={true}
605
+ >
606
+ {!sel_pos.posValue?.isHorCenter && (
607
+ <PanelRow className="position_row">
608
+ <ComboboxControl
609
+ options={[
610
+ { value: "left", label: "Left" },
611
+ { value: "right", label: "Right" },
612
+ ]}
613
+ value={sel_pos.posValue?.horBase || "left"}
614
+ onChange={(newValue) => {
615
+ const newValObj = {
616
+ ...(sel_pos.posValue || {}),
617
+ horBase: newValue,
618
+ };
619
+ props.onPosValueChange(newValObj);
620
+ }}
621
+ />
622
+ <UnitControl
623
+ dragDirection="e"
624
+ onChange={(newValue) => {
625
+ const newValObj = {
626
+ ...(sel_pos.posValue || {}),
627
+ horValue: newValue,
628
+ };
629
+ props.onPosValueChange(newValObj);
630
+ }}
631
+ value={sel_pos.posValue?.horValue || "3em"}
632
+ />
633
+ </PanelRow>
634
+ )}
635
+ <ToggleControl
636
+ label={__("Is Center", "block-collections")}
637
+ checked={sel_pos.posValue?.isHorCenter}
602
638
  onChange={(newValue) => {
603
639
  const newValObj = {
604
640
  ...(sel_pos.posValue || {}),
605
- horValue: newValue,
641
+ isHorCenter: newValue,
606
642
  };
607
643
  props.onPosValueChange(newValObj);
608
644
  }}
609
- value={sel_pos.posValue?.horValue || "3em"}
610
645
  />
611
- </PanelRow>
646
+ </PanelBody>
612
647
  </>
613
648
  )}
614
649
  </PanelBody>
@@ -703,16 +738,10 @@ export function BlockWidth(props) {
703
738
  </ToolbarGroup>
704
739
 
705
740
  {sel_pos.width_val === "free" && (
706
- <RangeControl
741
+ <UnitControl
742
+ dragDirection="e"
743
+ onChange={(newValue) => props.onFreeWidthChange(newValue)}
707
744
  value={sel_pos.free_width}
708
- label={__("Max width", "block-collections")}
709
- max={1800}
710
- min={50}
711
- step={10}
712
- onChange={(newValue) => {
713
- props.onFreeWidthChange(newValue);
714
- }}
715
- withInputField={true}
716
745
  />
717
746
  )}
718
747
  </>
@@ -766,16 +795,10 @@ export function BlockHeight(props) {
766
795
  </ToolbarItem>
767
796
  </ToolbarGroup>
768
797
  {sel_pos.height_val === "free" && (
769
- <RangeControl
798
+ <UnitControl
799
+ dragDirection="e"
800
+ onChange={(newValue) => props.onFreeHeightChange(newValue)}
770
801
  value={sel_pos.free_height}
771
- label={__("Height", "block-collections")}
772
- max={1800}
773
- min={50}
774
- step={10}
775
- onChange={(newValue) => {
776
- props.onFreeHeightChange(newValue);
777
- }}
778
- withInputField={true}
779
802
  />
780
803
  )}
781
804
  </>
@@ -2,6 +2,10 @@
2
2
  const capitalizeFirstLetter = (string) => {
3
3
  return string.charAt(0).toUpperCase() + string.slice(1);
4
4
  };
5
+ // objectかどうか判定する関数
6
+ const isObject = (value) => {
7
+ return value !== null && typeof value === "object" && !Array.isArray(value);
8
+ };
5
9
 
6
10
  //角丸のパラメータを返す
7
11
  export const radius_prm = (radius) => {
@@ -24,14 +28,26 @@ export const space_prm = (space) => {
24
28
  };
25
29
  //positionのオブジェクトを返します
26
30
  export const position_prm = (pos, type) => {
27
- if (pos) {
31
+ //値でポジションを設定
32
+ if (isObject(pos)) {
28
33
  const resetVertBase = pos.vertBase === "top" ? "bottom" : "top";
29
34
  const resetHorBase = pos.horBase === "left" ? "right" : "left";
35
+ const centerVert = "50%";
36
+ const centerHor = "50%";
37
+ const centerTrans =
38
+ pos.isVertCenter && pos.isHorCenter
39
+ ? "transform: translate(-50%, -50%);"
40
+ : pos.isVertCenter
41
+ ? "transform: translateY(-50%);"
42
+ : pos.isHorCenter
43
+ ? "transform: translateX(-50%);"
44
+ : null;
30
45
  const ret_pos_prm =
31
46
  pos && (type === "absolute" || type === "fixed" || type === "sticky")
32
47
  ? `
33
- ${pos.vertBase}: ${pos.vertValue};
34
- ${pos.horBase}: ${pos.horValue};
48
+ ${pos.vertBase}: ${pos.isVertCenter ? centerVert : pos.vertValue};
49
+ ${pos.horBase}: ${pos.isHorCenter ? centerHor : pos.horValue};
50
+ ${centerTrans}
35
51
  ${resetVertBase}: auto;
36
52
  ${resetHorBase}: auto;
37
53
  ${
@@ -42,6 +58,10 @@ export const position_prm = (pos, type) => {
42
58
  `
43
59
  : "";
44
60
  return ret_pos_prm;
61
+ //縦横中央揃え
62
+ } else if (pos) {
63
+ const ret_pos_prm = "top:50%;left: 50%;transform: translate(-50%, -50%);";
64
+ return ret_pos_prm;
45
65
  }
46
66
  return null;
47
67
  };
@@ -53,7 +73,7 @@ export const max_width_prm = (width, free_val) => {
53
73
  : width === "contentSize"
54
74
  ? "width: 100%; max-width: var(--wp--style--global--content-size);"
55
75
  : width === "free"
56
- ? `width: 100%; max-width: ${free_val}px;`
76
+ ? `width: 100%; max-width: ${free_val};`
57
77
  : width === "full"
58
78
  ? "width: fit-content; max-width: 100%;"
59
79
  : " width: fit-content;";
@@ -67,7 +87,7 @@ export const width_prm = (width, free_val) => {
67
87
  : width === "contentSize"
68
88
  ? " width: var(--wp--style--global--content-size);"
69
89
  : width === "free"
70
- ? ` width: ${free_val}px; `
90
+ ? ` width: ${free_val}; `
71
91
  : width === "full"
72
92
  ? " width: 100%;"
73
93
  : " width: fit-content;";
@@ -79,7 +99,7 @@ export const height_prm = (height, free_val) => {
79
99
  height === "fit"
80
100
  ? " height: fit-content;"
81
101
  : height === "free"
82
- ? ` height: ${free_val}px; `
102
+ ? ` height: ${free_val}; `
83
103
  : "height: 100%;";
84
104
  return ret_height_prm;
85
105
  };