Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
emotion-icons
Advanced tools
Font Awesome, Material Icons, and Octicons available as Emotion Components
emotion-icons is a fork from emotion-icons that uses emotion instead of styled-components.
react-emotion
provides the Font Awesome, Feather, Material Design, and Octicons icon packs as emotion-js, with full support for TypeScript types and tree-shaking / ES modules.
yarn add react-emotion
or
npm install react-emotion --save
Additionally, you will need to have installed a version of react-emotion
, as emotion-icons
depends on react-emotion
as a peer dependency.
All Font Awesome (free), Feather, 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 'emotion-icons'
import * as faBrands from 'emotion-icons/fa-brands'
import * as faRegular from 'emotion-icons/fa-regular'
import * as faSolid from 'emotion-icons/fa-solid'
import * as feather from 'emotion-icons/feather'
import * as material from 'emotion-icons/material'
import * as octicons from 'emotion-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 'emotion-icons/material'
const App = () => (
<Fragment>
<Account />
<Lock />
</Fragment>
)
Styled Icons accept all the valid props of an <svg />
element, in addition to the following custom props:
Prop | Required | Type | Description |
---|---|---|---|
size | optional | string, number | This is a convenience for setting both width and height to the same value |
title | optional | string | This sets the icon title and enables the standalone icon accessability mode. See accessibility below for additional details |
css | optional | string, function, css tagged template literal | This prop accepts additional CSS to attach to the icon. It accepts the CSS as a string or as any valid Style Components interpolation |
Example
import React from 'react'
import {Lock} from 'emotion-icons/material'
const App = () => <Lock size="48" title="Unlock account" css="color: red;" />
Some icons natively have non-square dimensions - original dimensions are exported from the individual icon exports:
import {LogoGithub, LogoGithubDimensions} from 'emotion-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 'emotion-icons/octicons'
import {octicons} from 'emotion-icons'
// octicons contains only icon exports
All icons are exported as Styled Components, which means it is possible to utilize the Styled Components API:
import styled from 'emotion-components'
import {Lock} from 'emotion-icons/material'
export const RedLock = styled(Lock)`
color: red;
font-weight: ${props => (props.important ? 'bold' : 'normal')};
`
Styled Icons have two different built-in "modes" for accessibility purposes. By default, icons are considered decorative, meaning the icon is just visual sugar and the surrounding content is sufficient for conveying meaning. This will set the aria-hidden
attribute on the resulting HTML to hide the icon from screen readers.
// this icon
<Lock />
// will result in
<svg aria-hidden="true">...</svg>
Alternatively the icon could be used in standalone mode, meaning the icon itself should convey meaning. This mode is enabled by setting a title
prop - this is the text that will be read by a screen reader. This results in role
being set to img
and the addition of a <title>
element.
// this icon
<Lock title="Lock account" />
// will result in
<svg role="img"><title>Lock account</title> ...</svg>
Since Style Icons accept all <svg>
element attributes as props, you are free to override these aria-*
attributes if you have a more complex use-case.
As this library provides direct access to the <svg>
element, you may wish to further wrap the icon for additional semantic meaning. For example, for a loading spinner:
import styled from 'emotion-components'
import {Spinner} from 'emotion-icons/fa-solid/Spinner'
const VisuallyHidden = styled.span`
border: 0 !important;
clip: rect(1px, 1px, 1px, 1px) !important;
height: 1px !important;
overflow: hidden !important;
padding-top: 0 !important;
padding-right: 0 !important;
padding-bottom: 0 !important;
padding-left: 0 !important;
position: absolute !important;
white-space: nowrap !important;
width: 1px !important;
`
<span title="Loading posts..." role="alert" aria-live="assertive">
<Spinner />
<VisuallyHidden>Loading posts...</VisuallyHidden>
</span>
NOTE: tree shaking should work without modification using Create React App.
Tree shaking has been tested with Create React App, Rollup, and Webpack. If your bundler is unable to import the icons, additional CommonJS bundles are available as .cjs
:
import React, {Fragment} from 'react'
// This will result in all Material icons being bundled
import {Account} from 'emotion-icons/material.cjs'
// This will only include the Lock icon
import {Lock} from 'emotion-icons/material/Lock.cjs'
const App = () => (
<Fragment>
<Account />
<Lock />
</Fragment>
)
Be aware though that importing from the CommonJS icon pack bundles will likely result in significantly larger bundle sizes, because unused icons will be included in the final bundle. If you are unable to configure your bundler to process the ES module bundles, you should import icons individually to avoid large bundles.
Contributions are welcome! Feel free to open an issue or a pull request and participate at whatever level you would like.
The MIT License - see LICENSE
.
The Font Awesome icons are licensed under the CC BY 4.0 License.
The Feather icons are licensed under the MIT License.
The Material Design icons are licensed under the Apache License Version 2.0.
The Octicons are licensed under the MIT License.
FAQs
Icons from packs like Font Awesome, Material, Octicons, Feather, Icomoon, and Boxicons available as Emotion Components
The npm package emotion-icons receives a total of 620 weekly downloads. As such, emotion-icons popularity was classified as not popular.
We found that emotion-icons demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.