forked from tiny-pilot/tinypilot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
keystroke-history-event.html
103 lines (87 loc) · 2.43 KB
/
keystroke-history-event.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template id="keystroke-history-event-template">
<style>
/**
* Don’t use CSS imports here, since Chrome will re-fetch the files
* on every keystroke otherwise. We can rely on the CSS variables
* to be loaded by the parent component (`<keystroke-history>`)
*/
#keystroke {
border-width: 1px;
border-color: white;
padding: 0.1em 0.3em;
border-radius: 4px;
opacity: 0.6;
min-width: 0.8em;
white-space: pre;
text-align: center;
font-family: "Overpass Mono", monospace;
font-size: 0.9em;
animation: appear ease 200ms forwards;
}
.pending {
border-style: dotted;
background-color: #acacacac;
}
.succeeded {
border-style: solid;
background-color: #7e7e7e7e;
}
.failed {
border-style: solid;
background-color: var(--brand-red-bright);
}
@keyframes appear {
0% {
opacity: 1;
background-color: #888;
/**
* The animation of newly appearing items is optimistic, so it has a
* solid border for the initial animation period.
*/
border-style: solid;
}
}
.hide {
animation: disappear ease 200ms forwards;
}
@keyframes disappear {
100% {
opacity: 0;
}
}
</style>
<div id="keystroke"></div>
</template>
<script>
(function () {
const doc = (document._currentScript || document.currentScript)
.ownerDocument;
const template = doc.querySelector("#keystroke-history-event-template");
customElements.define(
"keystroke-history-event",
class extends HTMLElement {
STATUSES = ["pending", "succeeded", "failed"];
connectedCallback() {
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild(template.content.cloneNode(true));
this.keystroke = this.shadowRoot.getElementById("keystroke");
this.status = "pending";
}
set status(newStatus) {
if (!this.STATUSES.includes(newStatus)) {
return;
}
this.keystroke.classList.remove(...this.STATUSES);
this.keystroke.classList.add(newStatus);
this.keystroke.title = `Keystroke ${newStatus}`;
}
set label(newLabel) {
this.keystroke.innerText = newLabel;
}
fadeOut() {
this.keystroke.classList.add("hide");
}
}
);
})();
</script>