@carbon/icon-helpers 0.0.1-alpha.25 → 0.0.1-alpha.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -0
- package/es/index.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +2 -2
- package/umd/index.js +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,85 @@ command instead:
|
|
|
19
19
|
yarn add @carbon/icon-helpers
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
`@carbon/icon-helpers` provides a couple of helpers for rendering `<svg>` nodes in a document, or to help get the correct attributes to
|
|
25
|
+
set on an `<svg>` node. These include:
|
|
26
|
+
|
|
27
|
+
| Name | Type | Description |
|
|
28
|
+
| ------------------ | --------------------------------- | ---------------------------------------------------------------------------- |
|
|
29
|
+
| `getAttributes` | `(attributes: Object) => Object` | Get the attributes for an `<svg>` node |
|
|
30
|
+
| `formatAttributes` | `(attributes: Object) => String` | Format the attributes into a string that can be applied to a node in the DOM |
|
|
31
|
+
| `toString` | `(descriptor: Object) => String` | Format the given icon descriptor into a string. Useful for templates |
|
|
32
|
+
| `toSVG` | `(descriptor: Object) => DOMNode` | Format the given icon descriptor into a DOM node |
|
|
33
|
+
|
|
34
|
+
For most of the methods, `attributes` corresponds with whatever the
|
|
35
|
+
name and value would be if you were writing the HTML for the `<svg>`.
|
|
36
|
+
For example, if we wanted to set `width` and `height` we would do the
|
|
37
|
+
following:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const { getAttributes } = require('@carbon/icon-helpers');
|
|
41
|
+
const attributes = getAttributes({ width: 20, height: 20 });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
In order for the icon to be considered focusable, you will need to
|
|
45
|
+
provide either `aria-label`, `aria-labelledby`, or `title` in the
|
|
46
|
+
given `attributes` in addition to `tabindex`. For example:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
const { getAttributes } = require('@carbon/icon-helpers');
|
|
50
|
+
const attributes = getAttributes({
|
|
51
|
+
'aria-label': 'My icon label',
|
|
52
|
+
tabindex: '0',
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Icon descriptors
|
|
57
|
+
|
|
58
|
+
An icon descriptor is the term we use to describe icon objects
|
|
59
|
+
exported by `@carbon/icons`. By default, they will have the following
|
|
60
|
+
shape:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
{
|
|
64
|
+
elem: 'svg',
|
|
65
|
+
attrs: {
|
|
66
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
67
|
+
viewBox: '0 0 16 16',
|
|
68
|
+
width: 16,
|
|
69
|
+
height: 16,
|
|
70
|
+
},
|
|
71
|
+
content: [
|
|
72
|
+
{
|
|
73
|
+
elem: 'path',
|
|
74
|
+
attrs: {
|
|
75
|
+
d: '...',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
name: 'IconName',
|
|
80
|
+
size: 16,
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
You can import these definitions directly from `@carbon/icons` and use
|
|
85
|
+
them alongside `toSVG` or `toString` by doing:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import { IconName } from '@carbon/icons';
|
|
89
|
+
import { toString, toSVG } from '@carbon/icon-helpers';
|
|
90
|
+
|
|
91
|
+
const iconString = toString(IconName);
|
|
92
|
+
const iconSVG = toSVG({
|
|
93
|
+
...IconName,
|
|
94
|
+
attrs: {
|
|
95
|
+
...IconName.attrs,
|
|
96
|
+
myCustomAttribute: 'myCustomAttributeValue',
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
22
101
|
## 🙌 Contributing
|
|
23
102
|
|
|
24
103
|
We're always looking for contributors to help us fix bugs, build new
|
package/es/index.js
CHANGED
|
@@ -83,7 +83,7 @@ var defaultAttributes = {
|
|
|
83
83
|
preserveAspectRatio: 'xMidYMid meet',
|
|
84
84
|
// Reference:
|
|
85
85
|
// https://github.com/ckeditor/ckeditor5/issues/668#issuecomment-344844027
|
|
86
|
-
style: '
|
|
86
|
+
style: 'will-change: transform;'
|
|
87
87
|
};
|
|
88
88
|
/**
|
|
89
89
|
* Get supplementary HTML attributes for a given <svg> element based on existing
|
package/lib/index.js
CHANGED
|
@@ -87,7 +87,7 @@ var defaultAttributes = {
|
|
|
87
87
|
preserveAspectRatio: 'xMidYMid meet',
|
|
88
88
|
// Reference:
|
|
89
89
|
// https://github.com/ckeditor/ckeditor5/issues/668#issuecomment-344844027
|
|
90
|
-
style: '
|
|
90
|
+
style: 'will-change: transform;'
|
|
91
91
|
};
|
|
92
92
|
/**
|
|
93
93
|
* Get supplementary HTML attributes for a given <svg> element based on existing
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon/icon-helpers",
|
|
3
3
|
"description": "Helpers used alongside icons for digital and software products using the Carbon Design System",
|
|
4
|
-
"version": "0.0.1-alpha.
|
|
4
|
+
"version": "0.0.1-alpha.26",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "es/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"clean": "rimraf es lib umd"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@carbon/bundler": "0.0.1-alpha.
|
|
30
|
+
"@carbon/bundler": "0.0.1-alpha.26",
|
|
31
31
|
"rimraf": "^2.6.2"
|
|
32
32
|
},
|
|
33
33
|
"sideEffects": false
|
package/umd/index.js
CHANGED
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
preserveAspectRatio: 'xMidYMid meet',
|
|
90
90
|
// Reference:
|
|
91
91
|
// https://github.com/ckeditor/ckeditor5/issues/668#issuecomment-344844027
|
|
92
|
-
style: '
|
|
92
|
+
style: 'will-change: transform;'
|
|
93
93
|
};
|
|
94
94
|
/**
|
|
95
95
|
* Get supplementary HTML attributes for a given <svg> element based on existing
|