|
| 1 | +# @carbon/pictograms-react |
| 2 | + |
| 3 | +> React components for pictograms in digital and software products using the |
| 4 | +> Carbon Design System |
| 5 | +
|
| 6 | +## Getting started |
| 7 | + |
| 8 | +To install `@carbon/pictograms-react` in your project, you will need to run the |
| 9 | +following command using [npm](https://www.npmjs.com/): |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install -S @carbon/pictograms-react |
| 13 | +``` |
| 14 | + |
| 15 | +If you prefer [Yarn](https://yarnpkg.com/en/), use the following command |
| 16 | +instead: |
| 17 | + |
| 18 | +```bash |
| 19 | +yarn add @carbon/pictograms-react |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +Icons in this package support the following sizes: `16`, `20`, `24`, and `32` |
| 25 | +pixels. These sizes refer to the width and height of the icon. You can import an |
| 26 | +icon component into your project by referring to its name and size: |
| 27 | + |
| 28 | +```jsx |
| 29 | +import { Add24 } from '@carbon/pictograms-react'; |
| 30 | +``` |
| 31 | + |
| 32 | +We also provide CommonJS and UMD files in the `lib` and `umd` directories, |
| 33 | +respectively. |
| 34 | + |
| 35 | +To import using CommonJS, you can do the following: |
| 36 | + |
| 37 | +```js |
| 38 | +const { Add24 } = require('@carbon/pictograms-react'); |
| 39 | +``` |
| 40 | + |
| 41 | +_Note: if you would like to find the import path for an icon, you can reference |
| 42 | +our |
| 43 | +[Icon Library](https://www.carbondesignsystem.com/guidelines/iconography/library)_ |
| 44 | + |
| 45 | +### Icon fill |
| 46 | + |
| 47 | +All icons from the library support being styled by the `fill` property. You can |
| 48 | +change the color of an icon by passing in a custom class name that sets this |
| 49 | +property (preferred), or by passing in an inline style. For example: |
| 50 | + |
| 51 | +```css |
| 52 | +// CSS custom class name to set the fill of the icon to `rebeccapurple` |
| 53 | +svg.my-custom-class { |
| 54 | + fill: rebeccapurple; |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +```jsx |
| 59 | +import { Airplane } from '@carbon/pictograms-react'; |
| 60 | + |
| 61 | +function MyComponent() { |
| 62 | + return ( |
| 63 | + <button> |
| 64 | + <Airplane aria-label="Add" className="my-custom-class" /> |
| 65 | + </button> |
| 66 | + ); |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +### Focus and `aria-label` |
| 71 | + |
| 72 | +By default, the icon components from `@carbon/pictograms-react` are treated as |
| 73 | +decorative content. This means that we set `aria-hidden="true"` unless certain |
| 74 | +props are passed to the component. |
| 75 | + |
| 76 | +If you would like the icon to be announced by a screen reader, you can supply an |
| 77 | +`aria-label` or `aria-labelledby`. For example: |
| 78 | + |
| 79 | +```jsx |
| 80 | +import { Airplane } from '@carbon/pictograms-react'; |
| 81 | + |
| 82 | +function MyComponent() { |
| 83 | + return ( |
| 84 | + <button> |
| 85 | + <Airplane aria-label="Add" /> |
| 86 | + </button> |
| 87 | + ); |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +Doing this will add the appropriate `role` to the `<svg>` node, as well. |
| 92 | + |
| 93 | +If you would like the `<svg>` to receive focus, you will need to pass in a |
| 94 | +`tabIndex` value. For example: |
| 95 | + |
| 96 | +```jsx |
| 97 | +import { Airplane } from '@carbon/pictograms-react'; |
| 98 | + |
| 99 | +function MyComponent() { |
| 100 | + return <Airplane aria-label="Add" tabIndex="0" />; |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +Including `tabIndex` and `aria-label` (or `aria-labelledby`) will set the |
| 105 | +corresponding `tabindex` on the underlying `<svg>` and verify support in older |
| 106 | +browsers like Internet Explorer 11 by setting `focusable` to `true`. |
| 107 | + |
| 108 | +## 🙌 Contributing |
| 109 | + |
| 110 | +We're always looking for contributors to help us fix bugs, build new features, |
| 111 | +or help us improve the project documentation. If you're interested, definitely |
| 112 | +check out our [Contributing Guide](/.github/CONTRIBUTING.md)! 👀 |
| 113 | + |
| 114 | +## 📝 License |
| 115 | + |
| 116 | +Licensed under the [Apache 2.0 License](/LICENSE). |
0 commit comments