Git Product home page Git Product logo

react-abc-modal's Introduction

react-abc-modal

NPM
Yarn

A react modal as simple as ABC.

  • Customize the modal as you wish
  • The modal can be closed with :
    • "Escape" key,
    • overlay click/touch (optional)
    • icon click/touch (optional)

About

  • This project was created as part of my OpenClassrooms apprenticeship as a JavaScript React developer
  • Any contributions are welcome!

Download with NPM or Yarn

npm i react-abc-modal
yarn add react-abc-modal

How to use it

What is necessary

import React, { useState } from "react";
import Modal from "react-abc-modal";

const yourComponent = () => {
  const [isOpen, setOpen] = useState(false);

  return (
    <>
      {/* Example to open Modal on click */}
      <button onClick={() => setOpen(true)}>Open modal</button>

      {/* Your Modal and its children */}
      <Modal isOpen={isOpen} setOpen={setOpen} closeOutside={true} icon={true}>
        <h1>Write anything inside!</h1>
      </Modal>
    </>
  );
};

export default yourComponent;

What can be customized

{
  /* The variables to set your custom inline css */
}
const styleOverlay = {
  backgroundColor: "red",
};
const styleSection = {
  backgroundColor: "blue",
};
const styleIconClose = {
  backgroundColor: "yellow",
};

return (
  <>
    {/* All existing props */}
    <Modal
      isOpen={isOpen}
      setOpen={setOpen}
      closeOutside={true}
      icon={true}
      classOverlay="myOverlayClass"
      classSection="mySectionClass"
      classIconClose="myIconCloseClass"
      styleOverlay={styleOverlay}
      styleSection={styleSection}
      styleIconClose={styleIconClose}
    >
      <p>Add any tag here</p>
      {/* If you want to use your own component to close the Modal on click */}
      <p onClick={() => setOpen(false)}>Click me!</p>
    </Modal>
  </>
);

About the props

  • isOpen : Compulsory to get the current state
  • setOpen : Compulsory to update the state
  • closeOutside : A boolean to set to true if you want to close the modal when the user clicks the overlay
  • icon : A boolean to set to true if you want to use our Icon svg
  • classOverlay : A string to add your custom class for the Overlay component
  • classSection : A string to add your custom class for the Main component
  • classIconClose : A string to add your custom class for the Icon Close component
  • styleOverlay : A variable to add your custom inline style for the Overlay Close component
  • styleSection : A variable to add your custom inline style for the Main Close component
  • styleIconClose : A variable to add your custom inline style for the Icon Close component

react-abc-modal's People

Contributors

claire-lavigne avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.