Compare commits

..
1 Commits
Author SHA1 Message Date
OS-jacobbell e4905987b7 fix(icon): load when properties initialize (#1490)
* fix(icons): load icons when properties initialize

* chore(deps): update package-lock
2026-03-16 21:02:53 -06:00
82 changed files with 703 additions and 2177 deletions
-1
View File
@@ -1 +0,0 @@
src/components.d.ts
+26 -71
View File
@@ -6,18 +6,20 @@ This document outlines the guidelines and processes for contributing to this pro
## 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)
- [Contributing to Ionicons](#contributing-to-ionicons)
- [Table of Contents](#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 Changes](#testing-changes)
- [Code Style](#code-style)
- [Building](#building)
- [Submitting Issues](#submitting-issues)
- [Submitting Pull Requests](#submitting-pull-requests)
## Code of Conduct
@@ -82,67 +84,20 @@ 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
3. Test your changes (see [Testing Changes](#testing-changes))
### Testing
### Testing Changes
Tests are crucial for maintaining confidence in changes. All PRs that modify component behavior must include tests covering those changes.
To preview component 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.
1. Run:
```bash
npm start
```
This will start a local version of the icon test with a test page
2. Modify the test page in `index.html` as needed to test your changes
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
### Code Style
@@ -193,4 +148,4 @@ When creating issues:
- 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.
- [Create a new pull request](https://github.com/ionic-team/ionicons/compare) with the `main` branch as the base.
+1 -2
View File
@@ -6,9 +6,8 @@ import { createJestStencilPreset } from 'jest-stencil-runner';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
export default createJestStencilPreset({
rootDir: __dirname,
rootDir: __dirname,
// Add any additional Jest configuration here
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.ts',
-2
View File
@@ -1,2 +0,0 @@
const Stencil = require('@stencil/core');
Stencil.Build.isBrowser = true;
+54 -93
View File
@@ -1,19 +1,18 @@
{
"name": "ionicons",
"version": "8.1.1",
"version": "8.0.13",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ionicons",
"version": "8.1.1",
"version": "8.0.13",
"license": "MIT",
"dependencies": {
"@stencil/core": "^4.43.5"
"@stencil/core": "^4.43.2"
},
"devDependencies": {
"@axe-core/playwright": "^4.12.1",
"@playwright/test": "^1.61.1",
"@playwright/test": "^1.53.2",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^30.0.0",
"@types/node": "^22.15.3",
@@ -21,7 +20,7 @@
"fs-extra": "^11.3.0",
"jest": "^30.0.4",
"jest-cli": "^30.0.4",
"jest-stencil-runner": "^0.0.20",
"jest-stencil-runner": "^0.0.8",
"npm-run-all2": "^8.0.4",
"prettier": "^3.6.2",
"puppeteer": "^24.12.0",
@@ -47,19 +46,6 @@
"node": ">=6.0.0"
}
},
"node_modules/@axe-core/playwright": {
"version": "4.12.1",
"resolved": "https://registry.npmjs.org/@axe-core/playwright/-/playwright-4.12.1.tgz",
"integrity": "sha512-rMd7xriptqKpP+w5265i4Hdkv2X5kbu6uiBi/B2I7uf3hieRBM3qDCfaKPtxfiYb2mKXfF+yLODJwIx+Jv1GDw==",
"dev": true,
"license": "MPL-2.0",
"dependencies": {
"axe-core": "~4.12.1"
},
"peerDependencies": {
"playwright-core": ">= 1.0.0"
}
},
"node_modules/@babel/code-frame": {
"version": "7.27.1",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz",
@@ -91,6 +77,7 @@
"integrity": "sha512-UlLAnTPrFdNGoFtbSXwcGFQBtQZJCNjaN6hQNP3UPvuNXT1i82N26KL3dZeIpNalWywr9IuQuncaAfUaS1g6sQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@ampproject/remapping": "^2.2.0",
"@babel/code-frame": "^7.27.1",
@@ -1584,13 +1571,13 @@
}
},
"node_modules/@playwright/test": {
"version": "1.61.1",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.61.1.tgz",
"integrity": "sha512-8nKv6+0RJSL9FE4jYOEGXnPeM/Hg12qZpmqzZjRh3qM0Y7c3z1mrOTfFLids72RDQYVh9WpLEfR5WdpNX4fkig==",
"version": "1.53.2",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.53.2.tgz",
"integrity": "sha512-tEB2U5z74ebBeyfGNZ3Jfg29AnW+5HlWhvHtb/Mqco9pFdZU1ZLNdVb2UtB5CvmiilNr2ZfVH/qMmAROG/XTzw==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright": "1.61.1"
"playwright": "1.53.2"
},
"bin": {
"playwright": "cli.js"
@@ -1654,9 +1641,6 @@
"cpu": [
"arm64"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -1670,9 +1654,6 @@
"cpu": [
"arm64"
],
"libc": [
"musl"
],
"license": "MIT",
"optional": true,
"os": [
@@ -1686,9 +1667,6 @@
"cpu": [
"x64"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -1702,9 +1680,6 @@
"cpu": [
"x64"
],
"libc": [
"musl"
],
"license": "MIT",
"optional": true,
"os": [
@@ -1765,10 +1740,11 @@
}
},
"node_modules/@stencil/core": {
"version": "4.43.5",
"resolved": "https://registry.npmjs.org/@stencil/core/-/core-4.43.5.tgz",
"integrity": "sha512-cgWD+GeuvJpTe1WQn40p02+BJ2j0j1YJ17GdkF2qKIQ23s2e3Zivq5yISXS3dcuV6oUJFN93jprdk+nk/sq99Q==",
"version": "4.43.2",
"resolved": "https://registry.npmjs.org/@stencil/core/-/core-4.43.2.tgz",
"integrity": "sha512-hOprMw/n1fyu5OOtZG7N8sqiKxPshR1oss/y1qr6r98cVV9NcVoCMz2x2TT2enkHan6pCMpiQgUU7vmN90lIVw==",
"license": "MIT",
"peer": true,
"bin": {
"stencil": "bin/stencil"
},
@@ -2400,16 +2376,6 @@
"node": ">=4"
}
},
"node_modules/axe-core": {
"version": "4.12.1",
"resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.12.1.tgz",
"integrity": "sha512-s7iGf5GaVMxEG0ENN9x+xTr7GFZCb1ZP/1uATUpCEK2X78nDB3RwbtFCo9pGAf9ru+VwoQ464DkaLEeRM08wJA==",
"dev": true,
"license": "MPL-2.0",
"engines": {
"node": ">=4"
}
},
"node_modules/b4a": {
"version": "1.6.7",
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.7.tgz",
@@ -2658,6 +2624,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"caniuse-lite": "^1.0.30001726",
"electron-to-chromium": "^1.5.173",
@@ -3208,7 +3175,8 @@
"resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1464554.tgz",
"integrity": "sha512-CAoP3lYfwAGQTaAXYvA6JZR0fjGUb7qec1qf4mToyoH2TZgUFeIqYcjh6f9jNuhHfuZiEdH+PONHYrLhRQX6aw==",
"dev": true,
"license": "BSD-3-Clause"
"license": "BSD-3-Clause",
"peer": true
},
"node_modules/dom-serializer": {
"version": "2.0.0",
@@ -4191,6 +4159,7 @@
"integrity": "sha512-9QE0RS4WwTj/TtTC4h/eFVmFAhGNVerSB9XpJh8sqaXlP73ILcPcZ7JWjjEtJJe2m8QyBLKKfPQuK+3F+Xij/g==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@jest/core": "30.0.4",
"@jest/types": "30.0.1",
@@ -4677,9 +4646,9 @@
}
},
"node_modules/jest-stencil-runner": {
"version": "0.0.20",
"resolved": "https://registry.npmjs.org/jest-stencil-runner/-/jest-stencil-runner-0.0.20.tgz",
"integrity": "sha512-jK3tc8s6vUXLirEP8mb6moEAxLAdj2cSYjwtkl/R5wgdTsT9sEig2iWUUDdN4vvel7PAtFsS1Z8YIGc1KgOlng==",
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/jest-stencil-runner/-/jest-stencil-runner-0.0.8.tgz",
"integrity": "sha512-1lArTozjdbnmHLhn899U9i2ZsfLRzO+VFUUO7pnxPH+DpEr39SlRp2G4Qsp8a9lrVeBDgJITFnzTIEgGemyCNQ==",
"dev": true,
"license": "MIT",
"dependencies": {
@@ -5574,13 +5543,13 @@
}
},
"node_modules/playwright": {
"version": "1.61.1",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.61.1.tgz",
"integrity": "sha512-DWnY5o3YbLWK4GovuAVwpqL+1VwGNdUGrRr++8j8PtQQzvAVZUIMjKQ90fY689sEJZJBbZVw1rXaOKSTitkzPQ==",
"version": "1.53.2",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.53.2.tgz",
"integrity": "sha512-6K/qQxVFuVQhRQhFsVZ9fGeatxirtrpPgxzBYWyZLEXJzqYwuL4fuNmfOfD5et1tJE4GScKyPNeLhZeRwuTU3A==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.61.1"
"playwright-core": "1.53.2"
},
"bin": {
"playwright": "cli.js"
@@ -5593,9 +5562,9 @@
}
},
"node_modules/playwright-core": {
"version": "1.61.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.61.1.tgz",
"integrity": "sha512-h7Qlt6m4REp25qvIdvbDtVmD4LqVXfpRxhORv9L0jzETM05p4fuPJ3dKyuSXQxDSbXnmS79HAgi9589lGSpLkg==",
"version": "1.53.2",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.53.2.tgz",
"integrity": "sha512-ox/OytMy+2w1jcYEYlOo1Hhp8hZkLCximMTUTMBXjGUA1KoFfiSZ+DU+3a739jsPY0yoKH2TFy9S2fsJas8yAw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
@@ -6664,6 +6633,7 @@
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
"dev": true,
"license": "Apache-2.0",
"peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@@ -7026,15 +6996,6 @@
"@jridgewell/trace-mapping": "^0.3.24"
}
},
"@axe-core/playwright": {
"version": "4.12.1",
"resolved": "https://registry.npmjs.org/@axe-core/playwright/-/playwright-4.12.1.tgz",
"integrity": "sha512-rMd7xriptqKpP+w5265i4Hdkv2X5kbu6uiBi/B2I7uf3hieRBM3qDCfaKPtxfiYb2mKXfF+yLODJwIx+Jv1GDw==",
"dev": true,
"requires": {
"axe-core": "~4.12.1"
}
},
"@babel/code-frame": {
"version": "7.27.1",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz",
@@ -7057,6 +7018,7 @@
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.28.0.tgz",
"integrity": "sha512-UlLAnTPrFdNGoFtbSXwcGFQBtQZJCNjaN6hQNP3UPvuNXT1i82N26KL3dZeIpNalWywr9IuQuncaAfUaS1g6sQ==",
"dev": true,
"peer": true,
"requires": {
"@ampproject/remapping": "^2.2.0",
"@babel/code-frame": "^7.27.1",
@@ -7984,12 +7946,12 @@
"dev": true
},
"@playwright/test": {
"version": "1.61.1",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.61.1.tgz",
"integrity": "sha512-8nKv6+0RJSL9FE4jYOEGXnPeM/Hg12qZpmqzZjRh3qM0Y7c3z1mrOTfFLids72RDQYVh9WpLEfR5WdpNX4fkig==",
"version": "1.53.2",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.53.2.tgz",
"integrity": "sha512-tEB2U5z74ebBeyfGNZ3Jfg29AnW+5HlWhvHtb/Mqco9pFdZU1ZLNdVb2UtB5CvmiilNr2ZfVH/qMmAROG/XTzw==",
"dev": true,
"requires": {
"playwright": "1.61.1"
"playwright": "1.53.2"
}
},
"@puppeteer/browsers": {
@@ -8080,9 +8042,10 @@
}
},
"@stencil/core": {
"version": "4.43.5",
"resolved": "https://registry.npmjs.org/@stencil/core/-/core-4.43.5.tgz",
"integrity": "sha512-cgWD+GeuvJpTe1WQn40p02+BJ2j0j1YJ17GdkF2qKIQ23s2e3Zivq5yISXS3dcuV6oUJFN93jprdk+nk/sq99Q==",
"version": "4.43.2",
"resolved": "https://registry.npmjs.org/@stencil/core/-/core-4.43.2.tgz",
"integrity": "sha512-hOprMw/n1fyu5OOtZG7N8sqiKxPshR1oss/y1qr6r98cVV9NcVoCMz2x2TT2enkHan6pCMpiQgUU7vmN90lIVw==",
"peer": true,
"requires": {
"@rollup/rollup-darwin-arm64": "4.44.0",
"@rollup/rollup-darwin-x64": "4.44.0",
@@ -8502,12 +8465,6 @@
"tslib": "^2.0.1"
}
},
"axe-core": {
"version": "4.12.1",
"resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.12.1.tgz",
"integrity": "sha512-s7iGf5GaVMxEG0ENN9x+xTr7GFZCb1ZP/1uATUpCEK2X78nDB3RwbtFCo9pGAf9ru+VwoQ464DkaLEeRM08wJA==",
"dev": true
},
"b4a": {
"version": "1.6.7",
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.7.tgz",
@@ -8674,6 +8631,7 @@
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.25.1.tgz",
"integrity": "sha512-KGj0KoOMXLpSNkkEI6Z6mShmQy0bc1I+T7K9N81k4WWMrfz+6fQ6es80B/YLAeRoKvjYE1YSHHOW1qe9xIVzHw==",
"dev": true,
"peer": true,
"requires": {
"caniuse-lite": "^1.0.30001726",
"electron-to-chromium": "^1.5.173",
@@ -9038,7 +8996,8 @@
"version": "0.0.1464554",
"resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1464554.tgz",
"integrity": "sha512-CAoP3lYfwAGQTaAXYvA6JZR0fjGUb7qec1qf4mToyoH2TZgUFeIqYcjh6f9jNuhHfuZiEdH+PONHYrLhRQX6aw==",
"dev": true
"dev": true,
"peer": true
},
"dom-serializer": {
"version": "2.0.0",
@@ -9707,6 +9666,7 @@
"resolved": "https://registry.npmjs.org/jest/-/jest-30.0.4.tgz",
"integrity": "sha512-9QE0RS4WwTj/TtTC4h/eFVmFAhGNVerSB9XpJh8sqaXlP73ILcPcZ7JWjjEtJJe2m8QyBLKKfPQuK+3F+Xij/g==",
"dev": true,
"peer": true,
"requires": {
"@jest/core": "30.0.4",
"@jest/types": "30.0.1",
@@ -10058,9 +10018,9 @@
}
},
"jest-stencil-runner": {
"version": "0.0.20",
"resolved": "https://registry.npmjs.org/jest-stencil-runner/-/jest-stencil-runner-0.0.20.tgz",
"integrity": "sha512-jK3tc8s6vUXLirEP8mb6moEAxLAdj2cSYjwtkl/R5wgdTsT9sEig2iWUUDdN4vvel7PAtFsS1Z8YIGc1KgOlng==",
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/jest-stencil-runner/-/jest-stencil-runner-0.0.8.tgz",
"integrity": "sha512-1lArTozjdbnmHLhn899U9i2ZsfLRzO+VFUUO7pnxPH+DpEr39SlRp2G4Qsp8a9lrVeBDgJITFnzTIEgGemyCNQ==",
"dev": true,
"requires": {
"@jest/globals": "^30.0.2",
@@ -10668,13 +10628,13 @@
}
},
"playwright": {
"version": "1.61.1",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.61.1.tgz",
"integrity": "sha512-DWnY5o3YbLWK4GovuAVwpqL+1VwGNdUGrRr++8j8PtQQzvAVZUIMjKQ90fY689sEJZJBbZVw1rXaOKSTitkzPQ==",
"version": "1.53.2",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.53.2.tgz",
"integrity": "sha512-6K/qQxVFuVQhRQhFsVZ9fGeatxirtrpPgxzBYWyZLEXJzqYwuL4fuNmfOfD5et1tJE4GScKyPNeLhZeRwuTU3A==",
"dev": true,
"requires": {
"fsevents": "2.3.2",
"playwright-core": "1.61.1"
"playwright-core": "1.53.2"
},
"dependencies": {
"fsevents": {
@@ -10687,9 +10647,9 @@
}
},
"playwright-core": {
"version": "1.61.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.61.1.tgz",
"integrity": "sha512-h7Qlt6m4REp25qvIdvbDtVmD4LqVXfpRxhORv9L0jzETM05p4fuPJ3dKyuSXQxDSbXnmS79HAgi9589lGSpLkg==",
"version": "1.53.2",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.53.2.tgz",
"integrity": "sha512-ox/OytMy+2w1jcYEYlOo1Hhp8hZkLCximMTUTMBXjGUA1KoFfiSZ+DU+3a739jsPY0yoKH2TFy9S2fsJas8yAw==",
"dev": true
},
"prettier": {
@@ -11395,7 +11355,8 @@
"version": "5.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz",
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
"dev": true
"dev": true,
"peer": true
},
"undici-types": {
"version": "6.21.0",
+11 -11
View File
@@ -1,6 +1,6 @@
{
"name": "ionicons",
"version": "8.1.1",
"version": "8.0.13",
"description": "Premium icons for Ionic.",
"files": [
"components/",
@@ -43,26 +43,26 @@
}
},
"scripts": {
"build": "run-s clean build.*",
"build": "run-s clean build.* prettier",
"build.files": "tsx scripts/build.ts",
"build.component": "stencil build",
"build.collection": "tsx scripts/collection-copy.ts",
"clean": "rimraf dist components icons www",
"lint": "npm run prettier -- --write",
"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",
"prettier": "npm run prettier.base -- --write",
"prettier.base": "prettier --cache \"./({bin,scripts,src,test}/**/*.{ts,tsx,js,jsx})|bin/stencil|.github/(**/)?*.(yml|yaml)|*.js\"",
"prettier.dry-run": "npm run prettier.base -- --list-different",
"start": "run-s build.files start.stencil",
"start.stencil": "stencil build --dev --watch --serve",
"test": "run-s test.spec",
"test.spec": "jest",
"test.e2e": "playwright test",
"test.e2e.install": "playwright install && playwright install-deps"
},
"dependencies": {
"@stencil/core": "^4.43.5"
"@stencil/core": "^4.43.2"
},
"devDependencies": {
"@axe-core/playwright": "^4.12.1",
"@playwright/test": "^1.61.1",
"@playwright/test": "^1.53.2",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^30.0.0",
"@types/node": "^22.15.3",
@@ -70,7 +70,7 @@
"fs-extra": "^11.3.0",
"jest": "^30.0.4",
"jest-cli": "^30.0.4",
"jest-stencil-runner": "^0.0.20",
"jest-stencil-runner": "^0.0.8",
"npm-run-all2": "^8.0.4",
"prettier": "^3.6.2",
"puppeteer": "^24.12.0",
+5 -30
View File
@@ -98,16 +98,9 @@ async function copyToTesting(rootDir: string, distDir: string, srcSvgData: SvgDa
const testDir = path.join(rootDir, 'www');
const testBuildDir = path.join(testDir, 'build');
const testSvgDir = path.join(testBuildDir, 'svg');
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([fs.ensureDir(testDir), fs.ensureDir(testBuildDir), fs.ensureDir(testSvgDir)]);
await Promise.all(
srcSvgData
@@ -118,27 +111,9 @@ async function copyToTesting(rootDir: string, distDir: string, srcSvgData: SvgDa
}),
);
const wwwCheatsheetFilePath = path.join(cheatsheetDir, 'index.html');
const srcIndexFilePath = path.join(rootDir, 'src', 'components', 'icon', 'test', 'index.html');
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);
const distCheatsheetFilePath = path.join(distDir, 'cheatsheet.html');
const testCheatsheetFilePath = path.join(testDir, 'cheatsheet.html');
await fs.copyFile(distCheatsheetFilePath, testCheatsheetFilePath);
}
async function createSvgSymbols(version: string, distDir: string, srcSvgData: SvgData[]) {
@@ -194,7 +169,7 @@ async function createCheatsheet(
const c = srcSvgData.map(
(svgData) =>
`<a href="/svg/${svgData.fileName}"><svg><use href="#${svgData.iconName}" xlink:href="#${svgData.iconName}"/></svg></a>`,
`<a href="./svg/${svgData.fileName}"><svg><use href="#${svgData.iconName}" xlink:href="#${svgData.iconName}"/></svg></a>`,
);
c.push(svgSymbolsContent);
+27 -23
View File
@@ -1,27 +1,24 @@
<!DOCTYPE html>
<html dir="ltr" lang="en">
<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>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>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ionicons {{version}} Cheatsheet</title>
<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 {
width: 32px;
height: 32px;
@@ -34,4 +31,11 @@
opacity: 0.7;
}
</style>
</head>
<body>
<h1>Ionicons {{version}} Cheatsheet</h1>
<h3>{{count}} icons</h3>
{{content}}
</body>
</html>
+8 -7
View File
@@ -28,11 +28,12 @@ npm start
## Release Steps
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"
3. Select the release type:
- **dev** — Creates a pre-release with a timestamp-based version (e.g., `8.0.14-dev.11784821417.1c794397`)
- **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)
Next, update `CHANGELOG.md`, then commit and push your changes Github.
```sh
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`.
+132 -129
View File
@@ -4,143 +4,146 @@
* This is an autogenerated file created by the Stencil compiler.
* It contains typing information for all components that exist in this project.
*/
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { HTMLStencilElement, JSXBase } from '@stencil/core/internal';
export namespace Components {
interface IonIcon {
/**
* The color to use for the background of the item.
*/
"color"?: string;
/**
* Specifies whether the icon should horizontally flip when `dir` is `"rtl"`.
*/
"flipRtl"?: boolean;
/**
* 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.
*/
"icon"?: any;
/**
* Specifies which icon to use on `ios` mode.
*/
"ios"?: string;
/**
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
* @default false
*/
"lazy": boolean;
/**
* Specifies which icon to use on `md` mode.
*/
"md"?: string;
/**
* The mode determines which platform styles to use.
* @default getIonMode()
*/
"mode": string;
/**
* Specifies which icon to use from the built-in set of icons.
*/
"name"?: string;
/**
* 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
*/
"sanitize": boolean;
/**
* The size of the icon. Available options are: `"small"` and `"large"`.
*/
"size"?: string;
/**
* Specifies the exact `src` of an SVG file to use.
*/
"src"?: string;
}
interface IonIcon {
/**
* The color to use for the background of the item.
*/
color?: string;
/**
* Specifies whether the icon should horizontally flip when `dir` is `"rtl"`.
*/
flipRtl?: boolean;
/**
* 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.
*/
icon?: any;
/**
* Specifies which icon to use on `ios` mode.
*/
ios?: string;
/**
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
* @default false
*/
lazy: boolean;
/**
* Specifies which icon to use on `md` mode.
*/
md?: string;
/**
* The mode determines which platform styles to use.
* @default getIonMode()
*/
mode: string;
/**
* Specifies which icon to use from the built-in set of icons.
*/
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`.
* @default true
*/
sanitize: boolean;
/**
* The size of the icon. Available options are: `"small"` and `"large"`.
*/
size?: string;
/**
* Specifies the exact `src` of an SVG file to use.
*/
src?: string;
}
}
declare global {
interface HTMLIonIconElement extends Components.IonIcon, HTMLStencilElement {
}
var HTMLIonIconElement: {
prototype: HTMLIonIconElement;
new (): HTMLIonIconElement;
};
interface HTMLElementTagNameMap {
"ion-icon": HTMLIonIconElement;
}
interface HTMLIonIconElement extends Components.IonIcon, HTMLStencilElement {}
var HTMLIonIconElement: {
prototype: HTMLIonIconElement;
new (): HTMLIonIconElement;
};
interface HTMLElementTagNameMap {
'ion-icon': HTMLIonIconElement;
}
}
declare namespace LocalJSX {
interface IonIcon {
/**
* The color to use for the background of the item.
*/
"color"?: string;
/**
* Specifies whether the icon should horizontally flip when `dir` is `"rtl"`.
*/
"flipRtl"?: boolean;
/**
* 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.
*/
"icon"?: any;
/**
* Specifies which icon to use on `ios` mode.
*/
"ios"?: string;
/**
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
* @default false
*/
"lazy"?: boolean;
/**
* Specifies which icon to use on `md` mode.
*/
"md"?: string;
/**
* The mode determines which platform styles to use.
* @default getIonMode()
*/
"mode"?: string;
/**
* Specifies which icon to use from the built-in set of icons.
*/
"name"?: string;
/**
* 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
*/
"sanitize"?: boolean;
/**
* The size of the icon. Available options are: `"small"` and `"large"`.
*/
"size"?: string;
/**
* Specifies the exact `src` of an SVG file to use.
*/
"src"?: string;
}
interface IonIcon {
/**
* The color to use for the background of the item.
*/
color?: string;
/**
* Specifies whether the icon should horizontally flip when `dir` is `"rtl"`.
*/
flipRtl?: boolean;
/**
* 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.
*/
icon?: any;
/**
* Specifies which icon to use on `ios` mode.
*/
ios?: string;
/**
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
* @default false
*/
lazy?: boolean;
/**
* Specifies which icon to use on `md` mode.
*/
md?: string;
/**
* The mode determines which platform styles to use.
* @default getIonMode()
*/
mode?: string;
/**
* Specifies which icon to use from the built-in set of icons.
*/
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`.
* @default true
*/
sanitize?: boolean;
/**
* The size of the icon. Available options are: `"small"` and `"large"`.
*/
size?: string;
/**
* Specifies the exact `src` of an SVG file to use.
*/
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 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 {
"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] };
}
interface IntrinsicElements {
'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 };
declare module "@stencil/core" {
export namespace JSX {
interface IntrinsicElements {
"ion-icon": LocalJSX.IntrinsicElements["ion-icon"] & JSXBase.HTMLAttributes<HTMLIonIconElement>;
}
declare module '@stencil/core' {
export namespace JSX {
interface IntrinsicElements {
'ion-icon': LocalJSX.IntrinsicElements['ion-icon'] & JSXBase.HTMLAttributes<HTMLIonIconElement>;
}
}
}
+3 -21
View File
@@ -4,13 +4,12 @@
width: 1em;
height: 1em;
font-size: 1em;
contain: layout style;
contain: strict;
fill: currentColor;
box-sizing: content-box !important;
}
:host .ionicon {
@@ -25,16 +24,7 @@
stroke-width: var(--ionicon-stroke-width, 32px);
}
.icon-inner {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
.icon-inner,
.ionicon,
svg {
display: block;
@@ -43,14 +33,6 @@ svg {
width: 100%;
}
/* Slotted Content
* -----------------------------------------------------------
*/
::slotted(*) {
font-size: inherit !important;
}
/* Icon RTL
* -----------------------------------------------------------
*/
+13 -35
View File
@@ -1,5 +1,5 @@
import { Build, Component, Element, Host, Prop, State, Watch, h } from '@stencil/core';
import { getCacheKey, getSvgContent, ioniconContent } from './request';
import { getSvgContent, ioniconContent } from './request';
import { getName, getUrl, inheritAttributes, isRTL } from './utils';
@Component({
@@ -12,7 +12,6 @@ export class Icon {
private io?: IntersectionObserver;
private iconName: string | null = null;
private inheritedAttributes: { [k: string]: any } = {};
private didLoadIcon = false;
@Element() el!: HTMLElement;
@@ -74,11 +73,9 @@ export class Icon {
@Prop() lazy = false;
/**
* 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.
* 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`.
* @default true
*/
@Prop() sanitize = true;
@@ -99,21 +96,6 @@ export class Icon {
});
}
/**
* Loads the icon after the component has finished rendering.
*/
componentDidLoad() {
/**
* Addresses an Angular issue where property values are assigned after the 'connectedCallback' but prior to the registration of watchers.
* This enhancement ensures the loading of an icon when the component has finished rendering and the icon has yet to apply the SVG data.
* This modification pertains to the usage of Angular's binding syntax:
* `<ion-icon [name]="myIconName"></ion-icon>`
*/
if (!this.didLoadIcon) {
this.loadIcon();
}
}
/**
* Disconnect the IntersectionObserver.
*/
@@ -167,25 +149,23 @@ export class Icon {
* 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('src')
@Watch('icon')
@Watch('ios')
@Watch('md')
@Watch('name', { immediate: true })
@Watch('src', { immediate: true })
@Watch('icon', { immediate: true })
@Watch('ios', { immediate: true })
@Watch('md', { immediate: true })
loadIcon() {
if (Build.isBrowser && this.isVisible) {
const url = getUrl(this);
if (url) {
const cacheKey = getCacheKey(url, this.sanitize);
if (ioniconContent.has(cacheKey)) {
if (ioniconContent.has(url)) {
// sync if it's already loaded
this.svgContent = ioniconContent.get(cacheKey);
this.svgContent = ioniconContent.get(url);
} else {
// async if it hasn't been loaded
getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(cacheKey)));
getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(url)));
}
this.didLoadIcon = true;
}
}
@@ -224,9 +204,7 @@ export class Icon {
{Build.isBrowser && this.svgContent ? (
<div class="icon-inner" innerHTML={this.svgContent}></div>
) : (
<div class="icon-inner">
<slot></slot>
</div>
<div class="icon-inner"></div>
)}
</Host>
);
+13 -13
View File
@@ -7,19 +7,19 @@
## Properties
| Property | Attribute | Description | Type | Default |
| ---------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -------------- |
| `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` |
| `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` |
| `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` |
| `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` |
| `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` |
| `src` | `src` | Specifies the exact `src` of an SVG file to use. | `string \| undefined` | `undefined` |
| Property | Attribute | Description | Type | Default |
| ---------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -------------- |
| `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` |
| `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` |
| `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` |
| `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` |
| `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` |
| `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` |
----------------------------------------------
+13 -34
View File
@@ -5,39 +5,20 @@ const requests = new Map<string, Promise<any>>();
let parser: DOMParser;
/**
* Unsanitized content gets its own key so it's never served to an icon that
* sanitizes.
*/
export const getCacheKey = (url: string, sanitize: boolean) =>
`${sanitize !== false ? 'sanitized' : 'unsanitized'}:${url}`;
/**
* Warns when the whole icon is rejected so it doesn't silently render nothing.
*/
const sanitizeSvg = (url: string, svgContent: string) =>
validateContent(svgContent, () => {
const source = url.length > 100 ? `${url.slice(0, 100)}...` : url;
console.warn(
`[Ionicons Warning]: The SVG from "${source}" was not rendered because it failed sanitization. Only set sanitize="false" for SVG content from a trusted source.`,
);
});
/**
* Safely fallback to an empty svg
*/
function safeFallback(cacheKey: string) {
function safeFallback(url: string) {
const svg = '';
ioniconContent.set(cacheKey, svg);
ioniconContent.set(url, 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);
const req = requests.get(url);
if (req) {
return req;
}
@@ -48,16 +29,16 @@ export const getSvgContent = (url: string, sanitize: boolean): Promise<string> =
* with the DOMParser. This works with content security policies enabled.
*/
if (isSvgDataUrl(url) && isEncodedDataUrl(url)) {
return Promise.resolve(getSvgByUrl(url, sanitize));
return Promise.resolve(getSvgByUrl(url));
}
return fetchSvg(url, sanitize);
}
return Promise.resolve(safeFallback(cacheKey));
return Promise.resolve(safeFallback(url));
};
function getSvgByUrl(url: string, sanitize: boolean): string {
function getSvgByUrl(url: string): string {
if (!parser) {
/**
* Create an instance of the DOM parser. This creates a single
@@ -68,16 +49,14 @@ function getSvgByUrl(url: string, sanitize: boolean): string {
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;
ioniconContent.set(url, svg.outerHTML);
return svg.outerHTML;
}
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
*/
@@ -92,20 +71,20 @@ function fetchSvg(url: string, sanitize: boolean): Promise<string> {
.text()
.then((svgContent) => {
if (svgContent && sanitize !== false) {
svgContent = sanitizeSvg(url, svgContent);
svgContent = validateContent(svgContent);
}
const svg = svgContent || '';
ioniconContent.set(cacheKey, svg);
ioniconContent.set(url, svg);
return svg;
})
.catch(() => safeFallback(cacheKey));
.catch(() => safeFallback(url));
})
.catch(() => safeFallback(cacheKey));
.catch(() => safeFallback(url));
/**
* Cache for the same requests
*/
requests.set(cacheKey, req);
requests.set(url, req);
return req;
}
-15
View File
@@ -1,15 +0,0 @@
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
@@ -1,59 +0,0 @@
<!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>
@@ -1,13 +0,0 @@
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.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

-101
View File
@@ -1,101 +0,0 @@
<!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>
-52
View File
@@ -1,52 +0,0 @@
<!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>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

@@ -1,45 +0,0 @@
<!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
@@ -1,14 +0,0 @@
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);
@@ -1,9 +1,18 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('icon: rtl', () => {
test.describe('icon: basic', () => {
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 }) => {
await page.goto(`/icon/test/rtl/`);
await page.goto(`/`);
const autoflip = page.locator('.auto-flip-chevrons [name=chevron-forward] .icon-inner');
const unflip = page.locator('.un-flip-chevrons [name=chevron-forward] .icon-inner');
@@ -20,11 +29,12 @@ test.describe('icon: rtl', () => {
// Wait for all SVGs to be lazily loaded before taking screenshots
await page.waitForLoadState('networkidle');
await expect(page).toHaveScreenshot(`icon-rtl.png`);
const rtlTests = page.locator('#rtl-tests');
await expect(rtlTests).toHaveScreenshot(`icon-rtl-diff.png`);
});
test('arrows should flip if dir changes on the element', async ({ page }) => {
await page.goto(`/icon/test/rtl/`);
await page.goto(`/`);
const autoflip = page.locator('.auto-flip-chevrons [name=chevron-forward] .icon-inner');
const unflip = page.locator('.un-flip-chevrons [name=chevron-forward] .icon-inner');
@@ -41,7 +51,7 @@ test.describe('icon: rtl', () => {
});
test('icon should reassess flipping when name changes', async ({ page }) => {
await page.goto(`/icon/test/rtl/`);
await page.goto(`/`);
await page.evaluate(() => {
document.dir = 'rtl';
Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+60 -183
View File
@@ -2,201 +2,78 @@ import { newSpecPage } from 'jest-stencil-runner';
import { Icon } from '../icon';
describe('icon', () => {
describe('basic rendering', () => {
it('renders', async () => {
const { root } = await newSpecPage({
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>
`);
it('renders', async () => {
const { root } = await newSpecPage({
components: [Icon],
html: '<ion-icon></ion-icon>',
});
expect(root).toEqualHtml(`
<ion-icon class="md" role="img">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
</ion-icon>
`);
});
describe('dynamic rendering', () => {
it('renders custom label after changing source', async () => {
const page = await newSpecPage({
components: [Icon],
html: `<ion-icon name="chevron-forward" aria-label="custom label"></ion-icon>`,
});
const icon = page.root;
expect(icon).toEqualHtml(`
<ion-icon class="flip-rtl md" name="chevron-forward" role="img" aria-label="custom label">
<mock:shadow-root>
<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 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"></div>
</mock:shadow-root>
</ion-icon>
`);
});
describe('svg rendering scenarios', () => {
it('svgContent=true: renders svg without slot', async () => {
const page = await newSpecPage({
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();
it('renders custom aria-label', async () => {
const { root } = await newSpecPage({
components: [Icon],
html: `<ion-icon name="star" aria-label="custom label"></ion-icon>`,
});
it('svgContent=false: renders slot for custom content', async () => {
const page = await newSpecPage({
components: [Icon],
html: `<ion-icon aria-hidden="true" part="close-icon" class="close-icon"></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();
});
expect(root).toEqualHtml(`
<ion-icon class="md" name="star" role="img" aria-label="custom label">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
</ion-icon>
`);
});
describe('slotted content', () => {
it('renders slotted font icon (Font Awesome)', async () => {
const { root } = await newSpecPage({
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>
`);
it('renders custom label after changing source', async () => {
const page = await newSpecPage({
components: [Icon],
html: `<ion-icon name="chevron-forward" aria-label="custom label"></ion-icon>`,
});
it('renders slotted font icon with color', async () => {
const { root } = await newSpecPage({
components: [Icon],
html: `
<ion-icon color="primary">
<i class="fa fa-heart"></i>
</ion-icon>
`,
});
expect(root).toEqualHtml(`
<ion-icon class="md ion-color ion-color-primary" color="primary" role="img">
<mock:shadow-root>
<div class="icon-inner">
<slot></slot>
</div>
</mock:shadow-root>
<i class="fa fa-heart"></i>
</ion-icon>
`);
});
const icon = page.root;
it('renders slotted font icon with custom style', async () => {
const { root } = await newSpecPage({
components: [Icon],
html: `
<ion-icon style="font-size: 48px">
<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>
`);
});
expect(icon).toEqualHtml(`
<ion-icon class="flip-rtl md" name="chevron-forward" role="img" aria-label="custom label">
<mock:shadow-root>
<div class="icon-inner"></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"></div>
</mock:shadow-root>
</ion-icon>
`);
});
});
-66
View File
@@ -1,66 +0,0 @@
<!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>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

-72
View File
@@ -1,72 +0,0 @@
<!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>
@@ -1,284 +0,0 @@
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.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

@@ -1,37 +0,0 @@
<!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
@@ -1,40 +0,0 @@
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.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

-39
View File
@@ -1,39 +0,0 @@
<!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>
@@ -1,13 +0,0 @@
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.

Before

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

-310
View File
@@ -1,310 +0,0 @@
<!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 - Slotted Content</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" />
<!-- Material Icons -->
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<!-- Phosphor Icons -->
<link
rel="stylesheet"
type="text/css"
href="https://cdn.jsdelivr.net/npm/@phosphor-icons/web@2.1.1/src/fill/style.css"
/>
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css" />
</head>
<body>
<test-header></test-header>
<main>
<h1>Icon - Slotted Content</h1>
<div class="grid">
<div class="grid-item">
<h2>Material Icons</h2>
<ion-icon>
<span class="material-icons">home</span>
</ion-icon>
<ion-icon>
<span class="material-icons">favorite</span>
</ion-icon>
<ion-icon>
<span class="material-icons">star</span>
</ion-icon>
<ion-icon>
<span class="material-icons">person</span>
</ion-icon>
<ion-icon>
<span class="material-icons">settings</span>
</ion-icon>
<br />
<ion-icon color="primary">
<span class="material-icons">home</span>
</ion-icon>
<ion-icon color="secondary">
<span class="material-icons">favorite</span>
</ion-icon>
<ion-icon color="success">
<span class="material-icons">star</span>
</ion-icon>
<ion-icon color="warning">
<span class="material-icons">warning</span>
</ion-icon>
<ion-icon color="danger">
<span class="material-icons">delete</span>
</ion-icon>
<br />
<ion-icon style="font-size: 24px">
<span class="material-icons">home</span>
</ion-icon>
<ion-icon style="font-size: 36px">
<span class="material-icons">favorite</span>
</ion-icon>
<ion-icon style="font-size: 48px">
<span class="material-icons">star</span>
</ion-icon>
</div>
<div class="grid-item">
<h2>Phosphor Icons</h2>
<ion-icon>
<i class="ph-fill ph-house"></i>
</ion-icon>
<ion-icon>
<i class="ph-fill ph-heart"></i>
</ion-icon>
<ion-icon>
<i class="ph-fill ph-star"></i>
</ion-icon>
<ion-icon>
<i class="ph-fill ph-user"></i>
</ion-icon>
<ion-icon>
<i class="ph-fill ph-gear"></i>
</ion-icon>
<br />
<ion-icon color="primary">
<i class="ph-fill ph-house"></i>
</ion-icon>
<ion-icon color="secondary">
<i class="ph-fill ph-heart"></i>
</ion-icon>
<ion-icon color="success">
<i class="ph-fill ph-star"></i>
</ion-icon>
<ion-icon color="warning">
<i class="ph-fill ph-warning"></i>
</ion-icon>
<ion-icon color="danger">
<i class="ph-fill ph-trash"></i>
</ion-icon>
<br />
<ion-icon style="font-size: 24px">
<i class="ph-fill ph-house"></i>
</ion-icon>
<ion-icon style="font-size: 36px">
<i class="ph-fill ph-heart"></i>
</ion-icon>
<ion-icon style="font-size: 48px">
<i class="ph-fill ph-star"></i>
</ion-icon>
</div>
<div class="grid-item">
<h2>Font Awesome Icons</h2>
<ion-icon>
<i class="fa fa-home"></i>
</ion-icon>
<ion-icon>
<i class="fa fa-heart"></i>
</ion-icon>
<ion-icon>
<i class="fa fa-star"></i>
</ion-icon>
<ion-icon>
<i class="fa fa-user"></i>
</ion-icon>
<ion-icon>
<i class="fa fa-cog"></i>
</ion-icon>
<br />
<ion-icon color="primary">
<i class="fa fa-home"></i>
</ion-icon>
<ion-icon color="secondary">
<i class="fa fa-heart"></i>
</ion-icon>
<ion-icon color="success">
<i class="fa fa-star"></i>
</ion-icon>
<ion-icon color="warning">
<i class="fa fa-exclamation-triangle"></i>
</ion-icon>
<ion-icon color="danger">
<i class="fa fa-trash"></i>
</ion-icon>
<br />
<ion-icon style="font-size: 24px">
<i class="fa fa-home"></i>
</ion-icon>
<ion-icon style="font-size: 36px">
<i class="fa fa-heart"></i>
</ion-icon>
<ion-icon style="font-size: 48px">
<i class="fa fa-star"></i>
</ion-icon>
</div>
<div class="grid-item">
<h2>Bootstrap Icons</h2>
<ion-icon>
<i class="bi bi-house-fill"></i>
</ion-icon>
<ion-icon>
<i class="bi bi-heart-fill"></i>
</ion-icon>
<ion-icon>
<i class="bi bi-star-fill"></i>
</ion-icon>
<ion-icon>
<i class="bi bi-person-fill"></i>
</ion-icon>
<ion-icon>
<i class="bi bi-gear-fill"></i>
</ion-icon>
<br />
<ion-icon color="primary">
<i class="bi bi-house-fill"></i>
</ion-icon>
<ion-icon color="secondary">
<i class="bi bi-heart-fill"></i>
</ion-icon>
<ion-icon color="success">
<i class="bi bi-star-fill"></i>
</ion-icon>
<ion-icon color="warning">
<i class="bi bi-exclamation-triangle-fill"></i>
</ion-icon>
<ion-icon color="danger">
<i class="bi bi-trash-fill"></i>
</ion-icon>
<br />
<ion-icon style="font-size: 24px">
<i class="bi bi-house-fill"></i>
</ion-icon>
<ion-icon style="font-size: 36px">
<i class="bi bi-heart-fill"></i>
</ion-icon>
<ion-icon style="font-size: 48px">
<i class="bi bi-star-fill"></i>
</ion-icon>
</div>
<div class="grid-item">
<h2>Custom Slotted SVG</h2>
<ion-icon>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm3.5-9c.83 0 1.5-.67 1.5-1.5S16.33 8 15.5 8 14 8.67 14 9.5s.67 1.5 1.5 1.5zm-7 0c.83 0 1.5-.67 1.5-1.5S9.33 8 8.5 8 7 8.67 7 9.5 7.67 11 8.5 11zm3.5 6.5c2.33 0 4.31-1.46 5.11-3.5H6.89c.8 2.04 2.78 3.5 5.11 3.5z"
/>
</svg>
</ion-icon>
<ion-icon>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
/>
</svg>
</ion-icon>
<ion-icon>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"
/>
</svg>
</ion-icon>
<br />
<ion-icon color="primary">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm3.5-9c.83 0 1.5-.67 1.5-1.5S16.33 8 15.5 8 14 8.67 14 9.5s.67 1.5 1.5 1.5zm-7 0c.83 0 1.5-.67 1.5-1.5S9.33 8 8.5 8 7 8.67 7 9.5 7.67 11 8.5 11zm3.5 6.5c2.33 0 4.31-1.46 5.11-3.5H6.89c.8 2.04 2.78 3.5 5.11 3.5z"
/>
</svg>
</ion-icon>
<ion-icon color="success">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
/>
</svg>
</ion-icon>
<ion-icon color="danger">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"
/>
</svg>
</ion-icon>
<br />
<ion-icon style="font-size: 24px">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm3.5-9c.83 0 1.5-.67 1.5-1.5S16.33 8 15.5 8 14 8.67 14 9.5s.67 1.5 1.5 1.5zm-7 0c.83 0 1.5-.67 1.5-1.5S9.33 8 8.5 8 7 8.67 7 9.5 7.67 11 8.5 11zm3.5 6.5c2.33 0 4.31-1.46 5.11-3.5H6.89c.8 2.04 2.78 3.5 5.11 3.5z"
/>
</svg>
</ion-icon>
<ion-icon style="font-size: 36px">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
/>
</svg>
</ion-icon>
<ion-icon style="font-size: 48px">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"
/>
</svg>
</ion-icon>
</div>
</div>
</main>
<style>
ion-icon {
font-size: 32px;
}
</style>
</body>
</html>
-107
View File
@@ -1,107 +0,0 @@
:root {
--color-primary: #0054e9;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
}
main {
padding: 16px;
}
h1 {
margin-bottom: 10px;
font-size: 28px;
}
h2 {
margin: 20px 0 10px;
font-size: 20px;
}
h3 {
font-size: 18px;
}
p {
margin-bottom: 10px;
color: #666;
}
header {
display: flex;
align-items: center;
min-height: 54px;
padding: 0 20px;
border-bottom: 1px solid #e0e0e0;
background: #ffffff;
}
.card {
min-height: 150px;
padding: 20px;
border: 1px solid #e0e0e0;
border-radius: 8px;
text-decoration: none;
color: inherit;
transition: all 0.2s;
}
.card:hover {
border-color: var(--color-primary);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.card h3 {
margin: 0 0 8px;
font-size: 18px;
color: var(--color-primary);
}
.card p {
margin: 0;
font-size: 14px;
color: #666;
}
.back-button {
display: inline-flex;
align-items: center;
gap: 6px;
text-decoration: none;
color: var(--color-primary);
font-size: 18px;
font-weight: 500;
transition: opacity 0.2s;
}
.back-button ion-icon {
font-size: inherit;
}
.back-button:hover {
opacity: 0.7;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 16px;
margin-top: 20px;
}
.grid-item {
padding: 16px;
border: 1px solid #e0e0e0;
border-radius: 4px;
background: #ffffff;
}
+33 -94
View File
@@ -1,65 +1,54 @@
import { readFileSync, readdirSync } from 'fs';
import { join } from 'path';
import { isEncodedDataUrl, isSvgDataUrl, isValid, validateContent } from '../validate';
const SVG_NS = 'http://www.w3.org/2000/svg';
const elm = (nodeName: string, attributes: { name: string; value?: string }[] = [], childNodes: any[] = []) =>
({ nodeType: 1, namespaceURI: SVG_NS, nodeName, attributes, childNodes }) as any;
import { isEncodedDataUrl, isSvgDataUrl, isValid } from '../validate';
describe('isValid', () => {
it('invalid onload attr', () => {
expect(isValid(elm('svg', [{ name: 'onload' }]))).toBe(false);
const el = {
nodeType: 1,
nodeName: 'svg',
attributes: [{ name: 'onload' }],
childNodes: [],
} as any;
expect(isValid(el)).toBe(false);
});
it('invalid onclick attr', () => {
expect(isValid(elm('svg', [{ name: 'OnClIcK' }]))).toBe(false);
const el = {
nodeType: 1,
nodeName: 'svg',
attributes: [{ name: 'OnClIcK' }],
childNodes: [],
} as any;
expect(isValid(el)).toBe(false);
});
it('invalid child SCRIPT elm', () => {
expect(isValid(elm('svg', [], [elm('SCRIPT')]))).toBe(false);
const el = {
nodeType: 1,
nodeName: 'svg',
attributes: [],
childNodes: [{ nodeType: 1, nodeName: 'SCRIPT', attributes: [], childNodes: [] }],
} as any;
expect(isValid(el)).toBe(false);
});
it('invalid script elm', () => {
expect(isValid(elm('script'))).toBe(false);
});
it('invalid foreignObject elm', () => {
expect(isValid(elm('svg', [], [elm('foreignObject')]))).toBe(false);
});
it.each(['iframe', 'embed', 'object'])('invalid %s elm', (name) => {
expect(isValid(elm('svg', [], [elm(name)]))).toBe(false);
});
it('invalid html namespace elm', () => {
const noscript = { ...elm('noscript'), namespaceURI: 'http://www.w3.org/1999/xhtml' };
expect(isValid(elm('svg', [], [elm('desc', [], [noscript])]))).toBe(false);
});
it('invalid javascript: url', () => {
expect(isValid(elm('a', [{ name: 'href', value: 'javascript:alert(1)' }]))).toBe(false);
});
it('invalid obfuscated javascript: url', () => {
expect(isValid(elm('a', [{ name: 'xlink:href', value: ' JaVa\tScRiPt:alert(1)' }]))).toBe(false);
});
it('invalid javascript: url in a value list', () => {
expect(isValid(elm('animate', [{ name: 'values', value: 'https://ionic.io;javascript:alert(1)' }]))).toBe(false);
const el = { nodeType: 1, nodeName: 'script', attributes: [], childNodes: [] } as any;
expect(isValid(el)).toBe(false);
});
it('is valid circle elm', () => {
expect(isValid(elm('circle'))).toBe(true);
const el = { nodeType: 1, nodeName: 'circle', attributes: [], childNodes: [] } as any;
expect(isValid(el)).toBe(true);
});
it('is valid SVG elm', () => {
expect(isValid(elm('SVG', [], [elm('line')]))).toBe(true);
});
it('is valid href', () => {
expect(isValid(elm('a', [{ name: 'href', value: 'https://ionic.io' }]))).toBe(true);
const el = {
nodeType: 1,
nodeName: 'SVG',
attributes: [],
childNodes: [{ nodeType: 1, nodeName: 'line', attributes: [], childNodes: [] }],
} as any;
expect(isValid(el)).toBe(true);
});
it('is valid text node', () => {
@@ -68,56 +57,6 @@ describe('isValid', () => {
});
});
describe('validateContent', () => {
it('removes foreignObject and keeps the artwork', () => {
const onRejected = jest.fn();
const result = validateContent(
`<svg xmlns="${SVG_NS}"><switch><foreignObject><iframe></iframe></foreignObject><g><path d="M0 0"></path></g></switch></svg>`,
onRejected,
);
expect(result).toContain('<path');
expect(result).not.toContain('foreignObject');
expect(onRejected).not.toHaveBeenCalled();
});
it('strips non-svg siblings', () => {
const result = validateContent(
`<img src="x" onerror="alert(1)"><svg xmlns="${SVG_NS}"><path d="M0 0"></path></svg>`,
);
expect(result).toContain('<path');
expect(result).not.toContain('<img');
});
it('rejects html inside desc and calls onRejected', () => {
const onRejected = jest.fn();
expect(validateContent(`<svg xmlns="${SVG_NS}"><desc><noscript><p></p></noscript></desc></svg>`, onRejected)).toBe(
'',
);
expect(onRejected).toHaveBeenCalledTimes(1);
});
it('rejects more than one root svg', () => {
const onRejected = jest.fn();
const svg = `<svg xmlns="${SVG_NS}"><path d="M0 0"></path></svg>`;
expect(validateContent(svg + svg, onRejected)).toBe('');
expect(onRejected).toHaveBeenCalledTimes(1);
});
it('accepts every shipped icon', () => {
const svgDir = join(__dirname, '../../../svg');
const rejected = readdirSync(svgDir)
.filter((file) => file.endsWith('.svg'))
.filter((file) => !validateContent(readFileSync(join(svgDir, file), 'utf8')));
expect(rejected).toEqual([]);
});
it('does not call onRejected when there is no svg', () => {
const onRejected = jest.fn();
expect(validateContent('<html><body>Not found</body></html>', onRejected)).toBe('');
expect(onRejected).not.toHaveBeenCalled();
});
});
it('isSvgDataUrl', () => {
expect(isSvgDataUrl('data:image/svg+xml;base64,xxx')).toBe(true);
expect(isSvgDataUrl('data:image/svg+xml;utf8,<svg></svg>')).toBe(true);
+16 -64
View File
@@ -1,91 +1,43 @@
import { isStr } from './utils';
/**
* Calls `onRejected` only when an `<svg>` was found and failed validation,
* not when there's no `<svg>` at all (like an HTML 404 page).
*/
export const validateContent = (svgContent: string, onRejected?: () => void) => {
/**
* Parse into a template so nothing loads or runs yet. Parsing into a live
* element would fire handlers like `<img onerror>` before validation.
*/
const template = document.createElement('template');
template.innerHTML = svgContent;
const content = template.content;
export const validateContent = (svgContent: string) => {
const div = document.createElement('div');
div.innerHTML = svgContent;
for (let i = content.childNodes.length - 1; i >= 0; i--) {
if (content.childNodes[i].nodeName.toLowerCase() !== 'svg') {
content.removeChild(content.childNodes[i]);
// setup this way to ensure it works on our buddy IE
for (let i = div.childNodes.length - 1; i >= 0; i--) {
if (div.childNodes[i].nodeName.toLowerCase() !== 'svg') {
div.removeChild(div.childNodes[i]);
}
}
const svgElm = content.firstElementChild;
// must only have 1 root element
const svgElm = div.firstElementChild;
if (svgElm && svgElm.nodeName.toLowerCase() === 'svg') {
const svgClass = svgElm.getAttribute('class') || '';
svgElm.setAttribute('class', (svgClass + ' s-ion-icon').trim());
/**
* Illustrator exports keep editor data in a `<foreignObject>` next to the
* artwork, so remove it instead of rejecting the icon.
*/
removeForeignObjects(svgElm);
// every root is serialized, so a second <svg> would skip validation
if (content.children.length === 1 && isValid(svgElm as any)) {
return template.innerHTML;
// root element must be an svg
// lets double check we've got valid elements
// do not allow scripts
if (isValid(svgElm as any)) {
return div.innerHTML;
}
onRejected?.();
}
return '';
};
const removeForeignObjects = (elm: Element) => {
for (let i = elm.children.length - 1; i >= 0; i--) {
const child = elm.children[i];
if (child.nodeName.toLowerCase() === 'foreignobject') {
child.remove();
} else {
removeForeignObjects(child);
}
}
};
/**
* Elements that can run script or load a document without an `on*` attribute.
*/
const disallowedElements = new Set(['script', 'foreignobject', 'iframe', 'embed', 'object']);
/**
* Browsers ignore whitespace and control characters in a URL scheme, so strip
* them first. Checking the whole value also catches lists like
* `<animate values="a;javascript:...">`.
*/
const hasJavascriptUrl = (value: string) =>
value
.replace(/[\u0000-\u0020]/g, '')
.toLowerCase()
.includes('javascript:');
const SVG_NS = 'http://www.w3.org/2000/svg';
export const isValid = (elm: HTMLElement) => {
if (elm.nodeType === 1) {
/**
* HTML inside `<desc>` or `<title>` (like `<noscript>`) can parse
* differently when it renders than it did here, so only allow SVG elements.
*/
if (elm.namespaceURI !== SVG_NS || disallowedElements.has(elm.nodeName.toLowerCase())) {
if (elm.nodeName.toLowerCase() === 'script') {
return false;
}
for (let i = 0; i < elm.attributes.length; i++) {
const { name, value } = elm.attributes[i];
const name = elm.attributes[i].name;
if (isStr(name) && name.toLowerCase().indexOf('on') === 0) {
return false;
}
if (isStr(value) && hasJavascriptUrl(value)) {
return false;
}
}
for (let i = 0; i < elm.childNodes.length; i++) {

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

@@ -1,9 +1,9 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
import { test } from '../../../utils/test/playwright';
test.describe('icon: csp', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/icon/test/csp');
await page.goto('/test/csp');
});
test('should load svg', async ({ page }) => {
+54
View File
@@ -0,0 +1,54 @@
<!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>IonIcon - Content Security Policy</title>
<script type="module" src="../../build/ionicons.esm.js"></script>
<script nomodule src="../../build/ionicons.js"></script>
<style>
body {
margin: 0;
padding: 16px;
font-size: 32px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
h1 {
margin: 15px 0 5px;
font-size: 25px;
}
h2 {
margin: 15px 0 5px;
font-size: 18px;
}
.custom {
stroke: red;
fill: goldenrod;
color: black;
}
</style>
</head>
<body>
<h1>Ionicons - Test </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>
</body>
</html>

Before

Width:  |  Height:  |  Size: 292 B

After

Width:  |  Height:  |  Size: 292 B

@@ -1,16 +1,17 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
import { test } from '../../../utils/test/playwright';
test.describe('icon: dynamic type', () => {
test.beforeEach(async ({ page }) => {
await page.goto(`/icon/test/dynamic-type/`);
await page.goto('/test/dynamic-type');
});
test('should scale text on larger font sizes', 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-dynamic-type.png`);
const icons = page.locator('#icons');
await expect(icons).toHaveScreenshot(`icon-dynamic-type-diff.png`);
});
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

@@ -0,0 +1,27 @@
<!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>IonIcon - Dynamic Type</title>
<script type="module" src="../../build/ionicons.esm.js"></script>
<script nomodule src="../../build/ionicons.js"></script>
<style>
html {
font-size: 28px;
}
</style>
</head>
<body>
<div id="icons">
<ion-icon name="star"></ion-icon>
<ion-icon name="star" size="small"></ion-icon>
<ion-icon name="star" size="large"></ion-icon>
</div>
</body>
</html>

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

+180
View File
@@ -0,0 +1,180 @@
<!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>Ionicons Icon Component</title>
<script type="module" src="/build/ionicons.esm.js"></script>
<script nomodule src="/build/ionicons.js"></script>
</head>
<body>
<h1>Ionicons</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>
<h2>Aria</h2>
<ion-icon name="cellular"></ion-icon>
<ion-icon name="cellular" aria-label="Mobile data"></ion-icon>
<ion-icon name="cellular" aria-hidden="true"></ion-icon>
<div id="rtl-tests">
<h1>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>
</div>
<h2>Sanitized (shouldn't show)</h2>
<ion-icon src="./assets/sanitize.svg"></ion-icon>
<h2>Not Sanitized (should show)</h2>
<ion-icon sanitize="false" src="./assets/no-sanitize.svg"></ion-icon>
<h2>Base64 url</h2>
<ion-icon
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJub25lIiBkPSJNMCAwaDI0djI0SDBWMHoiLz48cGF0aCBkPSJNMjAgMkg0Yy0xLjEgMC0yIC45LTIgMnYxOGw0LTRoMTRjMS4xIDAgMi0uOSAyLTJWNGMwLTEuMS0uOS0yLTItMnptMCAxNEg2bC0yIDJWNGgxNnYxMnoiLz48L3N2Zz4="></ion-icon>
<p>
<a href="./cheatsheet.html">Cheatsheet</a>
</p>
<style>
html {
font-size: 32px;
}
body {
margin: 0;
padding: 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
h1 {
margin: 15px 0 5px;
font-size: 25px;
}
h2 {
margin: 15px 0 5px;
font-size: 18px;
}
.custom {
stroke: red;
fill: blue;
}
</style>
</body>
</html>
@@ -1,2 +1 @@
export * from './goto';
export * from './set-content';
@@ -1,73 +0,0 @@
import type { Page, TestInfo } from '@playwright/test';
import type { E2EPage } from '@utils/test/playwright';
/**
* Overwrites the default Playwright page.setContent method.
*
* Navigates to a blank page, sets the content, and waits for the
* Stencil components to be hydrated before proceeding with the test.
*
* Ported from Ionic Framework's fixture. Ionicons has no mode, direction,
* or palette config, so only the ionicons build is injected.
*
* @param page The Playwright page object.
* @param html The HTML content to set on the page body.
* @param testInfo The TestInfo associated with the current test run.
* @param options Navigation options passed to page.goto.
*/
export const setContent = async (
page: Page,
html: string,
testInfo: TestInfo,
options?: Parameters<E2EPage['goto']>[1],
) => {
if (page.isClosed()) {
throw new Error('setContent unavailable: page is already closed');
}
const baseUrl = testInfo.project.use.baseURL;
if (!baseUrl) {
throw new Error('setContent requires a baseURL in the Playwright config');
}
const output = `
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<title>Ionicons Playwright Test</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
<script type="module" src="${baseUrl}/build/ionicons.esm.js"></script>
</head>
<body>
${html}
</body>
</html>
`;
await page.route(baseUrl, (route) => {
if (route.request().url() === `${baseUrl}/`) {
/**
* Intercepts the empty page request and returns the
* HTML content that was passed in.
*/
route.fulfill({
status: 200,
contentType: 'text/html',
body: output,
});
} else {
// Allow all other requests to pass through
route.continue();
}
});
/**
* URL query parameters cause the custom Playwright `page.route`
* interceptor to fail, which is necessary to inject the test HTML.
*
* To avoid this, the final navigation URL is kept simple by using
* hash params to ensure the route interceptor always works.
*/
await page.goto(`${baseUrl}#`, options);
};
@@ -54,10 +54,4 @@ export interface E2EPage extends Page {
waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
},
) => Promise<null | Response>;
/**
* Replaces the page content with the given HTML, loads the ionicons build,
* and waits for the Stencil components to be hydrated.
*/
setContent: (html: string, options?: Parameters<E2EPage['goto']>[1]) => Promise<void>;
}
+1 -2
View File
@@ -7,7 +7,7 @@ import type {
} from '@playwright/test';
import { test as base } from '@playwright/test';
import { goto as goToPage, setContent } from './page/utils';
import { goto as goToPage } from './page/utils';
import type { E2EPage } from './playwright-declarations';
type CustomTestArgs = PlaywrightTestArgs &
@@ -43,7 +43,6 @@ export async function extendPageFixture(page: E2EPage, testInfo: TestInfo) {
})();`);
// Overridden Playwright methods
page.goto = (url: string, options) => goToPage(page, url, options, testInfo, originalGoto);
page.setContent = (html: string, options) => setContent(page, html, testInfo, options);
return page;
}
+4 -4
View File
@@ -21,12 +21,12 @@ export const config: Config = {
type: 'www',
copy: [
{
src: './components/icon/assets',
dest: './icon/assets/',
src: './components/test/*.svg',
dest: './assets/',
},
{
src: './components/icon/test',
dest: './icon/test',
src: './components/test/',
dest: './test/',
},
{
src: './svg/*.svg',