Hide menus on mobile version
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-07-19 09:02:59 +02:00
parent eb1bf5bf58
commit 647f114c4a
3 changed files with 38 additions and 6 deletions

View File

@ -46,7 +46,11 @@ vn-layout {
justify-content: flex-end; justify-content: flex-end;
} }
.show-menu { .show-menu {
margin-right: 5px display: none;
}
& > .show-menu {
margin-right: 5px;
display: block
} }
.vn-button { .vn-button {
color: inherit; color: inherit;

View File

@ -12,6 +12,7 @@ export default class SideMenu extends Component {
constructor($element, $) { constructor($element, $) {
super($element, $); super($element, $);
this.side = 'left'; this.side = 'left';
this.mobileWidth = 800;
} }
$onInit() { $onInit() {
@ -27,10 +28,30 @@ export default class SideMenu extends Component {
this.layout.element.classList.add('left-menu'); this.layout.element.classList.add('left-menu');
} }
const stateParts = this.$state.current.name.split('.'); // Eliminar todos los eventos keydown para prevenir pulsar escape despues de minimizar y maximizar ventana
if (stateParts[1] === 'card') this.show();
this.stateHandler = this.$transitions.onStart({}, t => this.onTransition(t)); this.stateHandler = this.$transitions.onStart({}, t => this.onTransition(t));
const resizeHandler = target => {
const stateParts = this.$state.current.name.split('.');
const handler = e => this.onEscape(e);
if (target.innerWidth <= this.mobileWidth) {
this.handler = handler;
this.$window.addEventListener('keydown', this.handler);
this.hide();
} else {
this.$window.removeEventListener('keydown', handler);
if (this.side == 'right' || stateParts[1] === 'card')
this.show();
}
};
this.$window.addEventListener('resize', event => {
resizeHandler(event.target);
this.$.$digest();
});
resizeHandler(this.$window);
} }
$onDestroy() { $onDestroy() {
@ -46,6 +67,7 @@ export default class SideMenu extends Component {
} }
onEscape(event) { onEscape(event) {
console.log('onEscape');
if (!event.defaultPrevented && event.key == 'Escape') { if (!event.defaultPrevented && event.key == 'Escape') {
this.hide(); this.hide();
this.$.$digest(); this.$.$digest();
@ -71,8 +93,12 @@ export default class SideMenu extends Component {
show() { show() {
if (this.shown) return; if (this.shown) return;
this.shown = true; this.shown = true;
this.handler = e => this.onEscape(e);
this.$window.addEventListener('keydown', this.handler); if (this.$window.innerWidth <= this.mobileWidth) {
this.handler = e => this.onEscape(e);
this.$window.addEventListener('keydown', this.handler);
}
this.stateHandler = this.$transitions.onStart({}, t => this.onTransition(t)); this.stateHandler = this.$transitions.onStart({}, t => this.onTransition(t));
this.layout.element.classList.add('shown'); this.layout.element.classList.add('shown');
} }

View File

@ -18,9 +18,11 @@ vn-side-menu > .menu {
&.left { &.left {
transform: translateZ(0) translateX(-$menu-width); transform: translateZ(0) translateX(-$menu-width);
left: 0
} }
&.right { &.right {
transform: translateZ(0) translateX($menu-width); transform: translateZ(0) translateX($menu-width);
right: 0
} }
&.shown { &.shown {