Skip to content

Commit 32d9837

Browse files
committed
move resizable map into it’s own component
1 parent 206b13c commit 32d9837

2 files changed

Lines changed: 56 additions & 53 deletions

File tree

src/components/ResizableMap.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
ResizableBox,
3+
} from '@wordpress/components';
4+
5+
const RESIZABLE_BOX_ENABLE_OPTION = {
6+
top: false,
7+
right: false,
8+
bottom: true,
9+
left: false,
10+
topRight: false,
11+
bottomRight: false,
12+
bottomLeft: false,
13+
topLeft: false,
14+
};
15+
16+
const MAP_MIN_HEIGHT = 100;
17+
18+
export function ResizableMap( {
19+
onResizeStart,
20+
onResize,
21+
onResizeStop,
22+
...props
23+
} ) {
24+
const [ isResizing, setIsResizing ] = useState( false );
25+
26+
return (
27+
<ResizableBox
28+
style={{
29+
position: 'absolute',
30+
top: 0,
31+
left: 0,
32+
right: 0,
33+
bottom: 0,
34+
}}
35+
className={ `apple-maps-block__resize-container ${isResizing ? 'is-resizing' : ''}` }
36+
enable={ RESIZABLE_BOX_ENABLE_OPTION }
37+
onResizeStart={ ( _event, _direction, elt ) => {
38+
onResizeStart( elt.clientHeight );
39+
onResize( elt.clientHeight );
40+
} }
41+
onResize={ ( _event, _direction, elt ) => {
42+
onResize( elt.clientHeight );
43+
if ( ! isResizing ) {
44+
setIsResizing( true );
45+
}
46+
} }
47+
onResizeStop={ ( _event, _direction, elt ) => {
48+
onResizeStop( elt.clientHeight );
49+
setIsResizing( false );
50+
} }
51+
minHeight={ MAP_MIN_HEIGHT }
52+
{ ...props }
53+
/>
54+
);
55+
}

src/edit.js

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Placeholder,
44
Toolbar,
55
ToolbarButton,
6-
ResizableBox,
76
} from '@wordpress/components';
87
import { __ } from '@wordpress/i18n';
98
import { useEffect, useRef, useState } from '@wordpress/element';
@@ -16,6 +15,7 @@ import InspectorSettings from './inspector-settings';
1615
import IsAdmin from './helper';
1716
import BlockIcon from './block-icon';
1817
import { debounce } from 'lodash';
18+
import { ResizableMap } from './components/ResizableMap'
1919

2020
export default function MapsBlockAppleEdit( props ) {
2121
const {
@@ -266,55 +266,3 @@ export default function MapsBlockAppleEdit( props ) {
266266
</>
267267
);
268268
}
269-
270-
const RESIZABLE_BOX_ENABLE_OPTION = {
271-
top: false,
272-
right: false,
273-
bottom: true,
274-
left: false,
275-
topRight: false,
276-
bottomRight: false,
277-
bottomLeft: false,
278-
topLeft: false,
279-
};
280-
281-
const MAP_MIN_HEIGHT = 100;
282-
283-
function ResizableMap( {
284-
onResizeStart,
285-
onResize,
286-
onResizeStop,
287-
...props
288-
} ) {
289-
const [ isResizing, setIsResizing ] = useState( false );
290-
291-
return (
292-
<ResizableBox
293-
style={{
294-
position: 'absolute',
295-
top: 0,
296-
left: 0,
297-
right: 0,
298-
bottom: 0,
299-
}}
300-
className={ `apple-maps-block__resize-container ${isResizing ? 'is-resizing' : ''}` }
301-
enable={ RESIZABLE_BOX_ENABLE_OPTION }
302-
onResizeStart={ ( _event, _direction, elt ) => {
303-
onResizeStart( elt.clientHeight );
304-
onResize( elt.clientHeight );
305-
} }
306-
onResize={ ( _event, _direction, elt ) => {
307-
onResize( elt.clientHeight );
308-
if ( ! isResizing ) {
309-
setIsResizing( true );
310-
}
311-
} }
312-
onResizeStop={ ( _event, _direction, elt ) => {
313-
onResizeStop( elt.clientHeight );
314-
setIsResizing( false );
315-
} }
316-
minHeight={ MAP_MIN_HEIGHT }
317-
{ ...props }
318-
/>
319-
);
320-
}

0 commit comments

Comments
 (0)