docs/.vitepress/theme/components/Collapsible.vue
59 lines · 1082 bytes
1<script setup lang="ts">
2import { ref } from 'vue'
3
4const props = defineProps<{
5 title?: string
6 type?: 'tip' | 'warning' | 'danger'
7}>()
8
9const open = ref(false)
10</script>
11
12<template>
13 <details class="details custom-block" :class="type" :open="open || undefined" @toggle="open = ($event.target as HTMLDetailsElement).open">
14 <summary>
15 <span v-if="open" class="i-iconoir-nav-arrow-down collapsible-icon" />
16 <span v-else class="i-iconoir-nav-arrow-right collapsible-icon" />
17 {{ title || 'Details' }}
18 </summary>
19 <slot />
20 </details>
21</template>
22
23<style scoped>
24summary {
25 list-style: none;
26 display: flex;
27 align-items: center;
28 gap: 0.4em;
29 cursor: pointer;
30}
31
32summary::-webkit-details-marker {
33 display: none;
34}
35
36.collapsible-icon {
37 width: 1em;
38 height: 1em;
39 flex-shrink: 0;
40}
41
42.tip {
43 background-color: #042a20;
44 color: #a8f0cc;
45 border-color: #0a5c42;
46}
47
48.warning {
49 background-color: #413306;
50 color: #fee38b;
51 border-color: #86680e;
52}
53
54.danger {
55 background-color: #430a0a;
56 color: #fec8c8;
57 border-color: #981b1b;
58}
59</style>