diff --git a/lib/extract/extractGradient.js b/lib/extract/extractGradient.js index eebf7ba5..6994aad5 100644 --- a/lib/extract/extractGradient.js +++ b/lib/extract/extractGradient.js @@ -9,7 +9,10 @@ import units from "../units"; const percentReg = /^([+\-]?\d+(?:\.\d+)?(?:[eE][+\-]?\d+)?)(%?)$/; function percentToFloat(percent) { - const matched = percent.toString().match(percentReg); + if (typeof percent === 'number') { + return percent; + } + const matched = percent.match(percentReg); if (!matched) { console.warn( `\`${percent}\` is not a valid number or percentage string.`, @@ -26,15 +29,18 @@ export default function(props) { } const stops = {}; - Children.forEach(props.children, child => { - if (child.props.stopColor && child.props.offset) { - // convert percent to float. - const offset = percentToFloat(child.props.offset); - - // add stop + Children.forEach(props.children, ({ + props: { + offset, + stopColor, + stopOpacity, + } + }) => { + offset = percentToFloat(offset); + if (stopColor && !isNaN(offset)) { //noinspection JSUnresolvedFunction - stops[offset] = Color(child.props.stopColor).alpha( - extractOpacity(child.props.stopOpacity), + stops[offset] = Color(stopColor).alpha( + extractOpacity(stopOpacity), ); } });