Skip to content

Commit 251aff3

Browse files
committed
Removed unnecessary top most markup at ViewPort and Fixed components
1 parent d45dc32 commit 251aff3

File tree

6 files changed

+48
-33
lines changed

6 files changed

+48
-33
lines changed

react-spaces/src/Fixed.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
2-
import * as Spaces from './Space';
32
import './Styles.css';
43
import * as PropTypes from "prop-types";
4+
import { SpaceInternal } from './Space';
55

66
interface IProps {
77
className?: string,
@@ -23,10 +23,9 @@ export const Fixed : React.FC<IProps> = (props) => {
2323
<div
2424
className={`spaces-fixedsize-layout${props.className ? ` ${props.className}` : ``}`}
2525
style={style}>
26-
27-
<Spaces.Fill>
26+
<SpaceInternal topMost={true}>
2827
{props.children}
29-
</Spaces.Fill>
28+
</SpaceInternal>
3029
</div>
3130
)
3231
}

react-spaces/src/Globals/Hooks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ export const useSpace = (props: AllProps, divElementRef: React.MutableRefObject<
200200
innerStyle,
201201
innerClasses,
202202
currentWidth: state.currentWidth,
203-
currentHeight: state.currentHeight
203+
currentHeight: state.currentHeight,
204+
state
204205
}
205206
}
206207

react-spaces/src/Globals/Types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ export interface IPrivateProps {
7171
anchorSize?: string | number,
7272
anchor?: AnchorType,
7373
resizable?: boolean,
74-
order?: number
74+
order?: number,
75+
topMost?: boolean
7576
}
7677

7778
export const privateProps = {
7879
anchorSize: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
7980
anchor: PropTypes.oneOf([ AnchorType.Bottom, AnchorType.Left, AnchorType.Right, AnchorType.Top ]),
8081
resizable: PropTypes.bool,
81-
order: PropTypes.number
82+
order: PropTypes.number,
83+
topMost: PropTypes.bool
8284
}
8385

8486
export interface IAnchoredProps {

react-spaces/src/Space.tsx

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ RightResizable.propTypes = {...publicProps, ...anchoredProps, ...resizableProps}
2626
export const Positioned : React.FC<IPublicProps & IResizableProps & IPositionedProps> = (props) => <SpaceInternal {...props} />
2727
RightResizable.propTypes = {...publicProps, ...resizableProps, ...positionedProps};
2828

29-
const SpaceInternal : React.FC<AllProps> = (props) => {
29+
export const SpaceInternal : React.FC<AllProps> = (props) => {
3030

3131
const divElementRef = React.useRef<HTMLDivElement>();
3232

@@ -38,7 +38,8 @@ const SpaceInternal : React.FC<AllProps> = (props) => {
3838
innerClasses,
3939
resizeHandle,
4040
currentWidth,
41-
currentHeight
41+
currentHeight,
42+
state
4243
} = useSpace(props, divElementRef);
4344

4445
let children = props.children;
@@ -53,25 +54,27 @@ const SpaceInternal : React.FC<AllProps> = (props) => {
5354
<SpaceContext.Provider value={currentContext}>
5455
<SpaceInfoContext.Provider value={{ width: Math.floor(currentWidth), height: Math.floor(currentHeight) }}>
5556
{
56-
React.createElement(
57-
props.as || 'div',
58-
{
59-
id: props.id,
60-
ref: divElementRef,
61-
className: outerClasses.join(' '),
62-
style: outerStyle,
63-
onClick: props.onClick,
64-
onMouseDown: props.onMouseDown,
65-
onMouseEnter: props.onMouseEnter,
66-
onMouseLeave: props.onMouseLeave
67-
},
68-
<>
69-
{ resizeHandle }
70-
<div className={innerClasses.join(' ')} style={innerStyle}>
71-
{ children }
72-
</div>
73-
</>
74-
)
57+
props.topMost ?
58+
children :
59+
React.createElement(
60+
props.as || 'div',
61+
{
62+
id: state.id,
63+
ref: divElementRef,
64+
className: outerClasses.join(' '),
65+
style: outerStyle,
66+
onClick: props.onClick,
67+
onMouseDown: props.onMouseDown,
68+
onMouseEnter: props.onMouseEnter,
69+
onMouseLeave: props.onMouseLeave
70+
},
71+
<>
72+
{ resizeHandle }
73+
<div className={innerClasses.join(' ')} style={innerStyle}>
74+
{ children }
75+
</div>
76+
</>
77+
)
7578
}
7679
</SpaceInfoContext.Provider>
7780
</SpaceContext.Provider>

react-spaces/src/ViewPort.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
2-
import * as Spaces from './Space';
32
import './Styles.css';
43
import * as PropTypes from "prop-types";
4+
import { SpaceInternal } from './Space';
55

66
interface IProps {
77
className?: string,
@@ -20,10 +20,9 @@ export const ViewPort : React.FC<IProps> = (props) => (
2020
right: props.right || 0,
2121
bottom: props.bottom || 0
2222
}}>
23-
24-
<Spaces.Fill>
23+
<SpaceInternal topMost={true}>
2524
{props.children}
26-
</Spaces.Fill>
25+
</SpaceInternal>
2726
</div>
2827
)
2928

react-spaces/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@ export * from './Centered';
22
export * from './ClearFix';
33
export * from './Fixed';
44
export * from './ViewPort';
5-
export * from './Space';
65
export * from './Layer';
76
export * from './SpaceInfo';
7+
export {
8+
Fill,
9+
Left,
10+
Right,
11+
Top,
12+
Bottom,
13+
LeftResizable,
14+
RightResizable,
15+
TopResizable,
16+
BottomResizable,
17+
Positioned
18+
} from './Space';
819

920
export {
1021
useParentSpace

0 commit comments

Comments
 (0)