可折叠
一个交互式组件,可以展开/折叠面板。
@peduarte 为 3 个仓库加了星标
@radix-ui/primitives
安装
运行以下命令
bash
npx shadcn-vue@latest add collapsible
更新 tailwind.config.js
将以下动画添加到 tailwind.config.js
文件中
js
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
keyframes: {
'collapsible-down': {
from: { height: 0 },
to: { height: 'var(--radix-collapsible-content-height)' },
},
'collapsible-up': {
from: { height: 'var(--radix-collapsible-content-height)' },
to: { height: 0 },
},
},
animation: {
'collapsible-down': 'collapsible-down 0.2s ease-in-out',
'collapsible-up': 'collapsible-up 0.2s ease-in-out',
},
},
},
}
用法
vue
<script setup lang="ts">
import { ref } from 'vue'
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from '@/components/ui/collapsible'
const isOpen = ref(false)
</script>
<template>
<Collapsible v-model:open="isOpen">
<CollapsibleTrigger>Can I use this in my project?</CollapsibleTrigger>
<CollapsibleContent>
Yes. Free to use for personal and commercial projects. No attribution
required.
</CollapsibleContent>
</Collapsible>
</template>