Skip to content

Commit

Permalink
feat: add support for .mjs ES6 file type
Browse files Browse the repository at this point in the history
This commit adds a new exported version of the SVG icons to support SSR
development that requires the ,mjs file type.

This update is also specifically restricted to icons, not logos or SVG
tails to keep package size increases at a minimum.

Changes to be committed:
modified:   scripts/generate.js
modified:   src/data/icons.json
modified:   src/data/logoIcons.json
modified:   src/data/restrictedIcons.json
  • Loading branch information
blackfalcon committed Feb 10, 2024
1 parent d538068 commit 3ad4080
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ Within the npm, `@alaskaairux/icons/dist/icons/`, developers may access the SVGs

This repo output two types of JS wrapped SVGs for easy inclusion with front-end frameworks.

#### Default style - iconName.js
#### ES5 style - iconName.js

**Note:** the ES5 `iconName.js` version has been deprecated. Please update to the newly supported `.mjs` file type.

```javascript
module.exports={ ... }
```

#### ES6 style - iconName_es6.js
#### ES6 style - iconName.mjs

**Note:** the `iconName_es6.js` file type is deprecated, be sure to update all references to `.mjs`.

```javascript
export default { ... }
Expand All @@ -58,7 +62,7 @@ In most cases, the default exported JS file will work. But in some cases, the ES
Lit-element requires the ES6 module export syntax for use, so an example dependency reference would be:

```js
import warning from '@alaskaairux/icons/dist/icons/alert/warning_es6.js';
import warning from '@alaskaairux/icons/dist/icons/alert/warning.mjs';
```

#### Non-directive use
Expand All @@ -84,16 +88,16 @@ In the head of your component file, import the [Lit Element directive](https://l

```js
// Lit2.0
import { unsafeSVG } from 'lit/directives/unsafe-svg.js';
import { unsafeSVG } from 'lit/directives/unsafe-svg.mjs';

// Legacy Lit Element
import { unsafeSVG } from 'lit-html/directives/unsafe-svg.js';
import { unsafeSVG } from 'lit-html/directives/unsafe-svg.mjs';
```

Import your icon SVG reference

```js
import warning from '@alaskaairux/icons/dist/icons/alert/warning_es6.js';
import warning from '@alaskaairux/icons/dist/icons/alert/warning.mjs';
```

Use in HTML template
Expand Down Expand Up @@ -235,7 +239,7 @@ arrowDown.svg = arrowDown.svg.replace(/role="img"/g, `role="img" aria-hidden="tr

Adding new icons to this repository requires a few steps.

1. Node.js minimum version `14.x`
1. Node.js minimum version `20.x`
1. Add a new icon `.svg` file to the `src/icons/` directory (see Guidelines below)
1. If the icons are to retain designed color specs, please place the new icon in the `src/icons/fullColor` directory
1. Add **shape schema** to `./src/data/icons.json` file (see example below)
Expand Down Expand Up @@ -291,7 +295,8 @@ The `title` attribute is needed when you may want a simpler name than the file n
"xmlns_xlink": "http://www.w3.org/1999/xlink",
"viewBox": "0 0 24 24",
"path": "/icons",
"style": "ico_squareLarge"
"style": "ico_squareLarge",
"type": "icon"
},
"icons": [
{
Expand Down
6 changes: 6 additions & 0 deletions scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,16 @@ function runGenerator(data) {
}

icons[icon.name] = icon;

// write the static .js file for the icon
fs.writeFileSync( `${buildIconsDir}/${distFilename}.js`, `module.exports=${JSON.stringify(icon)};`);
fs.writeFileSync( `${buildIconsDir}/${distFilename}_es6.js`, `export default ${JSON.stringify(icon)};`);

// restrict new extension to only "type": "icon"
if (icon.type === 'icon') {
fs.writeFileSync( `${buildIconsDir}/${distFilename}.mjs`, `export default ${JSON.stringify(icon)};`);
}

// write new SVGs to ./dist
fs.writeFileSync( `${buildIconsDir}/${distFilename}.svg`, icon.svg);
process.stdout.write(`- `);
Expand Down
3 changes: 2 additions & 1 deletion src/data/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"xmlns_xlink": "http://www.w3.org/1999/xlink",
"viewBox": "0 0 24 24",
"path": "/icons",
"style": "ico_squareLarge"
"style": "ico_squareLarge",
"type": "icon"
},
"icons": [
{
Expand Down
5 changes: 3 additions & 2 deletions src/data/logoIcons.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"xmlns": "http://www.w3.org/2000/svg",
"xmlns_xlink": "http://www.w3.org/1999/xlink",
"path": "/icons/logos",
"style": ""
"style": "",
"type": "logo"
},
"icons": [
{
Expand Down Expand Up @@ -309,7 +310,7 @@
"title": "Airplane tail image for Mokulele Airlines",
"viewBox": "0 0 856 830"
},

{
"name": "tail-M5",
"title": "Airplane tail image for Kenmore Air",
Expand Down
3 changes: 2 additions & 1 deletion src/data/restrictedIcons.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"xmlns": "http://www.w3.org/2000/svg",
"xmlns_xlink": "http://www.w3.org/1999/xlink",
"path": "/icons/restricted",
"style": ""
"style": "",
"type": "restricted"
},
"icons": [
{
Expand Down

0 comments on commit 3ad4080

Please sign in to comment.