import React from 'react' ; import PropTypes from 'prop-types' ; import { LGGlyph } from './types' ; import { Size } from './glyphCommon' ; export interface IconProps extends Omit < LGGlyph . ComponentProps , 'size' > { glyph : string ; size ? : Size | number ; } type GlyphObject = Record < string , LGGlyph . Component > ; export default function createIconComponent < G extends GlyphObject = GlyphObject > ( glyphs ) { const Icon = ( { glyph , ... rest } ) => { const SVGComponent = glyphs [ glyph ] ; return < SVGComponent { ... rest } / > ; } ; Icon . displayName = 'Icon' ; Icon . propTypes = { glyph : PropTypes . oneOf ( Object . keys ( glyphs ) ) . isRequired , size : PropTypes . oneOfType ( [ PropTypes . oneOf ( Object . values ( Size ) ) , PropTypes . number , ] ) , } as any ; return Icon ; }