- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
A collapsible card with a header and body, open by default, on a card, muted or plain surface.
Installation#
pnpm dlx shadcn@latest add @zui/collapsible-cardThe CLI writes components/layout/collapsible-card.tsx, installs Button,
Collapsible, Icon,
Text, Text children and Utils, and adds class-variance-authority and
lucide-react-native.
Usage#
import {
CollapsibleCard,
CollapsibleCardActions,
CollapsibleCardContent,
CollapsibleCardHeader,
CollapsibleCardTitle,
CollapsibleCardTrigger,
} from '@/components/layout/collapsible-card';<CollapsibleCard>
<CollapsibleCardHeader>
<CollapsibleCardTitle>Layers</CollapsibleCardTitle>
<CollapsibleCardActions>
<CollapsibleCardTrigger />
</CollapsibleCardActions>
</CollapsibleCardHeader>
<CollapsibleCardContent className="p-3">Background, shadow, text</CollapsibleCardContent>
</CollapsibleCard>Use it for a card whose body the reader can hide, such as a code block's wrapper or a preview pane. A string title or body is set in a Text for you.
Composition#
CollapsibleCard
|-- CollapsibleCardHeader
| |-- CollapsibleCardTitle
| `-- CollapsibleCardActions
| `-- CollapsibleCardTrigger
`-- CollapsibleCardContentVariants#
<CollapsibleCard variant="muted">...</CollapsibleCard>default draws the card surface, its hairline as a border; muted a borderless fill for a block nested in
another card; plain no surface and a rule underneath, for a titled group of rows in a panel, with a narrower
header; flush no surface at all, for a block filling a surface its container draws.
API reference#
CollapsibleCard#
Takes every prop of Collapsible, plus:
| Prop | Type | Default |
|---|---|---|
variant | 'default' | 'muted' | 'plain' | 'flush' | 'default' |
default and muted rule the body off from the header, on the body, so the header keeps its height as the card
opens and closes. It opens by default (defaultOpen defaults to true, rather than Collapsible's own false),
and follows open when given it; each press is reported through onOpenChange.
CollapsibleCardHeader#
Takes every prop of React Native's View. The row above the body: a title, and the actions pushed to the far end
when it holds a CollapsibleCardActions.
CollapsibleCardTitle#
Takes every prop of React Native's View. The header's muted title, as tall as the style's icon button, so the
header is one height whether or not it holds actions. An Icon in it with no
size of its own is drawn at size-4 as its leading icon.
CollapsibleCardActions#
Takes every prop of React Native's View. The header's trailing controls, such as a
Copy button and the CollapsibleCardTrigger.
CollapsibleCardTrigger#
Takes every prop of Button, drawn as a ghost icon-sized Button, and is
announced as a button with its expanded state. Its default content is a chevron, pointing up while the body is
open. children replace the chevron, and text in them names the button; without text, as with the chevron or an
icon alone, it is named "Toggle content" unless an aria-label is given.
CollapsibleCardContent#
Takes every prop of CollapsibleContent. The body that the trigger
opens and closes; unmounted while closed unless keepMounted. It pads nothing: a text body takes p-3, the
small card's spacing.
collapsibleCardVariants#
The variant variant: default (the default) adds the card surface, muted a borderless muted fill, plain a
bottom border only, flush no surface classes at all.
Differences from the web#
- The chevron is a static icon that points down or up; the web's turns over and plays while the trigger is hovered or focused, which a phone has not.
- The web's
data-slotanddata-variantattributes are not set; a View takes no data attributes, so the parts read the variant from the card instead.