Getting Started
Components
- Advanced Toast
- ArrowButton
- Arrows
- Avatar
- Backdrop
- Basic Toast
- Breadcrumb
- Button
- CardBackground
- Card
- Carousel
- ChatButton
- ChatInput
- ChatMessage
- ChatTypingIndicator
- ChatWindow
- CheckboxSelect
- Checkbox
- Checkboxes
- Chip
- ChoiceExpander
- Clickable
- Date Field
- Dropdown
- ElasticHeight
- ExpandableCard
- Filter
- Form Control
- Form Label
- Frame
- HamburgerIcon
- Heading
- Image
- Link
- Loader
- Number Field
- Pagination
- Password
- Phone Field
- Popin
- Portal
- Prose
- Radio Group
- Radio
- Range
- Scrollbar
- Select
- SidebarLayout
- SliderFrame
- Spinner
- Switch
- Tabs
- Tag
- TextField
- Tooltip
- ValidationMessage
Expandable Content
This content smoothly animates when the container expands or collapses. The ElasticHeight component automatically adjusts to the height of its children.
Perfect for accordions, collapsible sections, and any UI element that needs smooth height transitions.
'use client';
import { useState } from 'react';
import { ElasticHeight } from '@/ui/ElasticHeight';
export function ElasticHeightDemo() {
const [isExpanded, setIsExpanded] = useState(false);
return (
<div className="w-full max-w-md space-y-4">
<button
onClick={() => setIsExpanded(!isExpanded)}
className="rounded-md bg-ultramarine px-4 py-2 text-white hover:bg-blue-700"
>
{isExpanded ? 'Collapse' : 'Expand'}
</button>
<ElasticHeight isExpanded={isExpanded} className="border rounded-md" min={24}>
<div className="p-4 space-y-2">
<p className="font-semibold">Expandable Content</p>
<p>
This content smoothly animates when the container expands or collapses. The
ElasticHeight component automatically adjusts to the height of its children.
</p>
<p>
Perfect for accordions, collapsible sections, and any UI element that needs smooth
height transitions.
</p>
</div>
</ElasticHeight>
</div>
);
}
Installation
npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/elastic-height.json
Usage
'use client';
import { useState } from 'react';
import { ElasticHeight } from '@/docs/lib/ui/elastic-height';
export function Component() {
const [isExpanded, setIsExpanded] = useState(false);
return (
<div>
<button onClick={() => setIsExpanded(!isExpanded)}>Toggle</button>
<ElasticHeight isExpanded={isExpanded}>
<div className="p-4">
<p>This content animates smoothly when expanded or collapsed.</p>
</div>
</ElasticHeight>
</div>
);
}API Reference
ElasticHeight
| Prop | Type | Default | Description |
|---|---|---|---|
isExpanded | boolean | false | Controls whether the container is expanded (showing full content height) or collapsed (showing minimum height) |
min | number | 0 | The minimum height in pixels when collapsed. Use 0 to fully hide content or a positive value to show partial content |
innerClassName | string | undefined | CSS classes applied to the inner wrapper div that contains the children. Use this to add padding, styling, or layout to the content area |
className | string | undefined | CSS classes applied to the outer container. Includes overflow-hidden and transition-all duration-500 by default |
Extends all standard HTML div attributes.
Implementation Details
- The component uses CSS Grid with
grid-rows-[1fr](expanded) andgrid-rows-[0fr](collapsed) for smooth height animations - No JavaScript height calculations required - the browser handles sizing automatically
- The height transition has a 500ms duration (
duration-500) with smooth easing for polished animations - The outer container has
overflow-hiddento clip content during the transition - The component sets a
data-expandedattribute on the outer container for styling and testing purposes - The inner container respects the
minprop viaminHeightinline style - Use
min={0}(default) to completely hide content when collapsed, or set a positive value to show a preview
Benefits of CSS Grid Approach
- Performance: No JavaScript calculations or ResizeObserver overhead
- Simplicity: Pure CSS solution with no imperative DOM manipulation
- Reliability: Works consistently across all browsers that support CSS Grid
- Automatic sizing: Content height adjusts naturally without manual measurement