Skip to content

Commit 253ec5c

Browse files
committed
Add nicer checkboxes
1 parent bd27dad commit 253ec5c

3 files changed

Lines changed: 49 additions & 32 deletions

File tree

src/includes/vscode-select/styles.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -313,37 +313,29 @@ export default [
313313
}
314314
315315
.checkbox-icon {
316-
background-color: var(--vscode-settings-checkboxBackground, #313131);
317-
border: 1px solid currentColor;
316+
align-items: center;
317+
background-color: var(--vscode-checkbox-background, #313131);
318+
border: 1px solid var(--vscode-checkbox-border);
318319
border-radius: 2px;
319320
box-sizing: border-box;
320-
height: 14px;
321+
color: var(--vscode-checkbox-foreground);
322+
display: inline-flex;
323+
height: 15px;
324+
justify-content: center;
321325
margin-right: 5px;
322326
overflow: hidden;
323327
position: relative;
324-
width: 14px;
325-
}
326-
327-
.checkbox-icon.checked:before,
328-
.checkbox-icon.checked:after {
329-
content: '';
330-
display: block;
331-
height: 5px;
332-
position: absolute;
333-
transform: rotate(-45deg);
334-
width: 10px;
328+
width: 15px;
335329
}
336330
337-
.checkbox-icon.checked:before {
338-
background-color: var(--vscode-foreground, #cccccc);
339-
left: 1px;
340-
top: 2.5px;
331+
.checkbox-icon svg {
332+
display: none;
333+
height: 13px;
334+
width: 13px;
341335
}
342336
343-
.checkbox-icon.checked:after {
344-
background-color: var(--vscode-settings-checkboxBackground, #313131);
345-
left: 1px;
346-
top: -0.5px;
337+
.checkbox-icon.checked svg {
338+
display: block;
347339
}
348340
349341
.dropdown-controls {

src/includes/vscode-select/template-elements.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {html} from 'lit';
1+
import {html, svg} from 'lit';
22

33
export const chevronDownIcon = html`
44
<span class="icon">
@@ -17,3 +17,17 @@ export const chevronDownIcon = html`
1717
</svg>
1818
</span>
1919
`;
20+
21+
export const checkIcon = svg`<svg
22+
width="16"
23+
height="16"
24+
viewBox="0 0 16 16"
25+
xmlns="http://www.w3.org/2000/svg"
26+
fill="currentColor"
27+
>
28+
<path
29+
fill-rule="evenodd"
30+
clip-rule="evenodd"
31+
d="M14.431 3.323l-8.47 10-.79-.036-3.35-4.77.818-.574 2.978 4.24 8.051-9.506.764.646z"
32+
/>
33+
</svg>`;

src/includes/vscode-select/vscode-select-base.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import {
88
import {classMap} from 'lit/directives/class-map.js';
99
import {ifDefined} from 'lit/directives/if-defined.js';
1010
import {repeat} from 'lit/directives/repeat.js';
11+
import {when} from 'lit/directives/when.js';
1112
import '../../vscode-button/index.js';
1213
import '../../vscode-option/index.js';
1314
import {VscodeOption} from '../../vscode-option/index.js';
1415
import {VscElement} from '../VscElement.js';
1516
import {filterOptionsByPattern, highlightRanges} from './helpers.js';
1617
import type {InternalOption, Option, FilterMethod} from './types.js';
1718
import {OptionListController} from './OptionListController.js';
19+
import {checkIcon} from './template-elements.js';
1820

1921
export const VISIBLE_OPTS = 10;
2022
export const OPT_HEIGHT = 22;
@@ -604,6 +606,19 @@ export class VscodeSelectBase extends VscElement {
604606
//#endregion
605607

606608
//#region render functions
609+
private _renderCheckbox(
610+
checked: boolean,
611+
label: string | TemplateResult | TemplateResult[]
612+
) {
613+
const checkboxClasses = {
614+
'checkbox-icon': true,
615+
checked,
616+
};
617+
618+
return html`<span class=${classMap(checkboxClasses)}>${checkIcon}</span
619+
><span class="option-label">${label}</span>`;
620+
}
621+
607622
protected _renderOptions(): TemplateResult | TemplateResult[] {
608623
const list = this._opts.options;
609624

@@ -640,11 +655,6 @@ export class VscodeSelectBase extends VscElement {
640655
selected,
641656
};
642657
643-
const checkboxClasses = {
644-
'checkbox-icon': true,
645-
checked: selected,
646-
};
647-
648658
const labelText =
649659
(op.ranges?.length ?? 0 > 0)
650660
? highlightRanges(op.label, op.ranges ?? [])
@@ -660,10 +670,11 @@ export class VscodeSelectBase extends VscElement {
660670
role="option"
661671
tabindex="-1"
662672
>
663-
${this._opts.multiSelect
664-
? html`<span class=${classMap(checkboxClasses)}></span
665-
><span class="option-label">${labelText}</span>`
666-
: labelText}
673+
${when(
674+
this._opts.multiSelect,
675+
() => this._renderCheckbox(selected, labelText),
676+
() => labelText
677+
)}
667678
</li>
668679
`;
669680
}

0 commit comments

Comments
 (0)