Skip to content

Commit

Permalink
feat(Icon): adds render prop.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Firsov committed Jul 18, 2019
1 parent 28aa59e commit 6aa7a87
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
24 changes: 20 additions & 4 deletions src/components/Icon/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,45 @@ export type IconProps = {
title?: string,
/** possible types of the css cursor property */
cursor?: 'pointer' | 'default' | 'auto',
//** allow pass props to an Icon */
children?: (Glyph: React$Component<Object, null>) => React$Node,
};

const Icon = ({ name, className, ...rest }: IconProps) => {

const Icon = ({ name, className, children, title, ...rest }: IconProps) => {
return (
<IconsConsumer>
{ ({ icons = {}}) => {
const Glyph: any = icons[name] || glyphs[name];

if (typeof children === 'function') {
return (
<IconWrapperTag tagName="span" { ...rest }>
<IconSvgTag
tagName="i"
title={ title }
modifiers={ rest }
className={ className }
>
{ children(Glyph) }
</IconSvgTag>
</IconWrapperTag>
);
}

return (
<IconWrapperTag tagName="span" { ...rest }>
<Choose>
<When condition={ !!className && !Glyph }>
<IconFontTag
tagName="i"
title={ rest.title }
title={ title }
modifiers={ rest }
/>
</When>
<When condition={ !!Glyph }>
<IconSvgTag
tagName="i"
title={ rest.title }
title={ title }
modifiers={ rest }
className={ className }
>
Expand Down
5 changes: 0 additions & 5 deletions src/components/Icon/__snapshots__/Icon.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,21 @@ exports[`<Icon /> should shallow input 1`] = `
color="DANGER"
size="md"
tagName="span"
title="Alert icon"
>
<Tag
className="emotion-0 emotion-1"
color="DANGER"
size="md"
tagName="span"
title="Alert icon"
>
<span
className="emotion-0 emotion-1"
title="Alert icon"
>
<Boost(iconSvg)
modifiers={
Object {
"color": "DANGER",
"size": "md",
"title": "Alert icon",
}
}
tagName="i"
Expand All @@ -41,7 +37,6 @@ exports[`<Icon /> should shallow input 1`] = `
Object {
"color": "DANGER",
"size": "md",
"title": "Alert icon",
}
}
tagName="i"
Expand Down
5 changes: 1 addition & 4 deletions src/components/Icon/glyphs/EditPencil.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6aa7a87

Please sign in to comment.