refactor(Icon): simplify return value

This commit is contained in:
EnixCoda 2019-12-26 16:40:35 +08:00
parent 929dc0f1b5
commit e33f270f1a
No known key found for this signature in database
GPG key ID: FE06F5DFC1C9B8E4

View file

@ -125,16 +125,19 @@ type Props = {
}
export function Icon({ type, className = undefined, placeholder, ...otherProps }: Props) {
if (placeholder) return <div className={cx('octicon-wrapper')} />
const { name, IconComponent } = getSVGIconComponent(type)
const mergedClassName = cx('octicon', name)
let children: React.ReactNode = null
if (!placeholder) {
const { name, IconComponent } = getSVGIconComponent(type)
const mergedClassName = cx('octicon', name)
children = React.createElement(Octicon, {
icon: IconComponent,
className: mergedClassName,
verticalAlign: 'text-bottom',
})
}
return (
<div className={cx('octicon-wrapper', className)} {...otherProps}>
{React.createElement(Octicon, {
icon: IconComponent,
className: mergedClassName,
verticalAlign: 'text-bottom',
})}
{children}
</div>
)
}