Skip to content

Commit 6df30fb

Browse files
committed
Matches VS Code radio and checkbox colors
1 parent 0980d98 commit 6df30fb

File tree

5 files changed

+48
-44
lines changed

5 files changed

+48
-44
lines changed

src/webviews/apps/shared/components/checkbox/checkbox.css.ts

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

src/webviews/apps/shared/components/checkbox/checkbox.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { html } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
3-
import { GlElement, observe } from '../element';
3+
import { GlElement } from '../element';
44
import { checkboxBaseStyles } from '../forms/checkbox.css';
5-
import { checkboxStyles } from './checkbox.css';
65

76
import '../code-icon';
87

@@ -15,7 +14,7 @@ export class Checkbox extends GlElement {
1514
delegatesFocus: true,
1615
};
1716

18-
static override readonly styles = [checkboxBaseStyles, checkboxStyles];
17+
static override readonly styles = [checkboxBaseStyles];
1918

2019
@property({ type: Boolean, reflect: true })
2120
disabled: boolean = false;
@@ -34,15 +33,9 @@ export class Checkbox extends GlElement {
3433

3534
constructor() {
3635
super();
37-
this.disabled = false;
3836
this._defaultChecked = this.checked;
3937
}
4038

41-
@observe(['defaultChecked'], { afterFirstUpdate: true })
42-
private initChecked() {
43-
this.checked = this.defaultChecked;
44-
}
45-
4639
handleChange(e: Event) {
4740
this.checked = (e.target as HTMLInputElement).checked;
4841
const event = new CustomEvent('gl-change-value');

src/webviews/apps/shared/components/forms/checkbox.css.ts

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,43 @@ import { css } from 'lit';
22

33
export const checkboxBaseStyles = css`
44
:host {
5+
--checkbox-foreground: var(--vscode-checkbox-foreground);
6+
--checkbox-background: var(--vscode-checkbox-background);
7+
--checkbox-border: var(--vscode-checkbox-border);
8+
--checkbox-checked-foreground: var(--vscode-inputOption-activeForeground);
9+
--checkbox-checked-background: var(--vscode-inputOption-activeBackground);
10+
--checkbox-checked-border: var(--vscode-inputOption-activeBorder);
11+
--checkbox-active-background: var(--vscode-checkbox-selectBackground);
12+
--checkbox-active-border: var(--vscode-checkbox-selectBorder);
13+
--checkbox-hover-background: var(--vscode-inputOption-hoverBackground);
14+
--checkbox-radius: 3px;
15+
--checkbox-border-width: 1px;
16+
--checkbox-size: 1.6rem;
17+
--checkbox-spacing: 1rem;
18+
519
display: block;
620
margin-block: 0.8rem;
721
}
822
923
label {
1024
display: flex;
11-
gap: var(--label-spacing);
25+
gap: var(--checkbox-spacing);
1226
align-items: center;
13-
color: var(--vscode-checkbox-foreground);
1427
user-select: none;
1528
white-space: nowrap;
1629
cursor: pointer;
30+
color: var(--checkbox-foreground);
1731
}
1832
19-
label[aria-disabled] {
33+
:host([disabled]) label {
2034
cursor: default;
2135
opacity: 0.5;
2236
}
2337
2438
.label-text {
2539
display: block;
2640
line-height: normal;
27-
margin-inline-end: var(--label-spacing);
41+
margin-inline-end: var(--checkbox-spacing);
2842
}
2943
3044
.input {
@@ -38,28 +52,34 @@ export const checkboxBaseStyles = css`
3852
align-items: center;
3953
justify-content: center;
4054
position: relative;
41-
width: var(--control-size);
42-
height: var(--control-size);
55+
width: var(--checkbox-size);
56+
height: var(--checkbox-size);
4357
box-sizing: border-box;
44-
border-radius: var(--control-corner-radius);
45-
border: var(--control-border-width) solid var(--vscode-checkbox-border);
46-
background: var(--vscode-checkbox-background);
58+
border-radius: var(--checkbox-radius);
59+
color: var(--checkbox-foreground);
60+
background: var(--checkbox-background);
61+
border: var(--checkbox-border-width, 1px) solid var(--vscode-checkbox-border);
4762
}
4863
49-
label:not([aria-disabled]) .input:hover + .control {
50-
background: var(--vscode-checkbox-background);
51-
border-color: var(--vscode-checkbox-border);
64+
.input:hover + .control {
65+
background-color: var(--checkbox-hover-background);
5266
}
5367
54-
label:not([aria-disabled]) .input:focus-visible + .control,
55-
label:not([aria-disabled]) .input:focus + .control {
68+
.input:focus-visible + .control,
69+
.input:focus + .control {
5670
outline: 1px solid var(--vscode-focusBorder);
71+
outline-offset: 2px;
72+
}
73+
74+
.input:active + .control {
75+
background-color: var(--checkbox-active-background);
76+
border-color: var(--checkbox-active-border);
5777
}
5878
59-
label:not([aria-disabled]):active .input + .control,
60-
label:not([aria-disabled]) .input:active + .control {
61-
background: var(--vscode-checkbox-background);
62-
border-color: var(--vscode-focusBorder);
79+
:host([checked]) .control {
80+
color: var(--checkbox-checked-foreground);
81+
background-color: var(--checkbox-checked-background);
82+
border-color: var(--checkbox-checked-border);
6383
}
6484
6585
code-icon {

src/webviews/apps/shared/components/radio/radio.css.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import { css } from 'lit';
22

33
export const radioStyles = css`
44
:host {
5-
--design-unit: 4;
6-
--control-corner-radius: 50%;
7-
--control-border-width: 1px;
8-
--control-size: calc(var(--design-unit) * 4px + 2px);
9-
--label-spacing: calc(var(--design-unit) * 2px + 2px);
5+
--checkbox-radius: 50%;
6+
--checkbox-foreground: var(--vscode-radio-inactiveForeground);
7+
--checkbox-background: var(--vscode-radio-inactiveBackground);
8+
--checkbox-border: var(--vscode-radio-inactiveBorder);
9+
--checkbox-checked-foreground: var(--vscode-radio-activeForeground);
10+
--checkbox-checked-background: var(--vscode-radio-activeBackground);
11+
--checkbox-checked-border: var(--vscode-radio-activeBorder);
12+
--checkbox-hover-background: var(--vscode-radio-inactiveHoverBackground);
1013
}
1114
`;

src/webviews/apps/shared/components/radio/radio.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export class Radio extends GlElement {
5252
}
5353

5454
override render() {
55-
console.log('render', this.value, this.checked);
5655
return html`<label ?aria-disabled=${this.disabled}
5756
><button class="input" .disabled=${this.disabled} @click=${this.handleClick}></button>
5857
<div class="control">${this.renderCircle()}</div>

0 commit comments

Comments
 (0)