Giter Site home page Giter Site logo

kielan / react-simple-hook-modal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mbrookson/react-simple-hook-modal

1.0 2.0 0.0 1.52 MB

A simple React modal with hook based API

Home Page: https://react-simple-hook-modal.now.sh

License: MIT License

HTML 3.39% TypeScript 80.37% JavaScript 14.28% CSS 1.95%

react-simple-hook-modal's Introduction

react-simple-hook-modal

Need a simple modal that just works? react-simple-hook-modal is just that!

build npm latest

react-simple-hook-modal

Installation

Simply install the package from npm and you're good to go!

npm install react-simple-hook-modal

or

yarn add react-simple-hook-modal

Usage

React

react-simple-hook-modal has a super simple API and utilises React hooks.

  • Simply wrap your app in <ModalProvider/>
  • Add instances of <Modal/> wherever you want to display a modal
    • This will not render anything to the DOM here
    • Modals are rendered after allthe children in side <ModalProvider/>
  • Use the useModal hook to control your modal's state
  • Use the ModalTransition enum to optionally set the transition animation
    • Currently there are 3 to select from, or choose NONE to disable the transitions
import {
  ModalProvider,
  Modal,
  useModal,
  ModalTransition,
} from 'react-simple-hook-modal';

const MyComponent = () => {
  const { isModalOpen, openModal, closeModal } = useModal();

  return (
    <>
      <button onClick={openModal}>Open</button>
      <Modal
        id="any-unique-identifier"
        isOpen={isModalOpen}
        transition={ModalTransition.BOTTOM_UP}
      >
        <button onClick={closeModal}>Close</button>
      </Modal>
    </>
  );
};

const App = () => (
  <ModalProvider>
    <MyComponent />
  </ModalProvider>
);

Styles

react-simple-hook-modal uses a subset of tailwindcss under the hood. The tailwind classes used have a prefix of rsm added to avoid potential conflicts with your own styles. You can import the default styles using:

import 'react-simple-hook-modal/dist/styles.css';

ModalProvider also takes optional props:

  • backdropClassName which can contain one or more classes to append and override the default styles (e.g. Changing the backdrop colour can be done by adding the class bg-blue-800).

Modal also takes optional props:

  • modalClassName which can contain one or more classes to append to the default modal div.

Example

See the example directory in the repository for a full example including multiple stacked modals.

Demo

Click here to see a live demo of react-simple-hook-modal in action!

Issues

If you have any issues, please create an issue here on GitHub.

Thanks and enjoy!

react-simple-hook-modal's People

Contributors

mbrookson avatar jakewtaylor avatar dependabot[bot] avatar iamraufu avatar

Stargazers

Kielan avatar

Watchers

James Cloos avatar  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.