React Suite Placement Drawer
Last Updated :
30 Jun, 2022
React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application.
In this article, we'll learn about React Suite Placement Drawer. The Drawer component is a panel that slides from the edge of the display screen and this drawer can be slide from four different sides i.e, from left, right, top, and bottom.
Using Drawer Component: Import the Drawer component to your App.js file as given below:
import { Drawer } from 'rsuite';
// or
import Drawer from 'rsuite/Drawer';
Syntax:
<Drawer placement={placement} open={isDrawer}
onClose={() => setIsDrawer(false)}>
<Drawer.Header>
<Drawer.Title>...</Drawer.Title>
<Drawer.Actions>
<Button onClick={() => setIsDrawer(false)}>
...
</Button>
</Drawer.Actions>
</Drawer.Header>
<Drawer.Body>
...
</Drawer.Body>
</Drawer>
Drawer Props:
- autoFocus: The Drawer is opened and is automatically focused on its own, and it is accessible to screen readers when this is set to true.
- backdrop: The Drawer will display the background when it is opened when this is set to true.
- backdropClassName: It is used to add an optional extra class name to .modal-backdrop.
- classPrefix: It is used to denote the prefix of the component CSS class.
- enforceFocus: The Drawer will prevent the focus from leaving when opened when this is set to true.
- full: This is a deprecated prop used to enable the full screen.
- keyboard: This will close the Drawer when the ESC key is pressed.
- onEnter: It is a callback function that is triggered before the Drawer transitions in.
- onEntered: It is a callback function that is triggered after the Drawer finishes transitioning in.
- onEntering: It is a callback function that is triggered as the Drawer begins to transition in.
- onExit: This is a callback function that is triggered right before the Drawer transitions out.
- onExited: This is a callback function that is triggered after the Drawer finishes transitioning out.
- onExiting: This is a callback function that is triggered as the Drawer begins to transition out.
- onClose: This is a callback function that is triggered when Drawer hides or closes.
- onOpen: This is a callback function that is triggered when the Drawer display.
- placement: This is used for the placement of the Drawer.
- open: This is used to open the Drawer.
- size: This is used to set the size of Drawer.
Creating React Application And Installing Module:
Step 1: Create a React application using the given command:
npm create-react-app projectname
Step 2: After creating your project, move to it using the given command
cd project-name
Step 3: Now Install the rsuite node package using the given command:
npm install rsuite
Project Structure: Now your project structure should look like the following:
Â
Example 1: Below example demonstrates the placement of the drawer on the Left side.
JavaScript
import React from "react";
import "rsuite/dist/rsuite.min.css";
import { Drawer, Button, ButtonToolbar,
IconButton } from "rsuite";
import { ArrowRight } from "@rsuite/icons/";
export default function App() {
const [isDrawer, setIsDrawer] = React.useState(false);
const [placement, setPlacement] = React.useState();
const handleOpen = key => {
setIsDrawer(true);
setPlacement(key);
};
return (
<div style={{ padding: 10 }}>
<h2>GeeksforGeeks</h2>
<h4 style={{ color: "green" }}>
React Suite Placement Drawer
</h4>
<div>
<ButtonToolbar>
<IconButton icon={<ArrowRight />}
onClick={() => handleOpen('left')}>
Left
</IconButton>
</ButtonToolbar>
<Drawer placement={placement} open={isDrawer}
onClose={() => setIsDrawer(false)}>
<Drawer.Header>
<Drawer.Title>GeeksforGeeks</Drawer.Title>
<Drawer.Actions>
<Button onClick={() => setIsDrawer(false)}
color="green" appearance="primary">
Close
</Button>
</Drawer.Actions>
</Drawer.Header>
<Drawer.Body>
<p>
Hi Geek! This is an
example of Left Drawer
</p>
</Drawer.Body>
</Drawer>
</div>
</div>
);
}
Output:
Â
Example 2: Below example demonstrates the placement of the drawer on the right side.
JavaScript
import React from "react";
import "rsuite/dist/rsuite.min.css";
import { Drawer, Button, ButtonToolbar,
IconButton } from "rsuite";
import { ArrowLeft } from "@rsuite/icons/";
export default function App() {
const [isDrawer, setIsDrawer] = React.useState(false);
const [placement, setPlacement] = React.useState();
const handleOpen = key => {
setIsDrawer(true);
setPlacement(key);
};
return (
<div style={{ padding: 10 }}>
<h2>GeeksforGeeks</h2>
<h4 style={{ color: "green" }}>
React Suite Placement Drawer
</h4>
<div>
<ButtonToolbar>
<IconButton icon={<ArrowLeft />}
onClick={() => handleOpen('right')}>
Right
</IconButton>
</ButtonToolbar>
<Drawer placement={placement} open={isDrawer}
onClose={() => setIsDrawer(false)}>
<Drawer.Header>
<Drawer.Title>GeeksforGeeks</Drawer.Title>
<Drawer.Actions>
<Button onClick={() => setIsDrawer(false)}
color="green" appearance="primary">
Close
</Button>
</Drawer.Actions>
</Drawer.Header>
<Drawer.Body>
<p>
Hi Geek! This is an
example of Right Drawer
</p>
</Drawer.Body>
</Drawer>
</div>
</div>
);
}
Output:
Â
Example 3: Below example demonstrates the placement of the drawer at the bottom.
JavaScript
import React from "react";
import "rsuite/dist/rsuite.min.css";
import { Drawer, Button, ButtonToolbar,
IconButton } from "rsuite";
import { ArrowDown } from "@rsuite/icons/";
export default function App() {
const [isDrawer, setIsDrawer] = React.useState(false);
const [placement, setPlacement] = React.useState();
const handleOpen = key => {
setIsDrawer(true);
setPlacement(key);
};
return (
<div style={{ padding: 10 }}>
<h2>GeeksforGeeks</h2>
<h4 style={{ color: "green" }}>
React Suite Placement Drawer
</h4>
<div>
<ButtonToolbar>
<IconButton icon={<ArrowDown />}
onClick={() => handleOpen('bottom')}>
Bottom
</IconButton>
</ButtonToolbar>
<Drawer placement={placement} open={isDrawer}
onClose={() => setIsDrawer(false)}>
<Drawer.Header>
<Drawer.Title>GeeksforGeeks</Drawer.Title>
<Drawer.Actions>
<Button onClick={() => setIsDrawer(false)}
color="green" appearance="primary">
Close
</Button>
</Drawer.Actions>
</Drawer.Header>
<Drawer.Body>
<p>
Hi Geek! This is an example of Bottom Drawer
</p>
</Drawer.Body>
</Drawer>
</div>
</div>
);
}
Output:
Â
Example 4: Below example demonstrates the placement of the drawer at the top.
JavaScript
import React from "react";
import "rsuite/dist/rsuite.min.css";
import { Drawer, Button, ButtonToolbar,
IconButton } from "rsuite";
import { ArrowUp } from "@rsuite/icons/";
export default function App() {
const [isDrawer, setIsDrawer] = React.useState(false);
const [placement, setPlacement] = React.useState();
const handleOpen = key => {
setIsDrawer(true);
setPlacement(key);
};
return (
<div style={{ padding: 10 }}>
<h2>GeeksforGeeks</h2>
<h4 style={{ color: "green" }}>
React Suite Placement Drawer
</h4>
<div>
<ButtonToolbar>
<IconButton icon={<ArrowUp />}
onClick={() => handleOpen('top')}>
Top
</IconButton>
</ButtonToolbar>
<Drawer placement={placement}
open={isDrawer}
onClose={() => setIsDrawer(false)}>
<Drawer.Header>
<Drawer.Title>GeeksforGeeks</Drawer.Title>
<Drawer.Actions>
<Button onClick={() => setIsDrawer(false)}
color="green" appearance="primary">
Close
</Button>
</Drawer.Actions>
</Drawer.Header>
<Drawer.Body>
<p>Hi Geek! This is an example of Top Drawer</p>
</Drawer.Body>
</Drawer>
</div>
</div>
);
}
Output:
Â
Reference: https://rsuitejs.com/components/drawer/#placement
Similar Reads
Drawer
Dropdown
Modal
Popover
Tooltip
React Suite Tooltip Follow CursorReact suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, weâll learn about React suite Tooltip Follow Cur
3 min read
React Suite Tooltip Hide Arrow IndicatorReact suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, weâll learn about React suite Tooltip Hide Arrow
3 min read
React Suite Tooltip Triggering eventsReact Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The tooltip component allows the user to display informative text when users hover over, focus on, or tap an element. The tooltip props are used to add property
3 min read
React Suite Tooltip Container and prevent overflowReact Suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React Suite Tooltip Container
3 min read
React Suite Tooltip Disabled elementsReact Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The tooltip component allows the user to display informative text when users hover over, focus on, or tap an element. The tooltip disabled attribute is used to
2 min read
React Suite Tooltip ComponentReact Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. Tooltip component allows the user to display informative text when users hover over, focus on, or tap an element. We can use the following approach in ReactJS to
3 min read
React Suite Tooltip <Whisper> PropsReact Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The tooltip component allows the user to display informative text when users hover over, focus on, or tap an element. Whisper Binds an event to an element and d
3 min read
React Suite Tooltip ts:Placement PropsReact Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The tooltip component allows the user to display informative text when users hover over, focus on, or tap an element. The placement props are used along with Wh
3 min read
React Suite Tooltip PlacementReact Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The tooltip component allows the user to display informative text when users hover over, focus on, or tap an element. Tooltip placement can be used to alter the
3 min read
Form
Icons
React Suite Avatar Component React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. Avatar component allows the user to display an avatar or brand. We can use the following approach in ReactJS to use the React Suite Avatar Component. Avatar Prop
2 min read