-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(icons-workflow): add workflow icons package
- Loading branch information
Showing
15 changed files
with
624 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src/icons | ||
src/icons.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
## Description | ||
|
||
[Spectrum Workflow Icons](https://spectrum.adobe.com/page/icons/) delivered in a flexible template tag so that they can be leveraged across various frameworks. The default export of this package pre-applies the `html` template tag from `lit-html` for ease of use in the Spectrum Web Components library. Please remember to consult Spectrum's [Iconography Guidelines](https://spectrum.adobe.com/page/iconography/) when planning how to leverage these icons in the visual delivery of your application. For technical information on using these iconos in projects powered by various javascript frameworks, check out the "Extended use cases" sectino below. | ||
|
||
### Installation | ||
|
||
``` | ||
npm install @spectrum-web-components/icons-workflow | ||
# or | ||
yarn add @spectrum-web-components/icons-workflow | ||
``` | ||
|
||
### Usage | ||
|
||
With the default exports of the packages prepared with the `html` template tag from `lit-html`, the default value of an icon export will be as follows: | ||
|
||
```js | ||
import { LitElement, html } from 'lit-element'; | ||
import '@spectrum-web-components/icon'; | ||
import { CircleIcon } from '@spectrum-web-components/icons-workflow'; | ||
|
||
class ElementWithIcon extends LitElement { | ||
protected render(): TemplateResult { | ||
return html` | ||
<sp-icon slot="icon"> | ||
${CircleIcon()} | ||
</sp-icon> | ||
` | ||
} | ||
} | ||
|
||
customElements.define('element-with-icon', ElementWithIcon); | ||
``` | ||
|
||
Every icons can be customized via the following options: | ||
|
||
```js | ||
{ | ||
width: 24, // number outlining the width to deliver the SVG element with | ||
height: 24, // number outlining the height to delivery the SVG element with | ||
hidden: false, // boolean representing whether to apply the `aria-hidden` attribute | ||
title: 'Icon title', // string of the title to deliver the icon with | ||
} | ||
``` | ||
|
||
### Extended use cases | ||
|
||
The default exports of this package are pre-wrapped via `setCustomTemplateLiteralTag` in the `html` template tag from `lit-html`, and work liek the following:: | ||
|
||
```js | ||
import { CircleIcon } from '@spectrum-web-components/icons-workflow'; | ||
|
||
console.log(CircleIcon()); | ||
|
||
/*** | ||
TemplateResult {strings: Array[1], values: Array[0], type: "html", processor: DefaultTemplateProcessor, constructor: Object} | ||
***/ | ||
``` | ||
|
||
When working in the context of other frameworks, it is possible to import the icons with a generic template tag as follows: | ||
|
||
```js | ||
import { CircleIcon } from '@spectrum-web-components/icons-workflow/lib/icons.js'; | ||
|
||
console.log(CircleIcon()); | ||
|
||
/*** | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 36 36" | ||
role="img" | ||
fill="currentColor" | ||
height="24" | ||
width="24" | ||
aria-hidden="false" | ||
aria-label="Circle" | ||
> | ||
<circle cx="18" cy="18" r="16"></circle> | ||
</svg> | ||
***/ | ||
``` | ||
|
||
What's more, if you're already working with a specific parser in your project, you can assign it as the one to use when delivering the icons in order to be sure that the SVG content is delivered as parsed content to your final template. The means if you were working with Preact via the `htm` tag as bound to the provided hyperscript function: | ||
|
||
```js | ||
import { | ||
CircleIcon, | ||
setCustomTemplateLiteralTag, | ||
} from '@spectrum-web-components/icons-workflow/lib/icons.js'; | ||
import htm from 'htm'; | ||
import { h } from 'preact'; | ||
|
||
const hPreact = htm.bind(h); | ||
|
||
setCustomTemplateLiteralTag(hPreact); | ||
|
||
console.log(CircleIcon()); | ||
|
||
/*** | ||
VNode {nodeName: "svg", children: Array[1], attributes: Object, key: undefined, constructor: Object} | ||
***/ | ||
``` | ||
|
||
In this way the icons exported by `@spectrum-web-components/icons-workflow` can be leveraged in projects powered by the the likes of hyperHTML, lighterhtml, lit-html, Preact, React, Vanilla JS, Vue.js, and more! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
Copyright 2020 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const glob = require('glob'); | ||
const path = require('path'); | ||
const cheerio = require('cheerio'); | ||
const prettier = require('prettier'); | ||
const Case = require('case'); | ||
|
||
const rootDir = path.join(__dirname, '../../../'); | ||
|
||
const iconsPath = process.argv.slice(2)[0]; | ||
const keepColors = process.argv.slice(2)[1]; | ||
|
||
const disclaimer = ` | ||
/* | ||
Copyright 2020 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/`; | ||
|
||
glob(`${rootDir}/node_modules/${iconsPath}/**.svg`, (err, icons) => { | ||
if (!fs.existsSync(`${rootDir}packages/icons-workflow/src`)) { | ||
fs.mkdirSync(`${rootDir}packages/icons-workflow/src`); | ||
} | ||
if (!fs.existsSync(`${rootDir}packages/icons-workflow/src/icons`)) { | ||
fs.mkdirSync(`${rootDir}packages/icons-workflow/src/icons`); | ||
} | ||
fs.writeFileSync( | ||
path.join(rootDir, 'packages', 'icons-workflow', 'src', 'icons.ts'), | ||
disclaimer, | ||
'utf-8' | ||
); | ||
|
||
icons.forEach((i) => { | ||
const svg = fs.readFileSync(i, 'utf-8'); | ||
const id = path | ||
.basename(i, '.svg') | ||
.replace('S_', '') | ||
.replace('_22_N', ''); | ||
const ComponentName = id === 'github' ? 'GitHub' : Case.pascal(id); | ||
const $ = cheerio.load(svg, { | ||
xmlMode: true, | ||
}); | ||
const title = Case.capital(id); | ||
const fileName = `${id}.ts`; | ||
const location = path.join( | ||
rootDir, | ||
'packages/icons-workflow/src/icons', | ||
fileName | ||
); | ||
|
||
if (!Number.isNaN(Number(ComponentName[0]))) { | ||
return; | ||
} | ||
|
||
$('*').each((index, el) => { | ||
if (el.name === 'svg') { | ||
$(el).attr('aria-hidden', '...'); | ||
$(el).attr('role', 'img'); | ||
if (keepColors !== 'keep') { | ||
$(el).attr('fill', 'currentColor'); | ||
} | ||
$(el).attr('aria-label', '${title}'); | ||
$(el).removeAttr('id'); | ||
} | ||
if (el.name === 'defs') { | ||
$(el).remove(); | ||
} | ||
Object.keys(el.attribs).forEach((x) => { | ||
if (x === 'class') { | ||
$(el).removeAttr(x); | ||
} | ||
if (keepColors !== 'keep' && x === 'stroke') { | ||
$(el).attr(x, 'currentColor'); | ||
} | ||
if (keepColors !== 'keep' && x === 'fill') { | ||
$(el).attr(x, 'currentColor'); | ||
} | ||
if (el.name === 'svg') { | ||
if (x === 'width' || x === 'height') { | ||
$(el).attr(x, '${' + x + '}'); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
const iconLiteral = ` | ||
${disclaimer} | ||
import {tag as html, TemplateResult} from '../custom-tag.js'; | ||
export {setCustomTemplateLiteralTag} from '../custom-tag.js'; | ||
export const ${ComponentName}Icon = ({ | ||
width = 24, | ||
height = 24, | ||
hidden = false, | ||
title = '${title}', | ||
} = {},): string | TemplateResult => { | ||
return html\`${$('svg') | ||
.toString() | ||
.replace( | ||
'aria-hidden="..."', | ||
"aria-hidden=\"${hidden ? 'true' : 'false'}\"" | ||
)}\`; | ||
} | ||
`; | ||
|
||
const icon = prettier.format(iconLiteral, { | ||
printWidth: 100, | ||
tabWidth: 2, | ||
useTabs: false, | ||
semi: true, | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
bracketSpacing: true, | ||
jsxBracketSameLine: false, | ||
arrowParens: 'avoid', | ||
parser: 'typescript', | ||
}); | ||
|
||
fs.writeFileSync(location, icon, 'utf-8'); | ||
|
||
const exportString = `export {${ComponentName}Icon} from './icons/${id}.js';\r\n`; | ||
fs.appendFileSync( | ||
path.join(rootDir, 'packages', 'icons-workflow', 'src', 'icons.ts'), | ||
exportString, | ||
'utf-8' | ||
); | ||
}); | ||
|
||
const exportString = `\r\nexport { setCustomTemplateLiteralTag } from './custom-tag.js';\r\n`; | ||
fs.appendFileSync( | ||
path.join(rootDir, 'packages', 'icons-workflow', 'src', 'icons.ts'), | ||
exportString, | ||
'utf-8' | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"name": "@spectrum-web-components/icons-workflow", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/adobe/spectrum-web-components.git", | ||
"directory": "packages/icons-workflow" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/adobe/spectrum-web-components/issues" | ||
}, | ||
"homepage": "https://adobe.github.io/spectrum-web-components/components/icons-workflow", | ||
"keywords": [ | ||
"spectrum css", | ||
"web components", | ||
"lit-element", | ||
"lit-html" | ||
], | ||
"version": "0.0.1", | ||
"description": "", | ||
"main": "lib/index.js", | ||
"module": "lib/index.js", | ||
"type": "module", | ||
"files": [ | ||
"custom-elements.json", | ||
"/lib/", | ||
"/src/" | ||
], | ||
"scripts": { | ||
"build": "node ./bin/build @adobe/spectrum-css-workflow-icons/dist/18" | ||
}, | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@spectrum-web-components/iconset": "^0.1.7", | ||
"tslib": "^1.10.0" | ||
}, | ||
"devDependencies": { | ||
"@adobe/spectrum-css-workflow-icons": "^1.0.0", | ||
"@spectrum-web-components/icon": "^0.4.4", | ||
"@spectrum-web-components/iconset": "^0.1.7", | ||
"case": "^1.6.1", | ||
"cheerio": "^1.0.0-rc.2", | ||
"feather-icons": "^4.14.0", | ||
"fs": "^0.0.1-security", | ||
"glob": "^7.1.3", | ||
"http-server": "^0.11.1", | ||
"path": "^0.12.7", | ||
"prettier": "^1.16.1" | ||
}, | ||
"peerDependencies": { | ||
"lit-element": "^2.1.0", | ||
"lit-html": "^1.0.0" | ||
} | ||
} |
Oops, something went wrong.