Skip to content

Commit 73c7254

Browse files
author
Federico Zivolo
committed
v2.4.1
- Allow multiple children
1 parent daea3c0 commit 73c7254

File tree

6 files changed

+67
-11
lines changed

6 files changed

+67
-11
lines changed

docs/example.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ function MyComponent(_ref) {
5151
function App() {
5252
return React.createElement(ReactResizeAware.default, {
5353
component: MyComponent,
54-
useBoundingClientRect: true,
5554
style: {position: 'relative'},
5655
onResize: function onResize(sizes) {
5756
return console.log(sizes);

docs/react-resize-aware.js

Lines changed: 4 additions & 3 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.4.0",
3+
"version": "2.4.1",
44
"description": "A resize aware component used to detect sizes changes on your components",
55
"main": "dist/index.js",
66
"scripts": {

src/__snapshots__/index.spec.jsx.snap

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,48 @@ exports[`allows to define an \`onResize\` property 1`] = `
6767
</ResizeAware>
6868
`;
6969

70+
exports[`allows to use its child as target 1`] = `
71+
<ResizeAware
72+
component="div"
73+
style={
74+
Object {
75+
"position": "relative",
76+
}
77+
}
78+
>
79+
<div
80+
style={
81+
Object {
82+
"position": "relative",
83+
}
84+
}
85+
>
86+
<object
87+
onLoad={[Function]}
88+
style={
89+
Object {
90+
"display": "block",
91+
"height": "100%",
92+
"left": 0,
93+
"overflow": "hidden",
94+
"pointerEvents": "none",
95+
"position": "absolute",
96+
"top": 0,
97+
"width": "100%",
98+
"zIndex": -1,
99+
}
100+
}
101+
type="text/html"
102+
/>
103+
<DummyComponent>
104+
<div>
105+
x
106+
</div>
107+
</DummyComponent>
108+
</div>
109+
</ResizeAware>
110+
`;
111+
70112
exports[`allows to use its children as target 1`] = `
71113
<ResizeAware
72114
component="div"

src/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright 2016, Federico Zivolo
77
//
88

9-
import {createElement, Component, cloneElement} from 'react';
9+
import {createElement, Component, Children, cloneElement} from 'react';
1010

1111
const style = {
1212
display: 'block',
@@ -62,14 +62,13 @@ export default class ResizeAware extends Component {
6262
const {width, height} = this.state;
6363

6464
const hasCustomComponent = typeof component !== 'string';
65-
const passSizeProps = !onlyEvent && hasCustomComponent;
6665

6766
return createElement(
6867
component,
6968
{
7069
[hasCustomComponent ? 'getRef' : 'ref']: el => (this.container = el),
71-
width,
72-
height,
70+
width: hasCustomComponent ? width : undefined,
71+
height: hasCustomComponent ? height : undefined,
7372
...props,
7473
},
7574
createElement('object', {
@@ -78,7 +77,9 @@ export default class ResizeAware extends Component {
7877
ref: el => (this.resizeElement = el),
7978
onLoad: this.handleObjectLoad,
8079
}),
81-
!!children && cloneElement(children, passSizeProps ? this.state : null)
80+
Children.map(children, child =>
81+
cloneElement(child, !onlyEvent ? this.state : null)
82+
)
8283
);
8384
}
8485
}

src/index.spec.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function DummyComponent2({getRef, ...props}) {
1111
return <div ref={getRef} {...props} />;
1212
}
1313

14-
it('allows to use its children as target', () => {
14+
it('allows to use its child as target', () => {
1515
const wrapper = mount(
1616
<ResizeAware style={{position: 'relative'}}>
1717
<DummyComponent />
@@ -21,6 +21,19 @@ it('allows to use its children as target', () => {
2121
expect(toJson(wrapper)).toMatchSnapshot();
2222
});
2323

24+
it('allows to use itself between a component markup', () => {
25+
const wrapper = mount(
26+
<div>
27+
<ResizeAware style={{position: 'relative'}}>
28+
<div />
29+
<div />
30+
</ResizeAware>
31+
</div>
32+
);
33+
34+
expect(toJson(wrapper)).toMatchSnapshot();
35+
});
36+
2437
it('allows to define an `onResize` property', () => {
2538
const handleResize = jest.fn();
2639
const wrapper = mount(

0 commit comments

Comments
 (0)