Skip to main content

Collapse Button

Render button or link with dropdown icon and collapsible content underneath

Usage

A collapsible button with content, combining Mantine's Button and Collapse. The button can be selected, with a dropdown icon on the right that opens the collapsed content underneath.

Uncontrolled

import { CollapseButton } from '@smile/haring-react';

<CollapseButton
defaultOpened=true
isOpenOnSelect=false
label="Home"
leftIcon=<HouseLine/>
>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed
varius bibendum dui non imperdiet. Donec vehicula fringilla lorem
vitae rutrum. Etiam malesuada ullamcorper aliquam. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia
curae; Cras elit lacus, viverra vitae risus et, pharetra tincidunt
felis. Aliquam erat volutpat. In vitae nibh eu turpis commodo
luctus vitae id libero. Curabitur eget nunc volutpat, luctus quam
rutrum, ultricies tellus. Integer diam nulla, vestibulum id enim
quis, molestie luctus magna. Phasellus et rhoncus augue, id
maximus mi. Vivamus consequat quam tristique ex laoreet, ut
eleifend eros sodales. Cras bibendum enim dolor, id rutrum urna
vestibulum non.
</CollapseButton/>

Controlled

import { CollapseButtonControlled } from '@smile/haring-react';

const [opened, setOpened] = useState(true);

<CollapseButtonControlled
isOpenOnSelect=false
label="Home"
leftIcon=<HouseLine/>
onCollapseChange={() => setOpened(!opened)}
opened={opened}
>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed
varius bibendum dui non imperdiet. Donec vehicula fringilla lorem
vitae rutrum. Etiam malesuada ullamcorper aliquam. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia
curae; Cras elit lacus, viverra vitae risus et, pharetra tincidunt
felis. Aliquam erat volutpat. In vitae nibh eu turpis commodo
luctus vitae id libero. Curabitur eget nunc volutpat, luctus quam
rutrum, ultricies tellus. Integer diam nulla, vestibulum id enim
quis, molestie luctus magna. Phasellus et rhoncus augue, id
maximus mi. Vivamus consequat quam tristique ex laoreet, ut
eleifend eros sodales. Cras bibendum enim dolor, id rutrum urna
vestibulum non.
</CollapseButtonControlled/>

Storybook Docs

Props

Uncontrolled

NameTypeDefaultDescription
childrenReactNode-Content either collapsed or opened under Button
componentElementTypebuttonCustom component to use around the label
componentPropsComponentPropsWithoutRef-Additional props for the custom component
defaultOpenedbooleanfalseInitial value of the Collapse, controls if initially opened or closed
idnumber | string-Optional ID given when onSelect is called
isOpenOnSelectbooleantrueWhen true, clicking/selecting anywhere on the button will also open theCollapse. When false, only clicking the collapse icon will open the Collapse
labelReactNode-Button label
levelnumber0Used in nested menus such as SidebarMenu, levels 0, 1 and 2 have slightly different styles
indentation"simple" | "line""simple"Used in nested menus such as SidebarMenu, when "line" will display a vertical line to the left of the button. When "simple" same thing without line
onSelect(id?: number | string) => void-Called when button is selected (does not include the collapse icon)
selectedboolean-Controlled value determining if the button is selected, affects the button style
...--extends Button props

Controlled

Only using <CollapseButtonControlled>, extends the uncontrolled <CollapseButton> props.

NameTypeDefaultDescription
collapsePropsPartial<CollapseProps>-Passed to the Collapse, extends Mantine's Collapse Props
onCollapseChangeElementType-Called when the dropdown icon is clicked
opened *booleanfalseControlled value of Collapse, controls of Collapse is opened or closed
...--extends uncontrolled CollapseButton props