feathericons / react-feather

React component for Feather icons
https://npm.im/react-feather
MIT License
1.92k stars 126 forks source link

Is there any option to set icon size by default globally #40

Open salih0313 opened 5 years ago

salih0313 commented 5 years ago

How can i set icon size from 24 to some other size by default

embee8 commented 4 years ago

I ended up solving this with a CSS rule: image

fdev commented 3 years ago

For backwards compatibility this library could use a Context that defines default icon options (which defaults to size 24px). That way everyone can safely upgrade, but you could choose to use a different default size by adding the context:

import { FeatherContext, Camera, Clock, Compass } from "react-feather"

const App = () => (
  <>
    <Camera /> {/* color currentColor, size 24px */}

    <FeatherContext.Provider
      value={{
        size: "1em",
        color: "maroon",
      }}
    >
      <Clock /> {/* color maroon, size 1em */}
      <Compass size={32} /> {/* color maroon, size 32px */}
    </FeatherContext.Provider>
  </>
)
jiayinghsu commented 3 years ago

@fdev I noticed that the size attribute does not modify the viewBox size, which is fixed to be viewBox="0 0 24 24".

fdev commented 3 years ago

@jiayinghsu I've since switched to react-icons which includes feather icons, defaults to 1em and provides the aforementioned context for overriding the defaults.

Ayagoumi commented 2 years ago

This is an ongoing issue, and it really frustrates me that I cannot change the size of the icon using the attribute.

zhangyu1818 commented 1 year ago

I think it is possible to change the icon's defaultProps.

// icon.js
import * as icons from 'react-feather'

Object.values(icons).forEach((icon) => {
  icon.defaultProps = {
    size: '1em',
  }
})

export * from 'react-feather'
import { Home } from "./icon"