0.2.6 • Published 9 months ago

lightest-modal v0.2.6

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

Lightest Modal

Lightest Modal is a simple and lightweight modal package for React.

Installation

To install Lightest Modal, you can use npm:

npm install lightest-modal

Requirment

You'll need a useState to handle the open & close

const [showModal, setShowModal] = useState(false)

Usage

import Modal from 'lightest-modal'

<Modal {props} />
Prop's nameTypeDefault valueDescriptionRequired
showModalBooleanfalseControls whether the modal is visible (true) or hidden (false)Yes
closeModalFunction-Close the modal, pass your useState setter like so: () => {setShowModal(false)}Yes
backgroundColorString'white'The background color of the modalNo
scrollBooleanfalseDetermines if the body scroll is blocked when the modal is openNo
roundedNumber4The border radius of the modalNo
paddingNumber10The padding size of the modalNo
smoothBooleantrueEnable fade transitionNo
widthNumber600The width of the modal. The maximum width is 100vw anywayNo

Example usage with props

import React, { useState } from 'react';
import Modal from 'lightest-modal';

const MyComponent = () => {
  const [showModal, setShowModal] = useState(false);

  return (
    <div>
      <button onClick={() => setShowModal(true)}>Open Modal</button>
      <Modal
        showModal={showModal}
        closeModal={() => {setShowModal(false)}}
      />
    </div>
  );
};

Example usage with children

with children way, you can customise the modal as you wish

import React, { useState } from 'react';
import Modal from 'lightest-modal';

const MyComponent = () => {
  const [showModal, setShowModal] = useState(false);

  return (
    <div>
      <button onClick={() => setShowModal(true)}>Open Modal</button>
      <Modal
        showModal={showModal}
        closeModal={() => {setShowModal(false)}}
      >
        <div>Hello there!</div>
      </Modal>
    </div>
  );
};
0.2.6

9 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago