Skip to content
This repository was archived by the owner on Sep 10, 2023. It is now read-only.

Commit fa87740

Browse files
author
Joe Ipson
committed
Updated to allow having multiple styles attached to a child
1 parent 6507f7e commit fa87740

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,18 @@ class AutoResponsive extends React.Component {
5454

5555
renderChildren() {
5656
return React.Children.map(this.props.children, function(child, childIndex) {
57+
let childStyle = {};
58+
59+
if(child.props.style instanceof Array) {
60+
child.props.style.forEach((style) => {
61+
childStyle = Util.extend(childStyle, style);
62+
});
63+
} else {
64+
childStyle = child.props.style;
65+
}
5766

58-
let childWidth = parseInt(child.props.style.width) + this.props.itemMargin;
59-
let childHeight = parseInt(child.props.style.height) + this.props.itemMargin;
67+
let childWidth = parseInt(childStyle.width) + this.props.itemMargin;
68+
let childHeight = parseInt(childStyle.height) + this.props.itemMargin;
6069
let calculatedPosition = this.sortManager.getPosition(childWidth, childHeight, this.containerStyle.height);
6170

6271
if (!this.fixedContainerHeight) {
@@ -80,7 +89,7 @@ class AutoResponsive extends React.Component {
8089
}
8190

8291
return React.cloneElement(child, {
83-
style: Util.extend({}, child.props.style, calculatedStyle)
92+
style: Util.extend({}, childStyle, calculatedStyle)
8493
});
8594
}, this);
8695
}

0 commit comments

Comments
 (0)