Skip to content

Commit c72a9e2

Browse files
authored
Merge pull request #143 from sagar-accacia/fix/component-styling-issue
FIX: #142
2 parents 3d07b3e + 550587e commit c72a9e2

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

nextjs-demo/pages/index.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Head from "next/head";
2+
import { useState } from "react";
23
import * as Space from "react-spaces";
34

45
export default function Home() {
6+
const [lsize, setLSize] = useState("10%"); // To check for the hover effect
57
return (
68
<>
79
<Space.SSR />
@@ -12,7 +14,12 @@ export default function Home() {
1214
<link rel="icon" href="/favicon.ico" />
1315
</Head>
1416
<Space.ViewPort>
15-
<Space.LeftResizable size="25%" centerContent={Space.CenterType.HorizontalVertical} style={{ backgroundColor: "white" }}>
17+
<Space.LeftResizable
18+
size={lsize}
19+
onMouseEnter={() => setLSize("25%")}
20+
onMouseLeave={() => setLSize("10%")}
21+
centerContent={Space.CenterType.HorizontalVertical}
22+
style={{ backgroundColor: "white", transition: "all 0.3s ease-in-out" }}>
1623
<span style={{ color: "black" }}>Hello world</span>
1724
</Space.LeftResizable>
1825
<Space.RightResizable size="25%" centerContent={Space.CenterType.HorizontalVertical} style={{ backgroundColor: "white" }}>

src/components/Space.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const SpaceInner: React.FC<IReactSpaceInnerProps & { wrapperInstance: Space }> =
4242
}
4343

4444
const {
45-
style,
45+
innerComponentStyle,
4646
className,
4747
onClick,
4848
onDoubleClick,
@@ -55,6 +55,7 @@ const SpaceInner: React.FC<IReactSpaceInnerProps & { wrapperInstance: Space }> =
5555
onTouchEnd,
5656
children,
5757
handleRender,
58+
style,
5859
} = props;
5960

6061
const events = {
@@ -103,10 +104,10 @@ const SpaceInner: React.FC<IReactSpaceInnerProps & { wrapperInstance: Space }> =
103104

104105
const innerClasses = [...["spaces-space-inner"], ...userClasses];
105106

106-
let innerStyle = style;
107+
let innerStyle = innerComponentStyle;
107108
if (space.handlePlacement === ResizeHandlePlacement.Inside) {
108109
innerStyle = {
109-
...style,
110+
...innerStyle,
110111
...{
111112
left: space.anchor === AnchorType.Right ? space.handleSize : undefined,
112113
right: space.anchor === AnchorType.Left ? space.handleSize : undefined,
@@ -125,6 +126,7 @@ const SpaceInner: React.FC<IReactSpaceInnerProps & { wrapperInstance: Space }> =
125126
className: outerClasses.join(" "),
126127
},
127128
...events,
129+
style,
128130
} as any;
129131

130132
return (

src/core-react.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ export interface IReactEvents {
9797
}
9898

9999
export interface IReactSpaceCommonProps extends ICommonProps, IReactEvents {
100-
style?: React.CSSProperties;
100+
innerComponentStyle?: React.CSSProperties; // For people who like to modify the inner `as` component
101101
as?: keyof React.ReactDOM | React.ComponentType<ICommonProps>;
102102
children?: React.ReactNode;
103+
style?: React.CSSProperties; // Normal styles for the wrapper itself as it is the main component that is resized
103104
}
104105

105106
export interface IReactSpaceInnerProps extends IReactSpaceCommonProps, ISpaceProps, IReactEvents {

0 commit comments

Comments
 (0)