Skip to content

Commit e2f94c9

Browse files
author
Federico Zivolo
committed
v2.4.0
- Added makeResizeAware decorator
1 parent d22076f commit e2f94c9

File tree

6 files changed

+64
-11
lines changed

6 files changed

+64
-11
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class MyComponent extend Component {
8080
}
8181
}
8282
```
83+
8384
## Self containing
8485

8586
If you need to keep your DOM structure clean and you don't want the additional
@@ -109,6 +110,43 @@ function App() {
109110
}
110111
```
111112

113+
## Decorator/enhancer
114+
115+
In case you prefer to directly decorate your component to add to it the ResizeAware
116+
functionalities, you can do as follow:
117+
118+
```
119+
import React from 'react';
120+
import { makeResizeAware } from 'react-resize-aware';
121+
122+
export default makeResizeAware(function MyComponent({width, height, getRef, children})) {
123+
return (
124+
<div ref={getRef} style={{ position: 'relative' }}>
125+
<span>{width}x{height}</span>
126+
{children}
127+
</div>
128+
);
129+
})
130+
```
131+
132+
Or, with ES7 decorators:
133+
134+
```
135+
import React from 'react';
136+
import { makeResizeAware } from 'react-resize-aware';
137+
138+
@makeResizeAware
139+
export default function MyComponent({width, height, getRef, children})) {
140+
return (
141+
<div ref={getRef} style={{ position: 'relative' }}>
142+
<span>{width}x{height}</span>
143+
{children}
144+
</div>
145+
);
146+
}
147+
```
148+
149+
112150
## Properties
113151

114152
- The `onlyEvent` property will prevent ResizeAware from passing the `height` and `width`

docs/example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function MyComponent(_ref) {
4949
}
5050

5151
function App() {
52-
return React.createElement(ReactResizeAware, {
52+
return React.createElement(ReactResizeAware.default, {
5353
component: MyComponent,
5454
useBoundingClientRect: true,
5555
style: {position: 'relative'},

docs/react-resize-aware.js

Lines changed: 17 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-resize-aware",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"description": "A resize aware component used to detect sizes changes on your components",
55
"main": "dist/index.js",
66
"scripts": {

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default {
66
moduleName: 'ReactResizeAware',
77
format: 'umd',
88
sourceMap: true,
9+
exports: 'named',
910
external: ['react'],
1011
globals: {
1112
react: 'React',

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export default class ResizeAware extends Component {
6868
component,
6969
{
7070
[hasCustomComponent ? 'getRef' : 'ref']: el => (this.container = el),
71-
...this.state,
71+
width,
72+
height,
7273
...props,
7374
},
7475
createElement('object', {
@@ -81,3 +82,7 @@ export default class ResizeAware extends Component {
8182
);
8283
}
8384
}
85+
86+
export function makeResizeAware(component) {
87+
return props => React.createElement(ReactResizeAware, {component, ...props});
88+
}

0 commit comments

Comments
 (0)