120k

可折叠

一个可展开/折叠面板的交互式组件。

Order #4189

StatusShipped
"use client"

import * as React from "react"

安装

pnpm dlx shadcn@latest add collapsible

用法

import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible"
<Collapsible>
  <CollapsibleTrigger>我可以在我的项目中使用它吗?</CollapsibleTrigger>
  <CollapsibleContent>
    可以。个人和商业项目均可免费使用。无需注明出处。
  </CollapsibleContent>
</Collapsible>

组合

使用以下组合来构建 Collapsible

Collapsible
├── CollapsibleTrigger
└── CollapsibleContent

受控状态

使用 isExpandedonExpandedChange 属性来控制状态。

import * as React from "react"
 
export function Example() {
  const [open, setOpen] = React.useState(false)
 
  return (
    <Collapsible isExpanded={open} onExpandedChange={setOpen}>
      <CollapsibleTrigger>切换</CollapsibleTrigger>
      <CollapsibleContent>内容</CollapsibleContent>
    </Collapsible>
  )
}

基础

import { ChevronDownIcon } from "@/registry/icons/__lucide__"
import { Button } from "@/components/ui/button"
import { Card, CardContent } from "@/components/ui/card"

设置面板

使用触发按钮显示其他设置。

Radius
Set the corner radius of the element.
"use client"

import * as React from "react"

文件树

使用嵌套的可折叠面板构建文件树。

import { ChevronRightIcon, FileIcon, FolderIcon } from "lucide-react"

import { Button } from "@/components/ui/button"

RTL

要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南

الطلب #4189

الحالةتم الشحن
"use client"

import * as React from "react"

API 参考

有关更多信息,请参阅 React Aria 文档。