UNPKG

monaco-editor-core

Version:

A browser based code editor

36 lines (35 loc) 1.5 kB
/*--------------------------------------------------------------------------------------------- * 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.js'; import { format } from '../../../common/strings.js'; import './countBadge.css'; export class CountBadge { constructor(container, options, styles) { this.options = options; this.styles = styles; this.count = 0; 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(); } 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}`; } } }