Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

styled-icons

Package Overview
Dependencies
Maintainers
1
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

styled-icons

Font Awesome, Material Icons, and Octicons available as Styled Components

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24K
increased by9.47%
Maintainers
1
Weekly downloads
 
Created
Source

💅 styled-icons

Build Status npm npm Built with TypeScript

styled-icons provides the Font Awesome, Material Design and Octicons icon packs as Styled Components, with full support for TypeScript types and ES6 modules / tree-shaking.

View Icons

Installation

yarn add styled-icons

or

npm install styled-icons --save

Additionally, you will need to have installed a version of styled-components, as styled-icons depends on styled-components as a peer dependency.

Usage

All Font Awesome (free), Material, and Octicon icons are available for preview at the Icon Explorer.

The entire icon packs are available via the main import and sub-imports:

import {material, octicons} from 'styled-icons'

import * as faBrands from 'styled-icons/fa-brands'
import * as faRegular from 'styled-icons/fa-regular'
import * as faSolid from 'styled-icons/fa-solid'
import * as material from 'styled-icons/material'
import * as octicons from 'styled-icons/octicons'

The icons are also available as individual imports - it is recommended that you import icons individually using ES modules along with a module bundler like Webpack or Rollup in order to enable tree-shaking. This means that the module bundler will remove unused icons from the final JavaScript bundle, saving bandwidth and speeding up loading:

import React, {Fragment} from 'react'
import {Account, Lock} from 'styled-icons/material'

const App = () => (
  <Fragment>
    <Account />
    <Lock />
  </Fragment>
)

Props

Styled Icons accept all the valid props of an <svg /> element, in addition to a size convenience prop that sets both width and height:

import React from 'react'
import {Lock} from 'styled-icons/material'

const App = () => <Lock size="48" />

Dimensions

Some icons natively have non-square dimensions - original dimensions are exported from the individual icon exports:

import {LogoGithub, LogoGithubDimensions} from 'styled-icons/octicons/LogoGithub'

const App = () => <LogoGithub />

console.log(LogoGithubDimension) // {height: 16, width: 45}

Dimension exports are not available on the icon pack or index exports:

import * as octicons from 'styled-icons/octicons'
import {octicons} from 'styled-icons'

// octicons contains only icon exports

Styled Components

All icons are exported as Styled Components, which means it is possible to extend their styles or otherwise utilize the Styled Components API:

import {Lock} from 'styled-icons/material'

export const RedLock = Lock.extend`
  color: red;

  font-weight: ${props => (props.important ? 'bold' : 'normal')};
`

TypeScript

The icons of styled-icons are built using TypeScript and export type definitions. By default, the theme prop is typed as any, but if you would like to override the theme interface, this is possible via the StyledIcon type:

import {StyledIcon} from 'styled-icons/material'
import {Lock} from 'styled-icons/material'

interface ThemeInterface {
  lockColor: string
}

export const ThemedLock: StyledIcon<ThemeInterface> = Lock.extend`
  color: ${props => props.theme.lockColor};
`

If you have any ideas for improvements to the TypeScript typing, please open an issue or PR!

Contributing

Contributions are welcome! Feel free to open an issue or a pull request and participate at whatever level you would like.

License

The MIT License - see LICENSE.

The Font Awesome icons are licensed under the CC BY 4.0 License.

The Material Design icons are licensed under the Apache License Version 2.0.

The Octicons are licensed under the MIT License.

Keywords

FAQs

Package last updated on 19 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc