Transitions

Transitions allow for easy way to animate stuff.

Source
  • Collapse - The Collapse component, that animates the height of the content.
  • Scale - The Scale component, that scales the element.
import { Collapse, Scale } from "@dreamy-ui/react";

Base usage of the Collapse component.

Hello
export function Collapsed() {
    const [isOpen, setIsOpen] = useState(false);
 
    return (
        <>
            <Button
                w={"min-content"}
                onClick={() => setIsOpen(!isOpen)}
            >
                Toggle
            </Button>
            <Collapse
                w={"full"}
                in={isOpen}
            >
                <Box
                    bg={"primary"}
                    color={"white"}
                    p={4}
                    rounded={"md"}
                    w={"full"}
                >
                    Hello
                </Box>
            </Collapse>
        </>
    );
}

Base usage of the Scale component.

Hello
export function Scaled() {
    const [isOpen, setIsOpen] = useState(false);
 
    return (
        <>
            <Button
                w={"min-content"}
                onClick={() => setIsOpen(!isOpen)}
            >
                Toggle
            </Button>
            <Scale
                w={"full"}
                in={isOpen}
            >
                <Box
                    bg={"primary"}
                    color={"white"}
                    p={4}
                    rounded={"md"}
                    w={"full"}
                >
                    Hello
                </Box>
            </Scale>
        </>
    );
}

You can set the starting and ending height of the content by setting the startingHeight and endingHeight props.

Hello
<Collapsed startingHeight={10} endingHeight={80} />

You can disable the opacity animation by setting the animateOpacity prop to false. This option works for both the Collapse and Scale components.

Hello
<Collapsed animateOpacity={false} />

You can unmount component on exit animation by setting the unmountOnExit prop to true. This option works for both the Collapse and Scale components.

<Collapsed unmountOnExit />

You can set the initial scale of the content by setting the initialScale prop. This option works for only for Scale component.

Hello
<Scaled initialScale={0} />