@octaviaflow/icon-helpers 1.0.0
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 +117 -0
- package/es/index.js +1 -0
- package/lib/index.cjs +1 -0
- package/package.json +58 -0
- package/telemetry.yml +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# @octaviaflow/icon-helpers
|
|
2
|
+
|
|
3
|
+
> Helpers used alongside icons for digital and software products using the
|
|
4
|
+
> Carbon Design System
|
|
5
|
+
|
|
6
|
+
## Getting started
|
|
7
|
+
|
|
8
|
+
To install `@octaviaflow/icon-helpers` 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 @octaviaflow/icon-helpers
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If you prefer [Yarn](https://yarnpkg.com/en/), use the following command
|
|
16
|
+
instead:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
yarn add @octaviaflow/icon-helpers
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
`@octaviaflow/icon-helpers` provides a couple of helpers for rendering `<svg>` nodes
|
|
25
|
+
in a document, or to help get the correct attributes to set on an `<svg>` node.
|
|
26
|
+
These include:
|
|
27
|
+
|
|
28
|
+
| Name | Type | Description |
|
|
29
|
+
| ------------------ | --------------------------------- | ---------------------------------------------------------------------------- |
|
|
30
|
+
| `getAttributes` | `(attributes: Object) => Object` | Get the attributes for an `<svg>` node |
|
|
31
|
+
| `formatAttributes` | `(attributes: Object) => String` | Format the attributes into a string that can be applied to a node in the DOM |
|
|
32
|
+
| `toString` | `(descriptor: Object) => String` | Format the given icon descriptor into a string. Useful for templates |
|
|
33
|
+
| `toSVG` | `(descriptor: Object) => DOMNode` | Format the given icon descriptor into a DOM node |
|
|
34
|
+
|
|
35
|
+
For most of the methods, `attributes` corresponds with whatever the name and
|
|
36
|
+
value would be if you were writing the HTML for the `<svg>`. For example, if we
|
|
37
|
+
wanted to set `width` and `height` we would do the following:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const { getAttributes } = require('@octaviaflow/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 provide
|
|
45
|
+
either `aria-label`, `aria-labelledby`, or `title` in the given `attributes` in
|
|
46
|
+
addition to `tabindex`. For example:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
const { getAttributes } = require('@octaviaflow/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 exported by
|
|
59
|
+
`@octaviaflow/icons`. By default, they will have the following shape:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
{
|
|
63
|
+
elem: 'svg',
|
|
64
|
+
attrs: {
|
|
65
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
66
|
+
viewBox: '0 0 16 16',
|
|
67
|
+
width: 16,
|
|
68
|
+
height: 16,
|
|
69
|
+
},
|
|
70
|
+
content: [
|
|
71
|
+
{
|
|
72
|
+
elem: 'path',
|
|
73
|
+
attrs: {
|
|
74
|
+
d: '...',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
name: 'IconName',
|
|
79
|
+
size: 16,
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
You can import these definitions directly from `@octaviaflow/icons` and use them
|
|
84
|
+
alongside `toSVG` or `toString` by doing:
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
import { IconName } from '@octaviaflow/icons';
|
|
88
|
+
import { toString, toSVG } from '@octaviaflow/icon-helpers';
|
|
89
|
+
|
|
90
|
+
const iconString = toString(IconName);
|
|
91
|
+
const iconSVG = toSVG({
|
|
92
|
+
...IconName,
|
|
93
|
+
attrs: {
|
|
94
|
+
...IconName.attrs,
|
|
95
|
+
myCustomAttribute: 'myCustomAttributeValue',
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 🙌 Contributing
|
|
101
|
+
|
|
102
|
+
We're always looking for contributors to help us fix bugs, build new features,
|
|
103
|
+
or help us improve the project documentation. If you're interested, definitely
|
|
104
|
+
check out our [Contributing Guide](/.github/CONTRIBUTING.md)! 👀
|
|
105
|
+
|
|
106
|
+
## 📝 License
|
|
107
|
+
|
|
108
|
+
Licensed under the [Apache 2.0 License](/LICENSE).
|
|
109
|
+
|
|
110
|
+
## <picture><source height="20" width="20" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ibm-telemetry/telemetry-js/main/docs/images/ibm-telemetry-dark.svg"><source height="20" width="20" media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/ibm-telemetry/telemetry-js/main/docs/images/ibm-telemetry-light.svg"><img height="20" width="20" alt="IBM Telemetry" src="https://raw.githubusercontent.com/ibm-telemetry/telemetry-js/main/docs/images/ibm-telemetry-light.svg"></picture> IBM Telemetry
|
|
111
|
+
|
|
112
|
+
This package uses IBM Telemetry to collect de-identified and anonymized metrics
|
|
113
|
+
data. By installing this package as a dependency you are agreeing to telemetry
|
|
114
|
+
collection. To opt out, see
|
|
115
|
+
[Opting out of IBM Telemetry data collection](https://github.com/ibm-telemetry/telemetry-js/tree/main#opting-out-of-ibm-telemetry-data-collection).
|
|
116
|
+
For more information on the data being collected, please see the
|
|
117
|
+
[IBM Telemetry documentation](https://github.com/ibm-telemetry/telemetry-js/tree/main#ibm-telemetry-collection-basics).
|
package/es/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l={focusable:"false",preserveAspectRatio:"xMidYMid meet"};function s({width:n,height:e,viewBox:o=`0 0 ${n} ${e}`,...i}={}){let{tabindex:r,...u}=i,t={...l,...u,width:n,height:e,viewBox:o};return t["aria-label"]||t["aria-labelledby"]||t.title?(t.role="img",r!=null&&(t.focusable="true",t.tabindex=r)):t["aria-hidden"]=!0,t}function a(n){let{elem:e="svg",attrs:o={},content:i=[]}=n,r=i.map(a).join("");return e!=="svg"?`<${e} ${c(o)}>${r}</${e}>`:`<${e} ${c(s(o))}>${r}</${e}>`}function c(n){return Object.keys(n).reduce((e,o,i)=>{let r=`${o}="${n[o]}"`;return i===0?r:e+" "+r},"")}function f(n){let{elem:e="svg",attrs:o={},content:i=[]}=n,r=document.createElementNS("http://www.w3.org/2000/svg",e),u=e!=="svg"?o:s(o);Object.keys(u).forEach(t=>{r.setAttribute(t,o[t])});for(let t=0;t<i.length;t++)r.appendChild(f(i[t]));return r}export{l as defaultAttributes,c as formatAttributes,s as getAttributes,f as toSVG,a as toString};
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var g=(r,t)=>{for(var o in t)l(r,o,{get:t[o],enumerable:!0})},$=(r,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of p(t))!b.call(r,e)&&e!==o&&l(r,e,{get:()=>t[e],enumerable:!(i=d(t,e))||i.enumerable});return r};var A=r=>$(l({},"__esModule",{value:!0}),r);var x={};g(x,{defaultAttributes:()=>m,formatAttributes:()=>u,getAttributes:()=>s,toSVG:()=>a,toString:()=>c});module.exports=A(x);var m={focusable:"false",preserveAspectRatio:"xMidYMid meet"};function s({width:r,height:t,viewBox:o=`0 0 ${r} ${t}`,...i}={}){let{tabindex:e,...f}=i,n={...m,...f,width:r,height:t,viewBox:o};return n["aria-label"]||n["aria-labelledby"]||n.title?(n.role="img",e!=null&&(n.focusable="true",n.tabindex=e)):n["aria-hidden"]=!0,n}function c(r){let{elem:t="svg",attrs:o={},content:i=[]}=r,e=i.map(c).join("");return t!=="svg"?`<${t} ${u(o)}>${e}</${t}>`:`<${t} ${u(s(o))}>${e}</${t}>`}function u(r){return Object.keys(r).reduce((t,o,i)=>{let e=`${o}="${r[o]}"`;return i===0?e:t+" "+e},"")}function a(r){let{elem:t="svg",attrs:o={},content:i=[]}=r,e=document.createElementNS("http://www.w3.org/2000/svg",t),f=t!=="svg"?o:s(o);Object.keys(f).forEach(n=>{e.setAttribute(n,o[n])});for(let n=0;n<i.length;n++)e.appendChild(a(i[n]));return e}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@octaviaflow/icon-helpers",
|
|
3
|
+
"description": "Helpers used alongside icons for digital and software products using the OctaviaFlow Design System",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"main": "lib/index.cjs",
|
|
7
|
+
"module": "es/index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./es/index.js",
|
|
12
|
+
"require": "./lib/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/octaviaflow-design-system.git",
|
|
18
|
+
"directory": "packages/icon-helpers"
|
|
19
|
+
},
|
|
20
|
+
"bugs": "https://github.com/octaviaflow-design-system/issues",
|
|
21
|
+
"files": [
|
|
22
|
+
"es",
|
|
23
|
+
"lib",
|
|
24
|
+
"umd",
|
|
25
|
+
"telemetry.yml"
|
|
26
|
+
],
|
|
27
|
+
"keywords": [
|
|
28
|
+
"octaviaflow",
|
|
29
|
+
"icon-helpers",
|
|
30
|
+
"elements",
|
|
31
|
+
"components",
|
|
32
|
+
"react"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@babel/runtime": "^7.25.0",
|
|
39
|
+
"tslib": "^2.6.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build:es": "esbuild src/index.ts --bundle --minify --outdir=es --target=es2020 --format=esm",
|
|
43
|
+
"build:cjs": "esbuild src/index.ts --bundle --minify --outdir=lib --target=es2020 --format=cjs --out-extension:.js=.cjs",
|
|
44
|
+
"build:types": "tsc",
|
|
45
|
+
"build": "bun run clean && bun run build:es & bun run build:cjs & bun run build:types",
|
|
46
|
+
"clean": "rimraf es lib umd"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@babel/core": "^7.28.6",
|
|
50
|
+
"@babel/preset-env": "^7.28.6",
|
|
51
|
+
"@octaviaflow/cli": "^1.0.0",
|
|
52
|
+
"esbuild": "^0.27.2",
|
|
53
|
+
"rimraf": "^6.0.0",
|
|
54
|
+
"typescript": "^5.9.3",
|
|
55
|
+
"typescript-config-octaviaflow": "^1.0.0"
|
|
56
|
+
},
|
|
57
|
+
"sideEffects": false
|
|
58
|
+
}
|
package/telemetry.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://unpkg.com/@octaviaflow/telemetry-config-schema@v1.0.0/dist/config.schema.json
|
|
2
|
+
version: 1
|
|
3
|
+
projectId: '56319a6c-7174-4766-850c-59307f0d1fe6'
|
|
4
|
+
name: 'OctaviaFlow Icon Helpers'
|
|
5
|
+
storage:
|
|
6
|
+
type: 'file'
|
|
7
|
+
file:
|
|
8
|
+
directory: '/Volumes/Main/Projects/OctaviaFlow-Design-System/telemetry-logs'
|
|
9
|
+
fileNamePattern: 'octaviaflow-icon-helpers-{timestamp}.json'
|
|
10
|
+
maxFileSizeMB: 10
|
|
11
|
+
compress: false
|
|
12
|
+
collect:
|
|
13
|
+
npm:
|
|
14
|
+
dependencies: null
|
|
15
|
+
js:
|
|
16
|
+
functions: {}
|
|
17
|
+
tokens: null
|