Skip to content

Commit 54d2a4b

Browse files
committed
docs(readme): further flesh out custom resize handles
1 parent 0bc58e6 commit 54d2a4b

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ This requires no special treatment.
147147
148148
##### Custom React Component
149149
150-
You must [forward the ref](https://reactjs.org/docs/forwarding-refs.html) to the underlying DOM element.
150+
You must [forward the ref](https://reactjs.org/docs/forwarding-refs.html) and props to the underlying DOM element.
151151
152152
###### Class Components
153153
154154
```js
155155
class MyHandleComponent extends React.Component {
156156
render() {
157-
return <div ref={this.props.innerRef} className="foo" />
157+
return <div ref={this.props.innerRef} className="foo" {...this.props} />
158158
}
159159
}
160160
const MyHandle = React.forwardRef((props, ref) => <MyHandleComponent innerRef={ref} {...props} />);
@@ -166,7 +166,7 @@ const MyHandle = React.forwardRef((props, ref) => <MyHandleComponent innerRef={r
166166
167167
```js
168168
const MyHandle = React.forwardRef((props, ref) => {
169-
return <div ref={ref} className="foo" />;
169+
return <div ref={ref} className="foo" {...props} />;
170170
});
171171

172172
<Resizable handle={<MyHandle />} />
@@ -178,7 +178,7 @@ You can define a function as a handle, which will simply receive props and ref.
178178
179179
```js
180180
const MyHandle = (props) => {
181-
return <div ref={props.innerRef} className="foo" />;
181+
return <div ref={props.innerRef} className="foo" {...props} />;
182182
};
183183

184184
<Resizable handle={(props, ref) => <MyHandle innerRef={ref} {...props} />} />

examples/ExampleLayout.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import ResizableBox from '../lib/ResizableBox';
44
import 'style-loader!css-loader!../css/styles.css';
55
import 'style-loader!css-loader!./example.css';
66

7+
const CustomResizeHandle = React.forwardRef((props, ref) => {
8+
return (
9+
<div
10+
className="custom-handle custom-handle-se custom-resize-handle-component"
11+
ref={ref}
12+
{...props}
13+
></div>
14+
)
15+
})
16+
717
export default class ExampleLayout extends React.Component<{}, {width: number, height: number}> {
818
state = {
919
width: 200,
@@ -77,7 +87,15 @@ export default class ExampleLayout extends React.Component<{}, {width: number, h
7787
className="custom-box box"
7888
width={200}
7989
height={200}
80-
handle={(h, ref) => <span className={`custom-handle custom-handle-${h}`} />}
90+
handle={<CustomResizeHandle />}
91+
handleSize={[8, 8]}>
92+
<span className="text">{"<ResizableBox> with a custom resize handle component."}</span>
93+
</ResizableBox>
94+
<ResizableBox
95+
className="custom-box box"
96+
width={200}
97+
height={200}
98+
handle={(h, ref) => <span className={`custom-handle custom-handle-${h}`} ref={ref} />}
8199
handleSize={[8, 8]}
82100
resizeHandles={['sw', 'se', 'nw', 'ne', 'w', 'e', 'n', 's']}>
83101
<span className="text">{"<ResizableBox> with custom handles in all locations."}</span>

examples/example.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,7 @@
112112
}
113113
.custom-handle-s {
114114
bottom: -4px;
115+
}
116+
.custom-resize-handle-component {
117+
background-color: red;
115118
}

0 commit comments

Comments
 (0)