Socket
Socket
Sign inDemoInstall

lightweight-react-modal

Package Overview
Dependencies
39
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    lightweight-react-modal

lightweight react modal


Version published
Weekly downloads
14
increased by55.56%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

React Modal

Lightweight react modal component.
Demo can be found here: Click

Installation

npm i lightweight-react-modal

Usage

import React from 'react';
import {
    Modal,
    ModalHeader,
    ModalContent,
    ModalFooter,
} from 'lightweight-react-modal';

<Modal>
    <ModalHeader>
        Modal Header.
    </ModalHeader>
    <ModalContent>
        Modal Content.
    </ModalContent>
    <ModalFooter>
        Modal Footer.
    </ModalFooter>
</Modal>

PropTypes

Modal
NameTypeDescriptionDefault value
onClosefuncOn close callback.null
fluidfuncSets the width and height to 90% of the screen.false
closableboolMakes modal closable/unclosable.true
maxHeightnumberSets modal max height.500
minHeightnumberSets modal min height.100
maxWidthnumberSets modal max width.500
minWidthnumberSets modal min width.200
customClassNames{ wrapper: string, modal: string, closeBtn: string, overlay:string }Modal custom classNames.null
closeButtonIconnodeModifies close button icon.null
ModalHeader, ModalContent, ModalFooter.
NameTypeDescriptionDefault value
classNamestringApplies extra className.null

Modal Context

You can use ModalContext to have better control of modal state in your application. With help of ModalContext you can trigger one or multiple modals from anywhere in our application.

Usage

Default Example:
import React from 'react';
import ReactDom from 'react-dom';
import {
    Modal,
    ModalContent,
    ModalProvider,
} from 'lightweight-react-modal';

const ModalExample = ({ modal }) => (
    <>
        <button
            type="button"
            onClick={modal.toggle('modal_name')}
        >
            Toggle modal
        </button>
        {modal.isOpen('modal_name') ? (
            <Modal>
                <ModalContent>
                    Modal
                </ModalContent>
            </Modal>
        ) : null}
    </>
);

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

ReactDom.render(<App />, document.getElementById('app'));
Modal Context hook example:
import React from 'react';
import ReactDom from 'react-dom';
import {
    Modal,
    ModalContent,
    ModalProvider,
    useModalContext,
} from 'lightweight-react-modal';

const ModalHookExample = ({ modal }) => {
    const modal = useModalContext();

    return (
        <>
            <button
                type="button"
                onClick={modal.toggle('modal_name')}
            >
                Toggle modal
            </button>
            {modal.isOpen('modal_name') ? (
                <Modal>
                    <ModalContent>
                        Modal
                    </ModalContent>
                </Modal>
            ) : null}
        </>
    );
};

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

ReactDom.render(<App />, document.getElementById('app'));

PropTypes

ModalProvider methods

NameparamsDescription
open(name)name: string/numberopens modal.
close(name)name: string/numbercloses modal.
toggle(name)name: string/numbertoggles modal.
closeAll()-closes all opened modals.
isOpen(name)name: string/numberchecks if modal is opened.
isClose(name)name: string/numberchecks if modal is closed.
list-returns list of opened modals.

Keywords

FAQs

Last updated on 30 Jul 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc