Drawer

Responsable :
igor0226
GitHub
resizable
disableEscapeKeyDown
disableOutsideClick
hideVeil
placement
import {Drawer} from '@gravity-ui/uikit';

The Drawer component is a versatile interface element used in web applications to provide a sliding panel that emerges from the edge of the screen. This panel can house navigations, tools, or additional content. The component is implemented using React and CSS transitions for smooth animations.

Usage

Here is a simple example of how to use the Drawer component:

import React from 'react';
import {Drawer} from '@gravity-ui/uikit';

const App = () => {
  const [isVisible, setVisible] = React.useState(false);

  return (
    <div>
      <button onClick={() => setVisible(true)}>Open Drawer</button>
      <Drawer onOpenChange={setVisible} open={isVisible}>
        <p>Content of the drawer</p>
      </Drawer>
    </div>
  );
};

export default App;

Placement

To control the placement of the Drawer, you can pass the placement prop. The possible values are left, right, top, and bottom.

<Drawer onOpenChange={setVisible} open={isVisible} placement="left">
  <p>Content of the drawer</p>
</Drawer>
<Drawer onOpenChange={setVisible} open={isVisible} placement="right">
  <p>Content of the drawer</p>
</Drawer>
<Drawer onOpenChange={setVisible} open={isVisible} placement="top">
  <p>Content of the drawer</p>
</Drawer>
<Drawer onOpenChange={setVisible} open={isVisible} placement="bottom">
  <p>Content of the drawer</p>
</Drawer>

Resizable

A Drawer can be resizable by passing the resizable prop.

<Drawer onOpenChange={setVisible} open={isVisible} resizable>
  <p>Content of the drawer</p>
</Drawer>

Additionally, you can use the size prop to control the size of the Drawer and pass the onResize handler to store the resized value.

const [size, setSize] = useState(500);

<Drawer onOpenChange={setVisible} open={isVisible} resizable size={size} onResize={setSize}>
  <p>Content of the drawer</p>
</Drawer>;

Properties

NameDescriptionTypeDefault
classNameclass HTML attribute for the root nodestring
qaTest attribute (data-qa)string
stylestyle HTML attribute for the root nodeReact.CSSProperties
aria-labelaria-label HTML attribute to describe Drawerstring
aria-labelledbyID of the visible Drawer caption elementstring
aria-describedbyaria-describedby for the Drawer elementstring
aria-detailsaria-details for the user Drawer elementstring
returnFocusElement to be focused on closingboolean React.Ref<HTMLElement>true
initialFocusInitial element to be focused. Positive number is the index of tabbable element.number React.Ref<HTMLElement>
placementSpecifies the side from which the drawer should slide instringleft
contentClassNameclass HTML attribute for the content nodestring
childrenAny React contentReact.ReactNode
containerDOM element to which component is mounted via PortalHTMLElementdocument.body
disableBodyScrollLockDisables locking scroll while openbooleanfalse
disableEscapeKeyDownDisables triggering close on Escbooleanfalse
disableOutsideClickDisables triggering close on outside clicksbooleanfalse
disablePortalDisables using Portalbooleanfalse
keepMountedDrawer will not be removed from the DOM upon hidingbooleanfalse
resizableEnables resizing of the drawer via pointerbooleanfalse
openManages Drawer visibilitybooleanfalse
hideVeilRemoves the Drawer's veilbooleanfalse
onOpenChangeCallback called at the moment of open state changeFunction
onTransitionInThe callback fired on transition "in" startFunction
onTransitionInCompleteThe callback fired on transition "in" completeFunction
onTransitionOutThe callback fired on transition "out" startFunction
onTransitionOutCompleteThe callback fired on transition "out" completeFunction
onResizeEndCallback called at the end of resizingFunction
onResizeCallback called when the drawer is being resizedFunction
onResizeStartCallback called at the start of resizingFunction
maxSizeMax width or height of the drawer in pixelsnumber
minSizeMin width or height of the drawer in pixelsnumber
sizeWidth or height of the drawer in pixels. When the auto option is passed, the Drawer's width or height will adjust to fit its content.number | 'auto'