ניתן לכיווץ
צמד של כפתור ולוח עבור עצי קבצים, הגדרות מתקדמות וקטעי "הצג עוד" — עם עיצוב ניאו-ברוטליסטי המשלב מסגרות וצללים.
"use client"
import * as React from "react"ה-collapsible הוא האח החד-מקטעי של ה-accordion: טריגר אחד, פאנל אחד, פתוח או סגור. נבנה על גבי רכיב Base UI Collapsible ומעוצב לפי המתכון הנאו-ברוטליסטי: מסגרות עבות, צללים חדים וטיפוגרפיה מודגשת.
השתמשו בו כש:
- עצי קבצים וניווט מקונן — מקננים collapsibles כדי לפתוח תיקיות (ראו את דוגמת עץ הקבצים למטה).
- הגדרות מתקדמות — משאירים את האפשרויות הנפוצות גלויות ומקפלים את השאר מאחורי מתג.
- תוכן "הצג עוד" — changelogs ארוכים, רשימות מקוצרות, פירוט אופציונלי בעמודים צפופים.
התקנה#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/collapsible.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/collapsible.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/collapsible.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/collapsible.json
התקינו את התלויות הבאות:
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/react
העתיקו והדביקו את הקוד הבא לפרויקט שלכם.
"use client"
import { Collapsible as CollapsiblePrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
function Collapsible({
...props
}: React.ComponentProps<typeof CollapsiblePrimitive.Root>) {
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />
}
function CollapsibleTrigger({
...props
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) {
return (
<CollapsiblePrimitive.CollapsibleTrigger
data-slot="collapsible-trigger"
{...props}
/>
)
}
function CollapsibleContent({
className,
...props
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
return (
<CollapsiblePrimitive.CollapsibleContent
data-slot="collapsible-content"
// Radix publishes the measured height as
// `--radix-collapsible-content-height`; the collapsible-down/up keyframes
// interpolate against it for a real slide open/close.
className={cn(
"overflow-hidden data-[state=open]:animate-collapsible-down data-[state=closed]:animate-collapsible-up",
className
)}
{...props}
/>
)
}
export { Collapsible, CollapsibleTrigger, CollapsibleContent }
עדכנו את נתיבי הייבוא כך שיתאימו למבנה הפרויקט שלכם.
שימוש#
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible"<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>קומפוזיציה#
השתמשו בקומפוזיציה הבאה כדי לבנות Collapsible:
Collapsible
├── CollapsibleTrigger
└── CollapsibleContentמצב מבוקר#
השתמשו ב-props open ו-onOpenChange כדי לשלוט במצב.
import * as React from "react"
export function Example() {
const [open, setOpen] = React.useState(false)
return (
<Collapsible open={open} onOpenChange={setOpen}>
<CollapsibleTrigger>Toggle</CollapsibleTrigger>
<CollapsibleContent>Content</CollapsibleContent>
</Collapsible>
)
}דוגמאות#
בסיסי#
import { ChevronDownIcon } from "@/registry/icons/__lucide__"
import { Button } from "@/components/ui/button"
import { Card, CardContent } from "@/components/ui/card"לוח הגדרות#
השתמשו בכפתור טריגר כדי לחשוף הגדרות נוספות.
"use client"
import * as React from "react"עץ קבצים#
השתמשו ברכיבי collapsible מקוננים כדי לבנות עץ קבצים.
import { ChevronRightIcon, FileIcon, FolderIcon } from "lucide-react"
import { Button } from "@/components/ui/button"RTL#
כדי להפעיל RTL ב-Neobrutalism, עיינו במדריך ההגדרה של RTL.
"use client"
import * as React from "react"נגישות#
ה-collapsible עוקב אחרי דפוס Disclosure של WAI-ARIA: הטריגר הוא כפתור אמיתי מחווט עם aria-expanded ו-aria-controls, כך שקוראי מסך מכריזים אם הפאנל פתוח.
אינטראקציות מקלדת:
| מקש | פעולה |
|---|---|
Tab / Shift + Tab | מעבירים מוקד אל ומהטריגר |
Space / Enter | מחליפים את הפאנל |
תיעוד ה-API#
למידע נוסף, עיינו בתיעוד של Base UI.