itmar-block-packages 1.3.11 → 1.3.13

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.11",
3
+ "version": "1.3.13",
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;
@@ -532,7 +532,19 @@ export default function BlockPlace(props) {
532
532
  }}
533
533
  />
534
534
  </div>
535
- {(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) ||
536
548
  positionType === "fixed" ||
537
549
  positionType === "sticky") && (
538
550
  <>
@@ -541,62 +553,97 @@ export default function BlockPlace(props) {
541
553
  ) : (
542
554
  <p>{__("Block Position(DeskTop)", "block-collections")}</p>
543
555
  )}
544
- <PanelRow className="position_row">
545
- <ComboboxControl
546
- label={__("Vertical", "block-collections")}
547
- options={[
548
- { value: "top", label: "Top" },
549
- { value: "bottom", label: "Bottom" },
550
- ]}
551
- value={sel_pos.posValue?.vertBase || "top"}
552
- onChange={(newValue) => {
553
- const newValObj = {
554
- ...(sel_pos.posValue || {}),
555
- vertBase: newValue,
556
- };
557
- props.onPosValueChange(newValObj);
558
- }}
559
- />
560
- <UnitControl
561
- dragDirection="e"
562
- onChange={(newValue) => {
563
- const newValObj = {
564
- ...(sel_pos.posValue || {}),
565
- vertValue: newValue,
566
- };
567
- props.onPosValueChange(newValObj);
568
- }}
569
- value={sel_pos.posValue?.vertValue || "3em"}
570
- />
571
- </PanelRow>
572
- <PanelRow className="position_row">
573
- <ComboboxControl
574
- label={__("Horizon", "block-collections")}
575
- options={[
576
- { value: "left", label: "Left" },
577
- { value: "right", label: "Right" },
578
- ]}
579
- 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}
580
592
  onChange={(newValue) => {
581
593
  const newValObj = {
582
594
  ...(sel_pos.posValue || {}),
583
- horBase: newValue,
595
+ isVertCenter: newValue,
584
596
  };
585
597
  props.onPosValueChange(newValObj);
586
598
  }}
587
599
  />
588
- <UnitControl
589
- 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}
590
638
  onChange={(newValue) => {
591
639
  const newValObj = {
592
640
  ...(sel_pos.posValue || {}),
593
- horValue: newValue,
641
+ isHorCenter: newValue,
594
642
  };
595
643
  props.onPosValueChange(newValObj);
596
644
  }}
597
- value={sel_pos.posValue?.horValue || "3em"}
598
645
  />
599
- </PanelRow>
646
+ </PanelBody>
600
647
  </>
601
648
  )}
602
649
  </PanelBody>
@@ -626,11 +673,11 @@ export function BlockWidth(props) {
626
673
  // 条件に応じて選択
627
674
  const blockWidthLabel = isMobile
628
675
  ? isSubmenu
629
- ? blockWidthMobile
630
- : blockMaxWidthMobile
676
+ ? blockMaxWidthMobile
677
+ : blockWidthMobile
631
678
  : isSubmenu
632
- ? blockWidthDesktop
633
- : blockMaxWidthDesktop;
679
+ ? blockMaxWidthDesktop
680
+ : blockWidthDesktop;
634
681
 
635
682
  return (
636
683
  <>
@@ -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
  };