Skip to content

Commit 55ec4a5

Browse files
committed
Refactored all state for child spaces to be held at parent space
1 parent cd6ed9d commit 55ec4a5

File tree

17 files changed

+518
-444
lines changed

17 files changed

+518
-444
lines changed

demo/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React from 'react';
22
import './App.scss';
33
import ReactGA from 'react-ga';
4-
import { Test } from './Test';
5-
//import { UI } from './ui-demo/UI';
4+
// import { Test } from './Test';
5+
import { UI } from './ui-demo/UI';
66

77
ReactGA.initialize("UA-144490437-1");
88
ReactGA.pageview(window.location.pathname + window.location.search);
99

1010
const App: React.FC = () => {
11-
return <Test />
11+
return <UI />
1212
}
1313

1414
export default App;

demo/src/Test.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import * as Space from "react-spaces";
33
import './Test.scss';
4+
import { Info } from "react-spaces";
45

56
const COLLAPSED_SIZE = 20;
67
const MINIMUM_SIZE = 200;
@@ -27,19 +28,25 @@ export const Test : React.FC = () => {
2728
onResizeStart={onResizeStart}
2829
onResizeEnd={onResizeEnd}
2930
order={1}>
30-
Hello
31+
<Space.Info>
32+
{(info) => <span>Hello<br />{info.width} x {info.height}</span>}
33+
</Space.Info>
3134
</Space.LeftResizable>
3235

33-
<Space.Left
36+
<Space.LeftResizable
3437
style={{ backgroundColor: 'navy', color: 'white', padding: 10 }}
3538
size={200}
3639
order={2}>
37-
Something
38-
</Space.Left>
40+
<Space.Info>
41+
{(info) => <span>Something<br />{info.width} x {info.height}</span>}
42+
</Space.Info>
43+
</Space.LeftResizable>
3944

4045
<Space.Fill
4146
style={{ backgroundColor: 'red', padding: 10 }}>
42-
World
47+
<Space.Info>
48+
{(info) => <span>World<br />{info.width} x {info.height}</span>}
49+
</Space.Info>
4350
</Space.Fill>
4451

4552
</Space.ViewPort>

demo/src/ui-demo/UI.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const DemoSelection = (props: {
125125

126126
const Main = (props: { selectedDemo: string, showSpaces: boolean }) => {
127127
return (
128-
<Space.Fill debug={props.showSpaces}>
128+
<Space.Fill>
129129
{ props.selectedDemo === "resizable" ? <Resizable /> : null }
130130
{ props.selectedDemo === "scrollable" ? <ScrollableDemo /> : null }
131131
{ props.selectedDemo === "layers" ? <LayersDemo /> : null }

demo/src/ui-demo/Windows.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const WindowInner : React.FC<{ onClick?: () => void }> = (props) => {
5858

5959
return (
6060
<>
61-
<Space.Top className="title-bar" onMouseDown={e => { props.onClick && props.onClick(); parentSpace.startDrag(e); }} size={40}>
61+
<Space.Top className="title-bar" onMouseDown={e => { props.onClick && props.onClick(); parentSpace.startDrag(); }} size={40}>
6262
{Description(`Window title`)}
6363
</Space.Top>
6464
<Space.Fill className="content" centerContent={Space.CenterType.HorizontalVertical}>

react-spaces/src/Fixed.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import * as React from 'react';
22
import './Styles.css';
33
import * as PropTypes from "prop-types";
44
import { SpaceInternal } from './Space';
5+
import { SpaceContext } from './Globals/Contexts';
6+
import { ISpace } from './Globals/Types';
7+
import { createSpaceContext } from './Globals/ISpaceContext';
58

69
interface IProps {
710
className?: string,
@@ -11,6 +14,8 @@ interface IProps {
1114
}
1215

1316
export const Fixed : React.FC<IProps> = (props) => {
17+
const [ children, setChildren ] = React.useState<ISpace[]>([]);
18+
1419
const style = {
1520
...props.style,
1621
...{
@@ -23,9 +28,11 @@ export const Fixed : React.FC<IProps> = (props) => {
2328
<div
2429
className={`spaces-fixedsize-layout${props.className ? ` ${props.className}` : ``}`}
2530
style={style}>
26-
<SpaceInternal topMost={true}>
27-
{props.children}
28-
</SpaceInternal>
31+
<SpaceContext.Provider value={createSpaceContext(children, setChildren)}>
32+
<SpaceInternal topMost={true}>
33+
{props.children}
34+
</SpaceInternal>
35+
</SpaceContext.Provider>
2936
</div>
3037
)
3138
}

react-spaces/src/Globals/Contexts.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
2-
import { ISpaceContext, ISpaceInfo } from './Types';
2+
import { ISpaceInfo } from './Types';
3+
import { ISpaceContext } from './ISpaceContext';
34

45
export const SpaceContext = React.createContext<ISpaceContext | null>(null);
56
export const SpaceLayerContext = React.createContext<number | null>(null);

react-spaces/src/Globals/Hooks.ts

Lines changed: 0 additions & 217 deletions
This file was deleted.

0 commit comments

Comments
 (0)