LiveAtlas/src/components/sidebar/CollapsibleSection.vue

66 lines
1.6 KiB
Vue
Raw Normal View History

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}">
<button :id="`${name}-heading`" type="button" class="section__heading"
@click.prevent="toggle" :title="title"
:aria-expanded="!collapsed" :aria-controls="`${name}-content`">
2021-05-26 01:10:34 +00:00
<span>
<slot name="heading"></slot>
</span>
<SvgIcon name="arrow"></SvgIcon>
2021-05-25 18:26:14 +00:00
</button>
<div :id="`${name}-content`" role="region" :aria-labelledby="`${name}-heading`" :aria-hidden="collapsed">
2021-05-25 18:26:14 +00:00
<slot></slot>
</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';
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: {
type: String as () => LiveAtlasSidebarSection,
2021-05-25 18:26:14 +00:00
required: true,
}
},
computed: {
title(): string {
return useStore().state.messages.toggleTitle;
},
collapsed(): boolean {
return useStore().state.ui.sidebar.collapsedSections.has(this.name);
2021-05-25 18:26:14 +00:00
},
},
methods: {
toggle() {
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>