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

Using ionicons 5 in react #835

Open
designerdarpan opened this issue May 25, 2020 · 5 comments
Open

Using ionicons 5 in react #835

designerdarpan opened this issue May 25, 2020 · 5 comments

Comments

@designerdarpan
Copy link

How to use it in react application , i found react-ionicon package but its kind of outdated and supports ionicons 3 , is there any way i can import ionicons 5 in my react application.
I kind of work around with cdn and it seems to work fine , but i couldnt work around with node modules.

@dotNetkow
Copy link

We definitely need to include better docs for those, sorry! For the time being, check out our first app tutorial to see how; specifically look at the demo app.

@designerdarpan
Copy link
Author

So when do you plan to include it ?

@lucej
Copy link

lucej commented Jun 7, 2020

Yeah the official IonIcon documentation is completely wrong for a react Ionic app.

No idea if this is official or up to date but this worked for me:

  • Replace ion-icon with IonIcon
  • Replace the attribute name with icon
  • Wrap icon name in brackets and change to camelCase
  • In the file be sure to import the icon from "ionicons/icons"

Instead of:
<ion-icon name="airplane-outline"></ion-icon>

For a react Ionic app it should be:
<IonIcon icon={airplaneOutline}></IonIcon>

And be sure to import the icon reference:
import {arrowBackCircleOutline} from "ionicons/icons";

@designerdarpan
Copy link
Author

designerdarpan commented Jun 16, 2020

@lucej this will import base64 image and should be enclosed inside a img tag , which would make changing color difficult , masking it would be an option but i need a simple way to do it.
i did a simple hack , works a gem.
making a component and replacing base64 image files such that i would only get svg markup

import React from 'react'
export default function IonIconComponent(props) {
    let icon = props.icon.replace("data:image/svg+xml;utf8,","");
    return (
        <div className="ion-icon-container">
            <div className="icon-inner" dangerouslySetInnerHTML={{__html:icon}}/>
        </div>
    )
}

now i can use this same component wherever i need

import {createOutline} from 'ionicons/icons/index';
export const ActionComponent = withRouter((props) => {
    const data = props;
  return (
    <>
          <IonIconComponent icon={createOutline}/>
    </>
  )
})

@wangzuo
Copy link

wangzuo commented Jan 2, 2022

https://github.com/swiftcarrot/react-ionicons we transfer svg from ionicons into react component with the help of svgr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants