Skip to content

Commit 45c04dd

Browse files
authored
feat(icon): support for dynamic type (#1246)
1 parent b123558 commit 45c04dd

8 files changed

+57
-5
lines changed

src/components/icon/icon.css

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
fill: currentColor;
1010

1111
box-sizing: content-box !important;
12+
13+
font-size: 1rem;
1214
}
1315

1416
:host .ionicon {
@@ -36,7 +38,7 @@ svg {
3638
/* Icon RTL
3739
* -----------------------------------------------------------
3840
*/
39-
41+
4042
/**
4143
* Safari <16.4 incorrectly reports
4244
* that it supports :dir(rtl) when it does not.
@@ -53,7 +55,7 @@ svg {
5355
transform: scaleX(-1);
5456
}
5557
}
56-
58+
5759
/**
5860
* Fallback for browsers that support
5961
* neither :host-context nor :dir.
@@ -91,11 +93,11 @@ svg {
9193
*/
9294

9395
:host(.icon-small) {
94-
font-size: 18px !important;
96+
font-size: 1.125rem !important;
9597
}
9698

9799
:host(.icon-large) {
98-
font-size: 32px !important;
100+
font-size: 2rem !important;
99101
}
100102

101103
/* Icon Colors

src/components/icon/test/icon.e2e.ts

+1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ test.describe('icon: basic', () => {
6767
await expect(iconLoc).toHaveAttribute('name', 'brush');
6868
await expect(iconLoc).not.toHaveClass(/flip-rtl/);
6969
});
70+
7071
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect } from '@playwright/test';
2+
import { test } from '../../../utils/test/playwright';
3+
4+
test.describe('icon: dynamic type', () => {
5+
6+
test.beforeEach(async ({ page }) => {
7+
await page.goto('/test/dynamic-type');
8+
});
9+
10+
test('should scale text on larger font sizes', async ({ page }) => {
11+
// Wait for all SVGs to be lazily loaded before taking screenshots
12+
await page.waitForLoadState('networkidle');
13+
14+
const icons = page.locator('#icons');
15+
16+
expect(await icons.screenshot()).toMatchSnapshot(`icon-dynamic-type-diff.png`);
17+
});
18+
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html dir="ltr" lang="en" mode="ios">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
6+
<meta
7+
http-equiv="Content-Security-Policy"
8+
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/*'"
9+
/>
10+
<title>IonIcon - Dynamic Type</title>
11+
<script type="module" src="../../build/ionicons.esm.js"></script>
12+
<script nomodule src="../../build/ionicons.js"></script>
13+
<style>
14+
html {
15+
font-size: 28px;
16+
}
17+
</style>
18+
</head>
19+
20+
<body>
21+
<div id="icons">
22+
<ion-icon name="star"></ion-icon>
23+
<ion-icon name="star" size="small"></ion-icon>
24+
<ion-icon name="star" size="large"></ion-icon>
25+
</div>
26+
</body>
27+
</html>

src/index.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,13 @@ <h2>Base64 url</h2>
151151
</p>
152152

153153
<style>
154+
html {
155+
font-size: 32px;
156+
}
157+
154158
body {
155159
margin: 0;
156160
padding: 16px;
157-
font-size: 32px;
158161
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
159162
}
160163

0 commit comments

Comments
 (0)