Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lightweight-react-modal

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lightweight-react-modal

lightweight react modal

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
decreased by-38.46%
Maintainers
1
Weekly downloads
 
Created
Source

React Modal

Lightweight react modal component.

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
customClassNamesshape({ 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 get better control of modal 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

Package last updated on 06 Jul 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc