Skip to content

Commit 0b66dd3

Browse files
authored
feat(pictograms-react): add pictograms-react (carbon-design-system#3850)
* feat(pictograms-react): add pictograms-react * docs(pictograms-react): remove two-tone reference
1 parent beef8e4 commit 0b66dd3

File tree

10 files changed

+8023
-0
lines changed

10 files changed

+8023
-0
lines changed

packages/pictograms-react/.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/__mocks__/**
2+
**/__tests__/**
3+
**/examples/**
4+
**/tasks/**

packages/pictograms-react/README.md

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn-offline-mirror false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '@storybook/addon-actions/register';
2+
import '@storybook/addon-links/register';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { configure } from '@storybook/react';
2+
3+
// automatically import all files ending in *.stories.js
4+
const req = require.context('../stories', true, /\.stories\.js$/);
5+
function loadStories() {
6+
req.keys().forEach(filename => req(filename));
7+
}
8+
9+
configure(loadStories, module);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "carbon-icons-react-storybook",
3+
"license": "Apache-2.0",
4+
"scripts": {
5+
"storybook": "start-storybook -p 6006",
6+
"build-storybook": "build-storybook"
7+
},
8+
"dependencies": {},
9+
"devDependencies": {
10+
"@babel/core": "^7.4.5",
11+
"@storybook/addon-actions": "^5.1.3",
12+
"@storybook/addon-links": "^5.1.3",
13+
"@storybook/addons": "^5.1.3",
14+
"@storybook/react": "^5.1.3",
15+
"babel-loader": "^8.0.6"
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Airplane } from '../../../es';
2+
import { storiesOf } from '@storybook/react';
3+
import { action } from '@storybook/addon-actions';
4+
import { linkTo } from '@storybook/addon-links';
5+
import React from 'react';
6+
7+
storiesOf('Icon', module)
8+
.add('default', () => <Airplane />)
9+
.add('with aria-label', () => <Airplane aria-label="Label" />)
10+
.add('with focus', () => <Airplane aria-label="Label" tabIndex="0" />);

0 commit comments

Comments
 (0)