partey_workadventure/front/src/Components/Menu/Menu.svelte

103 lines
3.0 KiB
Svelte
Raw Normal View History

2021-07-12 17:39:16 +02:00
<script lang="typescript">
2021-08-09 14:49:17 +02:00
import {fly} from "svelte/transition";
import type { SvelteComponent } from "svelte";
import SettingsSubMenu from "./SettingsSubMenu.svelte";
import CreateMapSubMenu from "./CreateMapSubMenu.svelte";
import ProfileSubMenu from "./ProfileSubMenu.svelte";
import ContactSubMenu from "./ContactSubMenu.svelte";
import AboutRoomSubMenu from "./AboutRoomSubMenu.svelte";
import GlobalMessagesSubMenu from "./GlobalMessagesSubMenu.svelte";
import {menuVisiblilityStore} from "../../Stores/MenuStore";
2021-07-12 17:39:16 +02:00
2021-08-09 14:49:17 +02:00
//TODO: When we register a new custom menu we need to add it here
const SubMenus = new Map<string, typeof SvelteComponent>([
['Settings', SettingsSubMenu],
['Profile', ProfileSubMenu],
['Create a Map', CreateMapSubMenu],
['About the room', AboutRoomSubMenu],
['Global Messages', GlobalMessagesSubMenu], //Remove if player has not the admin tag
['Contact', ContactSubMenu] //Always last (except custom)
]);
2021-07-12 17:39:16 +02:00
2021-08-09 14:49:17 +02:00
let activeSubMenu = 'Settings';
let activeComponent = SubMenus.get(activeSubMenu);
2021-07-12 17:39:16 +02:00
2021-08-09 14:49:17 +02:00
function switchMenu(menu: string) {
if (SubMenus.has(menu)) {
activeSubMenu = menu
activeComponent = SubMenus.get(activeSubMenu);
}
2021-07-12 17:39:16 +02:00
}
2021-07-13 12:00:09 +02:00
2021-08-09 14:49:17 +02:00
function closeMenu() {
menuVisiblilityStore.set(false);
}
function onKeyDown(e:KeyboardEvent) {
if (e.key === 'Escape') {
closeMenu();
}
2021-07-13 12:00:09 +02:00
}
2021-07-12 17:39:16 +02:00
</script>
2021-08-09 14:49:17 +02:00
<svelte:window on:keydown={onKeyDown}/>
2021-07-12 17:39:16 +02:00
2021-08-09 14:49:17 +02:00
<div class="menu-container-main">
<div class="menu-nav-sidebar nes-container is-rounded" transition:fly="{{ x: -1000, duration: 500 }}">
<h2>Menu</h2>
2021-07-12 17:39:16 +02:00
<nav>
2021-08-09 14:49:17 +02:00
{#each [...SubMenus] as [submenuKey, submenuComponent]}
<button type="button" class="nes-btn {activeComponent === submenuComponent ? 'is-disabled' : ''}" on:click|preventDefault={() => switchMenu(submenuKey)}>{submenuKey}</button>
{/each}
2021-07-12 17:39:16 +02:00
</nav>
2021-08-09 14:49:17 +02:00
</div>
<div class="menu-submenu-container nes-container is-rounded" transition:fly="{{ y: -1000, duration: 500 }}">
<h2>{activeSubMenu}</h2>
{#if activeComponent}
<svelte:component this="{activeComponent}"/>
2021-07-12 17:39:16 +02:00
{/if}
2021-08-09 14:49:17 +02:00
</div>
</div>
2021-07-12 17:39:16 +02:00
<style lang="scss">
2021-08-09 14:49:17 +02:00
.nes-container {
padding: 5px;
}
2021-07-12 17:39:16 +02:00
2021-08-09 14:49:17 +02:00
div.menu-container-main {
--size-first-columns-grid: 15%; //TODO: clamp value
font-family: "Press Start 2P";
pointer-events: auto;
height: 70vh;
width: 75vw;
top: 10vh;
position: relative;
margin: auto;
display: grid;
grid-template-columns: var(--size-first-columns-grid) calc(100% - var(--size-first-columns-grid));
grid-template-rows: 100%;
h2 {
text-align: center;
margin-bottom: 20px;
2021-07-12 17:39:16 +02:00
}
2021-08-09 14:49:17 +02:00
div.menu-nav-sidebar {
background-color: #333333;
color: whitesmoke;
nav button {
width: calc(100% - 10px);
margin-bottom: 10px;
}
2021-07-12 17:39:16 +02:00
}
2021-08-09 14:49:17 +02:00
div.menu-submenu-container {
background-color: #333333;
color: whitesmoke;
}
}
2021-07-12 17:39:16 +02:00
</style>