Skip to content

Commit b03fc39

Browse files
committed
Panels can now only be resized to 70% of full available height
Note that this does not reset on resize. useResizeObserver should be used once merged in to the same branch as this code.
1 parent 9a714ba commit b03fc39

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

assets/src/edit-story/components/inspector/context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
*/
44
import { createContext } from '@wordpress/element';
55

6-
export default createContext( { tabs: {} } );
6+
export default createContext( { state: {}, actions: {}, tabs: {} } );

assets/src/edit-story/components/inspector/inspectorLayout.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import styled from 'styled-components';
66
/**
77
* Internal dependencies
88
*/
9+
import useInspector from './useInspector';
910
import InspectorTabs from './inspectorTabs';
1011
import InspectorContent from './inspectorContent';
1112

@@ -32,12 +33,13 @@ const InspectorBackground = styled.div`
3233
`;
3334

3435
function InspectorLayout() {
36+
const { actions: { setInspectorContentNode } } = useInspector();
3537
return (
3638
<Layout>
3739
<TabsArea>
3840
<InspectorTabs />
3941
</TabsArea>
40-
<InspectorBackground>
42+
<InspectorBackground ref={ setInspectorContentNode }>
4143
<InspectorContent />
4244
</InspectorBackground>
4345
</Layout>

assets/src/edit-story/components/inspector/inspectorProvider.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ function InspectorProvider( { children } ) {
2323
const [ tab, setTab ] = useState( DESIGN );
2424
const [ users, setUsers ] = useState( [] );
2525
const [ statuses, setStatuses ] = useState( [] );
26+
const [ inspectorContentHeight, setInspectorContentHeight ] = useState( null );
2627

2728
const [ isUsersLoading, setIsUsersLoading ] = useState( false );
2829
const [ isStatusesLoading, setIsStatusesLoading ] = useState( false );
2930

31+
// TODO Implement `useResizeObserver` once either branch is merged
32+
const setInspectorContentNode = useCallback( ( node ) => {
33+
setInspectorContentHeight( node.clientHeight );
34+
}, [] );
35+
3036
const loadStatuses = useCallback( () => {
3137
if ( ! isStatusesLoading && statuses.length === 0 ) {
3238
setIsStatusesLoading( true );
@@ -69,11 +75,13 @@ function InspectorProvider( { children } ) {
6975
tab,
7076
users,
7177
statuses,
78+
inspectorContentHeight,
7279
},
7380
actions: {
7481
setTab,
7582
loadStatuses,
7683
loadUsers,
84+
setInspectorContentNode,
7785
},
7886
data: {
7987
tabs: {

assets/src/edit-story/panels/panel/title.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useContext, useCallback } from '@wordpress/element';
1212
/**
1313
* Internal dependencies
1414
*/
15+
import useInspector from '../../components/inspector/useInspector';
1516
import panelContext from './context';
1617
import DragHandle from './handle';
1718
import Arrow from './arrow.svg';
@@ -58,10 +59,14 @@ function Title( { children, isPrimary, isResizable } ) {
5859
state: { isCollapsed },
5960
actions: { collapse, expand, setHeight },
6061
} = useContext( panelContext );
62+
const { state: { inspectorContentHeight } } = useInspector();
63+
64+
// Max panel height is set to 70% of full available height.
65+
const maxHeight = Math.round( inspectorContentHeight * 0.7 );
6166

6267
const handleHeightChange = useCallback(
63-
( deltaHeight ) => setHeight( ( height ) => height + deltaHeight ),
64-
[ setHeight ],
68+
( deltaHeight ) => setHeight( ( height ) => Math.max( 0, Math.min( maxHeight, height + deltaHeight ) ) ),
69+
[ setHeight, maxHeight ],
6570
);
6671

6772
return (

0 commit comments

Comments
 (0)