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
Icon file name could be referenced in the website #348
Comments
Adding it below the title could be a nice touch. I’ve opened #349 to change the humanized icon name on the homepage to the regular file name as well. Echoing the filename as |
Hi @mdo great, would you like me to do some contribution ? |
Can having a copy button be a good idea too ? |
Hi @M-ZubairAhmed, I am rendering stars in a questionnaire, where the user can click on stars to rate. I now want to include them and then use it as react component. Thanks for your help. For general styling I use react-bootstrap: https://github.com/react-bootstrap/react-bootstrap |
@yuki-93 Yes we basically use a svg loader in our webpack setup, follow here https://react-svgr.com/docs/webpack/#usage {
test: /\.svg$/,
use: ['@svgr/webpack'],
} and then directly import the svg as react components import IconGearFill from 'bootstrap-icons/icons/gear-fill.svg' for styling i pass on props on to the object and webpack loaders apply the transformation accordingly <IconGearFill className="text-success" style={{ fontSize: '1.8em' }} /> |
@M-ZubairAhmed Thanks for your quick reply. I also figured out, that create-react-app does the webpack magic for you. So you can simply Maybe the use of react should be documented in the docs. Should this go into a new issue or could be done here? @mdo |
@yuki-93 your welcome, yes we use custom webpack setup for our app. |
I quickly wrapped all together in a short blog-post https://yuki-93.gitlab.io/aboutme/tech/bootstrap-icons-with-react/. Feel free to use or copy this on your docs page. |
haha this is great @yuki-93. Makes me want to write short one for custom webpack setup 😛 |
If you throw me over your markdown, I add this to the page and link your GitHub profile :) |
If the app uses custom webpack configuration, then loader is needed to handle svgs in your app. Lets use SVGR webpack loader. yarn add @svgr/webpack --dev and then in your webpack config file add the following rule : {
test: /\.svg$/,
use: ['@svgr/webpack'],
} and then directly import the svg as react components import IconGearFill from 'bootstrap-icons/icons/gear-fill.svg' for styling you can pass on style or classname prop, and they will be applied on to your svg component. <IconGearFill className="text-success" style={{ fontSize: '1.8em' }} />
|
@M-ZubairAhmed There it is online https://yuki-93.gitlab.io/aboutme/tech/bootstrap-icons-with-react/ |
Catching up after being out for vacation, I'd love to come back to this and add a guide for this into the Icons docs, too. Appreciate all the details and steps here! <3 |
I'm adapting the icons to React components, to import them like |
@erickriva Thanks for your work. Before I found the solution I'm using now (import-as), I was looking for a way like yours. Also the color feature is nice, as I'm using custom CSS classes here and of course the way of multiple imports at once. In my current setup, I have to import from the path of one svg icon. |
@yuki-93 do you think it is necessary, for those who use it, to change all the SVG attributes or just a specific list like "width, height, fill, style and className"? |
@erickriva thats is nice recomendation, yes its good the default attributes can be changed. I usually try to import import ModA from 'package/modA' rather than import {ModA} from 'paclage' let me know your thoughts |
@erickriva For me className and color would be enough, as the size is the normal textsize, as I use the icons inline with text. But of course exposing all attributes is nice for other devs. |
@M-ZubairAhmed I'm reading about "tree shaking" to see what i can do about this. I never thought about it, it's a good thing to try for sure. |
@M-ZubairAhmed I found this repository right now. |
@erickriva yes i have seen this library :) i think this is a good library, you can use it as it is. Regarding the multi lines import, as i said if you have configured your app properly to do tree shaking and dead code elimination you should be able to either of the import approach. https://webpack.js.org/guides/tree-shaking/ |
Updated docs went out with v1.2.0 and include more names and snippets of HTML to copy-paste. Hope that helps! |
Awesome work on the library, we have started using this as npm package.
We are currently rendering the icons directly in our react app via webpack svg loader that mean this is how we are importing
I was wondering if it would be a good idea to have a link in the view of the icon page referencing the icon in the github repo. Just below tag line.
Let me know your thoughts, i would be happy to send a PR :)
The text was updated successfully, but these errors were encountered: