Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Fixed

- **Icon**: Eliminating style tags to prevent CSP violations.

## [1.11.0] - 2025-01-22

### Fixed
Expand Down
16 changes: 14 additions & 2 deletions dev/vscode-icon/nonce.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; script-src 'nonce-abc123'; script-src-elem 'nonce-abc123'; font-src 'self' data: 'nonce-abc123'; style-src-elem 'nonce-abc123'"
/>
<title>VSCode Elements</title>
<link
rel="stylesheet"
Expand All @@ -13,9 +17,14 @@
<script
type="module"
src="/node_modules/@vscode-elements/webview-playground/dist/index.js"
nonce="abc123"
></script>
<script type="module" src="/dist/main.js"></script>
<script>
<script nonce="abc123">
window.litNonce = 'abc123';
window.vscodeWebviewPlaygroundNonce = 'abc123';
</script>
<script type="module" src="/dist/main.js" nonce="abc123"></script>
<script nonce="abc123">
const logEvents = (selector, eventType) => {
document.querySelector(selector).addEventListener(eventType, (ev) => {
console.log(ev);
Expand All @@ -29,6 +38,9 @@ <h1>Using nonce property</h1>
<main>
<vscode-demo>
<vscode-icon name="account"></vscode-icon>
<vscode-icon name="loading" size="32" spin spin-duration="3"></vscode-icon>
<vscode-button icon="account">Hello World</vscode-button>
<vscode-button secondary>Hello World</vscode-button>
</vscode-demo>
</main>
</body>
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"@types/node": "^22.10.5",
"@typescript-eslint/eslint-plugin": "^8.19.1",
"@typescript-eslint/parser": "^8.19.1",
"@vscode-elements/webview-playground": "^1.3.0",
"@vscode-elements/webview-playground": "^1.4.0",
"@vscode/codicons": "^0.0.36",
"@web/dev-server": "^0.4.6",
"@web/dev-server-esbuild": "^1.0.3",
Expand Down
4 changes: 4 additions & 0 deletions src/vscode-icon/vscode-icon.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ const styles: CSSResultGroup = [
}

.codicon[class*='codicon-'] {
animation-duration: var(--spin-duration) !important;
display: block;
font-size: var(--size);
height: var(--size);
width: var(--size);
}

.icon,
Expand Down
19 changes: 11 additions & 8 deletions src/vscode-icon/vscode-icon.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {html, TemplateResult} from 'lit';
import {html, PropertyValues, TemplateResult} from 'lit';
import {customElement, property} from 'lit/decorators.js';
import {classMap} from 'lit/directives/class-map.js';
import {styleMap} from 'lit/directives/style-map.js';
import {ifDefined} from 'lit/directives/if-defined.js';
import {VscElement} from '../includes/VscElement.js';
import styles from './vscode-icon.styles.js';
Expand Down Expand Up @@ -70,6 +69,16 @@ export class VscodeIcon extends VscElement {
VscodeIcon.nonce = nonce;
}

protected willUpdate(changedProperties: PropertyValues): void {
if(changedProperties.has('size')) {
this.style.setProperty('--size', `${this.size}px`);
}

if (changedProperties.has('spinDuration')) {
this.style.setProperty('--spin-duration', `${this.spinDuration}s`);
}
}

/**
* For using web fonts in web components, the font stylesheet must be included
* twice: on the page and in the web component. This function looks for the
Expand Down Expand Up @@ -102,12 +111,6 @@ export class VscodeIcon extends VscElement {
['codicon-' + this.name]: true,
spin: this.spin,
})}
style=${styleMap({
animationDuration: String(this.spinDuration) + 's',
fontSize: this.size + 'px',
height: this.size + 'px',
width: this.size + 'px',
})}
></span>`;

const wrapped = this.actionIcon
Expand Down