Coder Social home page Coder Social logo

styled-icons / styled-icons Goto Github PK

View Code? Open in Web Editor NEW
2.1K 19.0 60.0 16.34 MB

💅 Popular icon packs like Font Awesome, Material Design, and Octicons, available as React Styled Components

Home Page: https://styled-icons.dev

License: MIT License

JavaScript 80.87% TypeScript 18.63% HTML 0.49%
icons styled-components svg font-awesome material octicons react boxicons cryptoicons evil-icons

styled-icons's Introduction

💅 styled-icons

Build Status npm npm Built with Styled Components Powered by TypeScript

Powered by Vercel

styled-icons provides over 20,000 icons from the following icon packs as Styled Components, with full support for TypeScript types and tree-shaking / ES modules.

➡️ View the Icon Explorer


Do you use Emotion?

Check out 👩‍🎤 Emotion Icons

Would you prefer plain SVGs?

Check out 🎛️ SVG Icons


Table of Contents

Installation

You can install all the icon packs simultaneously:

yarn add styled-icons

or

npm install styled-icons --save

Alternatively you can install only the icon packs you need:

yarn add @styled-icons/bootstrap
yarn add @styled-icons/boxicons-logos
yarn add @styled-icons/boxicons-regular
yarn add @styled-icons/boxicons-solid
yarn add @styled-icons/crypto
yarn add @styled-icons/entypo
yarn add @styled-icons/entypo-social
yarn add @styled-icons/evaicons-outline
yarn add @styled-icons/evaicons-solid
yarn add @styled-icons/evil
yarn add @styled-icons/fa-brands
yarn add @styled-icons/fa-regular
yarn add @styled-icons/fa-solid
yarn add @styled-icons/feather
yarn add @styled-icons/fluentui-system-filled
yarn add @styled-icons/fluentui-system-regular
yarn add @styled-icons/foundation
yarn add @styled-icons/heroicons-outline
yarn add @styled-icons/heroicons-solid
yarn add @styled-icons/icomoon
yarn add @styled-icons/ionicons-sharp
yarn add @styled-icons/ionicons-solid
yarn add @styled-icons/ionicons-outline
yarn add @styled-icons/material
yarn add @styled-icons/material-outlined
yarn add @styled-icons/material-rounded
yarn add @styled-icons/material-twotone
yarn add @styled-icons/material-sharp
yarn add @styled-icons/octicons
yarn add @styled-icons/open-iconic
yarn add @styled-icons/remix-fill
yarn add @styled-icons/remix-editor
yarn add @styled-icons/remix-line
yarn add @styled-icons/simple-icons
yarn add @styled-icons/typicons
yarn add @styled-icons/zondicons

Finally, you will need to have installed a version of styled-components at least version 4.1.0 or newer, as styled-icons depends on styled-components as a peer dependency.

Usage

All 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 bootstrap from '@styled-icons/bootstrap'
import * as boxiconsLogos from '@styled-icons/boxicons-logos'
import * as boxiconsRegular from '@styled-icons/boxicons-regular'
import * as boxiconsSolid from '@styled-icons/boxicons-solid'
import * as crypto from '@styled-icons/crypto'
import * as entypo from '@styled-icons/entypo'
import * as entypoSocial from '@styled-icons/entypo-social'
import * as evaiconsOutline from '@styled-icons/evaicons-outline'
import * as evaiconsSolid from '@styled-icons/evaicons-solid'
import * as evil from '@styled-icons/evil'
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 feather from '@styled-icons/feather'
import * as fluentUISystemFilled from '@styled-icons/fluentui-system-filled'
import * as fluentUISystemRegular from '@styled-icons/fluentui-system-regular'
import * as foundation from '@styled-icons/foundation'
import * as heroiconsOutline from '@styled-icons/heroicons-outline'
import * as heroiconsSolid from '@styled-icons/heroicons-solid'
import * as icomoon from '@styled-icons/icomoon'
import * as ioniconsSharp from '@styled-icons/ionicons-sharp'
import * as ioniconsSolid from '@styled-icons/ionicons-solid'
import * as ioniconsOutline from '@styled-icons/ionicons-outline'
import * as material from '@styled-icons/material'
import * as materialOutlined from '@styled-icons/material-outlined'
import * as materialRounded from '@styled-icons/material-rounded'
import * as materialSharp from '@styled-icons/material-sharp'
import * as materialTwoTone from '@styled-icons/material-twotone'
import * as octicons from '@styled-icons/octicons'
import * as openIconic from '@styled-icons/open-iconic'
import * as remixFill from '@styled-icons/remix-fill'
import * as remixEditor from '@styled-icons/remix-editor'
import * as remixLine from '@styled-icons/remix-line'
import * as simpleIcons from '@styled-icons/simple-icons'
import * as typicons from '@styled-icons/typicons'
import * as zondicons from '@styled-icons/zondicons'

