Skip to content

Commit d1392e3

Browse files
committed
WIP to allow percentage sizes to be specified on anchored spaces
1 parent d3f51b6 commit d1392e3

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

demo/src/App.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ pre {
9494
display: none;
9595
}
9696

97+
.all-content {
98+
top: 0px !important;
99+
}
100+
97101
.main {
98102
position: fixed;
99103
left: inherit !important;

demo/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const App: React.FC = () => {
146146
</SyntaxHighlighter>
147147

148148
<Space.Fixed height={400}>
149-
<Space.Left size={100} style={{ backgroundColor: '#e0eae0' }}>
149+
<Space.Left size={200} style={{ backgroundColor: '#e0eae0' }}>
150150
{Description("Left")}
151151
</Space.Left>
152152
<Space.Fill style={{ backgroundColor: '#eee0e0' }}>

demo/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9184,7 +9184,7 @@ react-slick@~0.24.0:
91849184
resize-observer-polyfill "^1.5.0"
91859185

91869186
"react-spaces@file:../react-spaces":
9187-
version "0.1.2"
9187+
version "0.1.3"
91889188
dependencies:
91899189
css-element-queries "^1.2.1"
91909190
guid-typescript "^1.0.9"

react-spaces/src/components/Space.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface IPrivateProps {
2020
}
2121

2222
interface IAnchoredProps {
23-
size?: number,
23+
size?: number | string,
2424
order?: number
2525
}
2626

@@ -36,12 +36,13 @@ interface IState {
3636
adjustedSize: number,
3737
spaceTakers: ISpaceTaker[],
3838

39+
parsedSize?: number;
3940
left?: number;
4041
top?: number;
4142
right?: number;
4243
bottom?: number;
43-
width?: number;
44-
height?: number;
44+
width?: number | string;
45+
height?: number | string;
4546
}
4647

4748
export const Fill : React.FC<IPublicProps> = (props) => <Space {...props} />
@@ -78,6 +79,7 @@ class Space extends React.Component<AllProps, IState> {
7879
adjustedSize: 0,
7980
spaceTakers: [],
8081

82+
parsedSize: typeof props.size === "string" ? 0 : props.size as number | undefined,
8183
left: props.anchor !== AnchorType.Right ? 0 : undefined,
8284
top: props.anchor !== AnchorType.Bottom ? 0 : undefined,
8385
right: props.anchor !== AnchorType.Left ? 0 : undefined,
@@ -95,8 +97,9 @@ class Space extends React.Component<AllProps, IState> {
9597

9698
const currentRect = this.divElementRef.current.getBoundingClientRect();
9799
this.setState({
98-
currentWidth: parseInt(currentRect.width.toFixed(), 10),
99-
currentHeight: parseInt(currentRect.height.toFixed(), 10)
100+
parsedSize: !this.state.parsedSize ? currentRect.width : this.state.parsedSize,
101+
currentWidth: currentRect.width,
102+
currentHeight: currentRect.height
100103
});
101104
}
102105
}
@@ -124,8 +127,8 @@ class Space extends React.Component<AllProps, IState> {
124127
top: this.state.top,
125128
right: this.state.right,
126129
bottom: this.state.bottom,
127-
width: this.isHorizontalSpace() && this.state.adjustedSize !== 0 ? (this.state.width || 0) + this.state.adjustedSize : this.state.width,
128-
height: this.isVerticalSpace() && this.state.adjustedSize !== 0 ? (this.state.height || 0) + this.state.adjustedSize : this.state.height
130+
width: this.isHorizontalSpace() ? (this.state.parsedSize || 0) + this.state.adjustedSize : undefined,
131+
height: this.isVerticalSpace() ? (this.state.parsedSize || 0) + this.state.adjustedSize : undefined
129132
};
130133

131134
if (parentContext) {
@@ -182,7 +185,7 @@ class Space extends React.Component<AllProps, IState> {
182185
id: this.state.id,
183186
order: this.props.order || 1,
184187
anchorType: this.props.anchor,
185-
size: this.props.size || (this.isVerticalSpace() ? this.state.currentHeight : this.state.currentWidth),
188+
size: (this.state.parsedSize || 0),
186189
adjustedSize: 0
187190
});
188191
}
@@ -217,7 +220,7 @@ class Space extends React.Component<AllProps, IState> {
217220
<Resizable
218221
type={resizeType}
219222
minimumAdjust={ -(this.props.size || 0) + (this.props.minimumSize || 20) }
220-
maximumAdjust={ this.props.maximumSize ? (this.props.maximumSize - (this.props.size || 0)) : undefined}
223+
maximumAdjust={ this.props.maximumSize ? (this.props.maximumSize - (this.state.parsedSize || 0)) : undefined}
221224
onResize={(adjustedSize) => {
222225
this.setState(
223226
{ adjustedSize: adjustedSize },

0 commit comments

Comments
 (0)