Skip to content

Commit

Permalink
container: Add icons to widget containers
Browse files Browse the repository at this point in the history
  • Loading branch information
naschmitz committed Jan 3, 2025
1 parent 13bdd69 commit c13e384
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
27 changes: 18 additions & 9 deletions js/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LitWidget } from "./lit_widget";
import { materialStyles } from "./styles";

export interface ContainerModel {
icon: string;
title: string;
collapsed: boolean;
hide_close_button: boolean;
Expand All @@ -27,6 +28,14 @@ export class Container extends LitWidget<ContainerModel, Container> {
padding: 4px;
}
.icon {
align-items: center;
display: flex;
font-size: 20px;
height: 28px;
justify-content: center;
}
.widget-container {
padding: 4px;
}
Expand All @@ -43,18 +52,20 @@ export class Container extends LitWidget<ContainerModel, Container> {
.header-text {
align-content: center;
padding-left: 4px;
padding-right: 4px;
flex-grow: 1;
padding-right: 12px;
}
`,
];

@property({ type: String }) icon: string = "";
@property({ type: String }) title: string = "";
@property({ type: Boolean }) collapsed: boolean = false;
@property({ type: Boolean }) hideCloseButton: boolean = false;

modelNameToViewName(): Map<keyof ContainerModel, keyof Container | null> {
return new Map([
["icon", "icon"],
["collapsed", "collapsed"],
["title", "title"],
["hide_close_button", "hideCloseButton"],
Expand All @@ -64,14 +75,15 @@ export class Container extends LitWidget<ContainerModel, Container> {
render() {
return html`
<div class="header">
${this.renderCloseButton()}
<span class="icon material-symbols-outlined">${this.icon}</span>
${this.renderTitle()}
<button
class="legacy-button header-button"
@click="${this.onCollapseToggled}"
>
${this.renderCollapseButtonIcon()}
</button>
${this.renderTitle()}
${this.renderCloseButton()}
</div>
<div class="widget-container ${this.collapsed ? "hidden" : ""}">
<slot></slot>
Expand All @@ -93,11 +105,8 @@ export class Container extends LitWidget<ContainerModel, Container> {
`;
}

private renderTitle(): HTMLTemplateResult | typeof nothing {
if (this.title) {
return html`<span class="legacy-text header-text">${this.title}</span>`;
}
return nothing;
private renderTitle(): HTMLTemplateResult {
return html`<span class="legacy-text header-text">${this.title}</span>`;
}

private onCloseButtonClicked(): void {
Expand Down
2 changes: 2 additions & 0 deletions js/inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export class Inspector extends LitWidget<InspectorModel, Inspector> {
render() {
return html`
<widget-container
icon="search"
title="Inspector"
.hideCloseButton="${this.hideCloseButton}"
@close-clicked="${this.onCloseButtonClicked}"
>
Expand Down
2 changes: 1 addition & 1 deletion js/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export class Legend extends LitWidget<LegendModel, Legend> {
render() {
return this.addHeader ? html`
<widget-container
.hideCloseButton="${!this.showCloseButton}"
.title="${this.title}"
.hideCloseButton="${!this.showCloseButton}"
@close-clicked="${this.onCloseButtonClicked}">
${this.renderLegend("")}
</widget-container>` : this.renderLegend(this.title);
Expand Down

0 comments on commit c13e384

Please sign in to comment.