You can also import just the icons you need:

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

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

For the individual icon pack packages (@styled-icons/PACK), the icons are also importable individually - this is not possible with the uber-styled-icons package containing all the packs:

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

const App = () => <Lock />

Props

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 accessibility mode. See accessibility below for additional details

Example

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

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

Icon 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 utilize the Styled Components API:

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

export const RedLock = styled(Lock)`
  color: red;

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

Base Icon Styles

If you wish to style all icons at once, you can create a wrapper styled component that imparts a particular style to all icons contained within the wrapper by targeting the StyledIconBase component:

import styled from 'styled-components'
import {StyledIconBase} from '@styled-icons/styled-icon'

export const IconStyleWrapper = styled.div`
  ${StyledIconBase} {
    color: red;
    /* icon styles go here */
  }
`

Accessibility

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 'styled-components'
import {Spinner} from '@styled-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>

Tree Shaking

Styled Icons supports automatic tree-shaking via the package.json module property from any of the import paths (icon pack, individual icon, etc.). Tree shaking has been tested with Create React App v2, Next.js, Rollup, and Webpack v4.

TypeScript

The icons of styled-icons are built using TypeScript and export type definitions. If you need a type to reference any styled icon, there is a StyledIcon type exported from the @styled-icons/styled-icon package (recommended) or the styled-icons/types import:

import styled from 'styled-components'

// Recommended:
import {StyledIcon} from '@styled-icons/styled-icon'
// Alternatively:
import {StyledIcon} from 'styled-icons/types'

interface Props {
  icon: StyledIcon
}

NOTE: you should ensure that the version of @types/react in your project is at least 16.8.14 or greater. That version of the React types package added support for ARIA attributes on SVG elements, which Styled Icons uses.

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 Bootstrap icons are licensed under the MIT License.

The Boxicons are licensed under the CC BY 4.0 License.

The Cryptocurrency icons are licensed under the CC0 1.0 Universal License.

The Entypo icons are licensed under the CC BY-SA 4.0 License.

The Eva Icons are licensed under the MIT License.

The Evil Icons are licensed under the MIT License.

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

The Feather icons are licensed under the MIT License.

The FluentUI System icons are licensed under the MIT License.

The Foundation icons are licensed under the MIT License.

The Heroicons are licensed under the MIT License.

The Icomoon icons are dual licensed under GPL / CC BY 4.0 License.

The Ionicons 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.

The Open Iconic icons are licensed under the MIT License.

The Remix icons are licensed under the Apache License 2.0.

The Simple Icons are licensed under the CC0 1.0 Universal License.

The Typicons are licensed under the CC BY SA 3.0 License.

The Zondicons are licensed under the MIT License.

Contributors

Thank you to all our backers! 🙏 [Become a backer]

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

styled-icons's People

Contributors

betree avatar caseylucas avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar diegohaz avatar dinoshauer avatar fr3fou avatar franciscop avatar github-actions[bot] avatar icon-bot avatar jacobwgillespie avatar jensderond avatar jgierer12 avatar kodiakhq[bot] avatar mergify[bot] avatar monkeywithacupcake avatar stramel avatar zachasme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

styled-icons's Issues

Tree Shaking isn't working as (I) expected

Prior to stating the issue I want to say that the reason I have installed this package is I am trying to replace our custom icons from https://www.github.com/MerlinLabs/styled-material-components with yours. Also I am currently rewriting the library build process to get tree shaking working. I have been down a rabbit hole and even created a whole new package to test how Tree shaking works in general.

What i've noticed so far...as soon as you introduce styled-components into a file tree shaking fails entirely for that file. I was using your code to forensic analyze my process and realized that tree shaking doesn't work with styled-icons with current version of styled-components (3.4.5, not 4) and create react app.

image

import React, { Component } from 'react';
import { NewPkgTest } from 'new-pkg';
import { AccountCircle } from 'styled-icons/material';
import logo from './logo.svg';
import './App.css';

class App extends Component {
  render() {
    return (
      <div className="App">
      <AccountCircle />
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to React</h1>
        </header>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
        <NewPkgTest />
      </div>
    );
  }
}

export default App;

The only file I have modified from the default create react app stack is the App.js file. I imported a single Icon from the material sub import and it includes all of the material icons in the generated bundle.

In dev mode it looks like the tree shaking is actually working so far as adding the comment to mark unused modules:

/***/ "./node_modules/styled-icons/material/Add.js":
/*!***************************************************!*\
  !*** ./node_modules/styled-icons/material/Add.js ***!
  \***************************************************/
/*! exports provided: Add, AddDimensions */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* unused harmony export Add */
/* unused harmony export AddDimensions */

Can you provide me any help figuring this out? Would love to include styled-icons in our library and get our library figured out so tree shaking doesn't result in a huge bundle.

Add search variable to URL params

It would be nice to store search in URL params to be able to share URLs such as https://styled-icons.js.org/?search=event that would show the page with filtered icons.

Problem using named imports (fa-solid)

Describe the bug
The error is being shown when bundling the app and using the example import shown below:

import { User, SignOutAlt, AngleDown } from 'styled-icons/fa-solid';

Image of the error
tsconfig.json

Using the .cjs imports work fine but we are dragging a lot of unused icons (all icons from fa-solid) and that's not the desired solution:

import { User, SignOutAlt, AngleDown } from 'styled-icons/fa-solid/index.cjs.js';

Updating the library version to the latest one didn't fix the issue.

Expected behaviour
Bundle only the imported icons without any errors.

System:

  • OS: MacOS
  • Device: Macbook Pro 2018
  • Typescript: "typescript": "^3.1.1",
  • Version: "styled-icons": "5.1.0",

Client/Server className mismatch in Next.JS

I've got a minimal reproduction of the issue here: https://github.com/ellsclytn/next-styled-icons

When using Styled Icons with Next.JS (and the associated with-styled-icons plugin), hot reloading works, but causes a browser console error and warning:

Error:

index.js:2178 Warning: Prop `className` did not match. Server: "sc-hbkdQL pages__MyIcon-sc-1wbo52z-1 KKtVi" Client: "sc-jzgbtB pages__MyIcon-sc-1wbo52z-1 KKtVi"

Warning:

styled-components.browser.esm.js:1927 It looks like you've wrapped styled() around your React component (svg), but the className prop is not being passed down to a child. No styles will be rendered unless className is composed within your React component.

This does not occur on an initial load immediately after server start, but rather only occurs when you perform a manual browser reload after making a change to the code. You can replicate this by commenting/uncommenting line 17 of pages/index.js and refreshing the page each time.

Duplicated SVG path in exported file

As of today, an exported icon looks like that:

[...]

export var Filter = styled.svg.attrs(function (props) { return ({
    children: props.title != null
        ? [React.createElement(..., React.createElement("path", { d: "[SVG PATH]", key: "k0" })]
        : [React.createElement("path", { d: "[SVG PATH]", key: "k0" })],

[...]

Though JS code optimizers probably know how to optimize that, we could reduce the bundle size by extracting the path to a top-level variable:

[...]

const svgPath = '[SVG PATH]'
export var Filter = styled.svg.attrs(function (props) { return ({
    children: props.title != null
        ? [React.createElement(..., React.createElement("path", { d: svgPath, key: "k0" })]
        : [React.createElement("path", { d: svgPath, key: "k0" })],

[...]
See the full exported Filter icon
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
import * as React from 'react';
import styled from 'styled-components';
export var Filter = styled.svg.attrs(function (props) { return ({
    children: props.title != null
        ? [React.createElement("title", { key: "Filter-title" }, props.title), React.createElement("path", { d: "M15.96 10.29l-2.75 3.54-1.96-2.36L8.5 15h11l-3.54-4.71zM3 5H1v16c0 1.1.9 2 2 2h16v-2H3V5zm18-4H7c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V3c0-1.1-.9-2-2-2zm0 16H7V3h14v14z", key: "k0" })
        ]
        : [React.createElement("path", { d: "M15.96 10.29l-2.75 3.54-1.96-2.36L8.5 15h11l-3.54-4.71zM3 5H1v16c0 1.1.9 2 2 2h16v-2H3V5zm18-4H7c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V3c0-1.1-.9-2-2-2zm0 16H7V3h14v14z", key: "k0" })
        ],
    viewBox: '0 0 24 24',
    height: props.height !== undefined ? props.height : props.size,
    width: props.width !== undefined ? props.width : props.size,
    // @ts-ignore - aria is not always defined on SVG in React TypeScript types
    'aria-hidden': props.title == null ? 'true' : undefined,
    focusable: 'false',
    role: props.title != null ? 'img' : undefined,
    "fill": "currentColor",
}); })(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  display: inline-block;\n  vertical-align: middle;\n  overflow: hidden;\n"], ["\n  display: inline-block;\n  vertical-align: middle;\n  overflow: hidden;\n"])));
Filter.displayName = 'Filter';
export var FilterDimensions = { height: 24, width: 24 };
var templateObject_1;

Naming conflict with components

Hello,
An issue I have experience using this lib is naming conflicts between my project components and styled-icons. Example
import { Home } from 'styled-icons/material';

I already have a component called Home. It would be nice with styled-icons had unique names. To solve this I currently do import { Home as SiHome } from 'styled-icons/material'; not the best naming convention but it gets the job done. One strategy I have seen font-awesome use is

import FontAwesomeIcon from '@fortawesome/react-fontawesome';
import { faHome } from '@fortawesome/fontawesome-free-solid';

<FontAwesomeIcon icon={faHome} />

This ensures that there will almost never be a naming conflict. While this is a great strategy this would require an API change, and its a little more verbose than styled-icons. Maybe, it could be considered for a future version or some other solution.

Warnings `Functions as object-form attrs({}) keys are now deprecated`

Hi. I have warnings with every components imported from styled-components. Am I doing something wrong?

warnings:

Functions as object-form attrs({}) keys are now deprecated and will be removed in a future version of styled-components. Switch to the new attrs(props => ({})) syntax instead for easier and more powerful composition. The attrs key in question is "children" on component "Archive".

Functions as object-form attrs({}) keys are now deprecated and will be removed in a future version of styled-components. Switch to the new attrs(props => ({})) syntax instead for easier and more powerful composition. The attrs key in question is "children" on component "Home".

component:

import React from 'react';
import { Archive, Home } from 'styled-icons/feather';

export default () => (
  <div>
    <Archive />
    <Home />
  </div>
);

versions:

styled-components: 4.1.2
styled-icons: 5.2.2

How to set size, color, etc.. to all styled icon

I have a file styledIcon.js and I am using below icons in different components, So I want to set set globally all icon size is "14px" and other things like color etc..

so how can it possible

`import { ExternalLinkSquareAlt } from 'styled-icons/fa-solid/ExternalLinkSquareAlt';
import { Phone } from 'styled-icons/icomoon/Phone';
import { Email } from 'styled-icons/material/Email';

