Modals are used for single-step create, add, edit, or delete actions. They are also used to display additional metadata about a screen or specific object on the screen.
Usage
import { Modal } from 'nr1'
Examples
Basic
class MyNerdlet extends React.PureComponent { constructor() { super(...arguments);
this._onClose = this._onClose.bind(this);
this.state = { hidden: true, }; }
_onClose() { this.setState({ hidden: true }); }
render() { return ( <> <Button onClick={() => this.setState({ hidden: false })}> Open modal </Button>
<Modal hidden={this.state.hidden} onClose={this._onClose}> <HeadingText type={HeadingText.TYPE.HEADING_3}>Modal</HeadingText>
<BlockText spacingType={[ BlockText.SPACING_TYPE.EXTRA_LARGE, BlockText.SPACING_TYPE.OMIT, ]} > Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Dictumst quisque sagittis purus sit amet. </BlockText>
<Button onClick={this._onClose}>Close</Button> </Modal> </> ); }}
Unmounting
class MyNerdlet extends React.PureComponent { constructor() { super(...arguments);
this._onClick = this._onClick.bind(this); this._onClose = this._onClose.bind(this); this._onHideEnd = this._onHideEnd.bind(this);
this.state = { hidden: true, mounted: false, }; }
_onClick() { this.setState({ hidden: false, mounted: true, }); }
_onClose() { this.setState({ hidden: true }); }
_onHideEnd() { this.setState({ mounted: false }); }
render() { return ( <> <Button onClick={this._onClick}>Open modal</Button>
{this.state.mounted && ( <Modal hidden={this.state.hidden} onClose={this._onClose} onHideEnd={this._onHideEnd} > <HeadingText type={HeadingText.TYPE.HEADING_3}>Modal</HeadingText>
<BlockText spacingType={[ BlockText.SPACING_TYPE.EXTRA_LARGE, BlockText.SPACING_TYPE.OMIT, ]} > Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Dictumst quisque sagittis purus sit amet. </BlockText>
<Button onClick={this._onClose}>Close</Button> </Modal> )} </> ); }}
Props
string | Pass the string of the text content which should better describe the purpose of the modal to be correctly announced by screen readers.
|
node | Content to render inside the modal. |
string | Appends class names to the component. |
boolean | If |
REQUIREDfunction | Callback fired when clicking on the Modal's close button. |
function | Callback fired when the Modal finishes the closing animation.Use this to unmount the Modal component. This ensures that the closing animation works properly.
|
function | Callback fired when the Modal starts the closing animation. |
function | Callback fired when the Modal finishes the opening animation. |
function | Callback fired when the Modal starts the opening animation. |
object | Inline style for custom styling. |
string | Adds a Note: You might not see |