dees-catalog/ts_web/elements/dees-windowlayer.ts

86 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-08-07 18:02:18 +00:00
import { customElement, DeesElement, type TemplateResult, html, property, type CSSResult, } from '@design.estate/dees-element';
2021-02-13 21:52:36 +00:00
2023-08-07 17:13:29 +00:00
import * as domtools from '@design.estate/dees-domtools';
2021-02-13 21:52:36 +00:00
declare global {
interface HTMLElementTagNameMap {
'dees-windowlayer': DeesWindowLayer;
}
}
@customElement('dees-windowlayer')
2022-01-24 00:39:47 +00:00
export class DeesWindowLayer extends DeesElement {
2021-09-01 19:48:22 +00:00
// STATIC
2021-02-13 21:52:36 +00:00
public static demo = () => html`<dees-windowlayer></dees-windowlayer>`;
2021-09-01 19:48:22 +00:00
// INSTANCE
@property({
type: Boolean
})
public visible = false;
2021-02-13 21:52:36 +00:00
constructor() {
super();
domtools.elementBasic.setup();
}
public render(): TemplateResult {
return html`
${domtools.elementBasic.styles}
<style>
.windowOverlay {
2021-09-01 19:48:22 +00:00
transition: all 0.3s;
2021-08-29 15:10:25 +00:00
will-change: transform;
2021-02-13 21:52:36 +00:00
position: fixed;
top: 0px;
left: 0px;
height: 100vh;
width: 100vw;
2021-08-29 15:10:25 +00:00
display: flex;
justify-content: center;
align-items: center;
2021-02-13 21:52:36 +00:00
background: rgba(0, 0, 0, 0.0);
2021-09-01 19:48:22 +00:00
backdrop-filter: brightness(1);
pointer-events: none;
2022-08-17 17:56:22 +00:00
z-index: 200;
2021-02-13 21:52:36 +00:00
}
2021-08-29 15:10:25 +00:00
2021-02-13 21:52:36 +00:00
.visible {
background: rgba(0, 0, 0, 0.2);
2021-08-29 15:10:25 +00:00
backdrop-filter: brightness(0.3);
2021-09-01 19:48:22 +00:00
pointer-events: all;
2021-02-13 21:52:36 +00:00
}
</style>
2021-09-01 19:48:22 +00:00
<div @click=${this.dispatchClicked} class="windowOverlay ${this.visible ? 'visible' : null}">
2021-02-13 21:52:36 +00:00
<slot></slot>
</div>
`;
}
firstUpdated() {
setTimeout(() => {
2021-09-01 19:48:22 +00:00
this.visible = true;
2021-02-13 21:52:36 +00:00
}, 100);
}
2021-09-01 19:48:22 +00:00
dispatchClicked() {
2022-08-17 16:49:33 +00:00
this.dispatchEvent(new CustomEvent('clicked'));
2021-09-01 19:48:22 +00:00
}
public toggleVisibility () {
this.visible = !this.visible;
}
2022-08-17 16:49:33 +00:00
public async show() {
const domtools = await this.domtoolsPromise;
await domtools.convenience.smartdelay.delayFor(0);
this.visible = true;
}
public async hide() {
const domtools = await this.domtoolsPromise;
await domtools.convenience.smartdelay.delayFor(0);
this.visible = false;
}
2021-02-13 21:52:36 +00:00
}