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G,GAAG,GAAG,eAAe,CAAC;SACrE;;AAED,gBAAQ,GAAG;AACP,qBAAS,EAAE,eAAe;AAC1B,qBAAS,EAAE,IAAI;SAClB,CAAC;KACL;;AAED,QAAI,WAAW,EAAE;AACb,qBAAa,GAAG,gBAAM,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;KACtE,MAAM;AACH,qBAAa,GAAG,gBAAM,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;KACzD;;AAED,WAAO,aAAa,CAAC;CACxB,CAAC;;kBAEa,SAAS","file":"linkClass.js","sourcesContent":["import React from 'react';\nimport makeConfiguration from './makeConfiguration';\nimport isIterable from './isIterable';\nimport _ from 'lodash';\n\nlet generateAppendClassName,\n linkClass,\n parseStyleName;\n\nparseStyleName = (styleNamePropertyValue: string, allowMultiple: boolean): Array<string> => {\n let styleNames;\n\n styleNames = styleNamePropertyValue.split(' ');\n styleNames = _.filter(styleNames);\n\n if (allowMultiple === false && styleNames.length > 1) {\n throw new Error('ReactElement styleName property defines multiple module names (\"' + styleNamePropertyValue + '\").');\n }\n\n return styleNames;\n};\n\ngenerateAppendClassName = (styles, styleNames: Array<string>, errorWhenNotFound: boolean): string => {\n let appendClassName;\n\n appendClassName = '';\n\n appendClassName = _.map(styleNames, (styleName) => {\n if (styles[styleName]) {\n return styles[styleName];\n } else {\n if (errorWhenNotFound === true) {\n throw new Error('\"' + styleName + '\" CSS module is undefined.');\n }\n\n return '';\n }\n });\n\n appendClassName = _.filter(appendClassName, 'length');\n\n appendClassName = appendClassName.join(' ');\n\n return appendClassName;\n};\n\n/**\n * @param {ReactElement} element\n * @param {Object} styles CSS modules class map.\n * @param {CSSModules~Options} userConfiguration\n * @returns {ReactElement}\n */\nlinkClass = (element, styles = {}, userConfiguration) => {\n let appendClassName,\n children,\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 = parseStyleName(element.props.styleName || '', configuration.allowMultiple);\n\n if (styleNames.length) {\n appendClassName = generateAppendClassName(styles, styleNames, configuration.errorWhenNotFound);\n }\n\n // element.props.children can be one of the following:\n // 'text'\n // ['text']\n // [ReactElement, 'text']\n // ReactElement\n\n children = element.props.children;\n\n if (React.isValidElement(children)) {\n newChildren = linkClass(React.Children.only(children), styles, configuration);\n } else if (_.isArray(children) || isIterable(children)) {\n /* eslint-disable lodash3/prefer-lodash-method */\n newChildren = React.Children.map(children, (node) => {\n /* eslint-enable lodash3/prefer-lodash-method */\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 styleName: null\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