2021-05-25 18:26:14 +00:00
|
|
|
<template>
|
|
|
|
<section :class="{'sidebar__section': true, 'section--collapsed': collapsed}">
|
2021-05-25 21:40:10 +00:00
|
|
|
<button :id="`${name}-heading`" type="button" class="section__heading"
|
|
|
|
@click.prevent="toggle" @keydown.prevent="handleKeydown" :title="title"
|
|
|
|
:aria-expanded="!collapsed" :aria-controls="`${name}-content`">
|
2021-05-25 18:26:14 +00:00
|
|
|
<slot name="heading"></slot>
|
|
|
|
</button>
|
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";
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'CollapsibleSection',
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return useStore().state.ui.collapsedSections.has(this.name);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2021-05-25 21:40:10 +00:00
|
|
|
handleKeydown(e: KeyboardEvent) {
|
2021-05-25 18:26:14 +00:00
|
|
|
if(e.key !== ' ' && e.key !== 'Enter') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.toggle();
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle() {
|
|
|
|
const store = useStore();
|
|
|
|
|
|
|
|
if(this.collapsed) {
|
|
|
|
store.state.ui.collapsedSections.delete(this.name);
|
|
|
|
} else {
|
|
|
|
store.state.ui.collapsedSections.add(this.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|