logigate/app/components/editor/Fold.vue

31 lines
1.0 KiB
Vue
Raw Normal View History

<script setup lang="ts">
// A folding group in the side panel. It remembers, per group, whether you
// left it open, so the panel stays as short as you like it.
const props = defineProps<{ title: string; id: string; open?: boolean; /** Short note after the title, like a count. */ note?: string }>()
const KEY = `logigate:fold:${props.id}`
const isOpen = ref(props.open ?? false)
try {
const saved = localStorage.getItem(KEY)
if (saved !== null) isOpen.value = saved === '1'
} catch {}
function toggle() {
isOpen.value = !isOpen.value
try {
localStorage.setItem(KEY, isOpen.value ? '1' : '0')
} catch {}
}
</script>
<template>
<div class="fold" :class="{ open: isOpen }">
<button class="fold-head" :aria-expanded="isOpen" @click="toggle">
<Icon name="lucide:chevron-right" class="fold-chev size-3.5" />
<span class="grow">{{ title }}</span>
<span v-if="note" class="fold-note">{{ note }}</span>
</button>
<div v-if="isOpen" class="fold-body"><slot /></div>
</div>
</template>