Collapse
Animate presence with slide down/up transition
Source
LLM docs
Docs
PackageIcon
Usage
From Bulbapedia: Bulbasaur is a small, quadrupedal Pokémon that has blue-green skin with darker patches. It has red eyes with white pupils, pointed, ear-like structures on top of its head, and a short, blunt snout with a wide mouth. A pair of small, pointed teeth are visible in the upper jaw when its mouth is open. Each of its thick legs ends with three sharp claws. On Bulbasaur's back is a green plant bulb, which is grown from a seed planted there at birth. The bulb also conceals two slender, tentacle-like vines and provides it with energy through photosynthesis as well as from the nutrient-rich seeds contained within.
import { Button, Group, Text, Collapse, Box } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
function Demo() {
const [expanded, { toggle }] = useDisclosure(false);
return (
<Box maw={400} mx="auto">
<Group justify="center" mb={5}>
<Button onClick={toggle}>Toggle content</Button>
</Group>
<Collapse expanded={expanded}>
<Text>{/* ... content */}</Text>
</Collapse>
</Box>
);
}Horizontal orientation
import { Button, Collapse, Stack, Typography } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
function Demo() {
const [expanded, handlers] = useDisclosure(false);
return (
<Stack h={240} align="flex-start">
<Button onClick={handlers.toggle} w="fit-content">
{expanded ? 'Collapse' : 'Expand'}
</Button>
<Collapse expanded={expanded} orientation="horizontal">
<Typography bg="var(--mantine-color-blue-light)" p="xs" bdrs="md" w={200}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
</Typography>
</Collapse>
</Stack>
);
}Change transition
Set the following props to control the transition:
transitionDuration– duration in mstransitionTimingFunction– timing function (ease, linear, etc.), defaults toeaseonTransitionEnd– called when transition ends (both open and close)
From Bulbapedia: Bulbasaur is a small, quadrupedal Pokémon that has blue-green skin with darker patches. It has red eyes with white pupils, pointed, ear-like structures on top of its head, and a short, blunt snout with a wide mouth. A pair of small, pointed teeth are visible in the upper jaw when its mouth is open. Each of its thick legs ends with three sharp claws. On Bulbasaur's back is a green plant bulb, which is grown from a seed planted there at birth. The bulb also conceals two slender, tentacle-like vines and provides it with energy through photosynthesis as well as from the nutrient-rich seeds contained within.
import { useDisclosure } from '@mantine/hooks';
import { Button, Group, Text, Collapse, Box } from '@mantine/core';
function Demo() {
const [expanded, { toggle }] = useDisclosure(false);
return (
<Box maw={400} mx="auto">
<Group justify="center" mb={5}>
<Button onClick={toggle}>Toggle with linear transition</Button>
</Group>
<Collapse expanded={expanded} transitionDuration={1000} transitionTimingFunction="linear">
<Text>{/* ...content */}</Text>
</Collapse>
</Box>
);
}Example: nested Collapse components
This collapse contains another collapse
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea atque in est quaerat dolore odio! Quibusdam, a nihil modi, maiores consequuntur ex quod suscipit illum ducimus doloribus odit commodi tenetur.
This collapse is inside another collapse
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea atque in est quaerat dolore odio! Quibusdam, a nihil modi, maiores consequuntur ex quod suscipit illum ducimus doloribus odit commodi tenetur.
use-collapse hook
use-collapse is the hook version of the Collapse component.
It allows more flexible usage and control over the collapse behavior.
import { Button, Typography } from '@mantine/core';
import { useCollapse, useDisclosure } from '@mantine/hooks';
function Demo() {
const [expanded, handlers] = useDisclosure(false);
const getCollapseProps = useCollapse({ expanded });
return (
<>
<Button onClick={handlers.toggle} mb="md">
{expanded ? 'Collapse' : 'Expand'}
</Button>
<div {...getCollapseProps()}>
<Typography bg="var(--mantine-color-blue-light)" p="xs" bdrs="md">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
</Typography>
</div>
</>
);
}