Components / Transitions and utilities
Collapse
Expands and collapses its children's height. Shortcut for <Transition effect="collapse">.
import { Collapse } from "@stylhero/ui";
Example
Code
import { useState, type ReactNode } from "react";
import { Button, Collapse, Stack, Text } from "@stylhero/ui";
function Toggle({ children }: { children: (show: boolean) => ReactNode }) {
const [show, setShow] = useState(true);
return (
<Stack gap={3} align="flex-start">
<Button size="sm" variant="secondary" onClick={() => setShow(!show)}>{show ? "Hide" : "Show"}</Button>
{children(show)}
</Stack>
);
}
function CollapseExample() {
return <Toggle>{(show) => <Collapse in={show}><Text>Collapse animates the height, so content below moves smoothly.</Text></Collapse>}</Toggle>;
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children required |
ReactNode |
- | |
in required |
boolean |
- | Show or hide the children. |
className |
string |
- | |
direction |
"up" | "down" | "left" | "right" |
- | |
duration |
number |
- | ms. |
keepMounted |
boolean |
- | Keep the children in the DOM while hidden (default: removed after the exit animation). |
Generated from src/components/Transitions.tsx. Something wrong or missing? Open an issue.