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
114 changes: 57 additions & 57 deletions src/screencast/infobar.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { html, render } from 'lit-html';
import { createRef, ref } from 'lit-html/directives/ref.js'
import { styleMap, StyleInfo } from 'lit-html/directives/style-map.js';

interface InfobarProps {
message: string;
}

export default class InfobarComponent {
#buttonRef = createRef();
#message: string;
#container: HTMLElement | undefined;

constructor(props: InfobarProps, container?: HTMLElement) {
this.#message = props.message;
this.#container = container;
this.#update();
}

#update(styles?: StyleInfo) {
let customStyles = styles ?? {
display: 'flex'
};

if (!this.#container) {
return;
}
render(this.template(customStyles), this.#container);
}

template(styles: StyleInfo) {
return html`
<div class="infobar" style=${styleMap(styles)}>
<div class="infobar-message">${this.#message}</div>
<button class="infobar-close-button" ${ref(this.#buttonRef)} @click=${this.#onClick}></button>
</div>
`;
}

#onClick = () => {
let styles = {
display: 'none',
} as StyleInfo;

this.#update(styles);
};

static render(props: InfobarProps, elementId: string) {
const currentContainer = document.getElementById(elementId);
if (currentContainer) {
new InfobarComponent(props, currentContainer);
}
}
}
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { html, render } from 'lit-html';
import { createRef, ref } from 'lit-html/directives/ref.js'
import { styleMap, StyleInfo } from 'lit-html/directives/style-map.js';
interface InfobarProps {
message: string;
}
export default class InfobarComponent {
#buttonRef = createRef();
#message: string;
#container: HTMLElement | undefined;
constructor(props: InfobarProps, container?: HTMLElement) {
this.#message = props.message;
this.#container = container;
this.#update();
}
#update(styles?: StyleInfo) {
let customStyles = styles ?? {
display: 'flex'
};
if (!this.#container) {
return;
}
render(this.template(customStyles), this.#container);
}
template(styles: StyleInfo) {
return html`
<div class="infobar" style=${styleMap(styles)}>
<div class="infobar-message">${this.#message}</div>
<button role="button" aria-label="Close infobar" class="infobar-close-button" ${ref(this.#buttonRef)} @click=${this.#onClick}></button>
</div>
`;
}
#onClick = () => {
let styles = {
display: 'none',
} as StyleInfo;
this.#update(styles);
};
static render(props: InfobarProps, elementId: string) {
const currentContainer = document.getElementById(elementId);
if (currentContainer) {
new InfobarComponent(props, currentContainer);
}
}
}
Loading
Loading