Collapse 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.
Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups. Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups. Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups.
</Collapse>
</Box>
);
}
Changing the startingHeight
EDITABLE EXAMPLE
functionExample(){
const[show, setShow]=React.useState(false);
consthandleToggle=()=>setShow(!show);
const textStyleProps ={
whiteSpace: show ?'wrap':'nowrap',
overflow:'hidden',
textOverflow:'ellipsis',
width:'100%',
};
return(
<BoxwhiteSpace="pre-wrap">
<CollapsestartingHeight={20}isOpen={show}>
<Text{...textStyleProps}>
Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups. Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups. Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups.
</Text>
</Collapse>
<LinkonClick={handleToggle}>
{show ?'Show less':'Show more'}
</Link>
</Box>
);
}
Props
Name
Type
Default
Description
isOpen
boolean
false
If true, the content will be visible.
animateOpacity
boolean
true
If true, the opacity of the content will be animated.
duration
number
The animation duration as it expands.
startingHeight
number
0
The height you want the content in it's collapsed state.
endingHeight
number
'auto'
The height you want the content in it's expanded state.
onAnimationEnd
function
A callback which will be called when animation starts. The first argument passed to this callback is an object containing newHeight, the pixel value of the height at which the animation will end.
onAnimationStart
function
A callback which will be called when animation ends. The first argument passed to this callback is an object containing newHeight, the pixel value of the height at which the animation ended.