Carbon: import all icons from @carbon/icons-react

Created on 8 Aug 2019  ·  7Comments  ·  Source: carbon-design-system/carbon

When I use icons under node_modules/carbon-icons, I can use following code to 'import' all icons and access them dynamically:

import * as carbonIcons from 'carbon-icons';

var iconName = "iconChevronDown";
carbonIcons[iconName],

The icons under node_modules/@carbon/icons-react/es spread in different files, is there a way to do the similar thing as above - importing all icons and accessing them dynamically?

inactive question ❓

All 7 comments

Hi 👋 would #3078 address your need?

#3078 does not provide an example to show how to do it.
BTW, it seems @carbon/icons-react is not ready for testing now. I try it by following the readme at https://github.com/carbon-design-system/carbon/tree/master/packages/icons-react
, and got an error from code below:

import { Add24 } from '@carbon/icons-react';

ERROR in ./src/js/renderers/React/IconFactory.js
Module not found: Error: Can't resolve '@carbon/icons-react' in '/Users/ibmadmin/Documents/temp/HA-AC/Projects/project_programs/CarbonCopy/src/

carbon-components-react code has been using @carbon/icons-react for quite some time. That said, would you just try doing similar thing to carbon-components-react code? Though the main entry point thing is a valid point, it does not make the library completely unusable.

We've marked this issue as stale because there hasn't been any activity for a couple of weeks. If there's no further activity on this issue in the next three days then we'll close it. You can keep the conversation going with just a short comment. Thanks for your contributions.

As there's been no activity since this issue was marked as stale, we are auto-closing it.

this is still the case:
it fails during build:

Failed to compile.
./node_modules/carbon-components-react/es/components/Icon/Icon.js
Module not found: Can't resolve 'carbon-icons' in '~/app/node_modules/carbon-components-react/es/components/Icon'

carbon-components-react code has been using @carbon/icons-react for quite some time. That said, would you just try doing similar thing to carbon-components-react code? Though the main entry point thing is a valid point, it does not make the library completely unusable.

This works, but I think that this should be stated in the docs.

Was this page helpful?
0 / 5 - 0 ratings