From 91f2df7bb9363a147b353f761f004d526d2f59fd Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sat, 16 Nov 2019 16:29:53 +0100 Subject: [PATCH] selectively import icons for smaller js --- src/components/atoms/Icon.tsx | 51 ++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/components/atoms/Icon.tsx b/src/components/atoms/Icon.tsx index aa4d7ad1..3f133337 100644 --- a/src/components/atoms/Icon.tsx +++ b/src/components/atoms/Icon.tsx @@ -1,31 +1,56 @@ import React from 'react' // https://featherstyles.com -import * as Feather from 'react-feather' +// import * as Feather from 'react-feather' +import { + ArrowDownCircle, + Edit, + GitHub, + Twitter, + Rss, + Sun, + Moon, + Compass, + X, + Clipboard, + Search, + ExternalLink, + Link, + ChevronRight, + ChevronLeft +} from 'react-feather' // custom icons import { ReactComponent as Jsonfeed } from '../../images/jsonfeed.svg' import { ReactComponent as Bitcoin } from '../../images/bitcoin.svg' import styles from './Icon.module.scss' const components: any = { - Download: Feather.ArrowDownCircle, - Blog: Feather.Edit, - Keybase: Feather.Key, + Download: ArrowDownCircle, Jsonfeed, - Bitcoin + Bitcoin, + ArrowDownCircle, + Edit, + GitHub, + Twitter, + Rss, + Sun, + Moon, + Compass, + X, + Clipboard, + Search, + ExternalLink, + Link, + ChevronRight, + ChevronLeft } const Icon = ({ name }: { name: string }) => { const IconMapped = components[name] - const Icon = (Feather as any)[name] + // const IconFeather = (Feather as any)[name] + if (!IconMapped) return null - if (!IconMapped && !Icon) return null - - return IconMapped ? ( - - ) : ( - - ) + return } export default Icon