Components / Transitions and utilities
Transition
Animates children in and out (MUI's Fade, Grow, Zoom, Slide and Collapse). Honors reduced motion.
import { Transition } from "@stylhero/ui";
Example
Code
import { useState, type ReactNode } from "react";
import { Button, Paper, Stack, Transition } 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>
);
}
const panel = <Paper padding={4} outlined>Animated content</Paper>;
function TransitionExample() {
return <Toggle>{(show) => <Transition in={show} effect="slide" direction="up">{panel}</Transition>}</Toggle>;
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children required |
ReactNode |
- | |
in required |
boolean |
- | Show or hide the children. |
className |
string |
- | |
direction |
"up" | "down" | "left" | "right" |
"up" |
|
duration |
number |
200 |
ms. |
effect |
"fade" | "grow" | "zoom" | "slide" | "collapse" |
"fade" |
fade: opacity · grow: fade + scale from 75% · zoom: scale from 0 · slide: from direction · collapse: height. |
keepMounted |
boolean |
- | Keep the children in the DOM while hidden (default: removed after the exit animation). |
Accessibility
- Respects
prefers-reduced-motion: the effect is skipped, content still shows and hides.
Generated from src/components/Transitions.tsx. Something wrong or missing? Open an issue.