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

124 lines
3.0 KiB
TypeScript
Raw Permalink Normal View History

2023-12-08 18:16:22 +00:00
import { customElement, DeesElement, domtools, type TemplateResult, html, property, type CSSResult, state, } from '@design.estate/dees-element';
2021-02-13 21:52:36 +00:00
declare global {
interface HTMLElementTagNameMap {
'dees-windowlayer': DeesWindowLayer;
}
}
2023-09-13 14:46:00 +00:00
export interface IOptions_DeesWindowLayer {
blur: boolean;
}
2021-02-13 21:52:36 +00:00
@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>`;
2023-09-13 14:46:00 +00:00
public static async createAndShow(optionsArg?: IOptions_DeesWindowLayer) {
2023-09-04 17:28:50 +00:00
const domtoolsInstance = domtools.DomTools.getGlobalDomToolsSync();
const windowLayer = new DeesWindowLayer();
2023-09-13 14:46:00 +00:00
windowLayer.options = {
...windowLayer.options,
...optionsArg,
}
2023-09-04 17:28:50 +00:00
document.body.append(windowLayer);
await domtoolsInstance.convenience.smartdelay.delayFor(0);
windowLayer.show();
return windowLayer;
}
2023-09-13 14:46:00 +00:00
@state()
public options: IOptions_DeesWindowLayer = {
blur: false
};
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 {
2023-09-04 17:28:50 +00:00
transition: all 0.2s;
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);
2023-09-13 14:46:00 +00:00
backdrop-filter: brightness(1) ${this.options.blur ? 'blur(0px)' : ''};
2021-09-01 19:48:22 +00:00
pointer-events: none;
2022-08-17 17:56:22 +00:00
z-index: 200;
2021-02-13 21:52:36 +00:00
}
2023-11-29 16:20:32 +00:00
.slotContent {
2023-11-29 19:39:17 +00:00
position: fixed;
2023-11-29 16:20:32 +00:00
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
2023-11-29 19:39:17 +00:00
z-index: 201;
2023-11-29 16:20:32 +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);
2023-09-13 14:46:00 +00:00
backdrop-filter: brightness(0.9) ${this.options.blur ? 'blur(2px)' : ''};
2023-12-08 17:22:18 +00:00
pointer-events: all;
2021-02-13 21:52:36 +00:00
}
</style>
2023-11-29 16:20:32 +00:00
<div class="windowOverlay ${this.visible ? 'visible' : null}">
</div>
<div @click=${this.dispatchClicked} class="slotContent">
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;
}
2023-09-04 17:28:50 +00:00
public async destroy() {
const domtools = await this.domtoolsPromise;
await this.hide();
await domtools.convenience.smartdelay.delayFor(300);
this.remove();
}
2021-02-13 21:52:36 +00:00
}