webwidget/ts_web/elements/uptimelink-webwidget.ts

199 lines
5.4 KiB
TypeScript
Raw Normal View History

2020-11-29 02:11:28 +00:00
import { DeesElement, property, html, customElement, TemplateResult } from '@designestate/dees-element';
2020-09-19 15:51:50 +00:00
import * as domtools from '@designestate/dees-domtools';
2021-03-09 20:47:00 +00:00
declare global {
interface HTMLElementTagNameMap {
'uptimelink-webwidget': UptimelinkWebwidget;
}
}
2020-09-19 15:51:50 +00:00
@customElement('uptimelink-webwidget')
2020-11-29 02:11:28 +00:00
export class UptimelinkWebwidget extends DeesElement {
2020-09-19 15:51:50 +00:00
public static demo = () => html`
<uptimelink-webwidget projectSlug="uptime.link"></uptimelink-webwidget>
`;
@property()
public projectSlug: string;
2021-03-08 23:11:56 +00:00
@property()
public isFocused = false;
2021-03-09 13:41:16 +00:00
@property()
public isElevated = false;
2021-03-08 23:11:56 +00:00
@property()
public showExpanded: boolean = false;
2020-09-19 15:51:50 +00:00
constructor() {
super();
domtools.DomTools.setupDomTools();
2021-03-08 23:11:56 +00:00
this.setupEventing();
2020-09-19 15:51:50 +00:00
}
public render(): TemplateResult {
return html`
${domtools.elementBasic.styles}
<style>
2020-11-23 22:03:02 +00:00
:host {
2021-03-08 23:27:50 +00:00
position: relative;
2020-11-23 22:03:02 +00:00
display: block;
2021-03-08 23:27:50 +00:00
height: 30px;
2021-03-09 13:41:16 +00:00
z-index: ${this.isElevated ? '10' : 'auto'} ;
2020-11-23 22:03:02 +00:00
}
2020-09-19 15:51:50 +00:00
.mainbox {
2021-03-08 23:11:56 +00:00
position: relative;
2020-11-23 22:03:02 +00:00
line-height: 1em;
2020-09-19 15:51:50 +00:00
margin: auto;
font-family: Roboto;
font-weight: 400;
font-size: 13px;
box-sizing: border-box;
width: 150px;
2021-03-08 23:11:56 +00:00
border-radius: 15px;
2020-09-19 15:51:50 +00:00
height: 30px;
2020-11-29 02:11:28 +00:00
background: ${this.goBright ? '#fff' : '#222' };
box-shadow: ${this.goBright ? '0px 0px 5px rgba(0,0,0,0.1)' : ''};
2020-09-19 15:51:50 +00:00
padding: 5px;
2020-11-29 02:11:28 +00:00
color: ${this.goBright ? '#333' : '#CCC' };
2020-09-19 15:51:50 +00:00
cursor: pointer;
2021-03-08 23:11:56 +00:00
transition: all 0.2s;
overflow: hidden;
}
.firstLine {
display: grid;
grid-template-columns: 26px auto;
}
.mainbox.focused {
width: 200px;
2021-03-08 23:58:57 +00:00
height: 118px;
2020-09-19 15:51:50 +00:00
}
2021-03-08 23:11:56 +00:00
2020-09-19 15:51:50 +00:00
.statusindicator {
height: 20px;
width: 20px;
background: #66BB6A;
border-radius: 10px;
}
.statustext {
padding-top: 3px;
}
2021-03-08 23:11:56 +00:00
.expanded {
opacity: 0;
transition: opacity 0.2s;
}
.miniHeading {
position: absolute;
width: 190px;
top: 25px;
left: calc(50% - 95px);
margin-top: 10px;
font-size: 12px;
}
.miniOverview24h {
position: absolute;
top: 55px;
left: calc(50% - 95px);
background: ${this.goBright ? 'rgba(0,0,0,0.07)' : 'rgba(255,255,255,0.07)'};
border-radius: 3px;
width: 190px;
2021-03-08 23:58:57 +00:00
height: 30px;
2021-03-08 23:11:56 +00:00
display: grid;
padding: 3px 3px;
grid-template-columns: repeat(30, 4px);
grid-column-gap: 3px;
}
.miniOverview24h .statusBar {
background: ${this.goBright ? 'rgba(0,0,0,0.15)' : 'rgba(255,255,255,0.15)'};
border-radius: 10px;
}
.miniOverview24h .statusBar.ok {
background: #66BB6A;
}
.viewStatuspage {
position: absolute;
width: 190px;
2021-03-08 23:58:57 +00:00
top: 80px;
2021-03-08 23:11:56 +00:00
left: calc(50% - 95px);
text-align: center;
background: ${this.goBright ? 'rgba(0,0,0,0.07)' : 'rgba(255,255,255,0.07)'};
border-radius: 3px 3px 10px 10px;
padding: 5px;
margin-top: 10px;
2021-03-09 13:54:01 +00:00
transition: background 0.1s;
}
.viewStatuspage:hover {
background: ${this.goBright ? 'rgba(0,0,0,0.1)' : 'rgba(255,255,255,0.1)'};
2021-03-08 23:11:56 +00:00
}
2020-09-19 15:51:50 +00:00
</style>
2021-03-08 23:11:56 +00:00
<div class="mainbox ${this.isFocused ? 'focused' : null}">
<div class="firstLine">
<div class="statusindicator"></div>
<div class="statustext">All systems are up!</div>
</div>
${this.showExpanded ? html`
<div class="expanded">
<div class="miniHeading">
last 26 hours:
</div>
<div class="miniOverview24h">
${(() => {
let counter = 0;
const returnArray = [];
while(counter < 26) {
returnArray.push(html`<div class="statusBar ok"></div>`)
counter++;
};
return returnArray;
})()}
</div>
<div class="viewStatuspage">View full Statuspage ...</div>
</div>
` : null}
2020-09-19 15:51:50 +00:00
</div>
`;
}
2021-03-08 23:11:56 +00:00
private async setupEventing() {
await this.updateComplete;
const mainbox: HTMLDivElement = this.shadowRoot.querySelector('.mainbox');
mainbox.onmouseenter = async () => {
2021-03-09 13:41:16 +00:00
this.isElevated = true;
2021-03-08 23:11:56 +00:00
this.isFocused = true;
await domtools.DomTools.getGlobalDomToolsSync().convenience.smartdelay.delayFor(200);
if (!this.isFocused) {
return;
}
this.showExpanded = true;
await this.performUpdate();
2021-03-09 13:41:16 +00:00
await (await this.domtoolsPromise).convenience.smartdelay.delayFor(50);
2021-03-08 23:11:56 +00:00
const expandedDiv = this.shadowRoot.querySelector('.expanded') as HTMLElement;
expandedDiv.style.opacity = '1';
};
mainbox.onmouseleave = async () => {
2021-03-09 13:41:16 +00:00
(await this.domtoolsPromise).convenience.smartdelay.delayFor(200).then(() => {
if (!this.isFocused) {
this.isElevated = false;
}
});
2021-03-08 23:11:56 +00:00
if (!this.showExpanded) {
this.isFocused = false;
return;
}
this.showExpanded = false;
await domtools.DomTools.getGlobalDomToolsSync().convenience.smartdelay.delayFor(50);
this.isFocused = false;
}
}
2020-09-19 15:51:50 +00:00
}