Skip to content

Commit 90a3cb1

Browse files
Enlarge icons for mobile screens using viewBox strategy (#11708)
Remerge changes from #11626 but with #11707 - [Spin link](https://admin.web.responsive-icons.sam-rose.us.spin.dev/store/shop1) - [Snapshot PR](Shopify/web#120771) --------- Co-authored-by: Charles Lee <charles.lee@shopify.com>
1 parent eac5c44 commit 90a3cb1

File tree

25 files changed

+28
-133
lines changed

25 files changed

+28
-133
lines changed

.changeset/twelve-dolphins-grow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
Increase icon size using viewBox for mobile screen sizes. This will enlarge icons on mobile without affecting the icon wrapper.

polaris-react/src/components/AccountConnection/tests/AccountConnection.test.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
import React from 'react';
22
import {mountWithApp} from 'tests/utilities';
3-
import {matchMedia} from '@shopify/jest-dom-mocks';
43

54
import {Avatar} from '../../Avatar';
65
import {Button} from '../../Button';
76
import {AccountConnection} from '../AccountConnection';
87

98
describe('<AccountConnection />', () => {
10-
beforeEach(() => {
11-
matchMedia.mock();
12-
});
13-
14-
afterEach(() => {
15-
matchMedia.restore();
16-
});
17-
189
describe('title', () => {
1910
it('shows the title when one is provided', () => {
2011
const title = 'Example app';

polaris-react/src/components/AppProvider/tests/AppProvider.test.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, {useContext} from 'react';
2-
import {matchMedia} from '@shopify/jest-dom-mocks';
32
import {mountWithApp} from 'tests/utilities';
43

54
import {LinkContext} from '../../../utilities/link';
@@ -8,14 +7,6 @@ import {MediaQueryProvider} from '../../MediaQueryProvider';
87
import {AppProvider} from '../AppProvider';
98

109
describe('<AppProvider />', () => {
11-
beforeEach(() => {
12-
matchMedia.mock();
13-
});
14-
15-
afterEach(() => {
16-
matchMedia.restore();
17-
});
18-
1910
it('updates context when props change', () => {
2011
const Child: React.FunctionComponent = () => {
2112
return useContext(LinkContext) ? <div id="child" /> : null;

polaris-react/src/components/Banner/tests/Banner.test.tsx

-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ import {
2727
import type {BannerTone} from '../Banner';
2828
import type {BannerHandles} from '../utilities';
2929

30-
window.matchMedia =
31-
window.matchMedia ||
32-
function () {
33-
return {
34-
matches: false,
35-
addListener() {},
36-
removeListener() {},
37-
};
38-
};
39-
4030
describe('<Banner />', () => {
4131
it('renders a title', () => {
4232
const banner = mountWithApp(<Banner title="Banner title" />);

polaris-react/src/components/Card/tests/Card.test.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import {mountWithApp} from 'tests/utilities';
3-
import {matchMedia} from '@shopify/jest-dom-mocks';
43
import {setMediaWidth} from 'tests/utilities/breakpoints';
54

65
import {WithinContentContext} from '../../../utilities/within-content-context';
@@ -11,14 +10,6 @@ const heading = <p>Online store dashboard</p>;
1110
const subheading = <p>View a summary of your online store performance</p>;
1211

1312
describe('Card', () => {
14-
beforeEach(() => {
15-
matchMedia.mock();
16-
});
17-
18-
afterEach(() => {
19-
matchMedia.restore();
20-
});
21-
2213
it('has a child with prop withinContentContainer set to true', () => {
2314
function TestComponent(_: {withinContentContainer: any}) {
2415
return null;

polaris-react/src/components/Filters/components/FilterPill/tests/FilterPill.test.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import {matchMedia} from '@shopify/jest-dom-mocks';
32
import {mountWithApp} from 'tests/utilities';
43
import {ChevronDownIcon} from '@shopify/polaris-icons';
54

@@ -21,13 +20,11 @@ describe('<Filters />', () => {
2120

2221
beforeEach(() => {
2322
originalScroll = HTMLElement.prototype.scroll;
24-
matchMedia.mock();
2523
mockUseBreakpoints(false);
2624
});
2725

2826
afterEach(() => {
2927
HTMLElement.prototype.scroll = originalScroll;
30-
matchMedia.restore();
3128
jest.clearAllMocks();
3229
});
3330

polaris-react/src/components/Filters/components/FiltersBar/tests/FiltersBar.test.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import {matchMedia} from '@shopify/jest-dom-mocks';
32
import {mountWithApp} from 'tests/utilities';
43

54
import {ActionList} from '../../../../ActionList';
@@ -13,12 +12,10 @@ describe('<FiltersBar />', () => {
1312

1413
beforeEach(() => {
1514
originalScroll = HTMLElement.prototype.scroll;
16-
matchMedia.mock();
1715
});
1816

1917
afterEach(() => {
2018
HTMLElement.prototype.scroll = originalScroll;
21-
matchMedia.restore();
2219
});
2320

2421
const defaultProps: FiltersBarProps = {

polaris-react/src/components/Filters/components/SearchField/tests/SearchField.test.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import type {ComponentProps} from 'react';
33
import {mountWithApp} from 'tests/utilities';
4-
import {matchMedia} from '@shopify/jest-dom-mocks';
54

65
import {SearchField} from '..';
76
import {TextField} from '../../../../TextField';
@@ -30,14 +29,9 @@ describe('SearchField', () => {
3029

3130
beforeEach(() => {
3231
jest.clearAllMocks();
33-
matchMedia.mock();
3432
mockUseBreakpoints(false);
3533
});
3634

37-
afterEach(() => {
38-
matchMedia.restore();
39-
});
40-
4135
it('will call onChange when changed', () => {
4236
const props = {...defaultProps};
4337
const spy = jest.fn();

polaris-react/src/components/Filters/tests/Filters.test.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import {matchMedia} from '@shopify/jest-dom-mocks';
32
import {mountWithApp} from 'tests/utilities';
43

54
import {Filters} from '../Filters';
@@ -11,12 +10,10 @@ describe('<Filters />', () => {
1110

1211
beforeEach(() => {
1312
originalScroll = HTMLElement.prototype.scroll;
14-
matchMedia.mock();
1513
});
1614

1715
afterEach(() => {
1816
HTMLElement.prototype.scroll = originalScroll;
19-
matchMedia.restore();
2017
});
2118

2219
const defaultProps: FiltersProps = {

polaris-react/src/components/Frame/components/ToastManager/tests/ToastManager.test.tsx

-10
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ import {Toast} from '../../Toast';
66
import {Frame} from '../../../Frame';
77
import {ToastManager} from '../ToastManager';
88

9-
window.matchMedia =
10-
window.matchMedia ||
11-
function () {
12-
return {
13-
matches: false,
14-
addListener() {},
15-
removeListener() {},
16-
};
17-
};
18-
199
describe('<ToastManager />', () => {
2010
it('updates toast safely', () => {
2111
const toastManager = mountWithApp(

polaris-react/src/components/Grid/tests/Grid.test.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import React from 'react';
2-
import {matchMedia, timer} from '@shopify/jest-dom-mocks';
2+
import {timer} from '@shopify/jest-dom-mocks';
33
import {mountWithApp} from 'tests/utilities';
44

55
import {formatAreas, Grid} from '../Grid';
66

77
describe('<Grid />', () => {
88
beforeEach(() => {
9-
matchMedia.mock();
109
timer.mock();
1110
});
1211

1312
afterEach(() => {
14-
matchMedia.restore();
1513
timer.restore();
1614
});
1715

polaris-react/src/components/Icon/Icon.module.scss

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
display: block;
55
height: 20px;
66
width: 20px;
7+
78
max-height: 100%;
89
max-width: 100%;
910
margin: auto;

polaris-react/src/components/Icon/Icon.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22

33
import {Text} from '../Text';
44
import {classNames, variationName} from '../../utilities/css';
5+
import {useBreakpoints} from '../../utilities/breakpoints';
56
import type {IconSource} from '../../types';
67

78
import styles from './Icon.module.scss';
@@ -62,13 +63,19 @@ export function Icon({source, tone, accessibilityLabel}: IconProps) {
6263
tone && styles[variationName('tone', tone)],
6364
);
6465

66+
const {mdDown} = useBreakpoints();
67+
6568
const SourceComponent = source;
6669
const contentMarkup = {
6770
function: (
6871
<SourceComponent
6972
className={styles.Svg}
7073
focusable="false"
7174
aria-hidden="true"
75+
// On Mobile we're scaling the viewBox to 18x18 to make the icons bigger
76+
// Also, we're setting the viewport origin to 1x1 to center the icon
77+
// We use this syntax so we don't override the existing viewBox value if we don't need to.
78+
{...(mdDown ? {viewBox: '1 1 18 18'} : {})}
7279
/>
7380
),
7481
placeholder: <div className={styles.Placeholder} />,

polaris-react/src/components/IndexFilters/tests/IndexFilters.test.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import type {ComponentProps} from 'react';
33
import {mountWithApp} from 'tests/utilities';
4-
import {matchMedia} from '@shopify/jest-dom-mocks';
54

65
import {Tabs} from '../../Tabs';
76
import {Filters} from '../../Filters';
@@ -93,13 +92,8 @@ describe('IndexFilters', () => {
9392
showEditColumnsButton: false,
9493
};
9594

96-
beforeEach(() => {
97-
matchMedia.mock();
98-
});
99-
10095
afterEach(() => {
10196
jest.resetAllMocks();
102-
matchMedia.restore();
10397
});
10498

10599
it('reacts correctly to pressing the search button and invokes setMode with the filtering argument', () => {

polaris-react/src/components/LegacyFilters/tests/LegacyFilters.test.tsx

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
import {matchMedia} from '@shopify/jest-dom-mocks';
32
import {mountWithApp} from 'tests/utilities';
3+
import {matchMedia} from '@shopify/jest-dom-mocks';
44

55
import {Button} from '../../Button';
66
import type {ButtonProps} from '../../Button';
@@ -51,14 +51,6 @@ describe('<LegacyFilters />', () => {
5151
jest.useFakeTimers();
5252
});
5353

54-
beforeEach(() => {
55-
matchMedia.mock();
56-
});
57-
58-
afterEach(() => {
59-
matchMedia.restore();
60-
});
61-
6254
it('renders WithinFilterContext with a value of true', () => {
6355
WithinFilterContext;
6456
const filters = mountWithApp(<LegacyFilters {...mockProps} />);

polaris-react/src/components/MediaQueryProvider/tests/MediaQueryProvider.test.tsx

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
import React from 'react';
2-
import {matchMedia} from '@shopify/jest-dom-mocks';
32
import {act} from 'react-dom/test-utils';
43
import {mountWithApp} from 'tests/utilities';
4+
import {matchMedia} from '@shopify/jest-dom-mocks';
55

66
// eslint-disable-next-line import/no-deprecated
77
import {EventListener} from '../../EventListener';
88
import {MediaQueryProvider} from '../MediaQueryProvider';
99
import {useMediaQuery} from '../../../utilities/media-query';
1010

1111
describe('MediaQueryProvider', () => {
12-
beforeEach(() => {
13-
matchMedia.mock();
14-
});
15-
16-
afterEach(() => {
17-
matchMedia.restore();
18-
});
19-
2012
it('renders EventListener with the resize event', () => {
2113
const mediaQueryProvider = mountWithApp(<MediaQueryProvider />);
2214
// eslint-disable-next-line import/no-deprecated

polaris-react/src/components/Navigation/components/Item/tests/Item.test.tsx

-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ import {SecondaryNavigation} from '../components';
1818
import {Tooltip} from '../../../../Tooltip';
1919

2020
describe('<Nav.Item />', () => {
21-
beforeEach(() => {
22-
matchMedia.mock();
23-
});
24-
25-
afterEach(() => {
26-
matchMedia.restore();
27-
});
28-
2921
// eslint-disable-next-line jest/no-disabled-tests
3022
it.skip('sets expanded to false on resize when !navigationBarCollapsed and location does not match', () => {
3123
const spy = jest.fn();

polaris-react/src/components/Navigation/components/Section/tests/Section.test.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe('<Navigation.Section />', () => {
1717
let cancelAnimationFrameSpy: jest.SpyInstance;
1818

1919
beforeEach(() => {
20-
matchMedia.mock();
2120
animationFrame.mock();
2221
context = {
2322
location: '/admin/products',
@@ -27,7 +26,6 @@ describe('<Navigation.Section />', () => {
2726
});
2827

2928
afterEach(() => {
30-
matchMedia.restore();
3129
animationFrame.restore();
3230
cancelAnimationFrameSpy.mockRestore();
3331
});

polaris-react/src/components/ResourceItem/tests/ResourceItem.test.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import type {AllHTMLAttributes} from 'react';
33
import {mountWithApp} from 'tests/utilities';
4-
import {matchMedia} from '@shopify/jest-dom-mocks';
54
import {setMediaWidth} from 'tests/utilities/breakpoints';
65

76
import {Avatar} from '../../Avatar';
@@ -21,12 +20,10 @@ describe('<ResourceItem />', () => {
2120
beforeEach(() => {
2221
spy = jest.spyOn(window, 'open');
2322
spy.mockImplementation(() => {});
24-
matchMedia.mock();
2523
});
2624

2725
afterEach(() => {
2826
spy.mockRestore();
29-
matchMedia.restore();
3027
});
3128

3229
const mockDefaultContext = {

polaris-react/src/components/ResourceList/tests/ResourceList.test.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import {mountWithApp} from 'tests/utilities';
33
import type {Root, Node, Element} from '@shopify/react-testing';
4-
import {matchMedia} from '@shopify/jest-dom-mocks';
54

65
import {BulkActions} from '../../BulkActions';
76
import {CheckableButton} from '../../CheckableButton';
@@ -55,14 +54,6 @@ const alternateTool = <div id="AlternateTool">Alternate Tool</div>;
5554
const defaultWindowWidth = window.innerWidth;
5655

5756
describe('<ResourceList />', () => {
58-
beforeEach(() => {
59-
matchMedia.mock();
60-
});
61-
62-
afterEach(() => {
63-
matchMedia.restore();
64-
});
65-
6657
describe('renderItem', () => {
6758
it('renders list items', () => {
6859
const resourceList = mountWithApp(

0 commit comments

Comments
 (0)