export { ExternalLinkSquareAlt, Phone, Email }`

Dependabot couldn't fetch all your path-based dependencies

Dependabot couldn't fetch one or more of your project's path-based JavaScript dependencies. The affected dependencies were styled-icons.

To use path-based dependancies with Dependabot the paths must be relative and resolve to a directory in this project's source code.

You can mention @dependabot in the comments below to contact the Dependabot team.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error while updating /yarn.lock:
Couldn't find any versions for "scheduler" that matches "^16.6.2"

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

You can mention @dependabot in the comments below to contact the Dependabot team.

Custom icons

Based on a custom SVG icon file I have, can styled icons be used as a mechanism to embed custom icons? How could I implement this feature in my project?

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Couldn't find any versions for "@fortawesome/fontawesome-common-types" that matches "^0.1.7"

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

You can mention @dependabot in the comments below to contact the Dependabot team.

Integrate IcoMoon icons

I don't especially need it, but I've used IcoMoon in the past. They have a large set of good-quality icons, with a good part licensed under GPL / CC BY 4.0 and provide a variety of formats (including SVGs).

See their free 490 icons here: https://icomoon.io/#preview-free

If it's easy to integrate, I think it would be a nice-to-have 🙂

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Couldn't find any versions for "gatsby-cli" that matches "^1.1.54"

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

You can mention @dependabot in the comments below to contact the Dependabot team.

Icon alignment

Hello, Greate project.

I'm replacing my font-awesome icons with styled-icons, however, I have encountered an issue. The icon alignment is off.
image

My markup
image

Using font-awesome
image
image

I see on the SVG element the class has the property vertical-align: middle. If I replace it vertical-align: -.150em similar to what font-awsome has the icons align properly.

Can't resolve '../../StyledIconBase'

I tried to upgrade from 6.4.0 to 7.1.0 today and hit the following error:

> Failed to build
{ Error: (client) ../node_modules/styled-icons/boxicons-regular/LoaderAlt/LoaderAlt.esm.js
Module not found: Error: Can't resolve '../../StyledIconBase' in '/home/circleci/project/node_modules/styled-icons/boxicons-regular/LoaderAlt'
 @ ../node_modules/styled-icons/boxicons-regular/LoaderAlt/LoaderAlt.esm.js 3:0-54 8:32-46
 @ ./components/StyledSpinner.js
 @ ./components/StepsProgress.js
 @ ./pages/createOrderNewFlow.js
 @ multi ./pages/createOrderNewFlow.js
    at /home/circleci/project/node_modules/next/dist/build/index.js:144:31
    at finalCallback (/home/circleci/project/node_modules/webpack/lib/MultiCompiler.js:247:12)
    at runWithDependencies.err (/home/circleci/project/node_modules/webpack/lib/MultiCompiler.js:270:6)
    at done (/home/circleci/project/node_modules/neo-async/async.js:2920:13)
    at runCompilers (/home/circleci/project/node_modules/webpack/lib/MultiCompiler.js:174:48)
    at err (/home/circleci/project/node_modules/webpack/lib/MultiCompiler.js:181:7)
    at compiler.run (/home/circleci/project/node_modules/webpack/lib/MultiCompiler.js:263:7)
    at finalCallback (/home/circleci/project/node_modules/webpack/lib/Compiler.js:204:39)
    at hooks.done.callAsync.err (/home/circleci/project/node_modules/webpack/lib/Compiler.js:220:13)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/circleci/project/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:33:1)
    at AsyncSeriesHook.lazyCompileHook (/home/circleci/project/node_modules/tapable/lib/Hook.js:154:20)
    at onCompiled (/home/circleci/project/node_modules/webpack/lib/Compiler.js:218:21)
    at hooks.afterCompile.callAsync.err (/home/circleci/project/node_modules/webpack/lib/Compiler.js:547:14)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/circleci/project/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook (/home/circleci/project/node_modules/tapable/lib/Hook.js:154:20)
    at compilation.seal.err (/home/circleci/project/node_modules/webpack/lib/Compiler.js:544:30)

I guess it comes from #612, probably because we don't use Typescript? I've downgraded to 7.0.0 and it works correctly.

Otherwise thanks for the automatic support of CommonJS and ES Modules code, that's a great change for us!

attrs and as support?

Hey Jacob, does styled-icons support styled-components's attrs constructor and as polymorphic prop?

I have a Toggle component on which I tried to use both but neither seemed to have any effect.

import React from 'react'
import styled from 'styled-components'

import { Close } from 'styled-icons/material/Close'
import { Menu } from 'styled-icons/feather/Menu'

const Toggle = styled(Close).attrs({ size: `1em` })`
  cursor: pointer;
  ${props => (props.inside ? inNavToggle : inHeaderToggle)};
  ${navLinkStyle};
