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GAAG,EAAE,IAAI,EAAE,EAAE;YACpD,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YAClB,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QAEA,cAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACxD,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC;YACvC,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QAIA,uBAAa,GAAG,gBAAgB,CAAC;QACjC,uBAAa,GAAG,aAAa,CAAC;QAC9B,wBAAc,GAAG,cAAc,CAAC;QAChC,iBAAO,GAAG,OAAO,CAAC;QAW3B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,IAAI,GAAG,qBAAqB,EAAE,CAAC;IACrC,IAAI,CAAC,MAAM,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import React, { PureComponent } from 'react';\n\nimport createIconSet from './createIconSet';\n\ntype FontStyle = {\n fontFamily: string;\n fontFile: any;\n glyphMap: any;\n fontStyle: any;\n};\n\ntype FontStyles = {\n [key: string]: FontStyle;\n};\n\nexport default function createMultiStyleIconSet(\n styles: FontStyles,\n optionsInput = {}\n): any {\n const styleNames = Object.keys(styles);\n\n if (styleNames.length === 0) {\n throw new Error('You need to add at least one style');\n }\n\n const options = {\n defaultStyle: styleNames[0],\n fallbackFamily: (_unused: any) => styleNames[0],\n glyphValidator: (_unused: any, __unused: any) => true,\n ...optionsInput,\n };\n\n const iconSets = styleNames.reduce((acc, name) => {\n const style = styles[name];\n\n acc[name] = createIconSet(\n style.glyphMap || {},\n style.fontFamily || '',\n style.fontFile || '',\n style.fontStyle || {}\n );\n\n return acc;\n }, {});\n\n function styleFromProps(props) {\n return Object.keys(props).reduce(\n (result, propName) =>\n styleNames.indexOf(propName) !== -1 && props[propName] === true\n ? propName\n : result,\n options.defaultStyle\n );\n }\n\n function getIconSetForProps(props) {\n const { name } = props;\n const style = styleFromProps(props);\n\n if (options.glyphValidator(name, style)) return iconSets[style];\n\n const family = options.fallbackFamily(name);\n\n if (styleNames.indexOf(family) === -1) {\n return options.defaultStyle;\n }\n\n return iconSets[family];\n }\n\n function selectIconClass(iconSet, iconClass) {\n return iconClass.length > 0 ? iconSet[iconClass] : iconSet;\n }\n\n function reduceProps(props) {\n return Object.keys(props).reduce((acc, prop) => {\n if (styleNames.indexOf(prop) === -1) {\n acc[prop] = props[prop];\n }\n\n return acc;\n }, {});\n }\n\n function getStyledIconSet(style, name = '') {\n if (styleNames.indexOf(style) === -1) {\n return iconSets[options.defaultStyle];\n }\n\n return !name\n ? iconSets[styleFromProps({ [style]: true })]\n : getIconSetForProps({ name, [style]: true });\n }\n\n function getFontFamily(style = options.defaultStyle) {\n return getStyledIconSet(style).getFontFamily();\n }\n\n function getRawGlyphMap(style = options.defaultStyle) {\n return getStyledIconSet(style).getRawGlyphMap();\n }\n\n function hasIcon(name, style = options.defaultStyle) {\n return options.glyphValidator(name, style);\n }\n\n function createStyledIconClass(selectClass = '') {\n class IconClass extends PureComponent {\n static defaultProps = styleNames.reduce((acc, name) => {\n acc[name] = false;\n return acc;\n }, {});\n\n static font = Object.values(styles).reduce((acc, style) => {\n acc[style.fontFamily] = style.fontFile;\n return acc;\n }, {});\n\n static Button: any;\n\n static StyledIconSet = getStyledIconSet;\n static getFontFamily = getFontFamily;\n static getRawGlyphMap = getRawGlyphMap;\n static hasIcon = hasIcon;\n\n render() {\n const selectedIconSet = getIconSetForProps(this.props);\n const SelectedIconClass = selectIconClass(selectedIconSet, selectClass);\n const props = reduceProps(this.props);\n\n return React.createElement(SelectedIconClass, props);\n }\n }\n\n return IconClass;\n }\n\n const Icon = createStyledIconClass();\n Icon.Button = createStyledIconClass('Button');\n return Icon;\n}\n"]} |