Mỗi ví dụ là một file Vue hoàn chỉnh. Chép vào ứng dụng đã cài registry, hoặc mở trong StackBlitz.
Thiết lập nâng cao
Thiết lập ít ai đổi được ẩn đi.
Cài đặt webhook
CollapsibleAdvanced.vue
<script setup lang="ts">
import { ChevronDown } from '@lucide/vue'
import { ref } from 'vue'
import { Button } from '@/components/ui/button'
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'
const open = ref(false)
const fields = [
{ label: 'Phiên bản API', value: 'v2' },
{ label: 'Thời gian chờ', value: '30 s' },
{ label: 'Số lần thử lại', value: '3' },
]
</script>
<template>
<!-- Trigger là một Button (as-child), nên có giao diện và vòng focus của Button. Nhãn nói rõ phần nào sẽ mở. -->
<Collapsible v-model:open="open" class="flex w-full max-w-80 flex-col gap-(--bh-space-100) [font:var(--bh-font-body-default)]">
<div class="flex items-center justify-between gap-(--bh-space-100) text-(--bh-color-text)">
<span>Cài đặt webhook</span>
<CollapsibleTrigger as-child>
<Button variant="ghost" size="sm">
{{ open ? 'Ẩn nâng cao' : 'Hiện nâng cao' }}
<ChevronDown :class="open ? 'rotate-180' : ''" />
</Button>
</CollapsibleTrigger>
</div>
<CollapsibleContent>
<dl class="m-0 grid grid-cols-[1fr_auto] gap-x-(--bh-space-200) gap-y-(--bh-space-050) rounded-(--bh-radius-card) bg-(--bh-color-surface-subtle) p-(--bh-space-150)">
<template v-for="field in fields" :key="field.label">
<dt class="text-(--bh-color-text-subtle)">{{ field.label }}</dt>
<dd class="m-0 text-end text-(--bh-color-text)">{{ field.value }}</dd>
</template>
</dl>
</CollapsibleContent>
</Collapsible>
</template>Nhật ký dài
Vài dòng đầu hiện; phần còn lại mở khi cần.
Đồng bộ đơn hàng thất bại lúc 09:30.
CollapsibleLog.vue
<script setup lang="ts">
import { CircleAlert } from '@lucide/vue'
import { Button } from '@/components/ui/button'
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'
const lines = [
'09:30:02 Đang kết nối tới ERP',
'09:30:05 Đang gửi 12 đơn hàng',
'09:30:06 ERP trả về 401: từ chối API key',
]
</script>
<template>
<Collapsible v-slot="{ open }" class="flex w-full max-w-120 flex-col gap-(--bh-space-100) [font:var(--bh-font-body-default)]">
<div class="flex items-center gap-(--bh-space-100) text-(--bh-color-text)">
<CircleAlert class="size-(--bh-size-icon-default) shrink-0 text-(--bh-color-icon-danger)" aria-hidden="true" />
<span class="flex-1">Đồng bộ đơn hàng thất bại lúc 09:30.</span>
<CollapsibleTrigger as-child>
<Button variant="link">{{ open ? 'Ẩn nhật ký' : 'Xem nhật ký' }}</Button>
</CollapsibleTrigger>
</div>
<CollapsibleContent>
<pre class="m-0 overflow-x-auto rounded-(--bh-radius-card) bg-(--bh-color-surface-subtle) p-(--bh-space-150) text-(--bh-color-text) [font:var(--bh-font-code-default)]">{{ lines.join('\n') }}</pre>
</CollapsibleContent>
</Collapsible>
</template>