Skip to content

Commit a762271

Browse files
authored
feat(icons): support "icons" contribution point #2594
## Problem This PR re-organizes how we do icons within the Toolkit, mostly by leveraging the VS Code icons contribution point. The old structure had the following problems: * No clear guidance for how to add and use icons within the Toolkit * Difficult to keep track of what icons are actually being used * Have to maintain separate light/dark icons for everything * Impossible to use our current icons with ThemeIcon * Using SVGs in Webviews in-lines them ## Solution * Put all icons in resources/icons * There's a single, top-level "namespace" to help a bit for organization * Everything within a namespace is flattened out at build time * Use the new icons contribution point * This section is generated (otherwise it'd be really tedious....) * Generate CSS classes from an icon font * Add function getIcon that handles all the legacy/Cloud9 compatibility logic. * Contributors no longer need to touch a bunch of files just to add a single icon.
1 parent c8c92b8 commit a762271

File tree

206 files changed

+2710
-2194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+2710
-2194
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules/**
2-
third-party
32
**/*.json
43
src/shared/telemetry/clienttelemetry.d.ts
54
src/codewhisperer/client/codewhispererclient.d.ts

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ src/codewhisperer/client/codewhispererclient.d.ts
3030
# Generated by tests
3131
src/testFixtures/**/bin
3232
src/testFixtures/**/obj
33+
34+
# Icons
35+
resources/icons/cloud9/generated/**
36+
resources/fonts/aws-toolkit-icons.woff
37+
resources/css/icons.css

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
out
22
resources/endpoints.json
3-
third-party/**
43
CHANGELOG.md
54
src/shared/telemetry/service-2.json
65
.changes

.vscode/settings.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// Place your settings in this file to overwrite default and user settings.
21
{
32
"files.exclude": {
4-
"src/testFixtures": true,
5-
"out": false // set this to true to hide the "out" folder with the compiled JS files
3+
"**/src/testFixtures": true
64
},
75
"search.exclude": {
8-
"out": true // set this to false to include "out" folder in search results
6+
"dist": true,
7+
"node_modules": true
8+
},
9+
"files.watcherExclude": {
10+
"**/src/testFixtures": true
911
},
1012
"typescript.preferences.importModuleSpecifier": "relative",
1113
"javascript.preferences.importModuleSpecifier": "relative"

.vscodeignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
!dist/libs
88
!dist/*/!(testFixtures|test)/**/!(*.*.map)
99
!dist/*/!(*.*.map)
10-
!media/**
1110
!resources/**
1211
!syntaxes/**
1312
!templates/**
14-
!third-party/**
1513
!types/**
1614
!LICENSE
1715
!NOTICE

CONTRIBUTING.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,25 @@ requests just from the model/types.
315315
req.send(function (err, data) { ... });
316316
```
317317
318+
### Font generation
319+
320+
For extensions to contribute their own codicons, VS Code requires a font file as well as how that font maps to codicon IDs. The mapping is found in `package.json` under the `icons` contribution point. Icons located in `resources/icons` are stitched together at build-time into a single font, automatically adding mappings to `package.json`. More information can be found [here](docs/icons.md).
321+
322+
As a simple example, let's say I wanted to add a new icon for CloudWatch log streams. I would do the following:
323+
324+
1. Place the icon in `resources/icons/aws/cloudwatch`. I'l name the icon `log-stream.svg`.
325+
1. Use `npm run generatePackage` to update `package.json`. Commit this change with the new icon.
326+
1. You can now use the icon in the Toolkit:
327+
328+
```ts
329+
getIcon('aws-cloudwatch-log-stream')
330+
```
331+
318332
## Importing icons from other open source repos
319333
320334
If you are contribuing visual assets from other open source repos, the source repo must have a compatible license (such as MIT), and we need to document the source of the images. Follow these steps:
321335
322-
1. Use a separate location in this repo for every repo where images are
323-
sourced from, in the form `third-party/resources/from-<BRIEF_REPO_NAME>`.
336+
1. Use a separate location in this repo for every repo/organization where images are sourced from. See `resources/icons/vscode` as an example.
324337
1. Copy the source repo's licence into this destination location's LICENSE.txt file
325338
1. Create a README.md in the destination location, and type in a copyright attribution:
326339
@@ -332,8 +345,7 @@ If you are contribuing visual assets from other open source repos, the source re
332345
<PASTE_SOURCE_LICENSE_HERE>
333346
```
334347
335-
1. Copy the SVG file(s) into a suitable place within the destination location, for example `.../dark/xyz.svg` and `.../light/xyz.svg`
336-
1. Add an entry to `third-party/README.md` summarizing the new destination location, where the asserts were sourced from, and a brief rationale.
348+
1. Add an entry [here](docs/icons.md#third-party) summarizing the new destination location, where the assets were sourced from, and a brief rationale.
337349
338350
[PR #227](https://github.com/aws/aws-toolkit-vscode/pull/227) shows an example.
339351

docs/icons.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Icons
2+
3+
All icons that are used in the Toolkit can be found in `resources/icons`.
4+
5+
A [build script](../../scripts/build/generateIcons.ts) generates Toolkit artifacts:
6+
7+
- `resources/icons/cloud9/generated`
8+
- `resources/fonts/aws-toolkit-icons.woff`
9+
- `resources/css/icons.css`
10+
- `contributes.icons` in [package.json](../../package.json)
11+
12+
This script should be ran using `npm run generatePackage` after making updates. Any changes made to `package.json` should be committed with the relevant icons.
13+
14+
## Fonts
15+
16+
Icons to be used in fonts should ideally be:
17+
18+
- Monochromatic (`currentColor` fill or stroke)
19+
- Equal in size and width
20+
- Defined by a single path
21+
22+
The benefits of doing this include:
23+
24+
- `ThemeIcon` support
25+
- Automatic generation of CSS classes for webviews
26+
- Static validation of icon identifiers
27+
28+
If your desired icon does not work well as a font, see [Theme Overrides](#theme-overrides) for adding icons as standalone images.
29+
30+
## Identifiers
31+
32+
Icons (except those in `cloud9`) can be referenced within the Toolkit by concatenating the icon path with hyphens, omitting the 'theme' if applicable.
33+
34+
Examples:
35+
36+
- `resources/icons/aws/apprunner/service.svg` -> `aws-apprunner-service`
37+
- `resources/icons/vscode/dark/help.svg` -> `vscode-help`
38+
- `resources/icons/vscode/codicons/close.svg` -> `vscode-close`
39+
40+
This specific format is used to keep things consistent with CSS classes while still supporting some semblance of namespacing. In Webviews, font-based icons can be used through the combination two CSS classes: `icon icon-${IDENTIFIER}`.
41+
42+
## Theme Overrides
43+
44+
By default, icons are assumed to be monochromatic and suitable for use as a font. If this is not the case, then icons specific to each theme (i.e. `dark` and `light`) must be added separately.
45+
46+
For example, if I wanted to use a special App Runner service icon, then I need to add the icons like so:
47+
48+
- `resources/icons/aws/dark/apprunner-service.svg`
49+
- `resources/icons/aws/light/apprunner-service.svg`
50+
51+
A similar format is used for overriding icons only on Cloud9:
52+
53+
- `resources/icons/cloud9/dark/aws-apprunner-service.svg`
54+
- `resources/icons/cloud9/light/aws-apprunner-service.svg`
55+
56+
These icons will **not** be usuable as Codicons or as font icons.
57+
58+
## Third Party
59+
60+
Icons sourced from third-party repositories need a corresponding entry placed within this section. Any added icons need to be placed in their own directory named after the source. Repositories that belong to the same organization may be placed in the same location.
61+
62+
### VS Code
63+
64+
[Visual Studio Code Icons](https://github.com/microsoft/vscode-icons) were moved to their own repository in August 2019. These files are located within [resources/icons/vscode](resources/icons/vscode).
65+
66+
[Visual Studio Code Codicons](https://github.com/microsoft/vscode-codicons). Codicons are VS Code's font-based icon set. These files are located within [resources/icons/vscode/codicons](resources/icons/vscode/codicons).

media/css/base-cloud9.css

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

media/js/loadVsCodeApi.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)