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port _ from 'lodash';\n\nlet linkClass;\n\n/**\n * @param {ReactElement} element\n * @param {Object} styles CSS modules class map.\n * @param {CSSModules~Options} userConfiguration\n * @return {ReactElement}\n */\nlinkClass = (element, styles = {}, userConfiguration) => {\n let appendClassName,\n clonedElement,\n configuration,\n newChildren,\n newProps,\n styleNames;\n\n // @see https://github.com/gajus/react-css-modules/pull/30\n if (!element) {\n return element;\n }\n\n configuration = makeConfiguration(userConfiguration);\n\n styleNames = element.props.styleName;\n\n if (styleNames) {\n styleNames = styleNames.split(' ');\n styleNames = _.filter(styleNames);\n\n if (configuration.allowMultiple === false && styleNames.length > 1) {\n throw new Error(`ReactElement styleName property defines multiple module names (\"${element.props.styleName}\").`);\n }\n\n appendClassName = styleNames.map((styleName) => {\n if (styles[styleName]) {\n return styles[styleName];\n } else {\n if (configuration.errorWhenNotFound === true) {\n throw new Error(`\"${styleName}\" CSS module is undefined.`);\n }\n\n return '';\n }\n });\n\n appendClassName = appendClassName.filter((className) => {\n return className.length;\n });\n\n appendClassName = appendClassName.join(' ');\n }\n\n // element.props.children can be one of the following:\n // 'text'\n // ['text']\n // [ReactElement, 'text']\n // ReactElement\n\n // console.log(`element.props.children`, element.props.children, `React.Children.count(element.props.children)`, React.Children.count(element.props.children));\n\n if (React.isValidElement(element.props.children)) {\n newChildren = linkClass(React.Children.only(element.props.children), styles, configuration);\n } else if (_.isArray(element.props.children)) {\n newChildren = React.Children.map(element.props.children, (node) => {\n if (React.isValidElement(node)) {\n return linkClass(node, styles, configuration);\n } else {\n return node;\n }\n });\n\n // https://github.com/facebook/react/issues/4723#issuecomment-135555277\n // Forcing children into an array produces the following error:\n // Warning: A ReactFragment is an opaque type. Accessing any of its properties is deprecated. Pass it to one of the React.Children helpers.\n // newChildren = _.values(newChildren);\n }\n\n if (appendClassName) {\n if (element.props.className) {\n appendClassName = `${element.props.className} ${appendClassName}`;\n }\n\n newProps = {\n className: appendClassName\n };\n }\n\n if (newChildren) {\n clonedElement = React.cloneElement(element, newProps, newChildren);\n } else {\n clonedElement = React.cloneElement(element, newProps);\n }\n\n return clonedElement;\n};\n\nexport default linkClass;\n"],"sourceRoot":"/source/"}
\No newline at end of file