0.0.14 • Published 8 years ago

react-common-modal v0.0.14

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

react-common-modal

Simple Modal Dialog

Installation

With npm

npm i react-common-modal --save --save-exact

With yarn

yarn add react-common-modal -E

Usage

./Dialog.js

import React from "react";
import {
  DialogTitle,
  DialogContent,
  DialogActions,
  Dialog as UIDialog,
} from "react-common-modal";

Dialog.propTypes = {
  open: PropTypes.bool,
  onRequestClose: PropTypes.func,

  title: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
  showCloseButton: PropTypes.bool,
  children: PropTypes.node.isRequired,
  position: PropTypes.string,
  alignActions: PropTypes.string
};

export default function Dialog(props) {
  return(
    <UIDialog open={props.open} position={props.position}>
      <DialogTitle
        title={props.title}
        onClose={props.showCloseButton ? props.onRequestClose : null}
      />

      <DialogContent>{props.children}</DialogContent>

      <DialogActions align={props.alignActions}>
        <Button onClick={props.onRequestClose}>Close</Button>
      </DialogActions>
    </UIDialog>
  )
}

./App.js

import React from "react";
import Dialog from "./Dialog";

export default class App extends React.Component {
  constructor() {
    super();

    this.state = {
      showModal: false
    }
  }

  render() {
    <div>
      <button
        onClick={() => this.setState({ showModal: true })}
      >
        Open Modal
      </button>

      <Dialog
        title="Dialog Title"
        alignActions="center"
        position="top-center"
        showCloseButton={true}
        open={this.state.showModal}
        onRequestClose={this.setState({ showModal: false })}
      >
        <h5>Dialog Content</h5>
      </Dialog>
    </div>
  }
}

Props

Dialog
NameTypeDefaultDescription
openBooleanfalseIf true the Modal Dialog is open
positionString:top-left | top-center | top-right center-left | center | center-rightbottom-left | bottom-center | bottom-rightcenterPosition Modal Dialog on the page
childrenNodeModal Dialog children, usually the included sub-components
classNameStringThe className to add to the content container
backdropClassNameStringThe className to add to the overlay container
DialogTitle
NameTypeDefaultDescription
titleString | NodeThe title to display on the Modal Dialog
onCloseFuncFired when to be click on the close button
classNameStringThe className to add to the content container
titleClassNameStringThe className to add to the title container
DialogContent
NameTypeDefaultDescription
childrenNodeContent children, usually the included sub-components
classNameStringThe className to add to the content container
DialogActions
NameTypeDefaultDescription
alignString:start | center | endendAlign actions content
childrenNodeActions children, usually the included sub-components
classNameStringThe className to add to the content container

Live Example

https://react-common-modal.firebaseapp.com/

Licence

MIT

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago