Skip to content

Commit 23497c4

Browse files
committed
Refactored and and allowed ID props to override unique space id
1 parent 21db54c commit 23497c4

File tree

7 files changed

+23
-16
lines changed

7 files changed

+23
-16
lines changed

demo/src/ui-demo/Layers.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const LayersDemo = () => {
66
const [ fixedSideBarHovered, setFixedSideBarHovered ] = React.useState(false);
77
const [ floatingSideBarHovered, setFloatingSideBarHovered ] = React.useState(false);
88
const [ showLayer1, setShowLayer1 ] = React.useState(true);
9-
const [ showLayer2, setShowLayer2 ] = React.useState(true);
9+
const [ showLayer2, setShowLayer2 ] = React.useState(false);
1010

1111
return (
1212
<Space.Fill className="layers-demo">
@@ -20,14 +20,15 @@ export const LayersDemo = () => {
2020
<Space.Layer zIndex={0}>
2121

2222
<Space.Left
23+
id="layer_1_left"
2324
size={fixedSideBarHovered ? "75%" : "60%" }
2425
onMouseEnter={() => setFixedSideBarHovered(true)}
2526
onMouseLeave={() => setFixedSideBarHovered(false)}
2627
as="nav">
2728
{Description("Left fixed (zIndex = 0)")}
2829
</Space.Left>
2930

30-
<Space.Fill as="main">
31+
<Space.Fill as="main" id="layer_1_main">
3132
{Description("Fill space not affected by floated left space in different layer but is affected by left space in same layer (zIndex = 0)")}
3233
</Space.Fill>
3334

@@ -38,6 +39,7 @@ export const LayersDemo = () => {
3839
<Space.Layer zIndex={1}>
3940

4041
<Space.Left
42+
id="layer_2_left"
4143
order={1}
4244
size={floatingSideBarHovered ? "30%" : "15%" }
4345
onMouseEnter={() => setFloatingSideBarHovered(true)}
@@ -46,6 +48,7 @@ export const LayersDemo = () => {
4648
{Description("Left floated (zIndex = 1)")}
4749
</Space.Left>
4850
<Space.Left
51+
id="layer_2_left1"
4952
order={2}
5053
size="15%"
5154
as="section">

demo/src/ui-demo/Windows.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ const Window : React.FC<IWindowProps> = (props) => {
4747
width={"50%"}
4848
height={"50%"}>
4949

50-
<WindowInner />
50+
<WindowInner onClick={() => props.onClick && props.onClick(props.window)} />
5151

5252
</Space.Positioned>
5353
)
5454
}
5555

56-
const WindowInner : React.FC = (props) => {
56+
const WindowInner : React.FC<{ onClick?: () => void }> = (props) => {
5757
const parentSpace = Space.useParentSpace();
5858

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

react-spaces/package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react-spaces/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"license": "MIT",
1515
"description": "React Layout Components",
1616
"dependencies": {
17-
"css-element-queries": "^1.2.1",
18-
"guid-typescript": "^1.0.9"
17+
"css-element-queries": "^1.2.1"
1918
},
2019
"devDependencies": {
2120
"@babel/core": "^7.5.5",
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const useSpace = (props: AllProps, divElementRef: React.MutableRefObject<
2626
height: isVerticalSpace(props) ? props.anchorSize || 0 : props.height,
2727
debug: props.debug !== undefined ? props.debug : false,
2828
})
29-
}, [ props.left, props.top, props.bottom, props.right, props.width, props.height, props.anchor, props.anchorSize, props.debug ]);
29+
}, [ props.zIndex, props.left, props.top, props.bottom, props.right, props.width, props.height, props.anchor, props.anchorSize, props.debug ]);
3030

3131
// Setup / cleanup
3232
React.useEffect(() => {
@@ -72,7 +72,10 @@ export const useSpace = (props: AllProps, divElementRef: React.MutableRefObject<
7272
};
7373

7474
if (parentContext) {
75-
onRemove.current = () => parentContext.removeSpaceTaker(state.id);
75+
onRemove.current = () => {
76+
console.log(`Removing ${state.id}`);
77+
parentContext.removeSpaceTaker(state.id);
78+
}
7679

7780
let adjustedTop: string[] = [];
7881
let adjustedLeft: string[] = [];

react-spaces/src/Globals/Utils.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import { Resizable, ResizeType } from '../Resizable';
3-
import { Guid } from 'guid-typescript';
43
import { AnchorType, AllProps, IState, ISpaceContext, ISpaceTaker, AnchorToResizeTypeMap } from './Types';
54

65
export const getSizeString =
@@ -15,8 +14,15 @@ export const isHorizontalSpace = (props: AllProps) =>
1514
export const isVerticalSpace = (props: AllProps) =>
1615
props.anchor && (props.anchor === AnchorType.Top || props.anchor === AnchorType.Bottom)
1716

17+
const uuid = () =>
18+
"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (char) => {
19+
let random = Math.random() * 16 | 0;
20+
let value = char === "x" ? random : (random % 4 + 8);
21+
return value.toString(16);
22+
});
23+
1824
export const initialState = (props: AllProps) => ({
19-
id: Guid.create().toString(),
25+
id: props.id || uuid(),
2026
currentWidth: 0,
2127
currentHeight: 0,
2228
adjustedSize: 0,

react-spaces/src/Space.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const Positioned : React.FC<IPublicProps & IResizableProps & IPositionedP
1818

1919
const SpaceInternal : React.FC<AllProps> = (props) => {
2020

21+
console.log(props.id);
2122
const divElementRef = React.useRef<HTMLDivElement>();
2223

2324
const {

0 commit comments

Comments
 (0)