Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
giswqs
GitHub Repository: giswqs/geemap
Path: blob/master/js/toolbar.ts
2313 views
1
import type { RenderProps } from "@anywidget/types";
2
import { html, css } from "lit";
3
import { property } from "lit/decorators.js";
4
import { classMap } from "lit/directives/class-map.js";
5
6
import { legacyStyles } from "./ipywidgets_styles";
7
import { LitWidget } from "./lit_widget";
8
import { materialStyles } from "./styles";
9
import { loadFonts, updateChildren } from "./utils";
10
11
import "./container";
12
import "./tab_panel";
13
14
export interface ToolbarModel {
15
main_tools: any;
16
extra_tools: any;
17
expanded: boolean;
18
}
19
20
export class Toolbar extends LitWidget<ToolbarModel, Toolbar> {
21
static get componentName() {
22
return `toolbar-panel`;
23
}
24
25
static override styles = [
26
legacyStyles,
27
materialStyles,
28
css`
29
.hide {
30
display: none;
31
}
32
33
.expanded {
34
display: block; !important
35
}
36
37
slot[name="extra-tools"] {
38
margin-top: 4px;
39
}
40
41
::slotted([slot="main-tools"]),
42
::slotted([slot="extra-tools"]) {
43
align-items: center;
44
display: inline-grid;
45
grid-template-columns: auto auto auto;
46
grid-gap: 4px;
47
justify-items: center;
48
}
49
`,
50
];
51
52
modelNameToViewName(): Map<keyof ToolbarModel, keyof Toolbar | null> {
53
return new Map([
54
["main_tools", null],
55
["extra_tools", null],
56
["expanded", "expanded"],
57
]);
58
}
59
60
@property()
61
expanded: boolean = false;
62
63
override render() {
64
return html`
65
<widget-container
66
icon="build"
67
title=""
68
.collapsed="${true}"
69
.hideCloseButton=${true}
70
.compactMode="${true}"
71
.reverseHeader="${true}"
72
>
73
<div class="tools-container">
74
<slot name="main-tools"></slot>
75
<slot
76
name="extra-tools"
77
class="${classMap({
78
hide: !this.expanded,
79
expanded: this.expanded,
80
})}"
81
></slot>
82
</div>
83
</widget-container>
84
`;
85
}
86
}
87
88
// Without this check, there's a component registry issue when developing locally.
89
if (!customElements.get(Toolbar.componentName)) {
90
customElements.define(Toolbar.componentName, Toolbar);
91
}
92
93
async function render({ model, el }: RenderProps<ToolbarModel>) {
94
loadFonts();
95
const manager = <Toolbar>document.createElement(Toolbar.componentName);
96
manager.model = model;
97
el.appendChild(manager);
98
99
const mainToolsEl = document.createElement("div");
100
mainToolsEl.slot = "main-tools";
101
manager.appendChild(mainToolsEl);
102
103
updateChildren(mainToolsEl, model, "main_tools");
104
model.on("change:main_tools", () => {
105
updateChildren(mainToolsEl, model, "main_tools");
106
});
107
108
const extraToolsEl = document.createElement("div");
109
extraToolsEl.slot = "extra-tools";
110
manager.appendChild(extraToolsEl);
111
112
updateChildren(extraToolsEl, model, "extra_tools");
113
model.on("change:extra_tools", () => {
114
updateChildren(extraToolsEl, model, "extra_tools");
115
});
116
}
117
118
export default { render };
119
120