2023-04-06 00:04:28 +02:00
|
|
|
/**
|
|
|
|
@license
|
|
|
|
Copyright (c) 2022 trading_peter
|
|
|
|
This program is available under Apache License Version 2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
import '@tp/tp-media-query/tp-media-query.js';
|
|
|
|
import { LitElement, html, css } from 'lit';
|
|
|
|
|
|
|
|
class TpResponsiveMenu extends LitElement {
|
|
|
|
static get styles() {
|
|
|
|
return [
|
|
|
|
css`
|
|
|
|
:host {
|
|
|
|
display: block;
|
2023-09-02 00:17:38 +02:00
|
|
|
pointer-events: none;
|
2023-04-06 00:04:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.content {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
background: #ffffff;
|
2023-09-02 00:17:38 +02:00
|
|
|
z-index: 1;
|
|
|
|
pointer-events: all;
|
2023-04-06 00:04:28 +02:00
|
|
|
}
|
|
|
|
|
2023-09-02 00:17:38 +02:00
|
|
|
:host([responsive]) {
|
2023-04-06 00:04:28 +02:00
|
|
|
position: fixed;
|
2023-09-02 00:17:38 +02:00
|
|
|
inset: 0;
|
2023-04-06 00:04:28 +02:00
|
|
|
z-index: 9999;
|
2023-09-02 00:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
:host([responsive]) .content {
|
|
|
|
position: absolute;
|
2023-04-06 00:04:28 +02:00
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
bottom: 0;
|
|
|
|
transform: translateX(-100%);
|
2023-09-02 00:17:38 +02:00
|
|
|
transition: transform 300ms ease-in-out;
|
2023-04-06 00:04:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
:host([responsive][visible]) .content {
|
|
|
|
transform: translateX(0);
|
|
|
|
}
|
2023-09-02 00:17:38 +02:00
|
|
|
|
|
|
|
.backdrop {
|
|
|
|
position: absolute;
|
|
|
|
inset: 0;
|
|
|
|
background: #000000;
|
|
|
|
opacity: 0;
|
|
|
|
transition: opacity 300ms ease-in-out;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
:host([visible]) .backdrop {
|
|
|
|
opacity: 0.7;
|
|
|
|
pointer-events: all;
|
|
|
|
}
|
2023-04-06 00:04:28 +02:00
|
|
|
`
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return html`
|
|
|
|
<tp-media-query query="(min-width: 0) and (max-width: ${this.responsiveWidth}px)" @media-query-update=${this._queryUpdated}></tp-media-query>
|
|
|
|
|
2023-09-02 00:17:38 +02:00
|
|
|
<div class="content" part="content">
|
2023-04-06 00:04:28 +02:00
|
|
|
<slot></slot>
|
|
|
|
</div>
|
2023-09-02 00:17:38 +02:00
|
|
|
|
|
|
|
<div class="backdrop" @click=${this.close}></div>
|
2023-04-06 00:04:28 +02:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get properties() {
|
|
|
|
return {
|
|
|
|
responsive: { type: Boolean, reflect: true },
|
|
|
|
responsiveWidth: { type: String },
|
|
|
|
visible: { type: Boolean, reflect: true },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.responsiveWidth = '480';
|
|
|
|
this.visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
|
|
|
this.visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
|
|
|
this.visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle() {
|
|
|
|
this.visible = !this.visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
_queryUpdated(e) {
|
|
|
|
this.responsive = e.detail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.customElements.define('tp-responsive-menu', TpResponsiveMenu);
|