Compare commits

...
61 Commits
Author SHA1 Message Date
ionitron 89cba595a7 8.1.1 2026-11-19 20:46:43 +00:00
Shane 02456263e0 Merge commit from fork 2026-11-19 12:31:02 -08:00
Shane a00f3134a5 chore(release): sync package version with published 8.1.0 release (#1521) 2026-11-19 12:30:04 -08:00
d1e2c48641 feat(icon): add font icon support to ion-icon (#1502)
Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
Co-authored-by: ionitron <hi@ionicframework.com>
2026-07-28 16:36:24 -04:00
b2d0708a51 chore(): improve build, lint, and test structure (#1498)
Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
Co-authored-by: ionitron <hi@ionicframework.com>
2026-07-28 14:18:21 -04:00
OS-jacobbell 2a8e43aff0 chore(workflows): refactor github workflows for new npm auth (#1486) 2026-03-09 12:03:24 -06:00
ionitron a9d1b7e23d 8.0.13 2025-07-08 22:02:57 +00:00
Christian Bromann 8f5ebc425c fix: publish missing svgs 2025-07-08 15:02:14 -07:00
ionitron 809a6d2a45 8.0.12 2025-07-08 21:44:18 +00:00
Christian Bromann 5d34943550 fix: add missing collection-copy script 2025-07-08 14:43:35 -07:00
ionitron f81cf0034b 8.0.11 2025-07-07 22:50:23 +00:00
Christian Bromann 76a68e4629 fix(ci): run test when pushing to main 2025-07-07 15:46:42 -07:00
Christian Bromann 53fb2905fd testing: add new jest runner 2025-07-07 15:43:57 -07:00
Christian Bromann a1a8ba85bb fix: update dependencies 2025-07-07 14:02:39 -07:00
Brandy SmithandBrandy Smith 72e8c23ecd fix(ionicons): add direct ion-icon component import path (#1464)
Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
2025-07-07 14:02:08 -07:00
ionitron d584c93c21 8.0.10 2025-07-02 19:08:40 +00:00
Sean Perkins 0e51cf1595 fix: stencil projects can build ionicons (#1462) 2025-07-02 12:08:02 -07:00
ionitron a9556e4901 8.0.9 2025-06-02 16:15:52 +00:00
Masahiko Sakakibara 505a7caeaa fix(): export ionicons.json in package exports (#1456) 2025-06-02 09:15:12 -07:00
Kenrick Tandrian 161eb6ad3c fix(docs): change module links (#1454) 2025-05-14 14:05:39 -07:00
ionitron 5d393395d3 8.0.8 2025-05-06 18:22:55 +00:00
Christian Bromann ac1b23751d chore: cleanup CHANGELOG file 2025-05-06 11:22:15 -07:00
Christian Bromann d9a095dea4 fix: fix export file path for /icons 2025-05-06 11:21:24 -07:00
ionitron 3dab196131 8.0.7 2025-05-06 18:17:46 +00:00
Brandy SmithandBrandy Smith 7f73379a7c docs(changelog): correct links and add two recent releases (#1451)
Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
2025-05-06 07:59:07 -07:00
ionitron abda804f39 8.0.6 2025-05-05 22:56:10 +00:00
Christian Bromann b9858daaab fix(ci): uncomment ci pipeline 2025-05-05 15:55:32 -07:00
ionitron 0807bbe045 8.0.5 2025-05-05 22:52:55 +00:00
Christian Bromann 0269306a15 fix(ci): remove auth step 2025-05-05 15:52:04 -07:00
Christian Bromann be3fcd7a70 fix(ci): fix auth command 2025-05-05 15:50:01 -07:00
Christian Bromann 4921d70e32 fix(ci): fix auth command 2025-05-05 15:48:06 -07:00
Christian Bromann bef34677cd fix(ci): fix propagating version 2025-05-05 15:44:13 -07:00
Christian Bromann 2e393282c9 fix(ci): fix git set up 2025-05-05 15:42:38 -07:00
Christian Bromann ecfff506b9 fix(ci): retrieve new version from package.json 2025-05-05 15:32:25 -07:00
Christian Bromann 87161a14a5 fix(ci): dry run it 2025-05-05 15:24:20 -07:00
Christian Bromann b1893f4ef6 fix(ci): test a different token 2025-05-05 15:22:11 -07:00
Christian Bromann fa5244e544 8.0.4 2025-05-05 15:18:31 -07:00
Christian Bromann d0e18dab3e fix(ci): tweak release pipeline 2025-05-05 15:18:26 -07:00
Christian Bromann e4d8d28253 8.0.3 2025-05-05 15:13:58 -07:00
Christian Bromann 77e5de20c8 fix(ci): set token before push 2025-05-05 15:13:45 -07:00
Christian Bromann 17ea00ef3c 8.0.2 2025-05-05 15:06:01 -07:00
Christian Bromann 04975203b7 8.0.1 2025-05-05 14:56:52 -07:00
Christian Bromann 2ad4148057 fix(ci): set proper token 2025-05-05 14:56:22 -07:00
Christian Bromann 5b23d0a963 fix(ci): set up git before calling npm version 2025-05-05 14:53:56 -07:00
Christian Bromann 987d118b0b ci: update pipelines 2025-05-05 14:52:10 -07:00
Christian Bromann a380c95899 docs: missing ; in readme 2025-05-05 12:20:36 -07:00
Christian Bromann fe60bd2490 docs: clarify usage of addIcons 2025-05-05 12:19:42 -07:00
Christian Bromann ba27560096 fix: exports 2025-05-05 12:15:51 -07:00
Christian Bromann dcca52d3b2 v8.0.0 2025-05-02 08:26:41 -07:00
e04eccc868 breaking: modernize project (#1447)
* chore: update project dependencies

* remove lerna

* update build

* plugin fixes

* Icons do not display when the svg is loaded from a file:// URL in Safari

fixes #1298

* Update path fill in warning-outline.svg exclamation mark

* set currentColor - fixes #1420

* add bell tag to notifications icon - fixes #1090

* add sliders and filters tags to option icon - fixes #1060

* add loveseat tag to bed icon - closes #503

* add contacts tag to people-circle
closes #779

* fix data.json

* update data.json

* set up prettier

* fix contributing link

* prettier after rebase

* add missing rimraf

* add more comments

* run prettier as part of the build

* set module resolution to bundle

* consolidate contributing guidelines and coc as part of the root directory

* fix link

* copy svg into www

* cut me some visual slack

* Update readme.md

Co-authored-by: Brandy Smith <brandyscarney@users.noreply.github.com>

* Update package.json

Co-authored-by: Maria Hutt <thetaPC@users.noreply.github.com>

* Update CONTRIBUTING.md

Co-authored-by: Maria Hutt <thetaPC@users.noreply.github.com>

* remove generating collections

* ensure all directories exist

* only define snapshot tolerance in config

* update dependencies

* Update src/components/icon/request.ts

Co-authored-by: Brandy Smith <brandyscarney@users.noreply.github.com>

* Update src/components/icon/request.ts

Co-authored-by: Brandy Smith <brandyscarney@users.noreply.github.com>

* Update src/components/icon/request.ts

Co-authored-by: Brandy Smith <brandyscarney@users.noreply.github.com>

* Update src/components/icon/request.ts

Co-authored-by: Brandy Smith <brandyscarney@users.noreply.github.com>

* prettier

* update release pipeline

* fix exports

* recommend to use esm.sh as cdn

---------

Co-authored-by: Brandy Smith <brandyscarney@users.noreply.github.com>
Co-authored-by: Maria Hutt <thetaPC@users.noreply.github.com>
2025-05-02 08:04:17 -07:00
Kerk en IT 5266d14dac Resolve #1242 (#1393) 2025-04-16 16:15:09 -07:00
jcesarmobile 4477c02512 chore(ci): update actions to v4 (#1415) 2024-11-19 11:39:07 +01:00
Liam DeBeasi d55d438ef0 chore: merge feature-7.4 2024-05-01 15:19:36 -04:00
Liam DeBeasi 70135edf3a chore: sync 2024-05-01 15:16:30 -04:00
Liam DeBeasi 2ac03a16d4 chore: sync with main 2024-05-01 15:15:44 -04:00
Liam DeBeasi 31c83d9d12 merge release-7.4.0
Release 7.4.0
2024-05-01 15:14:21 -04:00
ionitron 0c34dde9e8 chore(): update package lock files 2024-05-01 19:11:34 +00:00
ionitron f1794e755a v7.4.0 2024-05-01 19:10:54 +00:00
Christian Bromann 87f2094890 feat: export setAssetPath (#1372)
resolves #1302
2024-05-01 14:57:37 -04:00
Liam DeBeasi 0963fe20b7 feat: add X logo (#1371)
resolves #1249
2024-05-01 14:41:10 -04:00
Liam DeBeasi b4ade9d887 feat: update server icon (#1259)
resolves #407
2024-03-22 16:24:15 -04:00
130 changed files with 8331 additions and 23570 deletions
-80
View File
@@ -1,80 +0,0 @@
# Contributing
Thanks for your interest in contributing to Ionicons! :tada:
## Contributing Etiquette
Please see our [Contributor Code of Conduct](./CODE_OF_CONDUCT.md) for information on our rules of conduct.
## Creating an Issue
* If you have a question about using Ionicons, please ask on the [Ionic Forum](http://forum.ionicframework.com/) or in the [Ionic Discord](https://ionic.link/discord).
* It is required that you clearly describe the steps necessary to reproduce the issue you are running into. Although we would love to help our users as much as possible, diagnosing issues without clear reproduction steps is extremely time-consuming and simply not sustainable.
* The issue list of this repository is exclusively for bug reports and feature requests. Non-conforming issues will be closed immediately.
* If you think you have found a bug, or have a new feature idea, please start by making sure it hasn't already been [reported](https://github.com/ionic-team/ionicons/issues?utf8=%E2%9C%93&q=is%3Aissue). You can search through existing issues to see if there is a similar one reported. Include closed issues as it may have been closed with a solution.
* Next, [create a new issue](https://github.com/ionic-team/ionicons/issues/new/choose) that thoroughly explains the problem.
## Creating a Pull Request
* We appreciate you taking the time to contribute! Before submitting a pull request, we ask that you please [create an issue](#creating-an-issue) that explains the bug or feature request and let us know that you plan on creating a pull request for it. If an issue already exists, please comment on that issue letting us know you would like to submit a pull request for it. This helps us to keep track of the pull request and make sure there isn't duplicated effort.
* Looking for an issue to fix? Make sure to look through our issues with the [help wanted](https://github.com/ionic-team/ionicons/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) label!
## Adding or Modifiying Icons
While we appreciate all contributions, please note that we do not accept contributions that add or modify icon SVG assets. All SVG asset modifications are done by Ionic's in-house design team to ensure design consistency across the entire icon set. If there is an icon you need added or an existing icon you need modified please [create a new issue](https://github.com/ionic-team/ionicons/issues/new/choose).
Contributions that fix bugs in or add features to the `ion-icon` component are welcome!
### Setup
1. [Download the installer](https://nodejs.org/) for the LTS version of Node.js. This is the best way to also [install npm](https://blog.npmjs.org/post/85484771375/how-to-install-npm#_=_).
2. Fork this repository.
3. Clone your fork.
4. Create a new branch from `main` for your change.
5. Run `npm install` from the root directory to install dependencies for this package.
6. Run `npm run build` to perform a first time build.
7. [Modify the Icon Component](#modifying-components) if desired.
8. Or, modify and [preview the site](#preview-site).
#### Modifying Components
1. Navigate to the `src/components/` directory and open the `icon` component to modify.
2. Make any changes to the icon component and then [preview the changes](#preview-component-changes).
#### Preview Component Changes
1. Run `npm start` from the root directory to start a local version of the icon test.
2. Modify the icon test as needed in the `index.html` file.
3. If you are modifying icons, you can run `npm run build.files` to re-run the SVG optimization script to verify there are no changes after optimizing the SVG.
<!-- #### Building Changes
TODO -->
### Submit Pull Request
1. [Create a new pull request](https://github.com/ionic-team/ionicons/compare) with the `main` branch as the `base`. You may need to click on `compare across forks` to find your changes.
2. See the [Creating a pull request from a fork](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) GitHub help article for more information.
3. Please fill out the Pull Request template to the best of your ability and include any issues that are related.
## Updating Documentation
The documentation site for Ionicons is located in the [ionicons-site](https://github.com/ionic-team/ionicons-site) repository.
## License
By contributing your code to the ionic-team/ionicons GitHub Repository, you agree to license your contribution under the MIT license.
+2 -2
View File
@@ -1,7 +1,7 @@
name: 🐛 Bug Report name: 🐛 Bug Report
description: Report a bug in the ion-icon component. Incorrect icons should use the "Incorrect Icon" template instead. description: Report a bug in the ion-icon component. Incorrect icons should use the "Incorrect Icon" template instead.
labels: ["triage"] labels: ['triage']
title: "bug: " title: 'bug: '
body: body:
- type: textarea - type: textarea
attributes: attributes:
+3 -3
View File
@@ -1,7 +1,7 @@
name: 💡 Feature Request name: 💡 Feature Request
description: Suggest a new feature for the ion-icon component. Icon requests should use the "Icon Request" template instead. description: Suggest a new feature for the ion-icon component. Icon requests should use the "Icon Request" template instead.
labels: ["triage"] labels: ['triage']
title: "feat: " title: 'feat: '
body: body:
- type: textarea - type: textarea
attributes: attributes:
@@ -20,4 +20,4 @@ body:
- type: textarea - type: textarea
attributes: attributes:
label: Additional Information label: Additional Information
description: Add any other context or screenshots about the feature request here. description: Add any other context or screenshots about the feature request here.
+3 -3
View File
@@ -1,7 +1,7 @@
name: 🚀 Icon Request name: 🚀 Icon Request
description: Request a new icon description: Request a new icon
labels: ["triage"] labels: ['triage']
title: "icon request: " title: 'icon request: '
body: body:
- type: textarea - type: textarea
attributes: attributes:
@@ -16,4 +16,4 @@ body:
- type: textarea - type: textarea
attributes: attributes:
label: Additional Information label: Additional Information
description: Add any other context about the icon request here. description: Add any other context about the icon request here.
+3 -3
View File
@@ -1,7 +1,7 @@
name: 😒 Incorrect Icon name: 😒 Incorrect Icon
description: Report an incorrect icon description: Report an incorrect icon
labels: ["triage"] labels: ['triage']
title: "incorrect icon: " title: 'incorrect icon: '
body: body:
- type: textarea - type: textarea
attributes: attributes:
@@ -14,4 +14,4 @@ body:
label: Expected Behavior label: Expected Behavior
description: A clear description of what the icon should look like. Please include any relevant screenshots. description: A clear description of what the icon should look like. Please include any relevant screenshots.
validations: validations:
required: true required: true
+5 -5
View File
@@ -26,7 +26,7 @@ closeAndLock:
comment: comment:
labels: labels:
- label: "help wanted" - label: 'help wanted'
message: > message: >
This issue has been labeled as `help wanted`. This label is added to issues This issue has been labeled as `help wanted`. This label is added to issues
that we believe would be good for contributors. that we believe would be good for contributors.
@@ -54,13 +54,13 @@ comment:
If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was
not enough for our team to reproduce the issue. not enough for our team to reproduce the issue.
- label: "community feedback wanted" - label: 'community feedback wanted'
message: > message: >
This issue has been labeled as `community feedback wanted`. This label is added to issues that we would like to hear from the community on before moving forward with any final decision on the feature request. This issue has been labeled as `community feedback wanted`. This label is added to issues that we would like to hear from the community on before moving forward with any final decision on the feature request.
If the requested feature is something you would find useful for your applications, please react to the original post with 👍 (`+1`). If you would like to provide an additional use case for the feature, please post a comment. If the requested feature is something you would find useful for your applications, please react to the original post with 👍 (`+1`). If you would like to provide an additional use case for the feature, please post a comment.
The team will review this feedback and make a final decision. Any decision will be posted on this thread, but please note that we may ultimately decide not to pursue this feature. The team will review this feedback and make a final decision. Any decision will be posted on this thread, but please note that we may ultimately decide not to pursue this feature.
@@ -71,7 +71,7 @@ comment:
noReply: noReply:
days: 14 days: 14
maxIssuesPerRun: 100 maxIssuesPerRun: 100
label: "needs: reply" label: 'needs: reply'
responseLabel: triage responseLabel: triage
exemptProjects: true exemptProjects: true
exemptMilestones: true exemptMilestones: true
@@ -89,7 +89,7 @@ noReply:
noReproduction: noReproduction:
days: 14 days: 14
maxIssuesPerRun: 100 maxIssuesPerRun: 100
label: "ionitron: needs reproduction" label: 'ionitron: needs reproduction'
responseLabel: triage responseLabel: triage
exemptProjects: true exemptProjects: true
exemptMilestones: true exemptMilestones: true
@@ -3,14 +3,14 @@ description: 'Build Ionicons'
runs: runs:
using: 'composite' using: 'composite'
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
with: with:
# Checkout the latest commit in this branch # Checkout the latest commit in this branch
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v3 - uses: actions/setup-node@v4
- name: Cache Node Modules - name: Cache Node Modules
uses: actions/cache@v3 uses: actions/cache@v4
env: env:
cache-name: node-modules cache-name: node-modules
with: with:
@@ -31,4 +31,4 @@ runs:
with: with:
name: ionicons-src name: ionicons-src
output: IoniconsSrc.zip output: IoniconsSrc.zip
paths: src paths: src
@@ -10,10 +10,10 @@ inputs:
runs: runs:
using: 'composite' using: 'composite'
steps: steps:
- uses: actions/download-artifact@v3 - uses: actions/download-artifact@v4
with: with:
name: ${{ inputs.name }} name: ${{ inputs.name }}
path: ${{ inputs.path }} path: ${{ inputs.path }}
- name: Exract Archive - name: Exract Archive
run: unzip -q -o ${{ inputs.path }}/${{ inputs.filename }} run: unzip -q -o ${{ inputs.path }}/${{ inputs.filename }}
shell: bash shell: bash
@@ -10,14 +10,18 @@ inputs:
folder: folder:
default: './' default: './'
description: 'A folder containing a package.json file.' description: 'A folder containing a package.json file.'
token: createRelease:
description: 'The NPM authentication token required to publish.' description: 'Create a release on GitHub.'
default: 'false'
ghToken:
description: 'The GitHub authentication token required to create a release.'
runs: runs:
using: 'composite' using: 'composite'
steps: steps:
- uses: actions/setup-node@v3 - uses: actions/setup-node@v4
with: with:
node-version: 18.x node-version: 22.x
- name: Install latest npm - name: Install latest npm
run: npm install -g npm@latest run: npm install -g npm@latest
shell: bash shell: bash
@@ -25,21 +29,35 @@ runs:
run: npm ci run: npm ci
shell: bash shell: bash
working-directory: ${{ inputs.working-directory }} working-directory: ${{ inputs.working-directory }}
- name: Set Git User
run: |
git config user.name ionitron
git config user.email hi@ionicframework.com
shell: bash
- name: Update Version - name: Update Version
run: npm version ${{ inputs.version }} --git-tag-version false id: update_version
run: |
npm version ${{ inputs.version }}
echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
shell: bash shell: bash
working-directory: ${{ inputs.working-directory }} working-directory: ${{ inputs.working-directory }}
- name: Run Build - name: Run Build
run: npm run build run: npm run build
shell: bash shell: bash
working-directory: ${{ inputs.working-directory }} working-directory: ${{ inputs.working-directory }}
- name: Prepare NPM Token
run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
working-directory: ${{ inputs.working-directory }}
shell: bash
env:
NPM_TOKEN: ${{ inputs.token }}
- name: Publish to NPM - name: Publish to NPM
run: npm publish ${{ inputs.folder }} --tag ${{ inputs.tag }} --provenance run: npm publish ${{ inputs.folder }} --tag ${{ inputs.tag }} --provenance
shell: bash shell: bash
working-directory: ${{ inputs.working-directory }} working-directory: ${{ inputs.working-directory }}
- name: Create Release
if: ${{ inputs.createRelease == 'true' }}
run: |
git remote set-url origin https://${GH_TOKEN}:x-oauth-basic@github.com/ionic-team/ionicons.git
git remote -v
git push origin main --tags
gh release create "v$VERSION" --title "v$VERSION" --generate-notes
shell: bash
env:
GH_TOKEN: ${{ inputs.ghToken }}
VERSION: ${{ env.VERSION }}
@@ -10,10 +10,10 @@ inputs:
runs: runs:
using: 'composite' using: 'composite'
steps: steps:
- uses: actions/setup-node@v3 - uses: actions/setup-node@v4
- name: Cache Node Modules - name: Cache Node Modules
uses: actions/cache@v3 uses: actions/cache@v4
env: env:
cache-name: node-modules cache-name: node-modules
with: with:
@@ -65,7 +65,7 @@ runs:
shell: bash shell: bash
- name: Archive Updated Screenshots - name: Archive Updated Screenshots
if: inputs.update == 'true' && steps.test-and-update.outputs.hasUpdatedScreenshots == 'true' if: inputs.update == 'true' && steps.test-and-update.outputs.hasUpdatedScreenshots == 'true'
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: updated-screenshots-${{ inputs.shard }}-${{ inputs.totalShards }} name: updated-screenshots-${{ inputs.shard }}-${{ inputs.totalShards }}
path: UpdatedScreenshots-${{ inputs.shard }}-${{ inputs.totalShards }}.zip path: UpdatedScreenshots-${{ inputs.shard }}-${{ inputs.totalShards }}.zip
@@ -81,4 +81,4 @@ runs:
with: with:
name: test-results-${{ inputs.shard }}-${{ inputs.totalShards }} name: test-results-${{ inputs.shard }}-${{ inputs.totalShards }}
output: TestResults-${{ inputs.shard }}-${{ inputs.totalShards }}.zip output: TestResults-${{ inputs.shard }}-${{ inputs.totalShards }}.zip
paths: playwright-report paths: playwright-report
@@ -3,10 +3,10 @@ description: 'Test Spec'
runs: runs:
using: 'composite' using: 'composite'
steps: steps:
- uses: actions/setup-node@v3 - uses: actions/setup-node@v4
- name: Cache Node Modules - name: Cache Node Modules
uses: actions/cache@v3 uses: actions/cache@v4
env: env:
cache-name: node-modules cache-name: node-modules
with: with:
@@ -7,8 +7,8 @@ on:
runs: runs:
using: 'composite' using: 'composite'
steps: steps:
- uses: actions/setup-node@v3 - uses: actions/setup-node@v4
- uses: actions/download-artifact@v3 - uses: actions/download-artifact@v4
with: with:
path: ./artifacts path: ./artifacts
- name: Extract Archives - name: Extract Archives
@@ -35,4 +35,4 @@ runs:
git add src/\*.png --force git add src/\*.png --force
git commit -m "chore(): add updated snapshots" git commit -m "chore(): add updated snapshots"
git push git push
shell: bash shell: bash
@@ -13,7 +13,7 @@ runs:
- name: Create Archive - name: Create Archive
run: zip -q -r ${{ inputs.output }} ${{ inputs.paths }} run: zip -q -r ${{ inputs.output }} ${{ inputs.paths }}
shell: bash shell: bash
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
with: with:
name: ${{ inputs.name }} name: ${{ inputs.name }}
path: ${{ inputs.output }} path: ${{ inputs.output }}
@@ -1,7 +1,7 @@
name: 'Ionicons Dev Build' name: 'Dev Release'
on: on:
workflow_dispatch: workflow_call:
jobs: jobs:
create-dev-hash: create-dev-hash:
@@ -9,7 +9,7 @@ jobs:
outputs: outputs:
dev-hash: ${{ steps.create-dev-hash.outputs.DEV_HASH }} dev-hash: ${{ steps.create-dev-hash.outputs.DEV_HASH }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Install Dependencies - name: Install Dependencies
run: npm ci --no-package-lock run: npm ci --no-package-lock
shell: bash shell: bash
@@ -20,13 +20,20 @@ jobs:
shell: bash shell: bash
release-ionicons: release-ionicons:
runs-on: ubuntu-latest
needs: [create-dev-hash] needs: [create-dev-hash]
uses: ./.github/workflows/release-ionicons.yml permissions:
with: id-token: write
tag: dev steps:
version: ${{ needs.create-dev-hash.outputs.dev-hash }} - name: Checkout
secrets: uses: actions/checkout@v4
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Publish to NPM
uses: ./.github/workflows/actions/publish-npm
with:
tag: dev
version: ${{ needs.create-dev-hash.outputs.dev-hash }}
working-directory: './'
createRelease: 'false'
get-build: get-build:
name: Get your dev build! name: Get your dev build!
+28
View File
@@ -0,0 +1,28 @@
name: 'Production Release'
on:
workflow_call:
inputs:
version:
required: false
type: string
description: npm version (major, minor, or patch)
jobs:
release-ionicons:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.IONITRON_TOKEN }}
- name: Publish to NPM
uses: ./.github/workflows/actions/publish-npm
with:
tag: latest
version: ${{ inputs.version }}
working-directory: './'
createRelease: true
ghToken: ${{ secrets.IONITRON_TOKEN }}
-30
View File
@@ -1,30 +0,0 @@
name: 'Release Ionicons'
on:
workflow_call:
inputs:
version:
description: 'The type of version to release.'
type: string
required: true
tag:
description: 'The tag to publish to on NPM.'
type: string
required: true
secrets:
NPM_TOKEN:
required: true
jobs:
release-core:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/actions/publish-npm
with:
tag: ${{ inputs.tag }}
version: ${{ inputs.version }}
working-directory: './'
token: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,37 @@
name: 'Release Orchestrator'
on:
workflow_dispatch:
inputs:
release-type:
description: 'Release type'
required: true
type: choice
options:
- dev
- production
version:
description: 'Version for production releases'
required: false
type: choice
options:
- patch
- minor
- major
permissions:
id-token: write
contents: read
jobs:
run-dev:
if: ${{ inputs.release-type == 'dev' }}
uses: ./.github/workflows/dev-release.yml
secrets: inherit
run-production:
if: ${{ inputs.release-type == 'production' }}
uses: ./.github/workflows/production-release.yml
secrets: inherit
with:
version: ${{ inputs.version }}
-97
View File
@@ -1,97 +0,0 @@
name: 'Ionicons Production Release'
on:
workflow_dispatch:
inputs:
version:
required: true
type: choice
description: Which version should be published?
options:
- patch
- minor
- major
tag:
required: true
type: choice
description: Which npm tag should this be published to?
options:
- latest
jobs:
release-ionicons:
uses: ./.github/workflows/release-ionicons.yml
with:
tag: ${{ inputs.tag }}
version: ${{ inputs.version }}
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
finalize-release:
needs: [release-ionicons]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.IONITRON_TOKEN }}
fetch-depth: 0
- name: Configure Identity
# Commits from github-actions do not
# trigger other GitHub Actions. As a result,
# we publish releases from Ionitron instead
# so actions run when merging the release branch
# back into main.
run: |
git config user.name ionitron
git config user.email hi@ionicframework.com
shell: bash
# This ensures the local version of Lerna is installed
# and that we do not use the global Lerna version. We currently
# rely on functionality that does not exist in newer versions of Lerna.
- name: Install root dependencies
run: npm ci
shell: bash
- name: Create GitHub Release
run: npx lerna@5 version ${{ inputs.version }} --yes --force-publish='*' --conventional-commits --create-release github
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
update-package-lock:
# This needs to run after finalize-release
# because we also push to the repo in that
# job. If these jobs ran in parallel then it is
# possible for them to push at the same time.
needs: [finalize-release]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Pull the latest version of the reference
# branch instead of the revision that triggered
# the workflow otherwise we won't get the commit
# created in the previous job and this next job
# will fail.
with:
ref: ${{ github.ref }}
- name: Configure Identity
# Commits from github-actions do not
# trigger other GitHub Actions. As a result,
# we push from Ionitron instead so actions
# run when merging the release branch
# back into main.
run: |
git config user.name ionitron
git config user.email hi@ionicframework.com
shell: bash
# Lerna does not automatically bump versions
# of Ionicons dependencies that have changed,
# so we do that here.
- name: Bump Package Lock
run: |
npx lerna@5 exec "npm install --package-lock-only --legacy-peer-deps"
git add .
git commit -m "chore(): update package lock files"
git push
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
+4 -4
View File
@@ -7,7 +7,7 @@ jobs:
build-core: build-core:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: ./.github/workflows/actions/build-core - uses: ./.github/workflows/actions/build-core
test-e2e: test-e2e:
@@ -28,7 +28,7 @@ jobs:
needs: [build-core] needs: [build-core]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: ./.github/workflows/actions/test-e2e - uses: ./.github/workflows/actions/test-e2e
with: with:
shard: ${{ matrix.shard }} shard: ${{ matrix.shard }}
@@ -39,7 +39,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [test-e2e] needs: [test-e2e]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
# Normally, we could just push with the # Normally, we could just push with the
# default GITHUB_TOKEN, but that will # default GITHUB_TOKEN, but that will
# not cause the build workflow # not cause the build workflow
@@ -49,4 +49,4 @@ jobs:
# to run when the screenshots are pushed. # to run when the screenshots are pushed.
with: with:
token: ${{ secrets.IONITRON_TOKEN }} token: ${{ secrets.IONITRON_TOKEN }}
- uses: ./.github/workflows/actions/update-reference-screenshots - uses: ./.github/workflows/actions/update-reference-screenshots
@@ -1,8 +1,10 @@
name: 'Ionicons Build' name: 'Validation'
on: on:
pull_request: pull_request:
branches: [ '**' ] branches: ['**']
push:
branches: ['main']
# When pushing a new commit we should # When pushing a new commit we should
# cancel the previous test run to not # cancel the previous test run to not
@@ -15,7 +17,7 @@ jobs:
build-core: build-core:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
with: with:
# Checkout the latest commit in this branch # Checkout the latest commit in this branch
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}
@@ -25,9 +27,9 @@ jobs:
needs: [build-core] needs: [build-core]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: ./.github/workflows/actions/test-spec - uses: ./.github/workflows/actions/test-spec
test-e2e: test-e2e:
strategy: strategy:
# This ensures that all screenshot shard # This ensures that all screenshot shard
@@ -46,12 +48,12 @@ jobs:
needs: [build-core] needs: [build-core]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: ./.github/workflows/actions/test-e2e - uses: ./.github/workflows/actions/test-e2e
with: with:
shard: ${{ matrix.shard }} shard: ${{ matrix.shard }}
totalShards: ${{ matrix.totalShards }} totalShards: ${{ matrix.totalShards }}
# Screenshots are required to pass # Screenshots are required to pass
# in order for the branch to be merge # in order for the branch to be merge
# eligible. However, the screenshot tests # eligible. However, the screenshot tests
@@ -68,4 +70,4 @@ jobs:
steps: steps:
- name: Check build matrix status - name: Check build matrix status
if: ${{ needs.test-e2e.result != 'success' }} if: ${{ needs.test-e2e.result != 'success' }}
run: exit 1 run: exit 1
+1
View File
@@ -24,3 +24,4 @@ www/
/playwright-report/ /playwright-report/
/playwright/.cache/ /playwright/.cache/
/src/**/*-snapshots /src/**/*-snapshots
*.tgz
+1
View File
@@ -0,0 +1 @@
src/components.d.ts
+1 -209
View File
@@ -1,211 +1,3 @@
# Change Log # Change Log
All notable changes to this project will be documented in this file. Please see https://github.com/ionic-team/ionicons/releases
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [7.3.1](https://github.com/ionic-team/ionicons/compare/v7.3.0...v7.3.1) (2024-03-27)
### Bug Fixes
* filled ellipsis circle icons renders correctly ([#1353](https://github.com/ionic-team/ionicons/issues/1353)) ([63e60ec](https://github.com/ionic-team/ionicons/commit/63e60ec44c11bda5902b5a496113f65a5e6f3d85)), closes [#1320](https://github.com/ionic-team/ionicons/issues/1320)
# [7.3.0](https://github.com/ionic-team/ionicons/compare/v7.2.3...v7.3.0) (2024-03-20)
### Features
* add appflow icon ([#1262](https://github.com/ionic-team/ionicons/issues/1262)) ([fa5e765](https://github.com/ionic-team/ionicons/commit/fa5e7659fc1622908c4e55b01d0573017a36af6a))
* add arrow box icons ([#1265](https://github.com/ionic-team/ionicons/issues/1265)) ([d5a55f8](https://github.com/ionic-team/ionicons/commit/d5a55f8541b208ab46dd41e53528aab48a90ed10))
* add binoculars icons ([#1258](https://github.com/ionic-team/ionicons/issues/1258)) ([3024818](https://github.com/ionic-team/ionicons/commit/302481846e48428a354bc36220506001ac4c645e))
* add trapeze icon ([#1260](https://github.com/ionic-team/ionicons/issues/1260)) ([3b85413](https://github.com/ionic-team/ionicons/commit/3b85413a059b2c91f10105d576cc717fd687a491))
* add updated wifi logos ([#1264](https://github.com/ionic-team/ionicons/issues/1264)) ([26aac36](https://github.com/ionic-team/ionicons/commit/26aac36334cc09e5887523bc99c3d746586ebb63)), closes [#323](https://github.com/ionic-team/ionicons/issues/323)
* add updated yahoo icon ([#1266](https://github.com/ionic-team/ionicons/issues/1266)) ([c6ed6b6](https://github.com/ionic-team/ionicons/commit/c6ed6b629e45465b49e8e35db3830083ca9520ef))
* **doc:** add Web Types ([#1301](https://github.com/ionic-team/ionicons/issues/1301)) ([f946a3e](https://github.com/ionic-team/ionicons/commit/f946a3ee3a4a1c2bdf9508b11a71fcb0a419d571))
* update gitlab logo ([#1261](https://github.com/ionic-team/ionicons/issues/1261)) ([2586fb2](https://github.com/ionic-team/ionicons/commit/2586fb26b2a493fcb4b5b0156dd00d6b5eab1ab0)), closes [#613](https://github.com/ionic-team/ionicons/issues/613)
* update ionic logo ([#1263](https://github.com/ionic-team/ionicons/issues/1263)) ([50fe570](https://github.com/ionic-team/ionicons/commit/50fe570566d4c28de7fb10694543cd6dc72f3935))
# [7.3.0](https://github.com/ionic-team/ionicons/compare/v7.2.3...v7.3.0) (2024-03-20)
### Features
* add appflow icon ([#1262](https://github.com/ionic-team/ionicons/issues/1262)) ([fa5e765](https://github.com/ionic-team/ionicons/commit/fa5e7659fc1622908c4e55b01d0573017a36af6a))
* add arrow box icons ([#1265](https://github.com/ionic-team/ionicons/issues/1265)) ([d5a55f8](https://github.com/ionic-team/ionicons/commit/d5a55f8541b208ab46dd41e53528aab48a90ed10))
* add binoculars icons ([#1258](https://github.com/ionic-team/ionicons/issues/1258)) ([3024818](https://github.com/ionic-team/ionicons/commit/302481846e48428a354bc36220506001ac4c645e))
* add trapeze icon ([#1260](https://github.com/ionic-team/ionicons/issues/1260)) ([3b85413](https://github.com/ionic-team/ionicons/commit/3b85413a059b2c91f10105d576cc717fd687a491))
* add updated wifi logos ([#1264](https://github.com/ionic-team/ionicons/issues/1264)) ([26aac36](https://github.com/ionic-team/ionicons/commit/26aac36334cc09e5887523bc99c3d746586ebb63)), closes [#323](https://github.com/ionic-team/ionicons/issues/323)
* add updated yahoo icon ([#1266](https://github.com/ionic-team/ionicons/issues/1266)) ([c6ed6b6](https://github.com/ionic-team/ionicons/commit/c6ed6b629e45465b49e8e35db3830083ca9520ef))
* **doc:** add Web Types ([#1301](https://github.com/ionic-team/ionicons/issues/1301)) ([f946a3e](https://github.com/ionic-team/ionicons/commit/f946a3ee3a4a1c2bdf9508b11a71fcb0a419d571))
* update gitlab logo ([#1261](https://github.com/ionic-team/ionicons/issues/1261)) ([2586fb2](https://github.com/ionic-team/ionicons/commit/2586fb26b2a493fcb4b5b0156dd00d6b5eab1ab0)), closes [#613](https://github.com/ionic-team/ionicons/issues/613)
* update ionic logo ([#1263](https://github.com/ionic-team/ionicons/issues/1263)) ([50fe570](https://github.com/ionic-team/ionicons/commit/50fe570566d4c28de7fb10694543cd6dc72f3935))
## [7.2.3](https://github.com/ionic-team/ionicons/compare/v7.2.2...v7.2.3) (2024-03-20)
### Bug Fixes
* **icon:** icon names with numbers are correctly converted to kebab case ([#1339](https://github.com/ionic-team/ionicons/issues/1339)) ([077168d](https://github.com/ionic-team/ionicons/commit/077168dac9347f25d2b8ce440bd0a3e8576f4cdf)), closes [#1338](https://github.com/ionic-team/ionicons/issues/1338)
## [7.2.2](https://github.com/ionic-team/ionicons/compare/v7.2.1...v7.2.2) (2023-12-13)
### Bug Fixes
* **icon:** add better warning when loading icons ([#1297](https://github.com/ionic-team/ionicons/issues/1297)) ([d582e62](https://github.com/ionic-team/ionicons/commit/d582e6208e626722e4350426a509a6870e90a0bc))
## [7.2.1](https://github.com/ionic-team/ionicons/compare/v7.2.0...v7.2.1) (2023-10-10)
### Bug Fixes
* **icon:** font scales without host style ([#1289](https://github.com/ionic-team/ionicons/issues/1289)) ([875bfd8](https://github.com/ionic-team/ionicons/commit/875bfd8300144c62e55a5a76dc2cff8cf1f01bfe))
# [7.2.0](https://github.com/ionic-team/ionicons/compare/v7.1.2...v7.2.0) (2023-10-10)
### Bug Fixes
* **icon:** mapping same icon does not warn ([#1279](https://github.com/ionic-team/ionicons/issues/1279)) ([8297018](https://github.com/ionic-team/ionicons/commit/8297018cb591f5e33a815ceb9e4e765271ecf5ad))
* **icon:** verify the icon loads in the lifecycle ([#1278](https://github.com/ionic-team/ionicons/issues/1278)) ([7f7f346](https://github.com/ionic-team/ionicons/commit/7f7f346af47f45531046e1d2f1a88f53acee77fa))
### Features
* allow passing in only icon SVG data to addIcons ([#1256](https://github.com/ionic-team/ionicons/issues/1256)) ([1e33313](https://github.com/ionic-team/ionicons/commit/1e3331347328c11a8b4c58c9200059bfd76b0e59))
* **icon:** support for dynamic type ([#1246](https://github.com/ionic-team/ionicons/issues/1246)) ([45c04dd](https://github.com/ionic-team/ionicons/commit/45c04dda6c905e535083b171cead374b1c993afa))
## [7.1.2](https://github.com/ionic-team/ionicons/compare/v7.1.1...v7.1.2) (2023-05-30)
### Bug Fixes
* **icon:** add :dir fallback ([#1223](https://github.com/ionic-team/ionicons/issues/1223)) ([06fa4a5](https://github.com/ionic-team/ionicons/commit/06fa4a528dd1906a5673ff6d80d22aef0f6e113b))
## [7.1.1](https://github.com/ionic-team/ionicons/compare/v7.1.0...v7.1.1) (2023-05-23)
### Bug Fixes
* **icon:** respond to changes of document dir ([#1210](https://github.com/ionic-team/ionicons/issues/1210)) ([e70bf21](https://github.com/ionic-team/ionicons/commit/e70bf214b82cd2187ea9394803283570d28ab28c))
# [7.1.0](https://github.com/ionic-team/ionicons/compare/v7.0.0...v7.1.0) (2023-03-23)
### Features
* chevron-expand and chevron-collapse icons ([#1198](https://github.com/ionic-team/ionicons/issues/1198)) ([cdb0d80](https://github.com/ionic-team/ionicons/commit/cdb0d80cde1dc5dd90fb2a1c3b4fa31d68294821))
# [7.0.0](https://github.com/ionic-team/ionicons/compare/v6.1.3...v7.0.0) (2023-03-07)
**Migration Note:** Developers should ensure that their `<ion-icon>` usages have either `aria-label` or `aria-hidden` to avoid accessibility issues. See https://ionic.io/ionicons/usage for more information.
### Bug Fixes
* **icon:** remove auto-generated aria-label ([#1170](https://github.com/ionic-team/ionicons/issues/1170)) ([98975ec](https://github.com/ionic-team/ionicons/commit/98975ec0f54b825c33f528683834a5e38298d598))
## [6.1.3](https://github.com/ionic-team/ionicons/compare/v6.1.2...v6.1.3) (2023-02-09)
### Bug Fixes
* DomParser usage in SSR ([#1180](https://github.com/ionic-team/ionicons/issues/1180)) ([8c412f6](https://github.com/ionic-team/ionicons/commit/8c412f67486d6cc9725de63f0c15b6c6cd8d47ce)), closes [#1179](https://github.com/ionic-team/ionicons/issues/1179)
## [6.1.2](https://github.com/ionic-team/ionicons/compare/v6.1.1...v6.1.2) (2023-02-08)
### Bug Fixes
* **icon:** load base64 data urls ([#1172](https://github.com/ionic-team/ionicons/issues/1172)) ([72f0936](https://github.com/ionic-team/ionicons/commit/72f09369de76b00697437f54d919782307843a87))
* **icon:** md and ios properties are reactive ([#1174](https://github.com/ionic-team/ionicons/issues/1174)) ([65bcbb4](https://github.com/ionic-team/ionicons/commit/65bcbb477734e33901a6f0c650d3f1f2c3084fca)), closes [#802](https://github.com/ionic-team/ionicons/issues/802)
## [6.1.1](https://github.com/ionic-team/ionicons/compare/v6.1.0...v6.1.1) (2023-01-18)
### Bug Fixes
* **icon:** remove <title> during build step ([#1169](https://github.com/ionic-team/ionicons/issues/1169)) ([93b4fa4](https://github.com/ionic-team/ionicons/commit/93b4fa449b0a072b24ef920fe73e1cb04d6f9b43)), closes [#1168](https://github.com/ionic-team/ionicons/issues/1168)
## [6.1.1](https://github.com/ionic-team/ionicons/compare/v6.1.0...v6.1.1) (2023-01-18)
### Bug Fixes
* **icon:** remove <title> during build step ([#1169](https://github.com/ionic-team/ionicons/issues/1169)) ([93b4fa4](https://github.com/ionic-team/ionicons/commit/93b4fa449b0a072b24ef920fe73e1cb04d6f9b43)), closes [#1168](https://github.com/ionic-team/ionicons/issues/1168)
# [6.1.0](https://github.com/ionic-team/ionicons/compare/v6.0.4...v6.1.0) (2023-01-17)
### Bug Fixes
* **icon:** remove default <title> ([#1166](https://github.com/ionic-team/ionicons/issues/1166)) ([e0efa5f](https://github.com/ionic-team/ionicons/commit/e0efa5f28d61adcaf2e1fa121f7e2f10cfad6d65)), closes [#838](https://github.com/ionic-team/ionicons/issues/838) [#1049](https://github.com/ionic-team/ionicons/issues/1049) [#1082](https://github.com/ionic-team/ionicons/issues/1082)
# [6.1.0](https://github.com/ionic-team/ionicons/compare/v6.0.4...v6.1.0) (2023-01-17)
### Bug Fixes
* **icon:** remove default <title> ([#1166](https://github.com/ionic-team/ionicons/issues/1166)) ([e0efa5f](https://github.com/ionic-team/ionicons/commit/e0efa5f28d61adcaf2e1fa121f7e2f10cfad6d65)), closes [#838](https://github.com/ionic-team/ionicons/issues/838) [#1049](https://github.com/ionic-team/ionicons/issues/1049) [#1082](https://github.com/ionic-team/ionicons/issues/1082)
+196
View File
@@ -0,0 +1,196 @@
# Contributing to Ionicons
Thank you for your interest in contributing to Ionicons! :tada:
This document outlines the guidelines and processes for contributing to this project.
## Table of Contents
- [Code of Conduct](#code-of-conduct)
- [Getting Started](#getting-started)
* [Prerequisites](#prerequisites)
* [Environment Setup](#environment-setup)
- [Development Workflow](#development-workflow)
* [Branch Strategy](#branch-strategy)
* [Component Modifications](#component-modifications)
* [Testing](#testing)
* [Code Style](#code-style)
* [Building](#building)
- [Submitting Issues](#submitting-issues)
- [Submitting Pull Requests](#submitting-pull-requests)
## Code of Conduct
Please read our [Contributor Code of Conduct](./CODE_OF_CONDUCT.md) for information on our rules of conduct. By contributing to Ionicons, you agree to abide by its terms.
## Getting Started
### Prerequisites
- [Node.js](https://nodejs.org/) (LTS version recommended)
- [npm](https://www.npmjs.com/) (comes with Node.js)
- Git
### Environment Setup
1. We recommend using [nvm](https://github.com/nvm-sh/nvm) (Node Version Manager) to manage Node.js versions:
- For macOS/Linux: `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash`
- For Windows: Use [nvm-windows](https://github.com/coreybutler/nvm-windows)
- Install and use the LTS version: `nvm install --lts && nvm use --lts`
Alternatively, you can [download the installer](https://nodejs.org/) for the LTS version of Node.js directly.
2. Fork the repository on GitHub
3. Clone your fork locally:
```bash
git clone https://github.com/YOUR-USERNAME/ionicons.git
cd ionicons
```
4. Add the original repository as an upstream remote:
```bash
git remote add upstream https://github.com/ionic-team/ionicons.git
```
5. Create a new branch from `main` for your change:
```bash
git checkout -b your-feature-branch
```
6. Install dependencies:
```bash
npm install
```
7. Run the initial build:
```bash
npm run build
```
8. If desired, [modify the Icon Component](#component-modifications)
9. Or, modify and preview the site
## Development Workflow
### Branch Strategy
- Always create a new branch from `main` for your changes:
```bash
git checkout main
git pull upstream main
git checkout -b your-feature-branch
```
### Component Modifications
If you're modifying the `ion-icon` component:
1. Navigate to `src/components/` directory and open the `icon` component to modify
2. Make your changes to the component code
3. Test your changes locally with `npm start`
4. Run the full test suite: `npm run test.spec` for unit tests and `npm run test.e2e` for E2E tests
5. All PRs that change component behavior must include tests covering the changes
### Testing
Tests are crucial for maintaining confidence in changes. All PRs that modify component behavior must include tests covering those changes.
#### Local Development & Previewing
To preview component changes during development:
```bash
npm start
```
This starts the dev server with live-reloading. The test landing page displays all available test pages.
Test pages are organized in `src/components/icon/test/` with individual folders for each test scenario.
#### Unit Tests
Run Jest tests for component logic:
```bash
npm run test.spec
```
#### E2E Tests
Run Playwright tests to generate visual regression snapshots and verify component behavior:
```bash
npm run test.e2e
```
View the HTML report after tests complete:
```bash
npx playwright show-report
```
> [!IMPORTANT]
> All E2E test navigation URLs must include a trailing slash (e.g., `/icon/test/basic/` not `/icon/test/basic`). The trailing slash ensures proper directory routing, correct timing for script initialization, and consistent page loading across browsers.
##### Updating Snapshots
To update visual regression snapshots with new baselines:
```bash
npm run test.e2e -- --update-snapshots
```
Or for a specific test:
```bash
npm run test.e2e -- src/components/icon/test/basic/icon.e2e.ts --update-snapshots
```
> [!NOTE]
> Updating snapshots locally updates your gitignored screenshot files for local testing. To update the official repository snapshots, run the "Update Reference Screenshots" GitHub action with your development branch selected.
### Code Style
- This project uses Prettier for code formatting
- Run `npm run prettier` to format your code before submitting
### Building
- Run `npm run build` to build the complete package
- Run `npm run build.files` to rebuild only the SVG icon files
## Submitting Issues
Please submit issues for:
- Bug reports
- Feature requests
- General questions about the project
When creating issues:
1. If you have a question about using Ionicons, please ask on the [Ionic Forum](http://forum.ionicframework.com/) or in the [Ionic Discord](https://ionic.link/discord).
2. It is required that you clearly describe the steps necessary to reproduce the issue you are running into. Although we would love to help our users as much as possible, diagnosing issues without clear reproduction steps is extremely time-consuming and simply not sustainable.
3. The issue list of this repository is exclusively for bug reports and feature requests. Non-conforming issues will be closed immediately.
4. Check if a similar issue already exists by searching through [existing issues](https://github.com/ionic-team/ionicons/issues?utf8=%E2%9C%93&q=is%3Aissue). You can search through existing issues to see if there is a similar one reported. Include closed issues as it may have been closed with a solution.
5. Use the provided issue templates and clearly describe:
- Expected behavior
- Actual behavior
- Steps to reproduce (for bugs)
- Browser/device information when relevant
6. [Create a new issue](https://github.com/ionic-team/ionicons/issues/new/choose) that thoroughly explains the problem.
## Submitting Pull Requests
1. Before submitting a Pull Request (PR), please:
- Create an issue first to discuss the proposed changes
- Comment on an existing issue mentioning you'd like to work on it
- Look for issues labeled with [`help wanted`](https://github.com/ionic-team/ionicons/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) if you're new to the project
2. Creating the PR:
- Update your fork to the latest upstream main
- Make your changes in a new git branch
- Follow the code style of the project
- Include relevant tests
- Make sure all tests pass: `npm test`
- Update documentation if needed
- [Create a new pull request](https://github.com/ionic-team/ionicons/compare) with the `main` branch as the base.
+20
View File
@@ -0,0 +1,20 @@
import path from 'path';
import url from 'url';
import { createJestStencilPreset } from 'jest-stencil-runner';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
export default createJestStencilPreset({
rootDir: __dirname,
// Add any additional Jest configuration here
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.ts',
],
testMatch: [
'**/__tests__/**/*.(ts|tsx|js)',
'**/*.(test|spec).(ts|tsx|js)'
]
});
+2
View File
@@ -0,0 +1,2 @@
const Stencil = require('@stencil/core');
Stencil.Build.isBrowser = true;
-6
View File
@@ -1,6 +0,0 @@
{
"packages": [
"./"
],
"version": "7.3.1"
}
+5429 -22060
View File
File diff suppressed because it is too large Load Diff
+63 -24
View File
@@ -1,6 +1,6 @@
{ {
"name": "ionicons", "name": "ionicons",
"version": "7.3.1", "version": "8.1.1",
"description": "Premium icons for Ionic.", "description": "Premium icons for Ionic.",
"files": [ "files": [
"components/", "components/",
@@ -10,37 +10,76 @@
"main": "./dist/index.cjs.js", "main": "./dist/index.cjs.js",
"module": "./dist/index.js", "module": "./dist/index.js",
"types": "dist/types/index.d.ts", "types": "dist/types/index.d.ts",
"unpkg": "dist/ionicons.js", "unpkg": "dist/ionicons/ionicons.esm.js",
"jsdelivr": "dist/ionicons/ionicons.esm.js",
"collection": "dist/collection/collection-manifest.json", "collection": "dist/collection/collection-manifest.json",
"collection:main": "dist/collection/index.js", "collection:main": "dist/collection/index.js",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs.js"
},
"./loader": {
"types": "./dist/loader/index.d.ts",
"import": "./dist/loader/index.js",
"require": "./dist/loader/index.cjs.js"
},
"./components": {
"types": "./components/index.d.ts",
"import": "./components/index.js"
},
"./components/ion-icon.js": {
"types": "./components/ion-icon.d.ts",
"import": "./components/ion-icon.js"
},
"./icons": {
"types": "./icons/index.d.ts",
"import": "./icons/index.mjs",
"require": "./icons/index.js"
},
"./dist/ionicons.json": {
"default": "./dist/ionicons.json"
}
},
"scripts": { "scripts": {
"compile.scripts": "tsc -p scripts/tsconfig.json", "build": "run-s clean build.*",
"build": "npm run compile.scripts && npm run build.files && npm run build.component && npm run collection.copy", "build.files": "tsx scripts/build.ts",
"build.files": "node scripts/build.js",
"build.component": "stencil build", "build.component": "stencil build",
"collection.copy": "node scripts/collection-copy.js", "build.collection": "tsx scripts/collection-copy.ts",
"start": "npm run compile.scripts && npm run build.files && stencil build --dev --watch --serve", "clean": "rimraf dist components icons www",
"test": "npm run test.spec", "lint": "npm run prettier -- --write",
"test.spec": "stencil test --spec" "prettier": "prettier \"./src/**/*.{html,ts,tsx,js,jsx,scss}\"",
"prettier.dry-run": "npm run prettier -- --list-different",
"start": "run-s build.files && stencil build --dev --watch --serve",
"test": "run-s test.spec test.e2e",
"test.spec": "jest",
"test.e2e": "playwright test",
"test.e2e.install": "playwright install && playwright install-deps"
}, },
"dependencies": { "dependencies": {
"@stencil/core": "^4.0.3" "@stencil/core": "^4.43.5"
}, },
"devDependencies": { "devDependencies": {
"@playwright/test": "^1.33.0", "@axe-core/playwright": "^4.12.1",
"@types/fs-extra": "^11.0.1", "@playwright/test": "^1.61.1",
"@types/jest": "^27.0.3", "@types/fs-extra": "^11.0.4",
"@types/node": "^20.2.1", "@types/jest": "^30.0.0",
"@types/svgo": "^1.3.3", "@types/node": "^22.15.3",
"fs-extra": "^11.1.1", "@types/svgo": "^3.0.0",
"jest": "^27.0.3", "fs-extra": "^11.3.0",
"jest-cli": "^27.0.3", "jest": "^30.0.4",
"lerna": "^6.6.2", "jest-cli": "^30.0.4",
"puppeteer": "^20.2.1", "jest-stencil-runner": "^0.0.20",
"semver": "^7.5.1", "npm-run-all2": "^8.0.4",
"serve": "^14.2.0", "prettier": "^3.6.2",
"svgo": "1.3.2", "puppeteer": "^24.12.0",
"typescript": "^5.0.4" "rimraf": "^6.0.1",
"semver": "^7.7.2",
"serve": "^14.2.4",
"svgo": "4.0.0",
"tsx": "^4.20.3",
"typescript": "^5.8.3"
}, },
"keywords": [ "keywords": [
"icon pack", "icon pack",
+19 -7
View File
@@ -1,7 +1,7 @@
import type { PlaywrightTestConfig } from '@playwright/test'; import type { PlaywrightTestConfig } from '@playwright/test';
import { devices, expect } from '@playwright/test'; import { devices, expect } from '@playwright/test';
const projects = [ const projects: PlaywrightTestConfig['projects'] = [
{ {
/** /**
* This is really just desktop Firefox * This is really just desktop Firefox
@@ -19,10 +19,6 @@ const projects = [
viewport: { viewport: {
width: 393, width: 393,
height: 727 height: 727
},
screen: {
width: 393,
height: 851
} }
}, },
}, },
@@ -52,7 +48,23 @@ const config: PlaywrightTestConfig = {
* Maximum time expect() should wait for the condition to be met. * Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();` * For example in `await expect(locator).toHaveText();`
*/ */
timeout: 5000 timeout: 5000,
/**
* Configure screenshot comparison settings
* to be more tolerant of minor visual differences
*/
toHaveScreenshot: {
// Increase the threshold to allow for small font rendering differences
// This sets the maximum allowed ratio of pixels that can be different
maxDiffPixelRatio: 0.02, // Allow up to 2% of pixels to be different
// Alternatively, you can use absolute pixel count
// maxDiffPixels: 100, // Allow up to 100 pixels to be different
// Add a threshold for per-pixel difference to handle anti-aliasing
threshold: 0.2, // Default is 0.1
}
}, },
/* Fail the build on CI if you accidentally left test.only in the source code. */ /* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI, forbidOnly: !!process.env.CI,
@@ -79,7 +91,7 @@ const config: PlaywrightTestConfig = {
}, },
/* Configure projects for major browsers */ /* Configure projects for major browsers */
projects: projects, projects,
webServer: { webServer: {
command: 'serve www -p 3333', command: 'serve www -p 3333',
port: 3333, port: 3333,
+15 -4
View File
@@ -10,7 +10,7 @@ We intend for this icon pack to be used with [Ionic](http://ionicframework.com/)
## Contributing ## Contributing
Thanks for your interest in contributing! Read up on our guidelines for Thanks for your interest in contributing! Read up on our guidelines for
[contributing](https://github.com/ionic-team/ionicons/blob/master/.github/CONTRIBUTING.md) [contributing](https://github.com/ionic-team/ionicons/blob/main/CONTRIBUTING.md)
and then look through our issues with a [help wanted](https://github.com/ionic-team/ionicons/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) and then look through our issues with a [help wanted](https://github.com/ionic-team/ionicons/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)
label. label.
@@ -26,8 +26,15 @@ Also note that only visible icons are loaded, and icons that are "below the fold
If you're using [Ionic Framework](https://ionicframework.com/), Ionicons is packaged by default, so no installation is necessary. Want to use Ionicons without Ionic Framework? Place the following `<script>` near the end of your page, right before the closing `</body>` tag, to enable them. If you're using [Ionic Framework](https://ionicframework.com/), Ionicons is packaged by default, so no installation is necessary. Want to use Ionicons without Ionic Framework? Place the following `<script>` near the end of your page, right before the closing `</body>` tag, to enable them.
```html ```html
<script type="module" src="https://cdn.jsdelivr.net/npm/ionicons@latest/dist/ionicons/ionicons.esm.js"></script> <script type="module" src="https://esm.sh/ionicons@latest/loader"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/ionicons@latest/dist/ionicons/ionicons.js"></script> <script nomodule src="https://esm.sh/ionicons@latest/loader"></script>
```
you can replace `latest` to pick any version of Ionicon, e.g.:
```html
<script type="module" src="https://esm.sh/ionicons@8.0.0/loader"></script>
<script nomodule src="https://esm.sh/ionicons@8.0.0/loader"></script>
``` ```
### Basic usage ### Basic usage
@@ -51,10 +58,14 @@ To use a custom SVG, provide its url in the `src` attribute to request the exter
If you have a different set of icons you would like to load or if the Ionicon icons are hosted on a different page or path, you can set the asset url from which Ionicons pulls the icons via: If you have a different set of icons you would like to load or if the Ionicon icons are hosted on a different page or path, you can set the asset url from which Ionicons pulls the icons via:
```ts ```ts
import { setAssetPath } from '@stencil/core' import { setAssetPath, addIcons } from 'ionicons';
import { add, logoIonic, save } from 'ionicons/icons';
// set root path for loading icons to "<root>/public/svg" // set root path for loading icons to "<root>/public/svg"
setAssetPath(`${window.location.origin}/public/svg/`); setAssetPath(`${window.location.origin}/public/svg/`);
// only load specific icons
addIcons({ add, logoIonic, save });
``` ```
This allows the use of named icons like this: This allows the use of named icons like this:
+136 -337
View File
@@ -1,27 +1,49 @@
import path from 'node:path';
import fs from 'fs-extra'; import fs from 'fs-extra';
import { join } from 'path'; import { optimize } from 'svgo';
import Svgo from 'svgo';
import { webComponentPassPlugins, sourcePassPlugins } from './plugins';
import { reservedKeywords } from './constants';
import pkgData from '../package.json' with { type: 'json' };
import type { SvgData } from './types';
async function build(rootDir: string) { async function build(rootDir: string) {
try { try {
const pkgJsonPath = join(rootDir, 'package.json'); const srcDir = path.join(rootDir, 'src');
const srcDir = join(rootDir, 'src'); const srcSvgDir = path.join(srcDir, 'svg');
const srcSvgDir = join(srcDir, 'svg'); const iconDir = path.join(rootDir, 'icons');
const iconDir = join(rootDir, 'icons'); const distDir = path.join(rootDir, 'dist');
const distDir = join(rootDir, 'dist'); const distIoniconsDir = path.join(distDir, 'ionicons');
const distIoniconsDir = join(distDir, 'ionicons'); const distSvgDir = path.join(distDir, 'svg');
const distSvgDir = join(distDir, 'svg'); const optimizedSvgDir = path.join(distIoniconsDir, 'svg');
await Promise.all([fs.emptyDir(iconDir), fs.emptyDir(distDir)]); /**
await fs.emptyDir(distSvgDir), await fs.emptyDir(distIoniconsDir); * Create the directories first, then empty them
* This ensures they exist before we try to write files to them
*/
await Promise.all([
fs.ensureDir(iconDir),
fs.ensureDir(distDir),
fs.ensureDir(distSvgDir),
fs.ensureDir(optimizedSvgDir),
fs.ensureDir(distIoniconsDir),
]);
/**
* Empty the directories
*/
await Promise.all([
fs.emptyDir(iconDir),
fs.emptyDir(distDir),
fs.emptyDir(distSvgDir),
fs.emptyDir(optimizedSvgDir),
fs.emptyDir(distIoniconsDir),
]);
const pkgData = await fs.readJson(pkgJsonPath);
const version = pkgData.version as string; const version = pkgData.version as string;
const srcSvgData = await getSvgs(srcSvgDir, distSvgDir, optimizedSvgDir);
const srcSvgData = await getSvgs(srcSvgDir, distSvgDir, distIoniconsDir);
await optimizeSvgs(srcSvgData); await optimizeSvgs(srcSvgData);
await Promise.all([ await Promise.all([
createDataJson(version, srcDir, distDir, srcSvgData), createDataJson(version, srcDir, distDir, srcSvgData),
createIconPackage(version, iconDir, srcSvgData), createIconPackage(version, iconDir, srcSvgData),
@@ -30,9 +52,7 @@ async function build(rootDir: string) {
const svgSymbolsContent = await createSvgSymbols(version, distDir, srcSvgData); const svgSymbolsContent = await createSvgSymbols(version, distDir, srcSvgData);
await createCheatsheet(version, rootDir, distDir, svgSymbolsContent, srcSvgData); await createCheatsheet(version, rootDir, distDir, svgSymbolsContent, srcSvgData);
await createWebTypes(version, rootDir, distDir, srcSvgData); await createWebTypes(version, rootDir, distDir, srcSvgData);
await copyToTesting(rootDir, distDir, srcSvgData); await copyToTesting(rootDir, distDir, srcSvgData);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@@ -41,173 +61,84 @@ async function build(rootDir: string) {
} }
async function optimizeSvgs(srcSvgData: SvgData[]) { async function optimizeSvgs(srcSvgData: SvgData[]) {
// https://github.com/svg/svgo
const optimizePass = new Svgo({});
const webComponentPass = new Svgo({
full: true,
plugins: [
{
addFillNoneCss: {
type: 'perItem',
fn: (item, params) => {
if (!Array.isArray(params.attrs)) {
params.attrs = [params.attrs];
}
/**
* All host SVG elements must have
* the ionicons class otherwise styles
* will not apply.
*/
if (item.elem === 'svg') {
item.class.add('ionicon');
}
if (item.isElem()) {
item.eachAttr((attr) => {
if (attr.name === 'fill') {
if (attr.value === 'none') {
item.class.add('ionicon-fill-none');
}
item.removeAttr('fill');
} else if (attr.name === 'stroke') {
item.removeAttr('stroke');
} else if (attr.name === 'stroke-width' && attr.value === '32') {
item.removeAttr('stroke-width');
item.class.add('ionicon-stroke-width');
}
});
}
},
},
} as any,
{
removeStyleElement: true,
},
{
removeScriptElement: true,
},
{
removeDimensions: true,
},
],
});
const sourcePass = new Svgo({
full: true,
plugins: [
{
addFillNoneCss: {
type: 'perItem',
fn: (item, params) => {
if (!Array.isArray(params.attrs)) {
params.attrs = [params.attrs];
}
if (item.isElem()) {
item.eachAttr((attr) => {
if (attr.name === 'stroke' || attr.name === 'fill') {
if (attr.value === '#000' || attr.value === 'currentColor') {
item.addAttr({
name: attr.name,
value: 'currentColor',
prefix: '',
local: attr.name,
});
} else if (attr.value !== 'none') {
throw new Error(`invalid "${attr.name}" value: ${attr.value}`);
}
}
});
}
},
},
} as any,
{
removeStyleElement: true,
},
{
removeScriptElement: true,
},
{
removeDimensions: true,
},
],
});
const validatePass = new Svgo({
full: true,
plugins: [
{
addFillNoneCss: {
type: 'perItem',
fn: (item, params) => {
if (!Array.isArray(params.attrs)) {
params.attrs = [params.attrs];
}
if (item.isElem()) {
item.eachAttr((attr) => {
if (attr.name === 'style') {
throw new Error('Inline style attributed detected');
}
});
}
if (item.isElem('style')) {
throw new Error('Inline style element detected');
}
},
},
} as any,
],
});
await Promise.all( await Promise.all(
srcSvgData.map(async (svgData) => { srcSvgData.map(async (svgData) => {
return optimizeSvg(optimizePass, webComponentPass, sourcePass, validatePass, svgData); return optimizeSvg(svgData);
}), }),
); );
} }
async function optimizeSvg( async function optimizeSvg(svgData: SvgData) {
optimizePass: Svgo,
webComponentPass: Svgo,
sourcePass: Svgo,
validatePass: Svgo,
svgData: SvgData,
) {
const srcSvgContent = await fs.readFile(svgData.srcFilePath, 'utf8'); const srcSvgContent = await fs.readFile(svgData.srcFilePath, 'utf8');
const optimizedSvg = await optimizePass.optimize(srcSvgContent, { path: svgData.srcFilePath }); const optimizedSvg = await optimize(srcSvgContent, { path: svgData.srcFilePath });
const webComponentSvg = await webComponentPass.optimize(optimizedSvg.data, { path: svgData.srcFilePath }); const webComponentSvg = await optimize(optimizedSvg.data, {
const sourceSvg = await sourcePass.optimize(optimizedSvg.data, { path: svgData.srcFilePath }); path: svgData.srcFilePath,
plugins: webComponentPassPlugins,
});
const sourceSvg = await optimize(optimizedSvg.data, {
path: svgData.srcFilePath,
plugins: sourcePassPlugins,
});
// Ensure directories exist before writing files
await Promise.all([
fs.ensureDir(path.dirname(svgData.optimizedFilePath)),
fs.ensureDir(path.dirname(svgData.distSvgFilePath)),
]);
svgData.optimizedSvgContent = webComponentSvg.data; svgData.optimizedSvgContent = webComponentSvg.data;
await Promise.all([
try { fs.writeFile(svgData.optimizedFilePath, svgData.optimizedSvgContent),
await validatePass.optimize(svgData.optimizedSvgContent, { path: svgData.srcFilePath }); fs.writeFile(svgData.distSvgFilePath, sourceSvg.data),
} catch (e) { ]);
console.error(`${e.message}: ${svgData.srcFilePath}`);
}
await fs.writeFile(svgData.optimizedFilePath, svgData.optimizedSvgContent);
await fs.writeFile(svgData.distSvgFilePath, sourceSvg.data);
} }
async function copyToTesting(rootDir: string, distDir: string, srcSvgData: SvgData[]) { async function copyToTesting(rootDir: string, distDir: string, srcSvgData: SvgData[]) {
const testDir = join(rootDir, 'www'); const testDir = path.join(rootDir, 'www');
const testBuildDir = join(testDir, 'build'); const testBuildDir = path.join(testDir, 'build');
const testSvgDir = join(testBuildDir, 'svg'); const testSvgDir = path.join(testBuildDir, 'svg');
await fs.ensureDir(testSvgDir); const cheatsheetDir = path.join(testDir, 'icon', 'test', 'cheatsheet');
const version = (await fs.readJson(path.join(rootDir, 'package.json'))).version;
// Ensure all directories exist
await Promise.all([
fs.ensureDir(testDir),
fs.ensureDir(testBuildDir),
fs.ensureDir(testSvgDir),
fs.ensureDir(cheatsheetDir),
]);
await Promise.all( await Promise.all(
srcSvgData.map(async (svgData) => { srcSvgData
const testSvgFilePath = join(testSvgDir, svgData.fileName); .filter((svgData): svgData is SvgData & { optimizedSvgContent: string } => Boolean(svgData.optimizedSvgContent))
await fs.writeFile(testSvgFilePath, svgData.optimizedSvgContent); .map(async (svgData) => {
}), const testSvgFilePath = path.join(testSvgDir, svgData.fileName);
await fs.writeFile(testSvgFilePath, svgData.optimizedSvgContent);
}),
); );
const distCheatsheetFilePath = join(distDir, 'cheatsheet.html'); const wwwCheatsheetFilePath = path.join(cheatsheetDir, 'index.html');
const testCheatsheetFilePath = join(testDir, 'cheatsheet.html'); const srcIndexFilePath = path.join(rootDir, 'src', 'components', 'icon', 'test', 'index.html');
await fs.copyFile(distCheatsheetFilePath, testCheatsheetFilePath); const testIndexFilePath = path.join(testDir, 'index.html');
await fs.copyFile(srcIndexFilePath, testIndexFilePath);
// Generate the cheatsheet with placeholders filled in
const svgSymbolsContent = await fs.readFile(path.join(distDir, 'ionicons.symbols.svg'), 'utf8');
const c = srcSvgData.map(
(svgData) =>
`<a href="/svg/${svgData.fileName}"><svg><use href="#${svgData.iconName}" xlink:href="#${svgData.iconName}"/></svg></a>`,
);
c.push(svgSymbolsContent);
const cheatsheetTemplate = await fs.readFile(path.join(rootDir, 'scripts', 'cheatsheet-template.html'), 'utf8');
const cheatsheetHtml = cheatsheetTemplate
.replace(/{{version}}/g, version)
.replace(/{{count}}/g, srcSvgData.length.toString())
.replace(/{{content}}/g, c.join('\n'));
await fs.writeFile(wwwCheatsheetFilePath, cheatsheetHtml);
} }
async function createSvgSymbols(version: string, distDir: string, srcSvgData: SvgData[]) { async function createSvgSymbols(version: string, distDir: string, srcSvgData: SvgData[]) {
@@ -217,7 +148,7 @@ async function createSvgSymbols(version: string, distDir: string, srcSvgData: Sv
return 0; return 0;
}); });
const symbolsSvgFilePath = join(distDir, 'ionicons.symbols.svg'); const symbolsSvgFilePath = path.join(distDir, 'ionicons.symbols.svg');
const lines = [ const lines = [
`<svg data-ionicons="${version}" style="display:none">`, `<svg data-ionicons="${version}" style="display:none">`,
@@ -235,19 +166,19 @@ async function createSvgSymbols(version: string, distDir: string, srcSvgData: Sv
`</style>`, `</style>`,
]; ];
srcSvgData.forEach((svgData) => { srcSvgData
const svg = svgData.optimizedSvgContent .filter((svgData): svgData is SvgData & { optimizedSvgContent: string } => Boolean(svgData.optimizedSvgContent))
.replace(`<svg xmlns="http://www.w3.org/2000/svg"`, `<symbol id="${svgData.iconName}"`) .forEach((svgData) => {
.replace(`</svg>`, `</symbol>`); const svg = svgData.optimizedSvgContent
lines.push(svg); .replace(`<svg xmlns="http://www.w3.org/2000/svg"`, `<symbol id="${svgData.iconName}"`)
}); .replace(`</svg>`, `</symbol>`);
lines.push(svg);
});
lines.push(`</svg>`, ``); lines.push(`</svg>`, ``);
const content = lines.join('\n'); const content = lines.join('\n');
await fs.writeFile(symbolsSvgFilePath, content); await fs.writeFile(symbolsSvgFilePath, content);
return content; return content;
} }
@@ -258,11 +189,12 @@ async function createCheatsheet(
svgSymbolsContent: string, svgSymbolsContent: string,
srcSvgData: SvgData[], srcSvgData: SvgData[],
) { ) {
const CheatsheetTmpFilePath = join(rootDir, 'scripts', 'cheatsheet-template.html'); const CheatsheetTmpFilePath = path.join(rootDir, 'scripts', 'cheatsheet-template.html');
const distCheatsheetFilePath = join(distDir, 'cheatsheet.html'); const distCheatsheetFilePath = path.join(distDir, 'cheatsheet.html');
const c = srcSvgData.map( const c = srcSvgData.map(
(svgData) => `<a href="./svg/${svgData.fileName}"><svg><use href="#${svgData.iconName}" xlink:href="#${svgData.iconName}"/></svg></a>`, (svgData) =>
`<a href="/svg/${svgData.fileName}"><svg><use href="#${svgData.iconName}" xlink:href="#${svgData.iconName}"/></svg></a>`,
); );
c.push(svgSymbolsContent); c.push(svgSymbolsContent);
@@ -275,35 +207,26 @@ async function createCheatsheet(
await fs.writeFile(distCheatsheetFilePath, html); await fs.writeFile(distCheatsheetFilePath, html);
} }
async function createWebTypes( async function createWebTypes(version: string, rootDir: string, distDir: string, srcSvgData: SvgData[]) {
version: string, const srcWebTypeFilePath = path.join(rootDir, 'src/ionicons.web-types.json');
rootDir: string, const distWebTypesFilePath = path.join(distDir, 'ionicons.web-types.json');
distDir: any, const webTypes = JSON.parse(await fs.readFile(srcWebTypeFilePath, 'utf8'));
srcSvgData: SvgData[]
) {
const srcWebTypeFilePath = join(rootDir, 'src/ionicons.web-types.json');
const distWebTypesFilePath = join(distDir, 'ionicons.web-types.json');
const webTypes = JSON.parse(await fs.readFile(srcWebTypeFilePath, 'utf8')) webTypes.version = version;
webTypes.version = version const icons = webTypes.contributions.html.ionicons;
const icons = webTypes.contributions.html.ionicons
for (let data of srcSvgData) { for (let data of srcSvgData) {
icons.push({ icons.push({
name: data.iconName, name: data.iconName,
icon: "dist/svg/" + data.fileName icon: 'dist/svg/' + data.fileName,
}) });
} }
const jsonStr = JSON.stringify(webTypes, null, 2) + '\n'; const jsonStr = JSON.stringify(webTypes, null, 2) + '\n';
await fs.writeFile(distWebTypesFilePath, jsonStr); await fs.writeFile(distWebTypesFilePath, jsonStr);
} }
async function getSvgs(srcSvgDir: string, distSvgDir: string, distIoniconsDir: string): Promise<SvgData[]> { async function getSvgs(srcSvgDir: string, distSvgDir: string, optimizedSvgDir: string): Promise<SvgData[]> {
const optimizedSvgDir = join(distIoniconsDir, 'svg');
await fs.emptyDir(optimizedSvgDir);
const svgFiles = (await fs.readdir(srcSvgDir)).filter((fileName) => { const svgFiles = (await fs.readdir(srcSvgDir)).filter((fileName) => {
return !fileName.startsWith('.') && fileName.endsWith('.svg'); return !fileName.startsWith('.') && fileName.endsWith('.svg');
}); });
@@ -317,13 +240,13 @@ async function getSvgs(srcSvgDir: string, distSvgDir: string, distIoniconsDir: s
} }
// srcFilePath: /src/svg/airplane-outline.svg // srcFilePath: /src/svg/airplane-outline.svg
const srcFilePath = join(srcSvgDir, fileName); const srcFilePath = path.join(srcSvgDir, fileName);
// srcFilePath: /src/svg/airplane-outline.svg // srcFilePath: /src/svg/airplane-outline.svg
const distSvgFilePath = join(distSvgDir, fileName); const distSvgFilePath = path.join(distSvgDir, fileName);
// optimizedFilePath: /dist/ionicons/svg/airplane-outline.svg // optimizedFilePath: /dist/ionicons/svg/airplane-outline.svg
const optimizedFilePath = join(optimizedSvgDir, fileName); const optimizedFilePath = path.join(optimizedSvgDir, fileName);
const dotSplit = fileName.split('.'); const dotSplit = fileName.split('.');
if (dotSplit.length > 2) { if (dotSplit.length > 2) {
@@ -357,7 +280,6 @@ async function getSvgs(srcSvgDir: string, distSvgDir: string, distIoniconsDir: s
distSvgFilePath, distSvgFilePath,
srcSvgContent: await fs.readFile(srcFilePath, 'utf8'), srcSvgContent: await fs.readFile(srcFilePath, 'utf8'),
optimizedFilePath, optimizedFilePath,
optimizedSvgContent: null,
iconName, iconName,
fileNameMjs, fileNameMjs,
fileNameCjs, fileNameCjs,
@@ -374,29 +296,15 @@ async function getSvgs(srcSvgDir: string, distSvgDir: string, distIoniconsDir: s
} }
async function createIconPackage(version: string, iconDir: string, srcSvgData: SvgData[]) { async function createIconPackage(version: string, iconDir: string, srcSvgData: SvgData[]) {
const iconPkgJsonFilePath = join(iconDir, 'package.json');
await Promise.all([ await Promise.all([
createEsmIcons(version, iconDir, srcSvgData), createEsmIcons(version, iconDir, srcSvgData),
createCjsIcons(version, iconDir, srcSvgData), createCjsIcons(version, iconDir, srcSvgData),
createDtsIcons(version, iconDir, srcSvgData), createDtsIcons(version, iconDir, srcSvgData),
]); ]);
const iconPkgJson = {
name: 'ionicons/icons',
version,
module: 'index.mjs',
main: 'index.js',
typings: 'index.d.ts',
private: true,
};
const jsonStr = JSON.stringify(iconPkgJson, null, 2) + '\n';
await fs.writeFile(iconPkgJsonFilePath, jsonStr);
} }
async function createEsmIcons(version: string, iconDir: string, srcSvgData: SvgData[]) { async function createEsmIcons(version: string, iconDir: string, srcSvgData: SvgData[]) {
const iconEsmFilePath = join(iconDir, 'index.mjs'); const iconEsmFilePath = path.join(iconDir, 'index.mjs');
const o = [`/* Ionicons v${version}, ES Modules */`, ``]; const o = [`/* Ionicons v${version}, ES Modules */`, ``];
@@ -408,7 +316,7 @@ async function createEsmIcons(version: string, iconDir: string, srcSvgData: SvgD
} }
async function createCjsIcons(version: string, iconDir: string, srcSvgData: SvgData[]) { async function createCjsIcons(version: string, iconDir: string, srcSvgData: SvgData[]) {
const iconCjsFilePath = join(iconDir, 'index.js'); const iconCjsFilePath = path.join(iconDir, 'index.js');
const o = [`/* Ionicons v${version}, CommonJS */`, ``]; const o = [`/* Ionicons v${version}, CommonJS */`, ``];
@@ -420,7 +328,7 @@ async function createCjsIcons(version: string, iconDir: string, srcSvgData: SvgD
} }
async function createDtsIcons(version: string, iconDir: string, srcSvgData: SvgData[]) { async function createDtsIcons(version: string, iconDir: string, srcSvgData: SvgData[]) {
const iconDtsFilePath = join(iconDir, 'index.d.ts'); const iconDtsFilePath = path.join(iconDir, 'index.d.ts');
const o = [`/* Ionicons v${version}, Types */`, ``]; const o = [`/* Ionicons v${version}, Types */`, ``];
@@ -433,6 +341,11 @@ async function createDtsIcons(version: string, iconDir: string, srcSvgData: SvgD
function getDataUrl(svgData: SvgData) { function getDataUrl(svgData: SvgData) {
let svg = svgData.optimizedSvgContent; let svg = svgData.optimizedSvgContent;
if (!svg) {
throw new Error(`oh no! no optimized SVG content! ${svgData.fileName}`);
}
if (svg.includes(`'`)) { if (svg.includes(`'`)) {
throw new Error(`oh no! no single quotes allowed! ${svgData.fileName}`); throw new Error(`oh no! no single quotes allowed! ${svgData.fileName}`);
} }
@@ -444,17 +357,10 @@ function getDataUrl(svgData: SvgData) {
} }
async function createDataJson(version: string, srcDir: string, distDir: string, srcSvgData: SvgData[]) { async function createDataJson(version: string, srcDir: string, distDir: string, srcSvgData: SvgData[]) {
const srcDataJsonPath = join(srcDir, 'data.json'); const srcDataJsonPath = path.join(srcDir, 'data.json');
const distDataJsonPath = join(distDir, 'ionicons.json'); const distDataJsonPath = path.join(distDir, 'ionicons.json');
let data: JsonData;
try {
data = await fs.readJson(srcDataJsonPath);
} catch (e) {
data = {} as any;
}
const data = await fs.readJson(srcDataJsonPath).catch(() => ({}));
data.icons = data.icons || []; data.icons = data.icons || [];
// add new icons // add new icons
@@ -503,60 +409,6 @@ function upFirst(word: string) {
return word[0].toUpperCase() + word.toLowerCase().slice(1); return word[0].toUpperCase() + word.toLowerCase().slice(1);
} }
interface SvgData {
/**
* airplane-outline.svg
*/
fileName: string;
/**
* airplane
*/
title: string;
/**
* /src/svg/airplane-outline.svg
*/
srcFilePath: string;
/**
* /dist/ionicons/svg/airplane-outline.svg
*/
optimizedFilePath: string;
/**
* /dist/svg/airplane-outline.svg
*/
distSvgFilePath: string;
optimizedSvgContent: string;
/**
* airplane-outline
*/
iconName: string;
/**
* airplane-outline.mjs
*/
fileNameMjs: string;
/**
* airplane-outline.js
*/
fileNameCjs: string;
/**
* airplaneOutline
*/
exportName: string;
}
interface JsonData {
icons: { name: string; tags?: string[] }[];
version?: string;
}
function toTitleCase(str: string) { function toTitleCase(str: string) {
const s = str.trim().toLowerCase().split(' '); const s = str.trim().toLowerCase().split(' ');
for (var i = 0; i < s.length; i++) { for (var i = 0; i < s.length; i++) {
@@ -565,58 +417,5 @@ function toTitleCase(str: string) {
return s.join(' '); return s.join(' ');
} }
// https://mathiasbynens.be/notes/reserved-keywords
const reservedKeywords = new Set([
'do',
'if',
'in',
'for',
'let',
'new',
'try',
'var',
'case',
'else',
'enum',
'eval',
'null',
'this',
'true',
'void',
'with',
'await',
'break',
'catch',
'class',
'const',
'false',
'super',
'throw',
'while',
'yield',
'delete',
'export',
'import',
'public',
'return',
'static',
'switch',
'typeof',
'default',
'extends',
'finally',
'package',
'private',
'continue',
'debugger',
'function',
'arguments',
'interface',
'protected',
'implements',
'instanceof',
'constructor',
]);
// let's do this // let's do this
build(join(__dirname, '..')); build(path.join(__dirname, '..'));
+23 -27
View File
@@ -1,24 +1,27 @@
<!doctype html> <!DOCTYPE html>
<html> <html dir="ltr" lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<title>Ionicons {{version}} Cheatsheet</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<title>Ionicons {{version}} Cheatsheet</title>
<script type="module" src="/build/ionicons.esm.js"></script>
<script nomodule src="/build/ionicons.js"></script>
<link rel="stylesheet" href="../styles.css" />
<script src="../header.js"></script>
</head>
<body>
<test-header></test-header>
<main>
<h1>Ionicons {{version}} Cheatsheet</h1>
<h3>{{count}} icons</h3>
{{content}}
</main>
</body>
<style> <style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background: #fff;
}
h1 {
margin: 0;
}
.options {
padding: 15px 0 20px 0;
}
label {
display: inline-block;
width: 100px;
font-size: 12px;
}
svg { svg {
width: 32px; width: 32px;
height: 32px; height: 32px;
@@ -31,11 +34,4 @@
opacity: 0.7; opacity: 0.7;
} }
</style> </style>
</head>
<body>
<h1>Ionicons {{version}} Cheatsheet</h1>
<h3>{{count}} icons</h3>
{{content}}
</body>
</html> </html>
-12
View File
@@ -29,18 +29,6 @@ async function collectionCopy(rootDir: string) {
}; };
await fs.writeFile(cePackageJsonPath, JSON.stringify(cePackageJson, null, 2)); await fs.writeFile(cePackageJsonPath, JSON.stringify(cePackageJson, null, 2));
/**
* TODO: Remove this in Ionicons v6.0
* Stencil 2 removed the legacy loader,
* but that is what Ionicons users were using
* to load Ionicons from a CDN. The lines
* below will add in a legacy loader for users
* to use so there is no breaking change in usage.
*/
const installLoaderSrc = join(rootDir, 'scripts', 'install-loader.js');
const installLoaderDest = join(rootDir, 'dist', 'ionicons.js');
await fs.copyFile(installLoaderSrc, installLoaderDest)
// this is temporary!!!! // this is temporary!!!!
// removing the `type` from the d.ts export // removing the `type` from the d.ts export
// to make it easier for users migrating between // to make it easier for users migrating between
+52
View File
@@ -0,0 +1,52 @@
// https://mathiasbynens.be/notes/reserved-keywords
export const reservedKeywords = new Set([
'do',
'if',
'in',
'for',
'let',
'new',
'try',
'var',
'case',
'else',
'enum',
'eval',
'null',
'this',
'true',
'void',
'with',
'await',
'break',
'catch',
'class',
'const',
'false',
'super',
'throw',
'while',
'yield',
'delete',
'export',
'import',
'public',
'return',
'static',
'switch',
'typeof',
'default',
'extends',
'finally',
'package',
'private',
'continue',
'debugger',
'function',
'arguments',
'interface',
'protected',
'implements',
'instanceof',
'constructor',
]);
-30
View File
@@ -1,30 +0,0 @@
(function(doc){
var scriptElm = doc.scripts[doc.scripts.length - 1];
var warn = ['[ionicons] Deprecated script, please remove: ' + scriptElm.outerHTML];
warn.push('To improve performance it is recommended to set the differential scripts in the head as follows:')
var parts = scriptElm.src.split('/');
parts.pop();
parts.push('ionicons');
var url = parts.join('/');
var scriptElm = doc.createElement('script');
scriptElm.setAttribute('type', 'module');
scriptElm.src = url + '/ionicons.esm.js';
warn.push(scriptElm.outerHTML);
scriptElm.setAttribute('data-stencil-namespace', 'ionicons');
doc.head.appendChild(scriptElm);
scriptElm = doc.createElement('script');
scriptElm.setAttribute('nomodule', '');
scriptElm.src = url + '/ionicons.js';
warn.push(scriptElm.outerHTML);
scriptElm.setAttribute('data-stencil-namespace', 'ionicons');
doc.head.appendChild(scriptElm)
console.warn(warn.join('\n'));
})(document);
+87
View File
@@ -0,0 +1,87 @@
import { PluginConfig } from 'svgo';
const setRootIoniconClass: PluginConfig = {
name: 'addClassesToSVGElement',
params: {
className: 'ionicon',
},
};
const addFillNoneCss: PluginConfig = {
name: 'addFillNoneCss',
fn: () => ({
element: {
enter: (element) => {
if (element.attributes.fill) {
if (element.attributes.fill === 'none') {
element.attributes.class = [...(element.attributes.class?.split(' ') || []), 'ionicon-fill-none'].join(' ');
}
delete element.attributes.fill;
}
if (element.attributes.stroke) {
delete element.attributes.stroke;
}
if (
element.attributes['stroke-width'] &&
(element.attributes['stroke-width'] === '32px' || element.attributes['stroke-width'] === '32')
) {
delete element.attributes['stroke-width'];
element.attributes.class = [...(element.attributes.class?.split(' ') || []), 'ionicon-stroke-width'].join(
' ',
);
}
},
},
}),
};
const forceCurrentColor: PluginConfig = {
name: 'forceCurrentColor',
fn: () => ({
element: {
enter: (element) => {
const attr = element.attributes.stroke || element.attributes.fill;
const attrName = element.attributes.stroke ? 'stroke' : element.attributes.fill ? 'fill' : undefined;
if (attrName) {
if (attr === '#000' || attr === 'currentColor') {
element.attributes[attrName] = 'currentColor';
} else if (attr !== 'none') {
throw new Error(`invalid "${attrName}" value: ${element.attributes[attrName]}`);
}
}
},
},
}),
};
const validatePlugin: PluginConfig = {
name: 'validate',
fn: () => ({
element: {
enter: (element) => {
if (element.attributes.style) {
console.warn(
`Inline style attributed detected: <${element.name} style="${element.attributes.style}">...</${element.name}>`,
);
}
if (element.name === 'style') {
console.warn('Inline style element detected');
}
},
},
}),
};
const basePlugins: PluginConfig[] = [
'removeStyleElement',
'convertStyleToAttrs',
'removeScripts',
'removeDimensions',
setRootIoniconClass,
validatePlugin,
];
export const webComponentPassPlugins: PluginConfig[] = [...basePlugins, addFillNoneCss];
export const sourcePassPlugins: PluginConfig[] = [...basePlugins, forceCurrentColor];
+13 -16
View File
@@ -4,38 +4,35 @@
The `src/svg` directory is the single source of truth for svgs. They should not already be optimized and can be the original svg export straight out of an svg editor. A build step before releasing will optimize the source svgs (remove comments, reduce the size, etc) and ensure they'll work within `ion-icon`. The `src/svg` directory is the single source of truth for svgs. They should not already be optimized and can be the original svg export straight out of an svg editor. A build step before releasing will optimize the source svgs (remove comments, reduce the size, etc) and ensure they'll work within `ion-icon`.
## Build Locally ## Build Locally
After an svg has been updated, added or deleted from the `src/svg` directory, run: After an svg has been updated, added or deleted from the `src/svg` directory, run:
npm run build ```sh
npm run build
```
The build command will optimize all of the icons and generate the files to be distributed. After the build command, all of the optimized svgs are saved in `dist/ionicons/svg`. Additionally the `dist` directory contains the distribution files for the `ion-icon` web component. The build command will optimize all of the icons and generate the files to be distributed. After the build command, all of the optimized svgs are saved in `dist/ionicons/svg`. Additionally the `dist` directory contains the distribution files for the `ion-icon` web component.
## Svg Symbols Cheatsheet ## Svg Symbols Cheatsheet
After a build, a new `www/cheatsheet.html` file will be created. This version uses svg symbols rather than `ion-icon`. After a build, a new `www/cheatsheet.html` file will be created. This version uses svg symbols rather than `ion-icon`.
## ion-icon Component Preview ## ion-icon Component Preview
To see the `ion-icon` component in action, run: To see the `ion-icon` component in action, run:
npm start ```sh
npm start
```
## Release Steps ## Release Steps
npm run release.prepare Releases are automated via GitHub Actions. To trigger a release:
The release script will ask what version to use. After the script completes, double check the `www/cheatsheet.html` to ensure everything is good to go. 1. Go to the [Release Orchestrator](https://github.com/ionic-team/ionicons/actions/workflows/release-orchestrator.yml) workflow
2. Click "Run workflow"
Next, update `CHANGELOG.md`, then commit and push your changes Github. 3. Select the release type:
- **dev** — Creates a pre-release with a timestamp-based version (e.g., `8.0.14-dev.11784821417.1c794397`)
Next run: - **production** — Creates a semver release; select `patch`, `minor`, or `major`
4. The workflow will build, publish to NPM, and create a GitHub release (for production releases)
npm run release
Triple check the version number is correct, and choose which tag this should be released as. If it's a pre-release, it should be `dev`.
-7
View File
@@ -1,7 +0,0 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
"target": "es2017"
}
}
+53
View File
@@ -0,0 +1,53 @@
import { PluginConfig } from 'svgo';
export interface SvgData {
/**
* airplane-outline.svg
*/
fileName: string;
/**
* airplane
*/
title: string;
/**
* /src/svg/airplane-outline.svg
*/
srcFilePath: string;
/**
* /dist/ionicons/svg/airplane-outline.svg
*/
optimizedFilePath: string;
/**
* /dist/svg/airplane-outline.svg
*/
distSvgFilePath: string;
/**
* optimized svg content
*/
optimizedSvgContent?: string;
/**
* airplane-outline
*/
iconName: string;
/**
* airplane-outline.mjs
*/
fileNameMjs: string;
/**
* airplane-outline.js
*/
fileNameCjs: string;
/**
* airplaneOutline
*/
exportName: string;
}
+23 -4
View File
@@ -25,6 +25,7 @@ export namespace Components {
"ios"?: string; "ios"?: string;
/** /**
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`. * If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
* @default false
*/ */
"lazy": boolean; "lazy": boolean;
/** /**
@@ -33,6 +34,7 @@ export namespace Components {
"md"?: string; "md"?: string;
/** /**
* The mode determines which platform styles to use. * The mode determines which platform styles to use.
* @default getIonMode()
*/ */
"mode": string; "mode": string;
/** /**
@@ -40,7 +42,7 @@ export namespace Components {
*/ */
"name"?: string; "name"?: string;
/** /**
* When set to `false`, SVG content that is HTTP fetched will not be checked if the response SVG content has any `<script>` elements, or any attributes that start with `on`, such as `onclick`. * When `true`, SVG content, including SVG `data:` URLs, is checked before it renders. SVGs with `<script>` elements, attributes that start with `on` (like `onclick`), `javascript:` URLs, or non-SVG elements aren't rendered, and `<foreignObject>` elements are removed. Only set this to `false` for SVG content from a trusted source.
* @default true * @default true
*/ */
"sanitize": boolean; "sanitize": boolean;
@@ -85,6 +87,7 @@ declare namespace LocalJSX {
"ios"?: string; "ios"?: string;
/** /**
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`. * If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
* @default false
*/ */
"lazy"?: boolean; "lazy"?: boolean;
/** /**
@@ -93,6 +96,7 @@ declare namespace LocalJSX {
"md"?: string; "md"?: string;
/** /**
* The mode determines which platform styles to use. * The mode determines which platform styles to use.
* @default getIonMode()
*/ */
"mode"?: string; "mode"?: string;
/** /**
@@ -100,7 +104,7 @@ declare namespace LocalJSX {
*/ */
"name"?: string; "name"?: string;
/** /**
* When set to `false`, SVG content that is HTTP fetched will not be checked if the response SVG content has any `<script>` elements, or any attributes that start with `on`, such as `onclick`. * When `true`, SVG content, including SVG `data:` URLs, is checked before it renders. SVGs with `<script>` elements, attributes that start with `on` (like `onclick`), `javascript:` URLs, or non-SVG elements aren't rendered, and `<foreignObject>` elements are removed. Only set this to `false` for SVG content from a trusted source.
* @default true * @default true
*/ */
"sanitize"?: boolean; "sanitize"?: boolean;
@@ -113,15 +117,30 @@ declare namespace LocalJSX {
*/ */
"src"?: string; "src"?: string;
} }
interface IonIconAttributes {
"mode": string;
"color": string;
"ios": string;
"md": string;
"flipRtl": boolean;
"name": string;
"src": string;
"icon": string;
"size": string;
"lazy": boolean;
"sanitize": boolean;
}
interface IntrinsicElements { interface IntrinsicElements {
"ion-icon": IonIcon; "ion-icon": Omit<IonIcon, keyof IonIconAttributes> & { [K in keyof IonIcon & keyof IonIconAttributes]?: IonIcon[K] } & { [K in keyof IonIcon & keyof IonIconAttributes as `attr:${K}`]?: IonIconAttributes[K] } & { [K in keyof IonIcon & keyof IonIconAttributes as `prop:${K}`]?: IonIcon[K] };
} }
} }
export { LocalJSX as JSX }; export { LocalJSX as JSX };
declare module "@stencil/core" { declare module "@stencil/core" {
export namespace JSX { export namespace JSX {
interface IntrinsicElements { interface IntrinsicElements {
"ion-icon": LocalJSX.IonIcon & JSXBase.HTMLAttributes<HTMLIonIconElement>; "ion-icon": LocalJSX.IntrinsicElements["ion-icon"] & JSXBase.HTMLAttributes<HTMLIonIconElement>;
} }
} }
} }

Before

Width:  |  Height:  |  Size: 512 B

After

Width:  |  Height:  |  Size: 512 B

Before

Width:  |  Height:  |  Size: 227 B

After

Width:  |  Height:  |  Size: 227 B

Before

Width:  |  Height:  |  Size: 641 B

After

Width:  |  Height:  |  Size: 641 B

Before

Width:  |  Height:  |  Size: 1000 B

After

Width:  |  Height:  |  Size: 1000 B

Before

Width:  |  Height:  |  Size: 292 B

After

Width:  |  Height:  |  Size: 292 B

Before

Width:  |  Height:  |  Size: 369 B

After

Width:  |  Height:  |  Size: 369 B

Before

Width:  |  Height:  |  Size: 544 B

After

Width:  |  Height:  |  Size: 544 B

Before

Width:  |  Height:  |  Size: 544 B

After

Width:  |  Height:  |  Size: 544 B

Before

Width:  |  Height:  |  Size: 372 B

After

Width:  |  Height:  |  Size: 372 B

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 233 B

Before

Width:  |  Height:  |  Size: 340 B

After

Width:  |  Height:  |  Size: 340 B

+21 -3
View File
@@ -4,12 +4,13 @@
width: 1em; width: 1em;
height: 1em; height: 1em;
contain: strict; font-size: 1em;
contain: layout style;
fill: currentColor; fill: currentColor;
box-sizing: content-box !important; box-sizing: content-box !important;
} }
:host .ionicon { :host .ionicon {
@@ -24,7 +25,16 @@
stroke-width: var(--ionicon-stroke-width, 32px); stroke-width: var(--ionicon-stroke-width, 32px);
} }
.icon-inner, .icon-inner {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
.ionicon, .ionicon,
svg { svg {
display: block; display: block;
@@ -33,6 +43,14 @@ svg {
width: 100%; width: 100%;
} }
/* Slotted Content
* -----------------------------------------------------------
*/
::slotted(*) {
font-size: inherit !important;
}
/* Icon RTL /* Icon RTL
* ----------------------------------------------------------- * -----------------------------------------------------------
*/ */
+83 -31
View File
@@ -1,5 +1,5 @@
import { Build, Component, Element, Host, Prop, State, Watch, h } from '@stencil/core'; import { Build, Component, Element, Host, Prop, State, Watch, h } from '@stencil/core';
import { getSvgContent, ioniconContent } from './request'; import { getCacheKey, getSvgContent, ioniconContent } from './request';
import { getName, getUrl, inheritAttributes, isRTL } from './utils'; import { getName, getUrl, inheritAttributes, isRTL } from './utils';
@Component({ @Component({
@@ -74,9 +74,11 @@ export class Icon {
@Prop() lazy = false; @Prop() lazy = false;
/** /**
* When set to `false`, SVG content that is HTTP fetched will not be checked * When `true`, SVG content, including SVG `data:` URLs, is checked before it
* if the response SVG content has any `<script>` elements, or any attributes * renders. SVGs with `<script>` elements, attributes that start with `on`
* that start with `on`, such as `onclick`. * (like `onclick`), `javascript:` URLs, or non-SVG elements aren't rendered,
* and `<foreignObject>` elements are removed. Only set this to `false` for
* SVG content from a trusted source.
* @default true * @default true
*/ */
@Prop() sanitize = true; @Prop() sanitize = true;
@@ -86,15 +88,20 @@ export class Icon {
} }
connectedCallback() { connectedCallback() {
// purposely do not return the promise here because loading /**
// the svg file should not hold up loading the app * purposely do not return the promise here because loading
// only load the svg if it's visible * the svg file should not hold up loading the app
* only load the svg if it's visible
*/
this.waitUntilVisible(this.el, '50px', () => { this.waitUntilVisible(this.el, '50px', () => {
this.isVisible = true; this.isVisible = true;
this.loadIcon(); this.loadIcon();
}); });
} }
/**
* Loads the icon after the component has finished rendering.
*/
componentDidLoad() { componentDidLoad() {
/** /**
* Addresses an Angular issue where property values are assigned after the 'connectedCallback' but prior to the registration of watchers. * Addresses an Angular issue where property values are assigned after the 'connectedCallback' but prior to the registration of watchers.
@@ -107,33 +114,59 @@ export class Icon {
} }
} }
/**
* Disconnect the IntersectionObserver.
*/
disconnectedCallback() { disconnectedCallback() {
if (this.io) { if (this.io) {
this.io.disconnect(); this.io.disconnect();
this.io = undefined; this.io = undefined;
} }
} }
private waitUntilVisible(el: HTMLElement, rootMargin: string, cb: () => void) {
if (Build.isBrowser && this.lazy && typeof window !== 'undefined' && (window as any).IntersectionObserver) {
const io = (this.io = new (window as any).IntersectionObserver(
(data: IntersectionObserverEntry[]) => {
if (data[0].isIntersecting) {
io.disconnect();
this.io = undefined;
cb();
}
},
{ rootMargin },
));
io.observe(el); /**
} else { * Wait until the icon is visible in the viewport.
// browser doesn't support IntersectionObserver * @param el - The element to observe.
// so just fallback to always show it * @param rootMargin - The root margin of the observer.
cb(); * @param cb - The callback to call when the element is visible.
*/
private waitUntilVisible(el: HTMLElement, rootMargin: string, cb: () => void) {
/**
* IntersectionObserver is a browser API that allows you to observe
* the visibility of an element relative to a root element. It is
* supported in all modern browsers, except IE and when server-side
* rendering.
*/
const hasIntersectionObserverSupport = Boolean(
Build.isBrowser && this.lazy && typeof window !== 'undefined' && window.IntersectionObserver,
);
/**
* browser doesn't support IntersectionObserver
* so just fallback to always show it
*/
if (!hasIntersectionObserverSupport) {
return cb();
} }
const io = (this.io = new window.IntersectionObserver(
(data: IntersectionObserverEntry[]) => {
if (data[0].isIntersecting) {
io.disconnect();
this.io = undefined;
cb();
}
},
{ rootMargin },
));
io.observe(el);
} }
/**
* Watch for changes to the icon name, src, icon, ios, or md properties.
* When a change is detected, the icon will be loaded.
*/
@Watch('name') @Watch('name')
@Watch('src') @Watch('src')
@Watch('icon') @Watch('icon')
@@ -144,12 +177,13 @@ export class Icon {
const url = getUrl(this); const url = getUrl(this);
if (url) { if (url) {
if (ioniconContent.has(url)) { const cacheKey = getCacheKey(url, this.sanitize);
if (ioniconContent.has(cacheKey)) {
// sync if it's already loaded // sync if it's already loaded
this.svgContent = ioniconContent.get(url); this.svgContent = ioniconContent.get(cacheKey);
} else { } else {
// async if it hasn't been loaded // async if it hasn't been loaded
getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(url))); getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(cacheKey)));
} }
this.didLoadIcon = true; this.didLoadIcon = true;
} }
@@ -161,11 +195,18 @@ export class Icon {
render() { render() {
const { flipRtl, iconName, inheritedAttributes, el } = this; const { flipRtl, iconName, inheritedAttributes, el } = this;
const mode = this.mode || 'md'; const mode = this.mode || 'md';
// we have designated that arrows & chevrons should automatically flip (unless flip-rtl is set to false) because "back" is left in ltr and right in rtl, and "forward" is the opposite
/**
* we have designated that arrows & chevrons should automatically flip (unless flip-rtl
* is set to false) because "back" is left in ltr and right in rtl, and "forward" is the opposite
*/
const shouldAutoFlip = iconName const shouldAutoFlip = iconName
? (iconName.includes('arrow') || iconName.includes('chevron')) && flipRtl !== false ? (iconName.includes('arrow') || iconName.includes('chevron')) && flipRtl !== false
: false; : false;
// if shouldBeFlippable is true, the icon should change direction when `dir` changes
/**
* if shouldBeFlippable is true, the icon should change direction when `dir` changes
*/
const shouldBeFlippable = flipRtl || shouldAutoFlip; const shouldBeFlippable = flipRtl || shouldAutoFlip;
return ( return (
@@ -176,23 +217,34 @@ export class Icon {
...createColorClasses(this.color), ...createColorClasses(this.color),
[`icon-${this.size}`]: !!this.size, [`icon-${this.size}`]: !!this.size,
'flip-rtl': shouldBeFlippable, 'flip-rtl': shouldBeFlippable,
'icon-rtl': shouldBeFlippable && isRTL(el) 'icon-rtl': shouldBeFlippable && isRTL(el),
}} }}
{...inheritedAttributes} {...inheritedAttributes}
> >
{Build.isBrowser && this.svgContent ? ( {Build.isBrowser && this.svgContent ? (
<div class="icon-inner" innerHTML={this.svgContent}></div> <div class="icon-inner" innerHTML={this.svgContent}></div>
) : ( ) : (
<div class="icon-inner"></div> <div class="icon-inner">
<slot></slot>
</div>
)} )}
</Host> </Host>
); );
} }
} }
/**
* Get the mode of the document.
* @returns The mode of the document.
*/
const getIonMode = () => const getIonMode = () =>
(Build.isBrowser && typeof document !== 'undefined' && document.documentElement.getAttribute('mode')) || 'md'; (Build.isBrowser && typeof document !== 'undefined' && document.documentElement.getAttribute('mode')) || 'md';
/**
* Create color classes for the icon.
* @param color - The color of the icon.
* @returns The color classes for the icon.
*/
const createColorClasses = (color: string | undefined) => { const createColorClasses = (color: string | undefined) => {
return color return color
? { ? {
+13 -13
View File
@@ -7,19 +7,19 @@
## Properties ## Properties
| Property | Attribute | Description | Type | Default | | Property | Attribute | Description | Type | Default |
| ---------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -------------- | | ---------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -------------- |
| `color` | `color` | The color to use for the background of the item. | `string \| undefined` | `undefined` | | `color` | `color` | The color to use for the background of the item. | `string \| undefined` | `undefined` |
| `flipRtl` | `flip-rtl` | Specifies whether the icon should horizontally flip when `dir` is `"rtl"`. | `boolean \| undefined` | `undefined` | | `flipRtl` | `flip-rtl` | Specifies whether the icon should horizontally flip when `dir` is `"rtl"`. | `boolean \| undefined` | `undefined` |
| `icon` | `icon` | A combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property. | `any` | `undefined` | | `icon` | `icon` | A combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property. | `any` | `undefined` |
| `ios` | `ios` | Specifies which icon to use on `ios` mode. | `string \| undefined` | `undefined` | | `ios` | `ios` | Specifies which icon to use on `ios` mode. | `string \| undefined` | `undefined` |
| `lazy` | `lazy` | If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`. | `boolean` | `false` | | `lazy` | `lazy` | If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`. | `boolean` | `false` |
| `md` | `md` | Specifies which icon to use on `md` mode. | `string \| undefined` | `undefined` | | `md` | `md` | Specifies which icon to use on `md` mode. | `string \| undefined` | `undefined` |
| `mode` | `mode` | The mode determines which platform styles to use. | `string` | `getIonMode()` | | `mode` | `mode` | The mode determines which platform styles to use. | `string` | `getIonMode()` |
| `name` | `name` | Specifies which icon to use from the built-in set of icons. | `string \| undefined` | `undefined` | | `name` | `name` | Specifies which icon to use from the built-in set of icons. | `string \| undefined` | `undefined` |
| `sanitize` | `sanitize` | When set to `false`, SVG content that is HTTP fetched will not be checked if the response SVG content has any `<script>` elements, or any attributes that start with `on`, such as `onclick`. | `boolean` | `true` | | `sanitize` | `sanitize` | When `true`, SVG content, including SVG `data:` URLs, is checked before it renders. SVGs with `<script>` elements, attributes that start with `on` (like `onclick`), `javascript:` URLs, or non-SVG elements aren't rendered, and `<foreignObject>` elements are removed. Only set this to `false` for SVG content from a trusted source. | `boolean` | `true` |
| `size` | `size` | The size of the icon. Available options are: `"small"` and `"large"`. | `string \| undefined` | `undefined` | | `size` | `size` | The size of the icon. Available options are: `"small"` and `"large"`. | `string \| undefined` | `undefined` |
| `src` | `src` | Specifies the exact `src` of an SVG file to use. | `string \| undefined` | `undefined` | | `src` | `src` | Specifies the exact `src` of an SVG file to use. | `string \| undefined` | `undefined` |
---------------------------------------------- ----------------------------------------------
+99 -45
View File
@@ -5,53 +5,107 @@ const requests = new Map<string, Promise<any>>();
let parser: DOMParser; let parser: DOMParser;
export const getSvgContent = (url: string, sanitize: boolean) => { /**
// see if we already have a request for this url * Unsanitized content gets its own key so it's never served to an icon that
let req = requests.get(url); * sanitizes.
*/
export const getCacheKey = (url: string, sanitize: boolean) =>
`${sanitize !== false ? 'sanitized' : 'unsanitized'}:${url}`;
if (!req) { /**
if (typeof fetch !== 'undefined' && typeof document !== 'undefined') { * Warns when the whole icon is rejected so it doesn't silently render nothing.
/** */
* If the url is a data url of an svg, then try to parse it const sanitizeSvg = (url: string, svgContent: string) =>
* with the DOMParser. This works with content security policies enabled. validateContent(svgContent, () => {
*/ const source = url.length > 100 ? `${url.slice(0, 100)}...` : url;
if (isSvgDataUrl(url) && isEncodedDataUrl(url)) { console.warn(
if (!parser) { `[Ionicons Warning]: The SVG from "${source}" was not rendered because it failed sanitization. Only set sanitize="false" for SVG content from a trusted source.`,
/** );
* Create an instance of the DOM parser. This creates a single });
* parser instance for the entire app, which is more efficient.
*/
parser = new DOMParser();
}
const doc = parser.parseFromString(url, 'text/html');
const svg = doc.querySelector('svg');
if (svg) {
ioniconContent.set(url, svg.outerHTML);
}
return Promise.resolve();
} else {
// we don't already have a request
req = fetch(url).then((rsp) => {
if (rsp.ok) {
return rsp.text().then((svgContent) => {
if (svgContent && sanitize !== false) {
svgContent = validateContent(svgContent);
}
ioniconContent.set(url, svgContent || '');
});
}
ioniconContent.set(url, '');
});
// cache for the same requests
requests.set(url, req);
}
} else { /**
// set to empty for ssr scenarios and resolve promise * Safely fallback to an empty svg
ioniconContent.set(url, ''); */
return Promise.resolve(); function safeFallback(cacheKey: string) {
} const svg = '';
ioniconContent.set(cacheKey, svg);
return svg;
}
export const getSvgContent = (url: string, sanitize: boolean): Promise<string> => {
const cacheKey = getCacheKey(url, sanitize);
/**
* See if we already have a request for this url
*/
const req = requests.get(cacheKey);
if (req) {
return req;
} }
return req; if (typeof fetch !== 'undefined' && typeof document !== 'undefined') {
/**
* If the url is a data url of an svg, then try to parse it
* with the DOMParser. This works with content security policies enabled.
*/
if (isSvgDataUrl(url) && isEncodedDataUrl(url)) {
return Promise.resolve(getSvgByUrl(url, sanitize));
}
return fetchSvg(url, sanitize);
}
return Promise.resolve(safeFallback(cacheKey));
}; };
function getSvgByUrl(url: string, sanitize: boolean): string {
if (!parser) {
/**
* Create an instance of the DOM parser. This creates a single
* parser instance for the entire app, which is more efficient.
*/
parser = new DOMParser();
}
const doc = parser.parseFromString(url, 'text/html');
const svg = doc.querySelector('svg');
if (svg) {
const svgContent = sanitize !== false ? sanitizeSvg(url, svg.outerHTML) : svg.outerHTML;
ioniconContent.set(getCacheKey(url, sanitize), svgContent);
return svgContent;
}
throw new Error(`Could not parse svg from ${url}`);
}
function fetchSvg(url: string, sanitize: boolean): Promise<string> {
const cacheKey = getCacheKey(url, sanitize);
/**
* We don't already have a request
*/
const req = fetch(url)
.then((rsp) => {
/**
* When fetching from a file:// URL, some browsers return
* a 0 status code even when the request succeeds so don't
* rely on rsp.ok as the only signal of success.
*/
return rsp
.text()
.then((svgContent) => {
if (svgContent && sanitize !== false) {
svgContent = sanitizeSvg(url, svgContent);
}
const svg = svgContent || '';
ioniconContent.set(cacheKey, svg);
return svg;
})
.catch(() => safeFallback(cacheKey));
})
.catch(() => safeFallback(cacheKey));
/**
* Cache for the same requests
*/
requests.set(cacheKey, req);
return req;
}
-1
View File
@@ -1,5 +1,4 @@
# this gitignore file is used as a placeholder # this gitignore file is used as a placeholder
# for this directory. The directory itself will # for this directory. The directory itself will
# contain files generated during a build step. # contain files generated during a build step.
*
!.gitignore !.gitignore
+15
View File
@@ -0,0 +1,15 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
import { AxeBuilder } from '@axe-core/playwright';
test.describe('icon: a11y', () => {
test('should pass accessibility checks', async ({ page }) => {
await page.goto(`/icon/test/a11y/`);
await page.waitForLoadState('networkidle');
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);
});
});
+59
View File
@@ -0,0 +1,59 @@
<!doctype html>
<html dir="ltr" lang="en" mode="ios">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<title>Icon - Accessibility</title>
<script type="module" src="/build/ionicons.esm.js"></script>
<script nomodule src="/build/ionicons.js"></script>
<link rel="stylesheet" href="../styles.css" />
<script src="../header.js"></script>
<!-- Font Awesome Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" />
</head>
<body>
<test-header></test-header>
<main>
<h1>Icon - Accessibility</h1>
<h2>SVG icon with aria-label</h2>
<ion-icon name="cellular" aria-label="Mobile data"></ion-icon>
<h2>Button with aria-label and SVG icon</h2>
<button aria-label="Mobile data">
<ion-icon name="cellular" aria-hidden="true"></ion-icon>
</button>
<h2>SVG icon with aria-hidden</h2>
<ion-icon name="cellular" aria-hidden="true"></ion-icon>
<hr />
<h2>Font icon with aria-label</h2>
<ion-icon aria-label="Mobile data">
<i class="fa fa-home"></i>
</ion-icon>
<h2>Button with aria-label and font icon</h2>
<button aria-label="Mobile data">
<ion-icon aria-hidden="true">
<i class="fa fa-home"></i>
</ion-icon>
</button>
<h2>Font icon with aria-hidden</h2>
<ion-icon aria-hidden="true">
<i class="fa fa-home"></i>
</ion-icon>
</main>
<style>
ion-icon {
font-size: 32px;
}
</style>
</body>
</html>
@@ -0,0 +1,13 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('icon: basic', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/icon/test/basic/`);
// Wait for all SVGs to be lazily loaded before taking screenshots
await page.waitForLoadState('networkidle');
await expect(page).toHaveScreenshot(`icon-basic.png`, { fullPage: true });
});
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

+101
View File
@@ -0,0 +1,101 @@
<!doctype html>
<html dir="ltr" lang="en" mode="ios">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<title>Icon - Basic</title>
<script type="module" src="/build/ionicons.esm.js"></script>
<script nomodule src="/build/ionicons.js"></script>
<link rel="stylesheet" href="../styles.css" />
<script src="../header.js"></script>
</head>
<body>
<test-header></test-header>
<main>
<h1>Icon - Basic</h1>
<h2>Default</h2>
<ion-icon name="cellular"></ion-icon>
<ion-icon name="at"></ion-icon>
<ion-icon name="call"></ion-icon>
<ion-icon name="football"></ion-icon>
<ion-icon name="analytics"></ion-icon>
<ion-icon name="grid"></ion-icon>
<ion-icon name="funnel"></ion-icon>
<ion-icon name="watch"></ion-icon>
<ion-icon name="add-circle-outline"></ion-icon>
<h2>Mode from html ios mode attribute</h2>
<ion-icon md="logo-android" ios="logo-apple"></ion-icon>
<ion-icon md="logo-android" ios="logo-apple"></ion-icon>
<h2>Mode set on icon</h2>
<ion-icon mode="ios" md="logo-android" ios="logo-apple"></ion-icon>
<ion-icon mode="md" md="logo-android" ios="logo-apple"></ion-icon>
<h2>Colors</h2>
<ion-icon color="primary" name="cellular"></ion-icon>
<ion-icon color="secondary" name="at"></ion-icon>
<ion-icon color="tertiary" name="call"></ion-icon>
<ion-icon color="success" name="football"></ion-icon>
<ion-icon color="warning" name="analytics"></ion-icon>
<ion-icon color="danger" name="grid"></ion-icon>
<ion-icon color="light" name="funnel"></ion-icon>
<ion-icon color="medium" name="watch"></ion-icon>
<ion-icon color="dark" name="toggle"></ion-icon>
<h2>Stroke width</h2>
<ion-icon name="heart-outline" style="--ionicon-stroke-width: 8px"></ion-icon>
<h2>Font size</h2>
<ion-icon name="book" style="font-size: 50px"></ion-icon>
<ion-icon src="../../assets/bug_report.svg" style="font-size: 50px"></ion-icon>
<h2>Custom SVGs</h2>
<ion-icon src="../../assets/bug_report.svg"></ion-icon>
<ion-icon src="../../assets/chat.svg"></ion-icon>
<ion-icon src="../../assets/commute.svg"></ion-icon>
<ion-icon src="../../assets/copyright.svg"></ion-icon>
<ion-icon src="../../assets/done_all.svg"></ion-icon>
<ion-icon src="../../assets/lock_open.svg"></ion-icon>
<ion-icon src="../../assets/toll.svg"></ion-icon>
<ion-icon src="../../assets/web_asset.svg"></ion-icon>
<ion-icon src="../../assets/work_outline.svg"></ion-icon>
<h2>Custom SVGs: colors</h2>
<ion-icon color="primary" src="../../assets/bug_report.svg"></ion-icon>
<ion-icon color="secondary" src="../../assets/chat.svg"></ion-icon>
<ion-icon color="tertiary" src="../../assets/commute.svg"></ion-icon>
<ion-icon color="success" src="../../assets/copyright.svg"></ion-icon>
<ion-icon color="warning" src="../../assets/done_all.svg"></ion-icon>
<ion-icon color="danger" src="../../assets/lock_open.svg"></ion-icon>
<ion-icon color="light" src="../../assets/toll.svg"></ion-icon>
<ion-icon color="medium" src="../../assets/web_asset.svg"></ion-icon>
<ion-icon color="dark" src="../../assets/work_outline.svg"></ion-icon>
<h2>Custom CSS</h2>
<ion-icon class="custom" name="grid"></ion-icon>
<ion-icon class="custom" name="funnel"></ion-icon>
<ion-icon class="custom" name="watch"></ion-icon>
<ion-icon class="custom" name="logo-react"></ion-icon>
<ion-icon class="custom" name="logo-javascript"></ion-icon>
<ion-icon class="custom" name="logo-angular"></ion-icon>
<ion-icon class="custom" src="../../assets/done_all.svg"></ion-icon>
<ion-icon class="custom" src="../../assets/web_asset.svg"></ion-icon>
<ion-icon class="custom" src="../../assets/work_outline.svg"></ion-icon>
</main>
<style>
ion-icon {
font-size: 32px;
}
.custom {
stroke: red;
fill: blue;
}
</style>
</body>
</html>
@@ -1,15 +1,13 @@
import { expect } from '@playwright/test'; import { expect } from '@playwright/test';
import { test } from '../../../utils/test/playwright'; import { test } from '@utils/test/playwright';
test.describe('icon: csp', () => { test.describe('icon: csp', () => {
test.beforeEach(async ({ page }) => { test.beforeEach(async ({ page }) => {
await page.goto('/test/csp'); await page.goto('/icon/test/csp');
}); });
test('should load svg', async ({ page }) => { test('should load svg', async ({ page }) => {
const svg = page.locator('ion-icon#icon-usage svg'); const svg = page.locator('ion-icon#icon-usage svg');
await expect(svg).toBeVisible(); await expect(svg).toBeVisible();
}); });
}); });
+52
View File
@@ -0,0 +1,52 @@
<!doctype html>
<html dir="ltr" lang="en" mode="ios">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com/*; img-src 'self'; connect-src 'self'; font-src https://fonts.gstatic.com/*'"
/>
<title>Icon - Content Security Policy</title>
<script type="module" src="/build/ionicons.esm.js"></script>
<script nomodule src="/build/ionicons.js"></script>
<link rel="stylesheet" href="../styles.css" />
<script src="../header.js"></script>
</head>
<body>
<test-header></test-header>
<main>
<h1>Icon - Content Security Policy</h1>
<h2>Default</h2>
<ion-icon src="/assets/chat.svg"></ion-icon>
<ion-icon name="add"></ion-icon>
<ion-icon
id="icon-usage"
icon="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><title>Watch</title><rect x='136' y='136' width='240' height='240' rx='8' ry='8'/><path d='M384 96h-48V16H176v80h-48a32 32 0 00-32 32v256a32 32 0 0032 32h48v80h160v-80h48a32 32 0 0032-32V128a32 32 0 00-32-32zm8 272a24 24 0 01-24 24H144a24 24 0 01-24-24V144a24 24 0 0124-24h224a24 24 0 0124 24z'/></svg>"
>
</ion-icon>
<ion-icon
class="custom"
icon="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><title>Watch</title><rect x='136' y='136' width='240' height='240' rx='8' ry='8'/><path d='M384 96h-48V16H176v80h-48a32 32 0 00-32 32v256a32 32 0 0032 32h48v80h160v-80h48a32 32 0 0032-32V128a32 32 0 00-32-32zm8 272a24 24 0 01-24 24H144a24 24 0 01-24-24V144a24 24 0 0124-24h224a24 24 0 0124 24z'/></svg>"
>
</ion-icon>
</main>
</body>
<style>
ion-icon {
font-size: 32px;
}
.custom {
stroke: red;
fill: goldenrod;
color: black;
}
</style>
</html>
@@ -1,19 +1,16 @@
import { expect } from '@playwright/test'; import { expect } from '@playwright/test';
import { test } from '../../../utils/test/playwright'; import { test } from '@utils/test/playwright';
test.describe('icon: dynamic type', () => { test.describe('icon: dynamic type', () => {
test.beforeEach(async ({ page }) => { test.beforeEach(async ({ page }) => {
await page.goto('/test/dynamic-type'); await page.goto(`/icon/test/dynamic-type/`);
}); });
test('should scale text on larger font sizes', async ({ page }) => { test('should scale text on larger font sizes', async ({ page }) => {
// Wait for all SVGs to be lazily loaded before taking screenshots // Wait for all SVGs to be lazily loaded before taking screenshots
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
const icons = page.locator('#icons'); const main = page.locator('main');
await expect(main).toHaveScreenshot(`icon-dynamic-type.png`);
await expect(icons).toHaveScreenshot(`icon-dynamic-type-diff.png`);
}); });
}); });
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

@@ -0,0 +1,45 @@
<!doctype html>
<html dir="ltr" lang="en" mode="ios">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<title>Icon - Dynamic Type</title>
<script type="module" src="/build/ionicons.esm.js"></script>
<script nomodule src="/build/ionicons.js"></script>
<link rel="stylesheet" href="../styles.css" />
<script src="../header.js"></script>
<!-- Font Awesome Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" />
</head>
<body>
<test-header></test-header>
<main>
<h1>Icon - Dynamic Type</h1>
<h2>Default Icons</h2>
<ion-icon name="star"></ion-icon>
<ion-icon name="star" size="small"></ion-icon>
<ion-icon name="star" size="large"></ion-icon>
<h2>Font Icons</h2>
<ion-icon>
<i class="fa fa-star"></i>
</ion-icon>
<ion-icon size="small">
<i class="fa fa-star"></i>
</ion-icon>
<ion-icon size="large">
<i class="fa fa-star"></i>
</ion-icon>
</main>
<style>
html {
font-size: 28px;
}
</style>
</body>
</html>
+14
View File
@@ -0,0 +1,14 @@
class TestHeader extends HTMLElement {
connectedCallback() {
const header = document.createElement('header');
header.innerHTML = `
<a href="/" class="back-button">
<ion-icon name="arrow-back" aria-hidden="true"></ion-icon>
Back
</a>
`;
this.appendChild(header);
}
}
customElements.define('test-header', TestHeader);
Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

+186 -63
View File
@@ -1,79 +1,202 @@
import { newSpecPage } from '@stencil/core/testing'; import { newSpecPage } from 'jest-stencil-runner';
import { Icon } from '../icon'; import { Icon } from '../icon';
describe('icon', () => { describe('icon', () => {
it('renders', async () => { describe('basic rendering', () => {
const { root } = await newSpecPage({ it('renders', async () => {
components: [Icon], const { root } = await newSpecPage({
html: '<ion-icon></ion-icon>', components: [Icon],
html: '<ion-icon></ion-icon>',
});
expect(root).toEqualHtml(`
<ion-icon class="md" role="img">
<mock:shadow-root>
<div class="icon-inner">
<slot></slot>
</div>
</mock:shadow-root>
</ion-icon>
`);
});
it('renders rtl with aria-hidden', async () => {
const { root } = await newSpecPage({
components: [Icon],
direction: 'rtl',
html: `<ion-icon name="chevron-forward" aria-hidden="true"></ion-icon>`,
});
expect(root).toEqualHtml(`
<ion-icon class="md flip-rtl icon-rtl" name="chevron-forward" role="img" aria-hidden="true">
<mock:shadow-root>
<div class="icon-inner">
<slot></slot>
</div>
</mock:shadow-root>
</ion-icon>
`);
});
it('renders custom aria-label', async () => {
const { root } = await newSpecPage({
components: [Icon],
html: `<ion-icon name="star" aria-label="custom label"></ion-icon>`,
});
expect(root).toEqualHtml(`
<ion-icon class="md" name="star" role="img" aria-label="custom label">
<mock:shadow-root>
<div class="icon-inner">
<slot></slot>
</div>
</mock:shadow-root>
</ion-icon>
`);
}); });
expect(root).toEqualHtml(`
<ion-icon class="md" role="img">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
</ion-icon>
`);
}); });
it('renders rtl with aria-hidden', async () => { describe('dynamic rendering', () => {
const { root } = await newSpecPage({ it('renders custom label after changing source', async () => {
components: [Icon], const page = await newSpecPage({
direction: 'rtl', components: [Icon],
html: `<ion-icon name="chevron-forward" aria-hidden="true"></ion-icon>`, html: `<ion-icon name="chevron-forward" aria-label="custom label"></ion-icon>`,
}); });
expect(root).toEqualHtml(` const icon = page.root;
<ion-icon class="md flip-rtl icon-rtl" name="chevron-forward" role="img" aria-hidden="true">
<mock:shadow-root> expect(icon).toEqualHtml(`
<div class="icon-inner"></div> <ion-icon class="flip-rtl md" name="chevron-forward" role="img" aria-label="custom label">
</mock:shadow-root> <mock:shadow-root>
</ion-icon> <div class="icon-inner">
`); <slot></slot>
</div>
</mock:shadow-root>
</ion-icon>
`);
if (icon) {
icon.name = 'trash';
}
await page.waitForChanges();
expect(icon).toEqualHtml(`
<ion-icon class="md" name="trash" role="img" aria-label="custom label">
<mock:shadow-root>
<div class="icon-inner">
<slot></slot>
</div>
</mock:shadow-root>
</ion-icon>
`);
});
}); });
it('renders custom aria-label', async () => { describe('svg rendering scenarios', () => {
const { root } = await newSpecPage({ it('svgContent=true: renders svg without slot', async () => {
components: [Icon], const page = await newSpecPage({
html: `<ion-icon name="star" aria-label="custom label"></ion-icon>`, components: [Icon],
html: `<ion-icon aria-hidden="true" part="close-icon" class="close-icon"></ion-icon>`,
});
const icon = page.root as any;
const instance = page.rootInstance as any;
instance.svgContent = '<svg><circle cx="50" cy="50" r="40"/></svg>';
await page.waitForChanges();
const shadowRoot = icon.shadowRoot;
const iconInner = shadowRoot?.querySelector('.icon-inner');
// Should have no slot
const slot = iconInner?.querySelector('slot');
expect(slot).toBeNull();
// SVG should be a direct child of icon-inner,
// not nested in another div
expect(iconInner?.children.length).toBe(1);
const firstChild = iconInner?.children[0];
expect((firstChild as any)?.tagName?.toLowerCase()).toBe('svg');
expect(firstChild?.querySelector('circle')).not.toBeNull();
}); });
expect(root).toEqualHtml(` it('svgContent=false: renders slot for custom content', async () => {
<ion-icon class="md" name="star" role="img" aria-label="custom label"> const page = await newSpecPage({
<mock:shadow-root> components: [Icon],
<div class="icon-inner"></div> html: `<ion-icon aria-hidden="true" part="close-icon" class="close-icon"></ion-icon>`,
</mock:shadow-root> });
</ion-icon>
`); const icon = page.root as any;
const shadowRoot = icon.shadowRoot;
const iconInner = shadowRoot?.querySelector('.icon-inner');
const slot = iconInner?.querySelector('slot');
const svg = iconInner?.querySelector('svg');
expect(slot).not.toBeNull();
expect(svg).toBeNull();
});
}); });
it('renders custom label after changing source', async () => { describe('slotted content', () => {
const page = await newSpecPage({ it('renders slotted font icon (Font Awesome)', async () => {
components: [Icon], const { root } = await newSpecPage({
html: `<ion-icon name="chevron-forward" aria-label="custom label"></ion-icon>`, components: [Icon],
html: `
<ion-icon>
<i class="fa fa-home"></i>
</ion-icon>
`,
});
expect(root).toEqualHtml(`
<ion-icon class="md" role="img">
<mock:shadow-root>
<div class="icon-inner">
<slot></slot>
</div>
</mock:shadow-root>
<i class="fa fa-home"></i>
</ion-icon>
`);
}); });
const icon = page.root;
expect(icon).toEqualHtml(` it('renders slotted font icon with color', async () => {
<ion-icon class="flip-rtl md" name="chevron-forward" role="img" aria-label="custom label"> const { root } = await newSpecPage({
<mock:shadow-root> components: [Icon],
<div class="icon-inner"></div> html: `
</mock:shadow-root> <ion-icon color="primary">
</ion-icon> <i class="fa fa-heart"></i>
`); </ion-icon>
`,
if (icon) { });
icon.name = 'trash'; expect(root).toEqualHtml(`
} <ion-icon class="md ion-color ion-color-primary" color="primary" role="img">
await page.waitForChanges(); <mock:shadow-root>
<div class="icon-inner">
<slot></slot>
</div>
</mock:shadow-root>
<i class="fa fa-heart"></i>
</ion-icon>
`);
});
expect(icon).toEqualHtml(` it('renders slotted font icon with custom style', async () => {
<ion-icon class="md" name="trash" role="img" aria-label="custom label"> const { root } = await newSpecPage({
<mock:shadow-root> components: [Icon],
<div class="icon-inner"></div> html: `
</mock:shadow-root> <ion-icon style="font-size: 48px">
</ion-icon> <i class="fa fa-star"></i>
`); </ion-icon>
`,
});
expect(root).toEqualHtml(`
<ion-icon class="md" role="img" style="font-size: 48px">
<mock:shadow-root>
<div class="icon-inner">
<slot></slot>
</div>
</mock:shadow-root>
<i class="fa fa-star"></i>
</ion-icon>
`);
});
}); });
}); });
+66
View File
@@ -0,0 +1,66 @@
<!doctype html>
<html dir="ltr" lang="en" mode="ios">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<title>Icon Tests</title>
<script type="module" src="/build/ionicons.esm.js"></script>
<script nomodule src="/build/ionicons.js"></script>
<link rel="stylesheet" href="./icon/test/styles.css" />
<script src="./icon/test/header.js"></script>
</head>
<body>
<main>
<h1>Icon Tests</h1>
<p>Select a test category to view the icon component tests.</p>
<div class="grid">
<a href="/icon/test/a11y/" class="card">
<h3>Accessibility</h3>
<p>ARIA labels and accessible icon patterns</p>
</a>
<a href="/icon/test/basic/" class="card">
<h3>Basic</h3>
<p>Default SVG icons, modes, colors, sizes, and custom SVGs</p>
</a>
<a href="/icon/test/cheatsheet/" class="card">
<h3>Cheatsheet</h3>
<p>Visual reference of all available ionicons</p>
</a>
<a href="/icon/test/csp/" class="card">
<h3>Content Security Policy</h3>
<p>SVG content loading with Content Security Policy</p>
</a>
<a href="/icon/test/dynamic-type/" class="card">
<h3>Dynamic Type</h3>
<p>Font size scaling and dynamic text sizing behavior</p>
</a>
<a href="/icon/test/rtl/" class="card">
<h3>RTL</h3>
<p>Right-to-left text direction and icon flipping behavior</p>
</a>
<a href="/icon/test/sanitization/" class="card">
<h3>Sanitization</h3>
<p>SVG content sanitization and security</p>
</a>
<a href="/icon/test/size/" class="card">
<h3>Size</h3>
<p>Size prop with small and large variants for native and slotted icons</p>
</a>
<a href="/icon/test/slotted/" class="card">
<h3>Slotted Content</h3>
<p>Font Awesome, Material, Phosphor, Bootstrap, and custom SVGs</p>
</a>
</div>
</main>
</body>
</html>
@@ -1,18 +1,9 @@
import { expect } from '@playwright/test'; import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright'; import { test } from '@utils/test/playwright';
test.describe('icon: basic', () => { test.describe('icon: rtl', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/`);
// Wait for all SVGs to be lazily loaded before taking screenshots
await page.waitForLoadState('networkidle');
await expect(page).toHaveScreenshot(`icon-diff.png`, { fullPage: true });
});
test('some icons should flip when rtl', async ({ page }) => { test('some icons should flip when rtl', async ({ page }) => {
await page.goto(`/`); await page.goto(`/icon/test/rtl/`);
const autoflip = page.locator('.auto-flip-chevrons [name=chevron-forward] .icon-inner'); const autoflip = page.locator('.auto-flip-chevrons [name=chevron-forward] .icon-inner');
const unflip = page.locator('.un-flip-chevrons [name=chevron-forward] .icon-inner'); const unflip = page.locator('.un-flip-chevrons [name=chevron-forward] .icon-inner');
@@ -29,12 +20,11 @@ test.describe('icon: basic', () => {
// Wait for all SVGs to be lazily loaded before taking screenshots // Wait for all SVGs to be lazily loaded before taking screenshots
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
const rtlTests = page.locator('#rtl-tests'); await expect(page).toHaveScreenshot(`icon-rtl.png`);
await expect(rtlTests).toHaveScreenshot(`icon-rtl-diff.png`);
}); });
test('arrows should flip if dir changes on the element', async ({ page }) => { test('arrows should flip if dir changes on the element', async ({ page }) => {
await page.goto(`/`); await page.goto(`/icon/test/rtl/`);
const autoflip = page.locator('.auto-flip-chevrons [name=chevron-forward] .icon-inner'); const autoflip = page.locator('.auto-flip-chevrons [name=chevron-forward] .icon-inner');
const unflip = page.locator('.un-flip-chevrons [name=chevron-forward] .icon-inner'); const unflip = page.locator('.un-flip-chevrons [name=chevron-forward] .icon-inner');
@@ -51,7 +41,7 @@ test.describe('icon: basic', () => {
}); });
test('icon should reassess flipping when name changes', async ({ page }) => { test('icon should reassess flipping when name changes', async ({ page }) => {
await page.goto(`/`); await page.goto(`/icon/test/rtl/`);
await page.evaluate(() => { await page.evaluate(() => {
document.dir = 'rtl'; document.dir = 'rtl';
@@ -67,5 +57,4 @@ test.describe('icon: basic', () => {
await expect(iconLoc).toHaveAttribute('name', 'brush'); await expect(iconLoc).toHaveAttribute('name', 'brush');
await expect(iconLoc).not.toHaveClass(/flip-rtl/); await expect(iconLoc).not.toHaveClass(/flip-rtl/);
}); });
}); });
Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

+72
View File
@@ -0,0 +1,72 @@
<!doctype html>
<html dir="ltr" lang="en" mode="ios">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<title>Icon - RTL</title>
<script type="module" src="/build/ionicons.esm.js"></script>
<script nomodule src="/build/ionicons.js"></script>
<link rel="stylesheet" href="../styles.css" />
<script src="../header.js"></script>
</head>
<body>
<test-header></test-header>
<main>
<h1>Icon - RTL</h1>
<h2>Default: Non-arrows</h2>
<ion-icon name="cut"></ion-icon>
<ion-icon name="call"></ion-icon>
<ion-icon name="checkbox"></ion-icon>
<ion-icon name="brush"></ion-icon>
<h2>Flip: Non-arrows</h2>
<ion-icon name="cut" flip-rtl></ion-icon>
<ion-icon name="call" flip-rtl></ion-icon>
<ion-icon name="checkbox" flip-rtl></ion-icon>
<ion-icon name="brush" flip-rtl></ion-icon>
<h2>Auto Flip: arrows</h2>
<ion-icon name="arrow-up"></ion-icon>
<ion-icon name="arrow-forward"></ion-icon>
<ion-icon name="arrow-down"></ion-icon>
<ion-icon name="arrow-back"></ion-icon>
<h2>Un-flip: arrows</h2>
<ion-icon name="arrow-up" flip-rtl="false"></ion-icon>
<ion-icon name="arrow-forward" flip-rtl="false"></ion-icon>
<ion-icon name="arrow-down" flip-rtl="false"></ion-icon>
<ion-icon name="arrow-back" flip-rtl="false"></ion-icon>
<h2>Auto Flip: chevrons</h2>
<div class="auto-flip-chevrons">
<ion-icon name="chevron-up"></ion-icon>
<ion-icon name="chevron-forward"></ion-icon>
<ion-icon name="chevron-down"></ion-icon>
<ion-icon name="chevron-back"></ion-icon>
</div>
<h2>Un-flip: chevrons</h2>
<div class="un-flip-chevrons">
<ion-icon name="chevron-up" flip-rtl="false"></ion-icon>
<ion-icon name="chevron-forward" flip-rtl="false"></ion-icon>
<ion-icon name="chevron-down" flip-rtl="false"></ion-icon>
<ion-icon name="chevron-back" flip-rtl="false"></ion-icon>
</div>
<h2>Auto Flip, RTL on components</h2>
<ion-icon name="arrow-up" dir="rtl" flip-rtl></ion-icon>
<ion-icon name="arrow-forward" dir="rtl" flip-rtl></ion-icon>
<ion-icon name="arrow-down" dir="rtl" flip-rtl></ion-icon>
<ion-icon name="arrow-back" dir="rtl" flip-rtl></ion-icon>
</main>
<style>
ion-icon {
font-size: 32px;
}
</style>
</body>
</html>
@@ -0,0 +1,284 @@
import { expect } from '@playwright/test';
import type { E2EPage } from '@utils/test/playwright';
import { test } from '@utils/test/playwright';
/**
* An SVG whose handler pushes `label` to `window.xssFired` if it ever runs.
*/
const imageOnErrorSvg = (label: string) =>
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><image href="x" onerror="window.xssFired.push('${label}')"/></svg>`;
const utf8DataUrl = (svg: string) => `data:image/svg+xml;utf8,${svg}`;
/**
* Sets `sanitize` before `src` so the icon loads with the intended setting.
*/
const addIcon = (page: E2EPage, id: string, src: string, sanitize?: boolean) =>
page.evaluate(
([id, src, sanitize]) => {
const icon = document.createElement('ion-icon') as any;
icon.id = id;
if (sanitize !== undefined) {
icon.sanitize = sanitize;
}
icon.src = src;
document.body.appendChild(icon);
},
[id, src, sanitize] as const,
);
/**
* Waits for the unsanitized control icon's handler to fire. Any `data:` URL
* payload added before it has had at least as long to fire.
*/
const waitForControl = (page: E2EPage) => page.waitForFunction(() => (window as any).xssFired.includes('control'));
const getFired = (page: E2EPage) => page.evaluate(() => (window as any).xssFired as string[]);
test.describe('icon: sanitization', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/icon/test/sanitization/`);
await page.waitForLoadState('networkidle');
const main = page.locator('main');
await expect(main).toHaveScreenshot(`icon-sanitization.png`);
});
});
test.describe('icon: sanitization: unsafe content', () => {
test.beforeEach(async ({ page }) => {
await page.setContent(`<script>window.xssFired = [];</script>`);
});
test('should not run handlers from a utf8 svg data url', async ({ page }) => {
await addIcon(page, 'attack', utf8DataUrl(imageOnErrorSvg('attack')));
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
await waitForControl(page);
expect(await getFired(page)).not.toContain('attack');
await expect(page.locator('#attack .icon-inner svg')).toHaveCount(0);
});
test('should render a clean utf8 svg data url', async ({ page }) => {
const clean = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>`;
await addIcon(page, 'clean', utf8DataUrl(clean));
await expect(page.locator('#clean .icon-inner svg path')).toHaveCount(1);
});
test('should warn when an svg is rejected', async ({ page }) => {
const warnings: string[] = [];
page.on('console', (msg) => {
if (msg.type() === 'warning') {
warnings.push(msg.text());
}
});
await addIcon(page, 'attack', utf8DataUrl(imageOnErrorSvg('attack')));
await expect.poll(() => warnings.some((warning) => warning.includes('[Ionicons Warning]'))).toBe(true);
});
test('should not warn about sanitizing when the response is not an svg', async ({ page }) => {
const warnings: string[] = [];
page.on('console', (msg) => {
if (msg.type() === 'warning') {
warnings.push(msg.text());
}
});
await page.route('**/missing.svg', (route) =>
route.fulfill({ status: 404, contentType: 'text/html', body: '<html><body>Not found</body></html>' }),
);
await page.route('**/rejected.svg', (route) =>
route.fulfill({ contentType: 'image/svg+xml', body: imageOnErrorSvg('attack') }),
);
const missingLoaded = page.waitForResponse('**/missing.svg');
await addIcon(page, 'missing', '/missing.svg');
await missingLoaded;
// This takes the same fetch and sanitize steps, so once it warns the 404 has been handled
await addIcon(page, 'rejected', '/rejected.svg');
await expect.poll(() => warnings.some((warning) => warning.includes('rejected.svg'))).toBe(true);
expect(warnings.filter((warning) => warning.includes('missing.svg'))).toHaveLength(0);
});
test('should not run handlers from a fetched svg while sanitizing it', async ({ page }) => {
await page.route('**/xss/*.svg', (route) => {
const label = route.request().url().includes('control') ? 'control' : 'attack';
route.fulfill({
contentType: 'image/svg+xml',
body: `<img src="x" onerror="window.xssFired.push('${label}')">${imageOnErrorSvg(label)}`,
});
});
// Fetches resolve independently, so let the attack load before the control starts
const attackLoaded = page.waitForResponse('**/xss/attack.svg');
await addIcon(page, 'attack', '/xss/attack.svg');
await attackLoaded;
await addIcon(page, 'control', '/xss/control.svg', false);
await waitForControl(page);
expect(await getFired(page)).not.toContain('attack');
await expect(page.locator('#attack .icon-inner svg')).toHaveCount(0);
});
test('should reject a fetched svg with more than one root svg', async ({ page }) => {
await page.route('**/xss/*.svg', (route) => {
const label = route.request().url().includes('control') ? 'control' : 'attack';
route.fulfill({
contentType: 'image/svg+xml',
body: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>${imageOnErrorSvg(label)}`,
});
});
const attackLoaded = page.waitForResponse('**/xss/attack.svg');
await addIcon(page, 'attack', '/xss/attack.svg');
await attackLoaded;
await addIcon(page, 'control', '/xss/control.svg', false);
await waitForControl(page);
expect(await getFired(page)).not.toContain('attack');
await expect(page.locator('#attack .icon-inner svg')).toHaveCount(0);
});
const htmlInSvgPayloads = [
{
name: 'noscript',
inner: `<desc><noscript><p title="</noscript><img src=x onerror=top.xssFired.push('attack')>"></p></noscript></desc>`,
},
{
name: 'template',
inner: `<desc><template><img src="x" onerror="top.xssFired.push('attack')"></template></desc>`,
},
];
htmlInSvgPayloads.forEach(({ name, inner }) => {
test(`should reject an svg containing an html ${name} element`, async ({ page }) => {
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">${inner}<path d="M0 0h24v24H0z"/></svg>`;
await addIcon(page, 'attack', utf8DataUrl(svg));
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
await waitForControl(page);
expect(await getFired(page)).not.toContain('attack');
await expect(page.locator('#attack .icon-inner svg')).toHaveCount(0);
});
});
const foreignObjectPayloads = [
{
name: 'iframe srcdoc',
inner: `<iframe xmlns="http://www.w3.org/1999/xhtml" srcdoc="&lt;script&gt;top.xssFired.push('attack')&lt;/script&gt;"></iframe>`,
},
{
name: 'iframe javascript: src',
inner: `<iframe xmlns="http://www.w3.org/1999/xhtml" src="javascript:top.xssFired.push('attack')"></iframe>`,
},
];
foreignObjectPayloads.forEach(({ name, inner }) => {
test(`should remove a foreignObject containing an ${name}`, async ({ page }) => {
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><foreignObject width="24" height="24">${inner}</foreignObject><path d="M0 0h24v24H0z"/></svg>`;
await addIcon(page, 'attack', utf8DataUrl(svg));
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
await waitForControl(page);
expect(await getFired(page)).not.toContain('attack');
await expect(page.locator('#attack .icon-inner svg path')).toHaveCount(1);
await expect(page.locator('#attack .icon-inner svg > :not(path)')).toHaveCount(0);
});
});
test('should render an illustrator export that uses a switch with a foreignObject', async ({ page }) => {
const svg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><switch><foreignObject requiredExtensions="http://ns.adobe.com/AdobeIllustrator/10.0/" x="0" y="0" width="1" height="1"><i:pgfRef xlink:href="#adobe_illustrator_pgf"></i:pgfRef></foreignObject><g i:extraneous="self"><path d="M0 0h24v24H0z"/></g></switch></svg>`;
await addIcon(page, 'illustrator', utf8DataUrl(svg));
await expect(page.locator('#illustrator .icon-inner svg path')).toHaveCount(1);
});
const javascriptUrlPayloads = [
{ name: 'an anchor href', inner: `<a href="javascript:top.xssFired.push('attack')"><path d="M0 0h24v24H0z"/></a>` },
{
name: 'an obfuscated xlink:href',
inner: `<a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href=" JaVa&#x09;ScRiPt:top.xssFired.push('attack')"><path d="M0 0h24v24H0z"/></a>`,
},
{
name: 'an animate element',
inner: `<a><animate attributeName="href" values="https://ionic.io;javascript:top.xssFired.push('attack')"/><path d="M0 0h24v24H0z"/></a>`,
},
{
name: 'a set element',
inner: `<a><set attributeName="href" to="javascript:top.xssFired.push('attack')"/><path d="M0 0h24v24H0z"/></a>`,
},
];
javascriptUrlPayloads.forEach(({ name, inner }) => {
test(`should reject an svg with a javascript: url in ${name}`, async ({ page }) => {
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">${inner}</svg>`;
await addIcon(page, 'attack', utf8DataUrl(svg));
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
await waitForControl(page);
await expect(page.locator('#attack .icon-inner svg')).toHaveCount(0);
});
});
test('should not reuse unsanitized content cached for the same data url', async ({ page }) => {
const shared = utf8DataUrl(imageOnErrorSvg('shared'));
await addIcon(page, 'unsanitized', shared, false);
await page.waitForFunction(() => (window as any).xssFired.includes('shared'));
await addIcon(page, 'sanitized', shared);
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
await waitForControl(page);
await expect(page.locator('#sanitized .icon-inner svg')).toHaveCount(0);
expect((await getFired(page)).filter((label) => label === 'shared')).toHaveLength(1);
});
test('should not reuse sanitized content cached for the same data url', async ({ page }) => {
const shared = utf8DataUrl(imageOnErrorSvg('shared'));
await addIcon(page, 'sanitized', shared);
await addIcon(page, 'unsanitized', shared, false);
await expect(page.locator('#unsanitized .icon-inner svg')).toHaveCount(1);
});
test('should not let a src forge the unsanitized cache key', async ({ page }) => {
const shared = utf8DataUrl(imageOnErrorSvg('shared'));
await addIcon(page, 'unsanitized', shared, false);
await page.waitForFunction(() => (window as any).xssFired.includes('shared'));
await addIcon(page, 'sanitized', `unsanitized:${shared}`);
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
await waitForControl(page);
await expect(page.locator('#sanitized .icon-inner svg')).toHaveCount(0);
expect((await getFired(page)).filter((label) => label === 'shared')).toHaveLength(1);
});
test('should not reuse an unsanitized in-flight fetch for the same url', async ({ page }) => {
await page.route('**/xss/*.svg', (route) => {
const label = route.request().url().includes('control') ? 'control' : 'shared';
// Sanitizing drops the <img> sibling and keeps the clean <svg>
route.fulfill({
contentType: 'image/svg+xml',
body: `<img src="x" onerror="window.xssFired.push('${label}')"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>`,
});
});
await addIcon(page, 'unsanitized', '/xss/shared.svg', false);
await addIcon(page, 'sanitized', '/xss/shared.svg');
await addIcon(page, 'control', '/xss/control.svg', false);
await waitForControl(page);
await page.waitForFunction(() => (window as any).xssFired.includes('shared'));
await expect(page.locator('#sanitized .icon-inner svg path')).toHaveCount(1);
await expect(page.locator('#sanitized .icon-inner img')).toHaveCount(0);
expect((await getFired(page)).filter((label) => label === 'shared')).toHaveLength(1);
});
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

@@ -0,0 +1,37 @@
<!doctype html>
<html dir="ltr" lang="en" mode="ios">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<title>Icon - Sanitization</title>
<script type="module" src="/build/ionicons.esm.js"></script>
<script nomodule src="/build/ionicons.js"></script>
<link rel="stylesheet" href="../styles.css" />
<script src="../header.js"></script>
</head>
<body>
<test-header></test-header>
<main>
<h1>Icon - Sanitization</h1>
<h2>Sanitized (shouldn't show)</h2>
<ion-icon src="/icon/assets/sanitize.svg"></ion-icon>
<h2>Not Sanitized (should show)</h2>
<ion-icon sanitize="false" src="/icon/assets/no-sanitize.svg"></ion-icon>
<h2>Base64 URL</h2>
<ion-icon
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJub25lIiBkPSJNMCAwaDI0djI0SDBWMHoiLz48cGF0aCBkPSJNMjAgMkg0Yy0xLjEgMC0yIC45LTIgMnYxOGw0LTRoMTRjMS4xIDAgMi0uOSAyLTJWNGMwLTEuMS0uOS0yLTItMnptMCAxNEg2bC0yIDJWNGgxNnYxMnoiLz48L3N2Zz4="
></ion-icon>
</main>
<style>
ion-icon {
font-size: 32px;
}
</style>
</body>
</html>
+40
View File
@@ -0,0 +1,40 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('icon: size', () => {
test.beforeEach(async ({ page }) => {
await page.goto(`/icon/test/size/`);
});
test('should scale the icon based on the size property', async ({ page }) => {
// Wait for all SVGs to be lazily loaded before taking screenshots
await page.waitForLoadState('networkidle');
const main = page.locator('main');
await expect(main).toHaveScreenshot(`icon-size.png`);
});
test('size prop should apply correct font-size to SVG icons', async ({ page }) => {
// Wait for all SVGs to be lazily loaded
await page.waitForLoadState('networkidle');
const icons = page.locator('ion-icon[name="heart"]');
// Default size is 16px, small is 18px, large is 32px
expect(await icons.nth(0).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('16px');
expect(await icons.nth(1).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('18px');
expect(await icons.nth(2).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('32px');
});
test('size prop should apply correct font-size to font icons', async ({ page }) => {
// Wait for document fonts to be ready
await page.evaluate(() => document.fonts.ready);
const icons = page.locator('ion-icon:not([name])');
// Default size is 16px, small is 18px, large is 32px
expect(await icons.nth(0).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('16px');
expect(await icons.nth(1).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('18px');
expect(await icons.nth(2).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('32px');
});
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+39
View File
@@ -0,0 +1,39 @@
<!doctype html>
<html dir="ltr" lang="en" mode="ios">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<title>Icon - Size</title>
<script type="module" src="/build/ionicons.esm.js"></script>
<script nomodule src="/build/ionicons.js"></script>
<link rel="stylesheet" href="../styles.css" />
<script src="../header.js"></script>
<!-- Font Awesome Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" />
</head>
<body>
<test-header></test-header>
<main>
<h1>Icon - Size</h1>
<h2>Default Icons</h2>
<ion-icon name="heart"></ion-icon>
<ion-icon name="heart" size="small"></ion-icon>
<ion-icon name="heart" size="large"></ion-icon>
<h2>Font Icons</h2>
<ion-icon>
<i class="fa fa-heart"></i>
</ion-icon>
<ion-icon size="small">
<i class="fa fa-heart"></i>
</ion-icon>
<ion-icon size="large">
<i class="fa fa-heart"></i>
</ion-icon>
</main>
</body>
</html>
@@ -0,0 +1,13 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('icon: slotted', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/icon/test/slotted/`);
// Wait for all SVGs to be lazily loaded before taking screenshots
await page.waitForLoadState('networkidle');
await expect(page).toHaveScreenshot(`icon-slotted.png`, { fullPage: true });
});
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Some files were not shown because too many files have changed in this diff Show More