Configurable modal component with keyboard control
Content-agnostic: only shows the content you pass in.
Press ESC or click outside the modal to close it.
Locks the scroll of background content.
Can be triggered with or without the click of a button.
Multiple "options" (buttons) can be configured. Each button can take an optional callback function.
If no options are passed to the Modal, it will automatically generate a single "Close" option, that simply closes the Modal.
Example triggered with button, with two options: "Accept" and "Close".
Click to open modal:
1import Modal from '@hummingbot/hbui/components/modal'
2import { P } from '@hummingbot/hbui/elements/typography'
3import { Button } from '@hummingbot/hbui/elements/buttons'
4
5<Modal
6 title='Modal title'
7 description='Description of the modal context or purpose'
8 content={
9 <P>
10 Your application has been successfully submitted. Please review your
11 order and if all looks good, click "Accept" to proceed.
12 </P>
13 }
14 options={[
15 {
16 label: "Cancel",
17 variant: "secondary",
18 },
19 {
20 label: "Accept",
21 variant: "success",
22 callBack: () => console.log('Clicked: Accept Option')
23 }
24 ]}
25 clickElement={
26 <Button variant='success'>Open modal</Button>
27 }
28/>Example triggered with button, without providing any button options: A "Close" button is automatically generated.
Click to open modal
1import Modal from '@hummingbot/hbui/components/modal'
2import { P } from '@hummingbot/hbui/elements/typography'
3import { Button } from '@hummingbot/hbui/elements/buttons'
4
5<Modal
6 title='Modal title'
7 description='Description of the modal context or purpose'
8 content={
9 <P>
10 Your application has been successfully submitted.
11 </P>
12 }
13 clickElement={
14 <Button variant='success'>Open modal</Button>
15 }
16/>Example triggered with code: Pass in "showOpen" and omit "clickElement".
1import Modal from '@hummingbot/hbui/components/modal'
2import { P } from '@hummingbot/hbui/elements/typography'
3
4<Modal
5 showOpen={true}
6 dialogOnClose={() => console.log('Modal closed')}
7 title='Modal title'
8 description='Description of the modal context or purpose'
9 content={
10 <P>
11 Your application has been successfully submitted.
12 </P>
13 }
14/>Prop Name
Type
Default
Required
Description
showOpen
Boolean
false
false
The state of the Modal. Pass 'true' to show the modal without having to click a button
dialogOnClose
React props
() => {}
false
The function to run when the Modal is closed. Usually used to set the 'showOpen' state to 'false'
clickElement
JSX
null
false
The React element to click to show the Modal - usually a button - used when you want to use a button to trigger the Modal
title
String
' '
true
Modal title
description
String
' '
false
Optional sentence explaining the Modal intent or purpose
content
JSX
null
true
The content for the modal. Without it, the Modal will have nothing to show except the title and subtitle.
options
Array
null
false
The options define the buttons the Modal will have. Every button will close the Modal but will also trigger a custom callBack is one is provided.
overlayProps
React props
null
false
To use in case you want to pass extra props to the Modal overlay element. Eg. change the background color
titleProps
React props
null
false
To use in case you want to pass extra props to the Modal title element. Eg. style it differently.
descriptionProps
React props
null
false
To use in case you want to pass extra props to the Modal description element. Eg. style it differently.