Skip to content

Instantly share code, notes, and snippets.

@sadewole
Last active January 24, 2022 13:05
Show Gist options
  • Save sadewole/3c4935ed9ad5b2a3a28ce235c724fec5 to your computer and use it in GitHub Desktop.
Save sadewole/3c4935ed9ad5b2a3a28ce235c724fec5 to your computer and use it in GitHub Desktop.
Accordion.vue - Template and script
<template>
<div>
<slot />
</div>
</template>
<script lang="ts">
import { provide, ref, computed, defineComponent } from "vue";
export default defineComponent({
name: "Accordion",
props: {
allowMultiple: {
type: Boolean,
},
},
setup(props) {
const initializeState = () => {
if (props.allowMultiple) {
return [];
} else {
return "";
}
};
const expandedIndex = ref(initializeState());
const _index = computed({
get() {
return expandedIndex.value;
},
set(val: any) {
expandedIndex.value = val;
},
});
provide("allowMultiple", props.allowMultiple);
provide("indices", _index);
provide("expandedIndex", expandedIndex);
},
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment