docs/.vitepress/theme/components/Collapsible.vue
40 lines · 777 bytes
1<script setup lang="ts">
2import { ref } from 'vue'
3
4const props = defineProps<{
5 title?: string
6}>()
7
8const open = ref(false)
9</script>
10
11<template>
12 <details class="details custom-block" :open="open || undefined" @toggle="open = ($event.target as HTMLDetailsElement).open">
13 <summary>
14 <span v-if="open" class="i-iconoir-nav-arrow-down collapsible-icon" />
15 <span v-else class="i-iconoir-nav-arrow-right collapsible-icon" />
16 {{ title || 'Details' }}
17 </summary>
18 <slot />
19 </details>
20</template>
21
22<style scoped>
23summary {
24 list-style: none;
25 display: flex;
26 align-items: center;
27 gap: 0.4em;
28 cursor: pointer;
29}
30
31summary::-webkit-details-marker {
32 display: none;
33}
34
35.collapsible-icon {
36 width: 1em;
37 height: 1em;
38 flex-shrink: 0;
39}
40</style>