`

const Nav = props => (
     ...
     <Toggle onClick={this.toggleNav} as={Menu} />
     ...
)

Deprecation warning since upgrading to styled-components 4.1.0

See the notes about the deprecation here: https://github.com/styled-components/styled-components/blob/master/CHANGELOG.md#v410---2018-11-12

Nothing breaks and everything will continue to work until styled-components v5. But, the many warnings are an eyesore.

Any plans on updating styled-icons to the new functionality?

Edit: here is the full deprecation warning:

Functions as object-form attrs({}) keys are now deprecated and will be removed in a future version of styled-components. Switch to the new attrs(props => ({})) syntax instead for easier and more powerful composition. The attrs key in question is "children" on component "AlertTriangle"

Using styled-icons with NextJS

Hello!

Tried setting styled-icons with next.js following first their styled-components example. Then I just imported styled-icons and then the icon I want to use from FontAwesome.

This is the result, basically an error:

Unexpected token export
/home/runner/node_modules/styled-icons/fa-solid/index.js:1
(function (exports, require, module, __filename, __dirname) { export { AddressBook } from './AddressBook';

Here's the resulting error:

https://repl.it/@fillipvt/nextjs-with-styled-components-and-styled-icons

I'm not sure what's going on and was hoping perhaps here I could find some guidance.

Thanks

Cannot use with TypeScript target ES5

I'm having difficulties importing the styled icons because it appears that the generated files are using ES6 exporting. It looks like your module setting in your tsconfig is commonjs so I'm not sure why that would be.

In particular the error is:

(function (exports, require, module, __filename, __dirname) { export { AddressBook } from './AddressBook';
                                                              ^^^^^^

SyntaxError: Unexpected token export
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)

create-react-app build fails to minify

Hi, just today i discovered this project - looks very nice so far.

However, i have the following issue when trying to create the production build with the create-react-app build step:

$ yarn build
yarn run v1.6.0
(node:49) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
$ react-scripts build
Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file: 

 	./node_modules/styled-icons/fa-brands/FiveHundredPx.js:4 

Read more here: http://bit.ly/2tRViJ9

Cannot read property 'StyledIconBase' of undefined

Attempting to import an icon leads to the error reported in the title of this topic:

import { PlusCircle } from "styled-icons/boxicons-solid/PlusCircle";

Resulting error output:

Uncaught TypeError: Cannot read property 'StyledIconBase' of undefined
URL: http://localhost:3000/app.js
Line: 75211, Column: 50
Stack: TypeError: Cannot read property 'StyledIconBase' of undefined

We are using the fuse-box bundler for typescript. Our tsconfig.json is as follows

{
  "compilerOptions": {
    "strict": true,
    "strictPropertyInitialization": false,
    "module": "CommonJS",
    "target": "ES5",
    "sourceMap": true,
    "inlineSources": true,
    "jsx": "react",
    "baseUrl": ".",
    "importHelpers": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "paths": {
      ...
    },
    "plugins": [
      {
        "name": "typescript-styled-plugin"
      }
    ]
  }
}

Our fuse-box configuration:

{
        homeDir: "..",
        output: "public/$name.js",
        target: "browser@es5"
}

We have tried various ways of making styled-icons work with fuse-box, and at this point we don't know if its because of fuse-box itself or a miss-configuration somewhere. If anyone could shed some light on the error and a possibly remedy that would be great.

Should use 'import * as React' in index.d.ts

likely in Typescript, you can't import React from 'react' directly.
the error message was:

.../node_modules/styled-icons/index.d.ts
Error:(1, 8) TS1192: Module '".../node_modules/@types/react/index"' has no default export.

after I edit the index.d.ts to be:

// import React from 'react';
import * as React from 'react';
import { StyledComponent } from 'styled-components';
......

above error disappeared.

Expose the custom StyledIconProps

Hi, I have cases where I want to create some default components, e.g.

import React from "react";
import { Menu } from "styled-icons/material/Menu";

const MenuBtn = (props: any) => {
  // some default functionality
  return <Menu size="2em" css="cursor: pointer" /* some other default props */ {...props} />;
};

export default MenuBtn;

Problem is with the props: any. I tried importing StyledIconProps from the base directory but the types are incompatible.

The goal is to be able to do sth like:
import { Menu, MenuProps } from "styled-icons/material/Menu";

and then (props: MenuProps)

or any other solution that will help not use any types.

Can't download from Yarn

Is anyone else having this issue. When i am trying to download the package i keep getting this error.

OS : Windows 10
Bit: 64
Registry: https://registry.yarnpkg.com

I can download anything else, browse the web, stream Lakers game and file this issue no problem.
This has been going on for a week. I really was looking forward to the library

yarn add styled-icons
yarn add v1.10.1
[1/4] Resolving packages...
[2/4] Fetching packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.yarnpkg.com/styled-icons/-/styled-icons-4.1.0.tgz: ESOCKETTIMEDOUT".
info If you think this is a bug, please open a bug report with the information provided in "C:\\Users\\shavauhng\\code\\Panacea\\PanaceaImage\\ImageServer\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Accessibility of icons

Hey there!

Alright, let’s talk about accessibility. Most of what I know comes from Florens Verschelde. He wrote a fantastic article about working with SVG icons and I highly suggest anyone to read it: https://fvsch.com/code/svg-icons/#section-html.

Here is a summary of the things that are necessary for accessible icons:

  • The SVG element should have focusable="false" to avoid a double-focus issue on Internet Explorer and Edge.

  • The SVG element should have aria-hidden="true" even when used as a standalone icon. The associated text should be passed alongside the icon, not within it.

  • To provide context without displaying it visually, you can use a combination of CSS rules. Refer to https://hugogiraudel.com/2016/10/13/css-hide-and-seek/ for more information.

  • In case the icon is used a standalone icon, it should have a title attribute to provide a tooltip on hover.

  • It should be possible to pass the role and aria-live attributes.

Here is how we implemented it at N26 (I inlined and simplified the styles for the sake of the explanation):

// 1. The default vertical-align is `baseline`, which leaves a few pixels of
//    space below the icon. Using `middle` prevents this.
// 2. Hide paths and strokes overflowing the viewbox.
const styles = {
  display: 'inline-block',
  height: '1em',
  width: '1em',
  color: 'inherit',
  fill: 'currentcolor',
  verticalAlign: 'middle', /* 1 */
  overflow: 'hidden' /* 2 */
}

// Hide content while keeping it accessible for users of assistive technologies.
// See: http://hugogiraudel.com/2016/10/13/css-hide-and-seek/
// See: https://github.com/twbs/bootstrap/pull/25197
const visuallyHidden = {
  border: '0 !important',
  clip: 'rect(1px, 1px, 1px, 1px) !important',
  height: '1px !important',
  overflow: 'hidden !important',
  paddingTop: '0 !important',
  paddingRight: '0 !important',
  paddingBottom: '0 !important',
  paddingLeft: '0 !important',
  position: 'absolute !important',
  whiteSpace: 'nowrap !important',
  width: '1px !important'
}

const Icon = props => {
  if (!props.icon) {
    return null
  }

  const SVG = (
    <svg
      styles={styles}
      viewBox='0 0 32 32'
      aria-hidden='true'
      focusable='false'
    >
      <use xlinkHref={`#icon-${props.icon}`} />
    </svg>
  )

  if (!props.label) {
    return SVG
  }

  // The `role` and `aria-live` attributes might be useful in case the icon
  // needs to provide further information to the accessibility tree such as
  // for a loading spinner.
  // See: https://codeburst.io/how-to-create-a-simple-css-loading-spinner-make-it-accessible-e5c83c2e464c
  return (
    <span
      title={props.label}
      role={props.role}
      aria-live={props['aria-live']}
    >
      {SVG}
      <span styles={visuallyHidden}>{props.label}</span>
    </span>
  )
}

And then we can use it like this:

// Icon used alongside with text
<Icon icon='cogs' /> Settings

Or like this:

// Standalone icon
<Icon icon='cogs' label='Settings' />

Or like this:

// Standalone icon with extra contextual information
<Icon icon='loader' label='Loading…' role='alert' aria-live='assertive' />

I hope it helps. :)

Empty svg being rendered

I'm sure I'm just missing something glaringly obvious but currently my usage of styled-icons is rendering an empty svg element.
<svg class="sc-fQejPQ jDkHNW"></svg>
I'm just using the example shown on the README section. Any thoughts?

Thanks!
Looking forward to getting some styled icons in my project!

Typescript type errors in strict mode

When using styled-icons with create-react-app (although I doubt that matters) and typescript configured in "strict" mode (the default for create-react-app), an error is generated when performing a production build.

All of the generated *.tsx files have the same error. An example:

.../node_modules/styled-icons/fa-brands/Wpforms/Wpforms.tsx
Type error: Element implicitly has an 'any' type because type '{}' has no index signature.  TS7017

    22 |     (p, k) => {
    23 |       if (validProp(k)) {
  > 24 |         p[k] = otherProps[k]
       |         ^
    25 |       }
    26 |       return p
    27 |     }, {}

This error can be fixed by casting the empty object on line 27:

    }, {} as {[x:string]: typeof otherProps[keyof typeof otherProps]}

