From dbd608b1bd07baa3a5e1a950b2d002da56904cad Mon Sep 17 00:00:00 2001 From: Enix Date: Fri, 1 Nov 2019 14:44:36 +0800 Subject: [PATCH] fix: octicon names was lost in production mode --- src/components/Icon.tsx | 85 ++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 18 deletions(-) diff --git a/src/components/Icon.tsx b/src/components/Icon.tsx index 438900b..a128ed5 100644 --- a/src/components/Icon.tsx +++ b/src/components/Icon.tsx @@ -8,6 +8,7 @@ import Octicon, { FileZip, Gear, Grabber, + Icon as OcticonIcon, Markdown, Octoface, Reply, @@ -17,37 +18,78 @@ import Octicon, { import * as React from 'react' import cx from 'utils/cx' -function getSVGIconComponent(type: string) { +function getSVGIconComponent( + type: string, +): { + IconComponent: OcticonIcon + name: string +} { switch (type) { case 'submodule': - return Submodule + return { + IconComponent: Submodule, + name: 'Submodule', + } case 'grabber': - return Grabber + return { + IconComponent: Grabber, + name: 'Grabber', + } case 'octoface': - return Octoface + return { + IconComponent: Octoface, + name: 'Octoface', + } case 'chevron-down': - return ChevronDown + return { + IconComponent: ChevronDown, + name: 'ChevronDown', + } case 'x': - return X + return { + IconComponent: X, + name: 'X', + } case 'gear': - return Gear + return { + IconComponent: Gear, + name: 'Gear', + } case 'folder': - return TriangleRight + return { + IconComponent: TriangleRight, + name: 'TriangleRight', + } case 'go-to': - return Reply + return { + IconComponent: Reply, + name: 'Reply', + } case '.pdf': - return FilePdf + return { + IconComponent: FilePdf, + name: 'FilePdf', + } case '.zip': case '.rar': case '.7z': - return FileZip + return { + IconComponent: FileZip, + name: 'FileZip', + } case '.md': - return Markdown + return { + IconComponent: Markdown, + name: 'Markdown', + } case '.png': case '.jpg': case '.gif': case '.bmp': - return FileMedia + return { + IconComponent: FileMedia, + name: 'FileMedia', + } case '.js': case '.jsx': case '.ts': @@ -58,14 +100,20 @@ function getSVGIconComponent(type: string) { case '.less': case '.scss': case '.sass': - return FileCode + return { + IconComponent: FileCode, + name: 'FileCode', + } // TODO: adapt to more file types // case '': return FileBinary // case '': return FileSubmodule // case '': return FileSymlinkDirectory // case '': return FileSymlinkFile default: - return File + return { + IconComponent: File, + name: 'File', + } } } @@ -76,12 +124,13 @@ type Props = { } const Icon: React.SFC = function Icon({ type, className = undefined, ...otherProps }) { - const icon = getSVGIconComponent(type) + const { name, IconComponent } = getSVGIconComponent(type) + const mergedClassName = cx('octicon', name) return (
{React.createElement(Octicon, { - icon, - className: cx('octicon', icon.name), + icon: IconComponent, + className: mergedClassName, })}
)