Skip to content

Commit 05193a4

Browse files
committed
Make height an object
1 parent 16505d9 commit 05193a4

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

block/block.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
"default": ""
1818
},
1919
"height": {
20-
"type": "string",
21-
"default": "600"
22-
},
23-
"heightUnit": {
24-
"type": "string",
25-
"default": "px"
20+
"type": "object",
21+
"default": {
22+
"value": 600,
23+
"unit": "px"
24+
}
2625
}
2726
},
2827
"supports": {

block/edit.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import './editor.scss';
55
import IFrame from "./iframe";
66
import InspectorControls from "./inspector";
77

8+
type Height = {
9+
value: number
10+
unit: string
11+
}
12+
813
export default function Edit({ attributes, setAttributes }): WPElement {
9-
const {
10-
height,
11-
heightUnit,
12-
} = attributes;
14+
const height: Height = attributes.height;
1315

1416
const heightWithUnit =
15-
height && heightUnit
16-
? `${height}${heightUnit}`
17-
: height;
17+
height.value && height.unit
18+
? `${height.value}${height.unit}`
19+
: height.value;
1820

1921
return (
2022
<>
@@ -23,7 +25,7 @@ export default function Edit({ attributes, setAttributes }): WPElement {
2325
<ResizableBox
2426
size={{
2527
width: "100%",
26-
height: attributes.height,
28+
height: heightWithUnit,
2729
}}
2830
enable={{
2931
top: false,
@@ -36,7 +38,7 @@ export default function Edit({ attributes, setAttributes }): WPElement {
3638
topLeft: false,
3739
}}
3840
onResizeStop={(_event, _direction, elt) => {
39-
setAttributes({ height: elt.clientHeight, heightUnit: "px" });
41+
setAttributes({ height: { value: elt.clientHeight, unit: "px" }});
4042
}}
4143
>
4244
<IFrame props={{ height: heightWithUnit }} attributes={attributes} focusable={true}/>

block/inspector.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export default function InspectorControls({ attributes, setAttributes }): WPElem
3838
<PanelRow>
3939
<TextControl
4040
label={__("height", "chatrix")}
41-
value={attributes.height}
42-
onChange={(value) => setAttributes({ height: value })}
41+
value={attributes.height.value}
42+
onChange={(value) => {
43+
setAttributes({ height: { value: value, unit: "px" } });
44+
}}
4345
help={"In pixels"}
4446
/>
4547
</PanelRow>

src/Block/block.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function render( array $attributes ): string {
3434
$container_id = 'wp-block-automattic-chatrix-container';
3535

3636
$style = array(
37-
'height' => "{$attributes['height']}{$attributes['heightUnit']}",
37+
'height' => "{$attributes['height']['value']}{$attributes['height']['unit']}",
3838
);
3939
$style_attr = '';
4040
array_walk($style, function($value, $key) use(&$style_attr) {

0 commit comments

Comments
 (0)