Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable passing style attribute to icons #44

Merged
merged 1 commit into from
Nov 12, 2022

Conversation

junhoyeo
Copy link
Contributor

@junhoyeo junhoyeo commented Oct 23, 2022

Background

  • style attributes are ignored because it's been overridden by style={{color}}.

Changes

  • Fixing it to pass all styles except color—Now you can pass styles to Icon!
import { Info } from '@geist-ui/icons';

<Info
  size={20}
  style={{
    marginRight: 8,
    display: 'inline-block',
    verticalAlign: 'text-bottom',
  }}
/>

image

junhoyeo added a commit to junhoyeo/junho.io-v2 that referenced this pull request Oct 23, 2022
@@ -65,7 +65,7 @@ const parseSvg = (svg: string, styles: any) => {
}

svg = svg.replace(/-([a-z])(?=[a-z\-]*[=\s/>])/g, g => g[1].toUpperCase())
svg = svg.replace(/<svg([^>]+)>/, `<svg$1 {...props} height={size} width={size} style={{color}}>`)
svg = svg.replace(/<svg([^>]+)>/, `<svg$1 {...props} height={size} width={size} style={{...style,color}}>`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to add a default value for style?

{...(style || {})}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nullish values are ignored for spread operators, so I don't think it's necessary.

{...undefined}
// {}
{...null}
// {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I have a bump? @unix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version 1.0.3 is out now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was fast. Many thanks! 🔥

@unix unix merged commit 90f9ec1 into geist-org:master Nov 12, 2022
@junhoyeo junhoyeo deleted the junhoyeo/fix-style-overriding branch November 12, 2022 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants