Skip to main content

Drawer

The Drawer component is often referred to as a off-canvas menu or side menu, it is used to display content in a hidden toggleable sidebar.


Usage

import { Drawer, Button } from '@newfold/ui-component-library';

const [isOpen, setIsOpen] = useState(false);

<>
<Button onClick={() => setIsOpen(true)}>Open Drawer</Button>
<Drawer isOpen={ isOpen } onClose={ () => setIsOpen(false) }>
<Drawer.Panel>
<Drawer.Header
title="Menu"
hasCloseButton={ true }
/>
<div className="nfd-flex nfd-flex-col nfd-gap-4 nfd-min-w-56 nfd-pt-4">
<a>Home</a>
<a>About</a>
<a>Services</a>
<a>Blog</a>
<a>Contact</a>
</div>
</Drawer.Panel>
</Drawer>
</>
info

In order to user the Drawer component, you must wrap its content in a Drawer.Panel sub-component.


Variants

The Drawer component offers two variants: classic and offset.

Classic

The classic variant is the default variant.

<Drawer variant="classic">
<Drawer.Panel>
...
</Drawer.Panel>
</Drawer>

Offset

The offset variant renders the drawer with spacing around the panel.

<Drawer variant="offset">
<Drawer.Panel>
...
</Drawer.Panel>
</Drawer>

Position

The Drawer component offers two positions: left and right.

The right position is the default position. It will render the drawer on the right side of the page.

<Drawer position="right">
<Drawer.Panel>
...
</Drawer.Panel>
</Drawer>

Left

The left position will render the drawer on the left side of the page.

<Drawer position="left">
<Drawer.Panel>
...
</Drawer.Panel>
</Drawer>

Props

AttributeTypeDescriptionDefault
isOpen*boolean | Whether the drawer is open or not.-
onClose*function | Callback function to be called when the drawer is closed.-
variantclassic | offset | The variant of the drawer.classic
positionleft | right | The position of the drawer.right
overlayboolean | Whether the drawer has an overlay or not.true
classNamestring | The class name of the drawer.-
children*<Drawer.Panel> | The content of the drawer.-

Drawer.Panel

The Drawer.Panel component is used to wrap the content of the drawer.

import { Drawer } from "@newfold/ui-component-library";

<Drawer>
<Drawer.Panel>
...
</Drawer.Panel>
</Drawer>

Drawer.Panel Props

AttributeTypeDescriptionDefault
classNamestring | The class name of the drawer panel.-
childrennode | The content of the drawer panel.-

Drawer.Header

The Drawer.Header component is used to an optional header to the drawer. The header offers a title and a close button.

import { Drawer } from "@newfold/ui-component-library";

<Drawer>
<Drawer.Panel>
<Drawer.Header
title="Menu"
titleAs="h2"
titleSize="4"
hasCloseButton={ true }
closeButtonScreenReaderText="Close"
/>
...
</Drawer.Panel>
</Drawer>

Drawer.Header Props

AttributeTypeDescriptionDefault
titlestring | The title of the drawer header.-
titleAsstring | The HTML tag to use for the title.h2
titleSizestring | The size of the title.4
hasCloseButtonboolean | Whether the drawer header has a close button or not.true
closeButtonScreenReaderTextstring | The screen reader text for the close button.Close
classNamestring | The class name of the drawer header.-

Hello From Root