Shards React
Shards React

Shards React

Documentation

Modal

Creating flexible modal dialogs can be achieved using the Modal component. They feature a series of helpful subcomponents, sizes and various other options that you can use to customize the display and behavior of your modals.

import React from "react";
import { Button, Modal, ModalBody, ModalHeader } from "shards-react";

export default class BasicModalExample extends React.Component {
  constructor(props) {
    super(props);
    this.state = { open: false };
    this.toggle = this.toggle.bind(this);
  }

  toggle() {
    this.setState({
      open: !this.state.open
    });
  }

  render() {
    const { open } = this.state;
    return (
      <div>
        <Button onClick={this.toggle}>Click Me!</Button>
        <Modal open={open} toggle={this.toggle}>
          <ModalHeader>Header</ModalHeader>
          <ModalBody>👋 Hello there!</ModalBody>
        </Modal>
      </div>
    );
  }
}

Modal Size

The modal's size can be adjusted via the size prop. You can use sm for small and lg for large.

import React from "react";
import { Button, Modal, ModalBody, ModalHeader } from "shards-react";

export default class ModalSizeExample extends React.Component {
  constructor(props) {
    super(props);
    this.state = { open: false };
    this.toggle = this.toggle.bind(this);
  }

  toggle() {
    this.setState({
      open: !this.state.open
    });
  }

  render() {
    const { open } = this.state;
    return (
      <div>
        <Button onClick={this.toggle}>Small Modal!</Button>
        <Modal size="sm" open={open} toggle={this.toggle}>
          <ModalHeader>Header</ModalHeader>
          <ModalBody>👋 Hello there!</ModalBody>
        </Modal>
      </div>
    );
  }
}

Props

The following props are available for the Modal component.

PropDescriptionTypeDefaultRequired
idThe id.String-No
classNameThe class name.String-No
openWhether it is open, or not.BoolfalseNo
fadeWhether it should fade, or not.BooltrueNo
backdropWhether it should display a backdrop, or not.BooltrueNo
showModalThe function that should be triggered when the modal is shown.Func-No
hideModalThe function that should be triggered when the modal is set to hide.Func-No
hiddenModalThe function that should be triggered when the modal is finally hidden.Func-No
centeredWhether it should be centered, or not.Bool-No
backdropClassNameThe class name for the backdrop element.String-No
toggleThe toggle function.Func-No
modalClassNameThe class name for the modal.String-No
animation-Bool-No
positionThe position.String-No
sizeThe size.String-No
tabIndexThe tab index.String-No
modalContentClassNameThe class name for the modal content.String-No
roleThe role attribute for the modal.String"dialog"No
childrenThe children nodes.Array[Node]Node-No

Subcomponents

The following subcomponents are available for the Modal component.

<ModalBody/>

PropDescriptionTypeDefaultRequired
classNameThe class name.String-No
childrenThe children nodes.Array[Node]Node-No

<ModalFooter/>

PropDescriptionTypeDefaultRequired
classNameThe class name.String-No
childrenThe children nodes.Array[Node]Node-No

<ModalHeader/>

PropDescriptionTypeDefaultRequired
classNameThe class name.String-No
toggleThe toggle function.Func-No
tagThe component's tag type.String"h5"No
closeAriaLabelThe close button's aria label.String"Close"No
titleClassThe class for the modal title.String-No
childrenThe children nodes.Array[Node]Node-No