43 lines
1.5 KiB
Vue
43 lines
1.5 KiB
Vue
<script setup lang="ts" generic="T">
|
|
import { Trash2 } from "@lucide/vue";
|
|
|
|
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
/**
|
|
* A list of configuration cards where one is open at a time. The owning page
|
|
* opens a new card when it adds one and refuses to add another while unsaved
|
|
* changes exist.
|
|
*/
|
|
defineProps<{
|
|
items: T[];
|
|
title: (item: T, index: number) => string;
|
|
removeLabel: string;
|
|
mono?: boolean;
|
|
}>();
|
|
const open = defineModel<string>("open", { default: "" });
|
|
defineEmits<{ remove: [index: number] }>();
|
|
</script>
|
|
|
|
<template>
|
|
<Accordion v-model="open" type="single" collapsible class="mb-4 gap-4">
|
|
<AccordionItem
|
|
v-for="(item, i) in items"
|
|
:key="i"
|
|
:value="String(i)"
|
|
class="rounded-xl bg-card px-4 ring-1 ring-foreground/10 not-last:border-b-0"
|
|
>
|
|
<header class="flex items-center gap-2 [&>h3]:min-w-0 [&>h3]:flex-1">
|
|
<AccordionTrigger class="min-w-0 flex-1 items-center text-title hover:no-underline" :class="mono && 'font-mono'">
|
|
<span class="truncate">{{ title(item, i) }}</span>
|
|
</AccordionTrigger>
|
|
<slot name="aside" :item="item" :index="i" />
|
|
<Button variant="ghost" size="icon" :aria-label="`${removeLabel} ${title(item, i)}`" @click="$emit('remove', i)"><Trash2 /></Button>
|
|
</header>
|
|
<AccordionContent>
|
|
<slot :item="item" :index="i" />
|
|
</AccordionContent>
|
|
</AccordionItem>
|
|
</Accordion>
|
|
</template>
|