Skip to content

Latest commit

 

History

History
70 lines (56 loc) · 1.54 KB

README.md

File metadata and controls

70 lines (56 loc) · 1.54 KB

Introduction

inspired by the container transform pattern of Material Design motion system

images

demo address

usage

  1. Import dependencies and module method
import React from "react";
import { render } from "react-dom";
import useModal from "react-transform-modal";
  1. Build UI
  • Modal : this component can wrap other element like title , content and button
  • open: open the modal
  • close: close the modal
  • styleModalContent: the style of modal
  • styleModalHeader: the style of modal's header
const ExampleModal = () => {
  const { Modal, open, close } = useModal();

  return (
    <div>
      <p>
        <button onClick={open}>Open</button>
      </p>
      <Modal>
        <div style={styleModalContent}>
          <div style={styleModalHeader}>
            <h5>Title</h5>
            <button style={styleModalClose} onClick={close} type="button">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div>
            <p style={stylePl}>
              You can also close me by pressing the &quot;ESC&quot; key.</br>
              This is the content area...
            </p>
          </div>
        </div>
      </Modal>
    </div>
  );
};

function App() {
  return (
    <div>
      <ExampleModal />
    </div>
  );
}
  1. render the modal
render(<App />, document.getElementById("root"));