Skip to content

Commit

Permalink
Merge pull request #86 from supabase/feature/icon-svg-import
Browse files Browse the repository at this point in the history
feat: added new `src` prop, for inserting SVG files into `<Icon>`
  • Loading branch information
MildTomato authored Jan 18, 2021
2 parents 6007315 + e11e0a4 commit 1d47dc0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/components/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,23 @@ IconList.args = {
size: 16,
strokeWidth: 2,
}

const SvgMessagesIcon = () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"
/>
</svg>
)

export const IconWithSVG = (args: any) => (
<Icon {...args} src={<SvgMessagesIcon />} />
)

IconWithSVG.args = {
size: 'xxxlarge',
strokeWidth: 4,
}
25 changes: 23 additions & 2 deletions src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface Props {
| 'indigo'
| 'purple'
| 'pink'
src?: React.ReactNode
}

interface StringMap {
Expand All @@ -44,6 +45,7 @@ function Icon({
fill = undefined,
stroke = undefined,
background,
src,
...props
}: Props) {
return (
Expand Down Expand Up @@ -100,14 +102,33 @@ function Icon({
/>
)

const Icon = src ? (
// custom SVG file
<svg
xmlns="http://www.w3.org/2000/svg"
color={!noColor ? color : 'currentColor'}
fill={!noColor ? (fill ? fill : 'none') : 'none'}
stroke={!noColor ? stroke : 'currentColor'}
className={`${className}`}
width={iconSize}
height={iconSize}
>
{src}
</svg>
) : (
// feather icon
<IconComponent />
)

return background ? (
<div
// circle coloured background
className={`sbui-icon-container sbui-icon-container--${background}`}
>
<IconComponent />
{Icon}
</div>
) : (
<IconComponent />
Icon
)
}}
</IconContext.Consumer>
Expand Down

0 comments on commit 1d47dc0

Please sign in to comment.