sussudio
Version:
An unofficial VS Code Internal API
50 lines (49 loc) • 1.81 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { $, append } from "../../dom.mjs";
import { format } from "../../../common/strings.mjs";
import "../../../../css!./countBadge.mjs";
export const unthemedCountStyles = {
badgeBackground: '#4D4D4D',
badgeForeground: '#FFFFFF',
badgeBorder: undefined
};
export class CountBadge {
options;
styles;
element;
count = 0;
countFormat;
titleFormat;
constructor(container, options, styles) {
this.options = options;
this.styles = styles;
this.element = append(container, $('.monaco-count-badge'));
this.countFormat = this.options.countFormat || '{0}';
this.titleFormat = this.options.titleFormat || '';
this.setCount(this.options.count || 0);
}
setCount(count) {
this.count = count;
this.render();
}
setCountFormat(countFormat) {
this.countFormat = countFormat;
this.render();
}
setTitleFormat(titleFormat) {
this.titleFormat = titleFormat;
this.render();
}
render() {
this.element.textContent = format(this.countFormat, this.count);
this.element.title = format(this.titleFormat, this.count);
this.element.style.backgroundColor = this.styles.badgeBackground ?? '';
this.element.style.color = this.styles.badgeForeground ?? '';
if (this.styles.badgeBorder) {
this.element.style.border = `1px solid ${this.styles.badgeBorder}`;
}
}
}