keeps a single menu open

This commit is contained in:
Ali Gator 2022-01-13 14:05:08 +01:00
parent 441238bfbc
commit 59b102e5a7
2 changed files with 29 additions and 7 deletions

View File

@ -1,12 +1,13 @@
<template> <template>
<div class="menu-row"> <div class="menu-row">
<h2 <h2
@click="isHidden = !isHidden" :id="rowTitle"
@click="updateActiveMenu"
> >
{{ rowTitle }} {{ rowTitle }}
</h2> </h2>
<div <div
v-if="!isHidden" v-if="activeMenu === rowTitle"
class="menu-row-content" class="menu-row-content"
> >
<slot /> <slot />
@ -15,6 +16,8 @@
</template> </template>
<script> <script>
import {mapGetters} from 'vuex'
export default { export default {
name: 'MenuRow', name: 'MenuRow',
props: { props: {
@ -23,9 +26,21 @@ export default {
default : '' default : ''
} }
}, },
data() { computed: {
return { ...mapGetters({
isHidden: true activeMenu: 'getActiveMenu',
})
},
methods: {
updateActiveMenu(event) {
const elem = event.target
const value = elem.id
this.$store.commit('setActiveMenu', value)
},
isActive(event) {
const elem = event.target
if (elem.id === this.activeMenu) return true
return false
} }
} }
} }

View File

@ -24,7 +24,8 @@ export default new Vuex.Store({
canvasWidth: 1280, canvasWidth: 1280,
canvasHeight: 720, canvasHeight: 720,
refreshRate: 300, refreshRate: 300,
initial1dState: "onecell" initial1dState: "onecell",
activeMenu: "Elementary Cellular Automata"
}, },
mutations: { mutations: {
update1dSingleRule(state, data) { update1dSingleRule(state, data) {
@ -50,7 +51,10 @@ export default new Vuex.Store({
}, },
setInitial1dState(state, data) { setInitial1dState(state, data) {
state.initial1dState = data state.initial1dState = data
} },
setActiveMenu(state, data) {
state.activeMenu = data
},
}, },
getters: { getters: {
getCellProperties(state) { getCellProperties(state) {
@ -76,6 +80,9 @@ export default new Vuex.Store({
}, },
getInitial1dState(state) { getInitial1dState(state) {
return state.initial1dState return state.initial1dState
},
getActiveMenu(state) {
return state.activeMenu
} }
}, },
actions: { actions: {