1.0.11 • Published 4 years ago

lightweight-react-modal v1.0.11

Weekly downloads
7
License
ISC
Repository
github
Last release
4 years ago

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.
1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago