Collapsible
Shows and hides one region, such as advanced options or the rest of a long list.
Status: beta. Category: Data display.
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '@glyphui/ui'
Exports: Collapsible, CollapsibleTrigger, CollapsibleContent, collapsibleStyles.
Notes
- The content animates its height open and closed and stays mounted until the closing animation ends.
- For several expandable sections where one opens at a time, use Accordion.
Collapsible props
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | boolean |
Example: Advanced options
import {
Button,
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
Field,
Input,
Switch,
} from '@glyphui/ui'
import { ChevronDown } from 'lucide-react'
export default function Example() {
return (
<Collapsible className="grid w-full max-w-sm gap-3">
<Field label="Webhook URL">
<Input defaultValue="https://api.acme.com/hooks/glyph" />
</Field>
<CollapsibleTrigger asChild>
<Button
variant="ghost"
size="sm"
className="group justify-self-start"
rightIcon={
<ChevronDown className="transition-transform group-data-[state=open]:rotate-180" />
}
>
Advanced options
</Button>
</CollapsibleTrigger>
<CollapsibleContent>
<div className="grid gap-4 pt-1">
<Field label="Signing secret" description="Used to verify that requests come from Glyph.">
<Input type="password" defaultValue="whsec_7f3a91" />
</Field>
<Field
orientation="horizontal"
label="Retry failed deliveries"
description="Up to 5 times over 24 hours."
>
<Switch defaultChecked />
</Field>
</div>
</CollapsibleContent>
</Collapsible>
)
}
Example: Show more
Reveal the rest of a list without leaving the page.
import { Button, Collapsible, CollapsibleContent, CollapsibleTrigger } from '@glyphui/ui'
import { useState } from 'react'
const releases = [
'0.2.0 · 25 new components',
'0.1.1 · Signed releases',
'0.1.0 · First public release',
'0.0.3 · Theme engine',
'0.0.2 · Presets',
'0.0.1 · Initial commit',
]
export default function Example() {
const [open, setOpen] = useState(false)
return (
<Collapsible open={open} onOpenChange={setOpen} className="w-full max-w-sm">
<ul className="grid divide-y divide-border rounded-lg border border-border text-small">
{releases.slice(0, 3).map((r) => (
<li key={r} className="px-4 py-2.5">
{r}
</li>
))}
</ul>
<CollapsibleContent>
<ul className="mt-2 grid divide-y divide-border rounded-lg border border-border text-small text-muted-foreground">
{releases.slice(3).map((r) => (
<li key={r} className="px-4 py-2.5">
{r}
</li>
))}
</ul>
</CollapsibleContent>
<CollapsibleTrigger asChild>
<Button variant="link" size="sm" className="mt-2">
{open ? 'Show fewer releases' : `Show ${releases.length - 3} older releases`}
</Button>
</CollapsibleTrigger>
</Collapsible>
)
}
Live page: https://glyphui.xyz/components/collapsible