2021-05-25 18:26:14 +00:00
|
|
|
<template>
|
2021-05-26 01:10:34 +00:00
|
|
|
<section :class="{'sidebar__section': true, 'section--collapsible': true, 'section--collapsed': collapsed}">
|
2021-05-26 22:28:03 +00:00
|
|
|
<h2 class="section__heading">
|
|
|
|
<button :id="`${name}-heading`" type="button"
|
2021-05-26 19:09:00 +00:00
|
|
|
@click.prevent="toggle" :title="title"
|
|
|
|
:aria-expanded="!collapsed" :aria-controls="`${name}-content`">
|
|
|
|
<span>
|
|
|
|
<slot name="heading"></slot>
|
|
|
|
</span>
|
|
|
|
<SvgIcon name="arrow"></SvgIcon>
|
|
|
|
</button>
|
|
|
|
</h2>
|
2021-05-25 21:40:10 +00:00
|
|
|
<div :id="`${name}-content`" role="region" :aria-labelledby="`${name}-heading`" :aria-hidden="collapsed">
|
2021-05-25 18:26:14 +00:00
|
|
|
<slot></slot>
|
2021-05-25 21:40:10 +00:00
|
|
|
</div>
|
2021-05-25 18:26:14 +00:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import {useStore} from "@/store";
|
|
|
|
import {LiveAtlasSidebarSection} from "@/index";
|
|
|
|
import {defineComponent} from "@vue/runtime-core";
|
2021-05-26 01:10:34 +00:00
|
|
|
import SvgIcon from "@/components/SvgIcon.vue";
|
|
|
|
import '@/assets/icons/arrow.svg';
|
2021-05-26 16:43:15 +00:00
|
|
|
import {MutationTypes} from "@/store/mutation-types";
|
2021-05-25 18:26:14 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'CollapsibleSection',
|
2021-05-26 01:10:34 +00:00
|
|
|
components: {SvgIcon},
|
2021-05-25 18:26:14 +00:00
|
|
|
props: {
|
|
|
|
name: {
|
2021-05-25 21:40:10 +00:00
|
|
|
type: String as () => LiveAtlasSidebarSection,
|
2021-05-25 18:26:14 +00:00
|
|
|
required: true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
title(): string {
|
|
|
|
return useStore().state.messages.toggleTitle;
|
|
|
|
},
|
|
|
|
|
|
|
|
collapsed(): boolean {
|
2021-05-26 16:43:15 +00:00
|
|
|
return useStore().state.ui.sidebar.collapsedSections.has(this.name);
|
2021-05-25 18:26:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
toggle() {
|
2021-05-26 16:43:15 +00:00
|
|
|
useStore().commit(MutationTypes.TOGGLE_SIDEBAR_SECTION_COLLAPSED_STATE, this.name);
|
2021-05-25 18:26:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2021-05-26 01:10:34 +00:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.section--collapsible {
|
|
|
|
.section__heading .svg-icon {
|
|
|
|
transform: rotate(180deg);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.section--collapsed {
|
|
|
|
.section__heading .svg-icon {
|
|
|
|
transform: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|