ExpansionPanel

This commit is contained in:
vadim committed 2026-10-02 20:36:17 +03:00
1 parent ab539bf84b
commit cdd7147d8e
1 file changed
+25 -3
+25 -3
View File
@@ -1,13 +1,35 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref } from 'vue' import { computed, ref, watch } from 'vue'
interface Props { interface Props {
title: string title: string
/** localStorage key for the open/closed state; defaults to one derived from the title. */
storageKey?: string
} }
const icons = ['mdi-chevron-right', 'mdi-chevron-down'] const icons = ['mdi-chevron-right', 'mdi-chevron-down']
const isOpen = ref(true) const { title, storageKey } = defineProps<Props>()
const { title } = defineProps<Props>()
const key = computed(() => `expansion-panel:${storageKey ?? title}`)
function readStoredOpen(): boolean {
try {
return localStorage.getItem(key.value) !== 'closed'
} catch {
// ignore storage errors (e.g. disabled in private mode)
return true
}
}
const isOpen = ref(readStoredOpen())
watch(isOpen, (value) => {
try {
localStorage.setItem(key.value, value ? 'open' : 'closed')
} catch {
// ignore storage errors (e.g. disabled in private mode)
}
})
const icon = computed(() => { const icon = computed(() => {
return isOpen.value ? icons[1] : icons[0] return isOpen.value ? icons[1] : icons[0]