mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-29 23:55:02 +00:00
66 lines
1.4 KiB
Plaintext
66 lines
1.4 KiB
Plaintext
---
|
|
title: Collapsible
|
|
description: An interactive component which expands/collapses a panel.
|
|
component: true
|
|
featured: true
|
|
radix:
|
|
link: https://www.radix-ui.com/docs/primitives/components/collapsible
|
|
api: https://www.radix-ui.com/docs/primitives/components/collapsible#api-reference
|
|
---
|
|
|
|
<ComponentExample src="/components/examples/collapsible/demo.tsx">
|
|
<CollapsibleDemo />
|
|
</ComponentExample>
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
npx shadcn-ui add collapsible
|
|
```
|
|
|
|
<Accordion type="single" collapsible>
|
|
<AccordionItem value="manual-installation">
|
|
<AccordionTrigger>Manual Installation</AccordionTrigger>
|
|
<AccordionContent>
|
|
|
|
1. Install the `@radix-ui/react-collapsible` component from radix-ui:
|
|
|
|
```bash
|
|
npm install @radix-ui/react-collapsible
|
|
```
|
|
|
|
2. Copy and paste the following code into your project.
|
|
|
|
<ComponentSource src="/components/ui/collapsible.tsx" />
|
|
|
|
<Callout>
|
|
|
|
This is the `<Collapsible />` primitive. You can place it in a file at `components/ui/collapsible.tsx`.
|
|
|
|
</Callout>
|
|
|
|
</AccordionContent>
|
|
|
|
</AccordionItem>
|
|
</Accordion>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import {
|
|
Collapsible,
|
|
CollapsibleContent,
|
|
CollapsibleTrigger,
|
|
} from "@/components/ui/collapsible"
|
|
```
|
|
|
|
```tsx
|
|
<Collapsible>
|
|
<CollapsibleTrigger>Can I use this in my project?</CollapsibleTrigger>
|
|
<CollapsibleContent>
|
|
Yes. Free to use for personal and commercial projects. No attribution
|
|
required.
|
|
</CollapsibleContent>
|
|
</Collapsible>
|
|
```
|