But then another error occurs:

Type error: Element implicitly has an 'any' type because type '{ 'aria-hidden'?: string | undefined; className?: string | undefined; color?: string | undefined; height?: string | number | undefined; id?: string | undefined; lang?: string | undefined; ... 412 more ...; key?: string | ... 1 more ... | undefined; }' has no index signature.  TS7017

    22 |     (p, k) => {
    23 |       if (validProp(k)) {
  > 24 |         p[k] = otherProps[k]
       |                ^
    25 |       }
    26 |       return p
    27 |     }, {} as {[x:string]: typeof otherProps[keyof typeof otherProps]}

This error can be fixed by helping out the return value from Object.keys. Changed from:

  const svgProps = Object.keys(otherProps).reduce(

to

  const svgProps = (Object.keys(otherProps) as Array<keyof typeof otherProps>).reduce(

Another option is to add // @ts-ignore before line 24.

Dependabot couldn't fetch all your path-based dependencies

Dependabot couldn't fetch one or more of your project's path-based JavaScript dependencies. The affected dependencies were styled-icons.

To use path-based dependancies with Dependabot the paths must be relative and resolve to a directory in this project's source code.

You can mention @dependabot in the comments below to contact the Dependabot team.

Typescript "css" prop missing

Property 'css' does not exist on type 'IntrinsicAttributes & Pick<StyledIconProps, "string" | "style"

For example, in js I have the following code, working just fine:


<FacebookLogo
        size="2em"
        css="cursor: pointer"
        onClick={() => console.log('click')}
      />

now rewriting in TS, I get the error that css prop does not exist. Does it not? Now I'm with the latest version of styled-icons, before I used to be with 2.something. Are there any changes or just the type is missing?

Support color icons

As of right now, all icons inherit their color from the current context, but there are some icon packs with colored icons, or even icons with multiple colors. Investigate supporting those icons and design an API for enabling / disabling colors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.