Skip to content

Commit 793e26f

Browse files
alex-pageyurm04
andauthored
Use @shopify/polaris-icons instead of /icons and copy-icons (#6934)
We tried these options. 😢 **Copy icons to `public`** Have to run a script, have to ignore or commit the files up. 🤷 **Create an API for icons** Works but has to be versioned. Unsure what happens with new icon releases and making sure the API refreshes it's cache. Doesn't feel like a problem we should maintain as an API. 🤔 **Use `@shopify/polaris-icons` as intended** Works (this PR) however we don't have a great way to get the buffer of the file. We generate it from a fetch for now. Co-authored-by: Yuraima Estevez <4642404+yurm04@users.noreply.github.com>
1 parent f702c83 commit 793e26f

File tree

19 files changed

+97
-133
lines changed

19 files changed

+97
-133
lines changed

.changeset/stupid-coats-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'polaris.shopify.com': minor
3+
---
4+
5+
Use @shopify/polaris-icons instead of /icons and copy-icons

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ node_modules
1212
/polaris-react/build-internal
1313
/polaris-react/src/styles/_media-queries.scss
1414
/polaris-tokens/build
15-
/polaris.shopify.com/public/icons
1615
/polaris.shopify.com/public/og-images
17-
/polaris.shopify.com/.env.local

polaris.shopify.com/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
"private": true,
55
"scripts": {
66
"build": "yarn run gen-assets && next build",
7+
"dev": "open http://localhost:3000 && next dev",
78
"postbuild": "yarn gen-sitemap",
8-
"dev": "node scripts/copy-icons.mjs && open http://localhost:3000 && next dev",
99
"start": "next start ",
1010
"lint": "run-p lint:*",
1111
"lint:js": "TIMING=1 eslint --cache .",
1212
"lint:styles": "stylelint '**/*.{css,scss}'",
1313
"clean": "rm -rf .turbo node_modules .next *.tsbuildinfo",
1414
"create-component": "generact --root src/components src/components/Template/Template.tsx",
15-
"gen-assets": "node scripts/gen-og-images.mjs && node scripts/copy-icons.mjs",
15+
"gen-assets": "node scripts/gen-og-images.mjs",
1616
"gen-sitemap": "yarn next-sitemap",
1717
"get-props": "ts-node --skip-project ./scripts/get-props.ts"
1818
},
@@ -34,11 +34,11 @@
3434
"remark-gfm": "^3.0.1"
3535
},
3636
"devDependencies": {
37+
"@types/gtag.js": "^0.0.10",
3738
"@types/js-yaml": "^4.0.5",
3839
"@types/marked": "^4.0.3",
3940
"@types/node": "17.0.21",
4041
"@types/prismjs": "^1.26.0",
41-
"@types/gtag.js": "^0.0.10",
4242
"@types/react": "*",
4343
"eslint-config-next": "12.1.0",
4444
"eslint": "8.10.0",

polaris.shopify.com/scripts/copy-icons.mjs

Lines changed: 0 additions & 20 deletions
This file was deleted.

polaris.shopify.com/src/components/Code/Code.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import Tooltip from '../Tooltip';
1+
import {ClipboardMinor} from '@shopify/polaris-icons';
2+
import {Tab} from '@headlessui/react';
3+
import {useState} from 'react';
24
import Prism from 'prismjs';
5+
36
import {useCopyToClipboard} from '../../utils/hooks';
7+
import Icon from '../Icon';
48
import styles from './Code.module.scss';
5-
import {Tab} from '@headlessui/react';
6-
import Image from '../Image';
7-
import {useState} from 'react';
9+
import Tooltip from '../Tooltip';
810

911
interface Props {
1012
code:
@@ -93,13 +95,7 @@ function CopyButton({code}: {code: string}) {
9395
onClick={copy}
9496
aria-label="Copy to clipboard"
9597
>
96-
<Image
97-
src="/icons/ClipboardMinor.svg"
98-
alt="Clipboard icon"
99-
width={16}
100-
height={16}
101-
icon
102-
/>
98+
<Icon source={ClipboardMinor} width={16} height={16} />
10399
</button>
104100
</Tooltip>
105101
</div>

polaris.shopify.com/src/components/Error404Page/Error404Page.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import Head from 'next/head';
2-
import Image from 'next/image';
32

43
import Longform from '../Longform';
4+
import Icon from '../Icon';
55
import Container from '../Container';
66
import styles from './Error404Page.module.scss';
77
import {useRouter} from 'next/router';
88
import {useEffect} from 'react';
99
import {useState} from 'react';
10+
import {CircleAlertMajor} from '@shopify/polaris-icons';
1011

1112
interface Props {}
1213

@@ -28,13 +29,9 @@ function Error404Page({}: Props) {
2829
<Container>
2930
<div style={{textAlign: 'center', marginTop: '4rem'}}>
3031
<Longform>
31-
<Image
32-
className={styles.Icon}
33-
src="/icons/CircleAlertMajor.svg"
34-
width={100}
35-
height={100}
36-
alt=""
37-
/>
32+
<div className={styles.Icon}>
33+
<Icon source={CircleAlertMajor} width={100} height={100} />
34+
</div>
3835
<h1 style={{marginTop: '2rem'}}>There’s no page at this address</h1>
3936
<p>
4037
Check the URL and try again, or use the search field to find what

polaris.shopify.com/src/components/FoundationsGrid/FoundationsGrid.module.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@
101101
width: 50px;
102102
border-radius: var(--border-radius-800);
103103

104-
img {
104+
svg {
105105
opacity: 0.66;
106106
}
107107

108108
@include dark-mode {
109-
img {
109+
svg {
110110
filter: invert(1);
111111
}
112112
}

polaris.shopify.com/src/components/FoundationsGrid/FoundationsGrid.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import Image from 'next/image';
1+
import Icon from '../Icon';
22
import Link from 'next/link';
33
import React from 'react';
44
import {stripMarkdownLinks} from '../../utils/various';
55
import {useGlobalSearchResult} from '../GlobalSearch/GlobalSearch';
66
import styles from './FoundationsGrid.module.scss';
7+
import * as polarisIcons from '@shopify/polaris-icons';
78

89
interface Props {
910
title?: string;
@@ -45,7 +46,7 @@ function FoundationsGridItem({
4546
<Link href={url} passHref>
4647
<a {...searchAttributes}>
4748
<div className={styles.Icon}>
48-
<Image src={`/icons/${icon}.svg`} alt="" width={20} height={20} />
49+
<Icon source={(polarisIcons as any)[icon]} />
4950
</div>
5051
<h4>{title}</h4>
5152
<p>{stripMarkdownLinks(description)}</p>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@import '../../styles/mixins.scss';
2+
3+
.Icon {
4+
filter: contrast(0) brightness(-5000%);
5+
opacity: 0.85;
6+
7+
@include dark-mode {
8+
filter: contrast(0) brightness(5000%);
9+
}
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import styles from './Icon.module.scss';
2+
3+
interface Props {
4+
source: React.ElementType;
5+
width?: number;
6+
height?: number;
7+
}
8+
9+
function Icon({source, height = 20, width = 20}: Props) {
10+
const SourceComponent = source;
11+
return <SourceComponent className={styles.Icon} style={{width, height}} />;
12+
}
13+
14+
export default Icon;

0 commit comments

Comments
 (0)