workadventure/front/src/Components/ActionsMenu/ActionsMenu.svelte

85 lines
2.2 KiB
Svelte
Raw Normal View History

2022-01-24 16:27:57 +01:00
<script lang="typescript">
import { fly } from "svelte/transition";
import { ActionsMenuInterface, actionsMenuStore } from '../../Stores/ActionsMenuStore';
2022-01-24 16:27:57 +01:00
import { requestActionsMenuStore, requestVisitCardsStore } from '../../Stores/GameStore';
let possibleActions: Map<string, ActionsMenuInterface>;
2022-01-25 15:09:34 +01:00
let backgroundHeight = 100;
const unsubscribe = actionsMenuStore.subscribe(value => {
possibleActions = value;
});
2022-01-24 16:27:57 +01:00
function onKeyDown(e: KeyboardEvent) {
if (e.key === "Escape") {
closeActionsMenu();
}
}
function closeActionsMenu() {
requestActionsMenuStore.set(false);
}
</script>
<svelte:window on:keydown={onKeyDown} />
2022-01-25 15:09:34 +01:00
<div class="actions-menu nes-container is-rounded" style="--background-height: {backgroundHeight};">
2022-01-24 16:27:57 +01:00
<button type="button" class="nes-btn is-error close" on:click={closeActionsMenu}>&times</button>
<h2>Actions</h2>
2022-01-25 15:09:34 +01:00
<div class="actions">
{#each [...possibleActions] as [key, menuAction]}
<button
type="button"
class="nes-btn"
on:click|preventDefault={() => { menuAction.callback(); }}
>
{menuAction.displayName}
</button>
{/each}
2022-01-25 15:09:34 +01:00
</div>
2022-01-24 16:27:57 +01:00
</div>
<style lang="scss">
.actions-menu {
position: absolute;
left: 50%;
transform: translate(-50%, 0);
2022-01-25 15:09:34 +01:00
width: 260px !important;
max-height: 300px;
2022-01-24 16:27:57 +01:00
margin-top: 200px;
pointer-events: auto;
font-family: "Press Start 2P";
background-color: #333333;
color: whitesmoke;
2022-01-25 15:09:34 +01:00
.actions {
max-height: 200px;
width: 100%;
display:block;
overflow-x:hidden;
overflow-y:auto;
button {
width: calc(100% - 10px);
margin-bottom: 10px;
}
}
.actions::-webkit-scrollbar {
display: none;
}
2022-01-24 16:27:57 +01:00
h2 {
text-align: center;
margin-bottom: 20px;
2022-01-25 15:09:34 +01:00
font-family: "Press Start 2P";
2022-01-24 16:27:57 +01:00
}
.nes-btn.is-error.close {
position: absolute;
top: -20px;
right: -20px;
}
}
</style>