Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
giswqs
GitHub Repository: giswqs/geemap
Path: blob/master/js/color_picker.ts
2313 views
1
import { css, html, LitElement } from "lit";
2
import { property } from "lit/decorators.js";
3
4
import { legacyStyles } from "./ipywidgets_styles";
5
6
export class ColorPicker extends LitElement {
7
static get componentName() {
8
return `color-picker`;
9
}
10
11
static override styles = [
12
legacyStyles,
13
css`
14
.color-swatch {
15
border-radius: 0;
16
height: 28px;
17
padding: 0 2px;
18
width: 28px;
19
}
20
21
.color-text {
22
width: 80px;
23
}
24
25
.widget-inline-hbox {
26
align-items: baseline;
27
box-sizing: border-box;
28
display: flex;
29
flex-direction: row;
30
line-height: 28px;
31
}
32
`,
33
];
34
35
@property({ type: String }) value: string = "#000000";
36
37
override render() {
38
return html`
39
<div class="widget-inline-hbox">
40
<input
41
type="text"
42
class="legacy-text-input color-text"
43
.value="${this.value}"
44
@change="${this.onValueChanged}"
45
>
46
<input
47
type="color"
48
class="legacy-color color-swatch"
49
.value="${this.value}"
50
@change="${this.onValueChanged}"
51
>
52
</div>
53
`;
54
}
55
56
private onValueChanged(event: Event): void {
57
this.value = (event.target as HTMLInputElement).value;
58
this.dispatchEvent(new CustomEvent("change", {}));
59
}
60
}
61
62
// Without this check, there's a component registry issue when developing locally.
63
if (!customElements.get(ColorPicker.componentName)) {
64
customElements.define(ColorPicker.componentName, ColorPicker);
65
}
66