Transitions

Nature UI exports four components `Fade`, `ScaleFade`, `Slide`, and `SlideFade` to provide simple transitions.

Nature UI exports four components Fade, ScaleFade, Slide, and SlideFade to provide simple transitions.

Import#

Most transition components are made using framer-motion. They accept the following props:

  • Common props from framer's motion elements
  • in prop used to trigger the transition
  • unmountOnExit prop used to unmount the component when it is not visible.
import { Fade, ScaleFade, Slide, SlideFade } from "@nature-ui/core";

Usage#

Fade transition#

function FadeEx() {
const { isOpen, onToggle } = useDisclosure();
return (
<>
<Button onClick={onToggle} className="bg-purple-500">
Click Me
</Button>
<Fade in={isOpen}>
<Box className="p-4 text-white bg-teal-500 rounded-md shadow-md mt-4">
Fade
<Lorem count={1} />
</Box>
</Fade>
</>
);
}

ScaleFade transition#

function ScaleFadeEx() {
const { isOpen, onToggle } = useDisclosure();
return (
<>
<Button onClick={onToggle} className="bg-purple-500">
Click Me
</Button>
<ScaleFade initialScale={0.9} in={isOpen}>
<Box className="p-4 text-white bg-teal-500 rounded-md shadow-md mt-4">
Scale Fade
<Lorem count={1} />
</Box>
</ScaleFade>
</>
);
}

Slide transition#

function SlideEx() {
const { isOpen, onToggle } = useDisclosure();
return (
<>
<Button onClick={onToggle} className="bg-purple-500">
Click Me
</Button>
<Slide direction="bottom" in={isOpen} style={{ zIndex: 10 }}>
<Box className="p-10 text-white bg-teal-600 rounded-md shadow-md mt-4">
Slide <br />
<br />
<Lorem count={1} />
</Box>
</Slide>
</>
);
}

Slide Fade transition#

function SlideFadeEx() {
const { isOpen, onToggle } = useDisclosure();
return (
<>
<Button onClick={onToggle} className="bg-purple-500">
Click Me
</Button>
<SlideFade in={isOpen}>
<Box className="p-10 text-white bg-teal-500 rounded-md shadow-md mt-4">
Slide Fade <br />
<br />
<Lorem count={1} />
</Box>
</SlideFade>
</>
);
}

Collapse transition#

The Collapse component is used to create regions of content that can expand/collapse with a simple animation. It helps to hide content that's not immediately relevant to the user.

function CollapseEx() {
const { isOpen, onToggle } = useDisclosure();
return (
<>
<Button onClick={onToggle} className="bg-purple-500">
Click Me
</Button>
<Collapse in={isOpen}>
<Box className="p-10 text-white bg-teal-500 rounded-md shadow-md mt-4">
Collapses <br />
<br />
<Lorem count={1} />
</Box>
</Collapse>
</>
);
}

Changing the startingHeight#

function Example() {
const [show, setShow] = React.useState(false);
const handleToggle = () => setShow(!show);
return (
<>
<Collapse startingHeight={20} in={show}>
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
labore wes anderson cred nesciunt sapiente ea proident.
</Collapse>
<Button size="sm" onClick={handleToggle} className="mt-4 bg-purple-500">
Show {show ? "Less" : "More"}
</Button>
</>
);
}

Props#

The transition components extends the framer-motion.

Fade Props#

NameTypeDefaultDescription
isOpenboolean-Show the component; triggers the enter or exit states
unmountOnExitboolean-If true, the element will unmount when in={false} and animation is done

ScaleFade Props#

NameTypeDefaultDescription
isOpenboolean-Show the component; triggers the enter or exit states
initialScalenumber0.95The initial scale of the element
unmountOnExitboolean-If true, the element will unmount when in={false} and animation is done

Slide Props#

NameTypeDefaultDescription
direction"top" | "right" | "bottom" | "left""right"The direction to slide from
isOpenboolean-Show the component; triggers the enter or exit states
unmountOnExitboolean-If true, the element will unmount when in={false} and animation is done

SlideFade Props#

NameTypeDefaultDescription
isOpenboolean-If true, the content will animate in
initialOffsetstring-The offset on the vertical or y axis
unmountOnExitboolean-If true, the element will unmount when in={false} and animation is done

Collapse Props#

NameTypeDefaultDescription
animateOpacityboolean-If true, the opacity of the content will be animated
inbooleanfalseIf true, the content will be expanded
startingHeightstring | number0The height you want the content in its collapsed state.
unmountOnExitboolean-If true, the element will unmount when in={false} and animation is done