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
30 changes: 30 additions & 0 deletions dev/vscode-badge/fallback-styles.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>VSCode Elements</title>
<link
rel="stylesheet"
href="/node_modules/@vscode/codicons/dist/codicon.css"
id="vscode-codicon-stylesheet"
/>
<script type="module" src="/dist/main.js"></script>
<script>
const logEvents = (selector, eventType) => {
document.querySelector(selector).addEventListener(eventType, (ev) => {
console.log(ev);
});
};
</script>
</head>

<body style="background-color: #1f1f1f;">
<main>
<p><vscode-badge>308 Settings Found</vscode-badge></p>
<p><vscode-badge variant="counter">6</vscode-badge></p>
<p><vscode-badge variant="activity-bar-counter">6</vscode-badge></p>
<p><vscode-badge variant="tab-header-counter">6</vscode-badge></p>
</main>
</body>
</html>
24 changes: 24 additions & 0 deletions src/includes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,27 @@ const DEFAULT_FONT_SIZE = 13;
export const INPUT_LINE_HEIGHT_RATIO = DEFAULT_LINE_HEIGHT / DEFAULT_FONT_SIZE;

export const DEFUALT_INPUT_WIDGET_WIDTH = 320;

export function getDefaultFontStack() {
if (navigator.userAgent.indexOf("Linux") > -1) {
return 'system-ui, "Ubuntu", "Droid Sans", sans-serif';
} else if (navigator.userAgent.indexOf("Mac") > -1) {
return "-apple-system, BlinkMacSystemFont, sans-serif";
} else if (navigator.userAgent.indexOf("Windows") > -1) {
return '"Segoe WPC", "Segoe UI", sans-serif';
} else {
return "sans-serif";
}
}

export function getDefaultEditorFontStack() {
if (navigator.userAgent.indexOf("Linux") > -1) {
return '"Droid Sans Mono", "monospace", monospace';
} else if (navigator.userAgent.indexOf("Mac") > -1) {
return 'Menlo, Monaco, "Courier New", monospace';
} else if (navigator.userAgent.indexOf("Windows") > -1) {
return 'Consolas, "Courier New", monospace';
} else {
return "monospace";
}
}
19 changes: 11 additions & 8 deletions src/vscode-badge/vscode-badge.styles.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import {css, CSSResultGroup} from 'lit';
import {css, CSSResultGroup, unsafeCSS} from 'lit';
import defaultStyles from '../includes/default.styles.js';
import {getDefaultFontStack} from '../includes/helpers.js';

const defaultFontStack = unsafeCSS(getDefaultFontStack());

const styles: CSSResultGroup = [
defaultStyles,
css`
:host {
background-color: var(--vscode-badge-background);
background-color: var(--vscode-badge-background, #616161);
border: 1px solid var(--vscode-contrastBorder, transparent);
border-radius: 2px;
box-sizing: border-box;
color: var(--vscode-badge-foreground);
color: var(--vscode-badge-foreground, #f8f8f8);
display: inline-block;
font-family: var(--vscode-font-family);
font-family: var(--vscode-font-family, ${defaultFontStack});
font-size: 11px;
font-weight: 400;
line-height: 14px;
Expand All @@ -30,19 +33,19 @@ const styles: CSSResultGroup = [
}

:host([variant='activity-bar-counter']) {
background-color: var(--vscode-activityBarBadge-background);
background-color: var(--vscode-activityBarBadge-background, #0078d4);
border-radius: 20px;
color: var(--vscode-activityBarBadge-foreground);
color: var(--vscode-activityBarBadge-foreground, #ffffff);
font-size: 9px;
font-weight: 600;
line-height: 16px;
padding: 0 4px;
}

:host([variant='tab-header-counter']) {
background-color: var(--vscode-activityBarBadge-background);
background-color: var(--vscode-activityBarBadge-background, #0078d4);
border-radius: 10px;
color: var(--vscode-activityBarBadge-foreground);
color: var(--vscode-activityBarBadge-foreground, #ffffff);
line-height: 10px;
min-height: 16px;
min-width: 16px;
Expand Down
11 changes: 6 additions & 5 deletions src/vscode-badge/vscode-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import styles from './vscode-badge.styles.js';
*
* @tag vscode-badge
*
* @cssprop --vscode-font-family
* @cssprop --vscode-badge-background - default and counter variant background color
* @cssprop --vscode-badge-foreground - default and counter variant foreground color
* @cssprop --vscode-activityBarBadge-background - activity bar variant background color
* @cssprop --vscode-activityBarBadge-foreground - activity bar variant foreground color
* @cssprop [--vscode-font-family=sans-serif] - A sans-serif font type depends on the host OS.
* @cssprop [--vscode-contrastBorder=transparent]
* @cssprop [--vscode-badge-background=#616161] - default and counter variant background color
* @cssprop [--vscode-badge-foreground=#f8f8f8] - default and counter variant foreground color
* @cssprop [--vscode-activityBarBadge-background=#0078d4] - activity bar variant background color
* @cssprop [--vscode-activityBarBadge-foreground=#ffffff] - activity bar variant foreground color
*/
@customElement('vscode-badge')
export class VscodeBadge extends VscElement {
Expand Down