carbon-components-react
Advanced tools
Comparing version 3.1.7 to 3.2.0
@@ -30,2 +30,27 @@ 'use strict'; | ||
/** | ||
* Adds striping to TableRows if the `even` prop wasn’t explicitly set. | ||
* @param {array} rows React elements that are children of the TableBody | ||
* @return {array} the updated child elements | ||
*/ | ||
var handleRowStriping = function handleRowStriping(rows) { | ||
var count = 0; | ||
return rows.map(function (child) { | ||
// Only make changes if it's a TableRow | ||
if (child.type.name === 'TableRow') { | ||
// manually increase the TableRow count | ||
count++; | ||
// Don’t override user-set `even` prop | ||
var even = 'even' in child.props ? child.props.even : count % 2 === 1; | ||
// Return a clone of the element with the `even` prop set. | ||
return _react2.default.cloneElement(child, { even: even }); | ||
} | ||
return child; | ||
}); | ||
}; | ||
var TableBody = function TableBody(props) { | ||
@@ -39,27 +64,4 @@ var children = props.children, | ||
var childArray = _react2.default.Children.toArray(children); | ||
var hasExpandedRows = childArray.some(function (child) { | ||
return child.type.name === 'TableRowExpanded'; | ||
}); | ||
var childrenWithProps = handleRowStriping(childArray); | ||
var childrenWithProps = hasExpandedRows ? childArray.map(function (child, index) { | ||
if (Math.floor(index / 2) % 2 === 0) { | ||
// eslint-disable-line | ||
return _react2.default.cloneElement(child, { | ||
even: true | ||
}); | ||
} | ||
return child; // eslint-disable-line | ||
}) // eslint-disable-line | ||
: childArray.map(function (child, index) { | ||
if (index % 2 === 0) { | ||
// eslint-disable-line | ||
return _react2.default.cloneElement(child, { | ||
even: true | ||
}); | ||
} | ||
return child; // eslint-disable-line | ||
}); // eslint-disable-line | ||
return _react2.default.createElement( | ||
@@ -66,0 +68,0 @@ 'tbody', |
@@ -14,2 +14,27 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
/** | ||
* Adds striping to TableRows if the `even` prop wasn’t explicitly set. | ||
* @param {array} rows React elements that are children of the TableBody | ||
* @return {array} the updated child elements | ||
*/ | ||
var handleRowStriping = function handleRowStriping(rows) { | ||
var count = 0; | ||
return rows.map(function (child) { | ||
// Only make changes if it's a TableRow | ||
if (child.type.name === 'TableRow') { | ||
// manually increase the TableRow count | ||
count++; | ||
// Don’t override user-set `even` prop | ||
var even = 'even' in child.props ? child.props.even : count % 2 === 1; | ||
// Return a clone of the element with the `even` prop set. | ||
return React.cloneElement(child, { even: even }); | ||
} | ||
return child; | ||
}); | ||
}; | ||
var TableBody = function TableBody(props) { | ||
@@ -23,27 +48,4 @@ var children = props.children, | ||
var childArray = React.Children.toArray(children); | ||
var hasExpandedRows = childArray.some(function (child) { | ||
return child.type.name === 'TableRowExpanded'; | ||
}); | ||
var childrenWithProps = handleRowStriping(childArray); | ||
var childrenWithProps = hasExpandedRows ? childArray.map(function (child, index) { | ||
if (Math.floor(index / 2) % 2 === 0) { | ||
// eslint-disable-line | ||
return React.cloneElement(child, { | ||
even: true | ||
}); | ||
} | ||
return child; // eslint-disable-line | ||
}) // eslint-disable-line | ||
: childArray.map(function (child, index) { | ||
if (index % 2 === 0) { | ||
// eslint-disable-line | ||
return React.cloneElement(child, { | ||
even: true | ||
}); | ||
} | ||
return child; // eslint-disable-line | ||
}); // eslint-disable-line | ||
return React.createElement( | ||
@@ -50,0 +52,0 @@ 'tbody', |
@@ -172,3 +172,3 @@ { | ||
}, | ||
"version": "3.1.7" | ||
"version": "3.2.0" | ||
} |
545897