Skip to content

Commit 98a9544

Browse files
committed
Updated docs for positioned space / custom handles and cleaned up props
1 parent 320eff7 commit 98a9544

16 files changed

+221
-141
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
![NPM](https://img.shields.io/npm/v/react-spaces.svg) ![Azure Pipelines](https://allan-eagle.visualstudio.com/All%20projects/_apis/build/status/aeagle.react-spaces?branchName=master)
44

5-
An easy to understand and nestable layout system, React Spaces allow you to divide a page or container into anchored, scrollable and resizable spaces enabling you to build desktop/mobile type user interfaces in the browser.
5+
An easy to understand and nestable layout system, React Spaces allow you to divide a page or container into anchored, scrollable and resizable spaces enabling you to build desktop/mobile type user interfaces in the browser.
66

77
Rather than a library of visual UI components, Spaces are intended to be the reusable foundational blocks for laying out a UI which responds neatly to view port resizes leaving you to fill them with whatever components you want.
88

9-
- No styling to achieve simple or complex layouts.
10-
- Spaces know how to behave in relation to each other and resize accordingly.
11-
- Spaces don't have any visual element to them (even padding or margins). You can fill them with whatever you want.
9+
- No styling to achieve simple or complex layouts.
10+
- Spaces know how to behave in relation to each other and resize accordingly.
11+
- Spaces don't have any visual element to them (even padding or margins). You can fill them with whatever you want.
1212

1313
**Version 0.2.0 release - read [release notes here](https://www.allaneagle.com/react-spaces/release-0.2.0).**
1414

@@ -48,18 +48,20 @@ There are resizable versions of these components called **\<LeftResizable /\>**,
4848

4949
A space which consumes any available area left in the parent container/space taking into account any anchored spaces on every side.
5050

51+
**\<Positioned /\>**
52+
53+
A space which can be absolutely placed within a parent space either by top, left, width and height or by top, left, right and bottom.
54+
5155
**\<Layer /\>**
5256

5357
Layers allow you to create layers within a parent space, for example:
5458

5559
```html
5660
<ViewPort>
57-
<Layer zIndex="{0}">
58-
<LeftResizable size="20%" /> // floating sidebar
59-
</Layer>
60-
<Layer zIndex="{1}">
61-
<Fill />
62-
</Layer>
61+
<Layer zIndex="{0}"> <LeftResizable size="20%" /> // floating sidebar </Layer>
62+
<Layer zIndex="{1}">
63+
<Fill />
64+
</Layer>
6365
</ViewPort>
6466
```
6567

src/components/Anchored.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,47 @@ import { SizeUnit, Type, AnchorType, ResizeHandlePlacement } from "../core-types
22
import * as React from "react";
33
import { Space } from "./Space";
44
import * as PropTypes from "prop-types";
5-
import { commonProps, IReactSpaceProps } from "../core-react";
5+
import { commonProps, IReactSpaceCommonProps, IResizeHandleProps } from "../core-react";
66

7-
interface IAnchorProps extends IReactSpaceProps {
7+
export interface IResizableProps extends IReactSpaceCommonProps {
88
size: SizeUnit;
99
order?: number;
10-
resizable?: boolean;
1110
handleSize?: number;
1211
handlePlacement?: ResizeHandlePlacement;
12+
handleRender?: (handleProps: IResizeHandleProps) => React.ReactNode;
1313
minimumSize?: number;
1414
maximumSize?: number;
1515
onResizeStart?: () => void | boolean;
1616
onResizeEnd?: (newSize: SizeUnit) => void;
1717
}
1818

19-
export const anchoredProps = {
19+
export const resizableProps = {
2020
...commonProps,
2121
...{
2222
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
2323
order: PropTypes.number,
24-
resizable: PropTypes.bool,
2524
handleSize: PropTypes.number,
2625
handlePlacement: PropTypes.oneOf([ResizeHandlePlacement.Inside, ResizeHandlePlacement.OverlayBoundary, ResizeHandlePlacement.OverlayInside]),
26+
handleRender: PropTypes.func,
2727
minimumSize: PropTypes.number,
2828
maximumSize: PropTypes.number,
2929
onResizeStart: PropTypes.func,
3030
onResizeEnd: PropTypes.func,
3131
},
3232
};
3333

34-
export const resizableProps = {
35-
...commonProps,
34+
export interface IAnchorProps extends IResizableProps {
35+
resizable?: boolean;
36+
}
37+
38+
export const anchoredProps = {
39+
...resizableProps,
3640
...{
37-
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
38-
order: PropTypes.number,
39-
handleSize: PropTypes.number,
40-
handlePlacement: PropTypes.oneOf([ResizeHandlePlacement.Inside, ResizeHandlePlacement.OverlayBoundary, ResizeHandlePlacement.OverlayInside]),
41-
minimumSize: PropTypes.number,
42-
maximumSize: PropTypes.number,
43-
onResizeStart: PropTypes.func,
44-
onResizeEnd: PropTypes.func,
41+
resizable: PropTypes.bool,
4542
},
4643
};
4744

48-
export const LeftResizable: React.FC<Omit<IAnchorProps, "resizable">> = ({ children, size, ...props }) => (
45+
export const LeftResizable: React.FC<IResizableProps> = ({ children, size, ...props }) => (
4946
<Space {...props} type={Type.Anchored} anchor={AnchorType.Left} position={{ left: 0, top: 0, bottom: 0, rightResizable: true, width: size }}>
5047
{children}
5148
</Space>
@@ -65,7 +62,7 @@ export const Left: React.FC<IAnchorProps> = ({ size, children, resizable, ...com
6562

6663
Left.propTypes = anchoredProps;
6764

68-
export const TopResizable: React.FC<Omit<IAnchorProps, "resizable">> = ({ children, size, ...props }) => (
65+
export const TopResizable: React.FC<IResizableProps> = ({ children, size, ...props }) => (
6966
<Space {...props} type={Type.Anchored} anchor={AnchorType.Top} position={{ left: 0, top: 0, right: 0, bottomResizable: true, height: size }}>
7067
{children}
7168
</Space>
@@ -85,7 +82,7 @@ export const Top: React.FC<IAnchorProps> = ({ size, children, resizable, ...comm
8582

8683
Top.propTypes = anchoredProps;
8784

88-
export const RightResizable: React.FC<Omit<IAnchorProps, "resizable">> = ({ children, size, ...props }) => (
85+
export const RightResizable: React.FC<IResizableProps> = ({ children, size, ...props }) => (
8986
<Space {...props} type={Type.Anchored} anchor={AnchorType.Right} position={{ bottom: 0, top: 0, right: 0, leftResizable: true, width: size }}>
9087
{children}
9188
</Space>
@@ -105,7 +102,7 @@ export const Right: React.FC<IAnchorProps> = ({ size, children, resizable, ...co
105102

106103
Right.propTypes = anchoredProps;
107104

108-
export const BottomResizable: React.FC<Omit<IAnchorProps, "resizable">> = ({ children, size, ...props }) => (
105+
export const BottomResizable: React.FC<IResizableProps> = ({ children, size, ...props }) => (
109106
<Space {...props} type={Type.Anchored} anchor={AnchorType.Bottom} position={{ bottom: 0, left: 0, right: 0, topResizable: true, height: size }}>
110107
{children}
111108
</Space>

src/components/Custom.tsx

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
1-
import { Type, SizeUnit, IPositionalProps, AnchorType, ResizeType, ResizeHandlePlacement } from "../core-types";
1+
import { Type, SizeUnit, IPositionalProps, AnchorType, ResizeType } from "../core-types";
22
import * as React from "react";
33
import { Space } from "./Space";
44
import * as PropTypes from "prop-types";
5-
import { commonProps, IReactSpaceProps } from "../core-react";
5+
import { IReactSpaceCommonProps } from "../core-react";
6+
import { anchoredProps, IAnchorProps } from "./Anchored";
67

7-
interface ICustomProps extends IReactSpaceProps {
8+
type ICustomProps = Omit<IReactSpaceCommonProps & IAnchorProps, "size"> & {
9+
// Anchored
10+
anchor?: AnchorType;
11+
anchorSize?: SizeUnit;
12+
13+
// Positioned
814
left?: SizeUnit | undefined;
915
top?: SizeUnit | undefined;
1016
right?: SizeUnit | undefined;
1117
bottom?: SizeUnit | undefined;
1218
width?: SizeUnit | undefined;
1319
height?: SizeUnit | undefined;
1420
isPositioned?: boolean;
15-
anchor?: AnchorType;
16-
anchorSize?: SizeUnit;
17-
resizable?: boolean;
1821
resizeTypes?: ResizeType[];
19-
handleSize?: number;
20-
handlePlacement?: ResizeHandlePlacement;
21-
overlayHandle?: boolean;
22-
minimumSize?: number;
23-
maximumSize?: number;
24-
onResizeStart?: () => void | boolean;
25-
onResizeEnd?: (newSize: SizeUnit) => void;
26-
}
22+
};
23+
24+
const customProps = {
25+
...anchoredProps,
26+
...{
27+
anchor: PropTypes.oneOf([AnchorType.Left, AnchorType.Top, AnchorType.Right, AnchorType.Bottom]),
28+
anchorSize: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
29+
30+
left: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
31+
top: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
32+
right: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
33+
bottom: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
34+
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
35+
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
36+
isPositioned: PropTypes.bool,
37+
resizeTypes: PropTypes.any,
38+
},
39+
};
2740

2841
export const Custom: React.FC<ICustomProps> = ({
2942
children,
@@ -87,23 +100,4 @@ export const Custom: React.FC<ICustomProps> = ({
87100
);
88101
};
89102

90-
Custom.propTypes = {
91-
...commonProps,
92-
...{
93-
left: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
94-
top: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
95-
right: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
96-
bottom: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
97-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
98-
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
99-
isPositioned: PropTypes.bool,
100-
anchor: PropTypes.oneOf([AnchorType.Left, AnchorType.Top, AnchorType.Right, AnchorType.Bottom]),
101-
anchorSize: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
102-
resizable: PropTypes.bool,
103-
handleSize: PropTypes.number,
104-
minimumSize: PropTypes.number,
105-
maximumSize: PropTypes.number,
106-
onResizeStart: PropTypes.func,
107-
onResizeEnd: PropTypes.func,
108-
},
109-
};
103+
Custom.propTypes = customProps;

src/components/Fill.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Type } from "../core-types";
22
import * as React from "react";
33
import { Space } from "./Space";
4-
import { commonProps, IReactSpaceProps } from "../core-react";
4+
import { commonProps, IReactSpaceCommonProps } from "../core-react";
55

6-
export const Fill: React.FC<IReactSpaceProps> = (props) => (
6+
export const Fill: React.FC<IReactSpaceCommonProps> = (props) => (
77
<Space {...props} type={Type.Fill} position={{ left: 0, top: 0, right: 0, bottom: 0 }}>
88
{props.children}
99
</Space>

src/components/Fixed.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { SizeUnit, Type } from "../core-types";
22
import * as React from "react";
33
import { Space } from "./Space";
44
import * as PropTypes from "prop-types";
5-
import { commonProps, IReactSpaceProps } from "../core-react";
5+
import { commonProps, IReactSpaceCommonProps } from "../core-react";
66

7-
interface IFixedProps extends IReactSpaceProps {
7+
interface IFixedProps extends IReactSpaceCommonProps {
88
width?: SizeUnit;
99
height: SizeUnit;
1010
}

src/components/Positioned.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Type, SizeUnit, ResizeType } from "../core-types";
22
import * as React from "react";
33
import { Space } from "./Space";
44
import * as PropTypes from "prop-types";
5-
import { commonProps, IReactSpaceProps } from "../core-react";
5+
import { commonProps, IReactSpaceCommonProps } from "../core-react";
66

7-
interface IPositionedProps extends IReactSpaceProps {
7+
interface IPositionedProps extends IReactSpaceCommonProps {
88
left?: SizeUnit;
99
top?: SizeUnit;
1010
right?: SizeUnit;

src/components/Space.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const SpaceInner: React.FC<IReactSpaceInnerProps & { wrapperInstance: Space }> =
3939
onTouchMove,
4040
onTouchEnd,
4141
children,
42-
handleRender
42+
handleRender,
4343
} = props;
4444

4545
const events = {
@@ -91,9 +91,7 @@ const SpaceInner: React.FC<IReactSpaceInnerProps & { wrapperInstance: Space }> =
9191

9292
return (
9393
<>
94-
{resizeHandles.mouseHandles.map((handleProps) => (
95-
handleRender?.(handleProps) || <div {...handleProps} />
96-
))}
94+
{resizeHandles.mouseHandles.map((handleProps) => handleRender?.(handleProps) || <div {...handleProps} />)}
9795
{React.createElement(
9896
props.as || "div",
9997
{

src/components/SpaceInfo.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ interface ISpaceInfoProps {
55
children: (info: DOMRect) => JSX.Element;
66
}
77

8+
/**
9+
* @deprecated use useCurrentSpace() hook instead
10+
*/
811
export const Info: React.FC<ISpaceInfoProps> = (props) => {
912
const domRect = React.useContext(DOMRectContext);
1013

src/components/ViewPort.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Type, SizeUnit } from "../core-types";
22
import * as React from "react";
33
import { Space } from "./Space";
44
import * as PropTypes from "prop-types";
5-
import { commonProps, IReactSpaceProps } from "../core-react";
5+
import { commonProps, IReactSpaceCommonProps } from "../core-react";
66

7-
interface IViewPortProps extends IReactSpaceProps {
7+
interface IViewPortProps extends IReactSpaceCommonProps {
88
left?: SizeUnit;
99
right?: SizeUnit;
1010
top?: SizeUnit;
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { Meta, Story, Canvas, Props } from "@storybook/addon-docs/blocks";
2-
import { CommonHeader, PropsTable, StandardProps } from "../Utils";
3-
4-
<CommonHeader />
5-
6-
<Meta title="React Spaces/Useful properties" />
7-
8-
## Useful properties
9-
10-
Applies to `<Fill />` `<Left />` `<Top />` `<Right />` `<Bottom />` `<LeftResizable />` `<TopResizable />` `<RightResizable />` `<BottomResizable />` `<Positioned />` `<Custom />`
11-
12-
<PropsTable>
13-
<StandardProps />
1+
import { Meta, Story, Canvas, Props } from "@storybook/addon-docs/blocks";
2+
import { CommonHeader, PropsTable, StandardProps } from "../Utils";
3+
4+
<CommonHeader />
5+
6+
<Meta title="React Spaces/Common properties" />
7+
8+
## Useful properties
9+
10+
Applies to `<Fill />` `<Left />` `<Top />` `<Right />` `<Bottom />` `<LeftResizable />` `<TopResizable />` `<RightResizable />` `<BottomResizable />` `<Positioned />` `<Custom />`
11+
12+
<PropsTable>
13+
<StandardProps />
1414
</PropsTable>

0 commit comments

Comments
 (0)