All Projects → trendmicro-frontend → react-modal

trendmicro-frontend / react-modal

Licence: MIT license
React Modal component

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to react-modal

ngx-simple-modal
A simple unopinionated framework to implement simple modal based behaviour in angular (v2+) projects.
Stars: ✭ 50 (+177.78%)
Mutual labels:  modal
JHTAlertController
A custom iOS alert that replaces the stock UIAlertController. Easily style the alert to match your app. Written in Swift for iOS.
Stars: ✭ 58 (+222.22%)
Mutual labels:  modal
react-native-lightning-modal
A performant bottom modal that works using React Native Reanimated 2
Stars: ✭ 20 (+11.11%)
Mutual labels:  modal
react-puzzle-confirm
React confirm modal, by matching puzzle piece
Stars: ✭ 15 (-16.67%)
Mutual labels:  modal
trashed
Trashed is an organizational tool designed to help users keep their communities clean.
Stars: ✭ 13 (-27.78%)
Mutual labels:  modal
react-accessible-modal
Accessible modal dialog component for React
Stars: ✭ 17 (-5.56%)
Mutual labels:  modal
react-native-card-animated-modal
An animated modal from a card item in a list for React Native.
Stars: ✭ 93 (+416.67%)
Mutual labels:  modal
modaltor
modal component for vuejs
Stars: ✭ 82 (+355.56%)
Mutual labels:  modal
angular-custom-modal
Angular2+ Modal / Dialog (with inner component support).
Stars: ✭ 30 (+66.67%)
Mutual labels:  modal
svelte-accessible-dialog
An accessible dialog component for Svelte apps
Stars: ✭ 24 (+33.33%)
Mutual labels:  modal
bs5-utils
A JavaScript utility package for Bootstrap 5 components.
Stars: ✭ 26 (+44.44%)
Mutual labels:  modal
vue-universal-modal
Universal modal plugin for Vue3
Stars: ✭ 57 (+216.67%)
Mutual labels:  modal
wechat-miniprogram-dialog
微信小程序弹窗组件 wxapp dialog component
Stars: ✭ 50 (+177.78%)
Mutual labels:  modal
eins-modal
Simple to use modal / alert / dialog / popup. Created with pure JS. No javascript knowledge required! Works on every browser and device! IE9
Stars: ✭ 30 (+66.67%)
Mutual labels:  modal
jquery.dialog.js
A lightweight replacement for the browser's default dialog boxes.
Stars: ✭ 17 (-5.56%)
Mutual labels:  modal
react-portalgun
Lightweight portal system for React. Mega seeds included 🔫
Stars: ✭ 75 (+316.67%)
Mutual labels:  modal
react-native-ios-modal
A react-native component for displaying a modal on iOS by natively wrapping a react-native view inside a UIViewController and presenting it.
Stars: ✭ 94 (+422.22%)
Mutual labels:  modal
tua-body-scroll-lock
🔐 Body scroll locking that just works with everything
Stars: ✭ 304 (+1588.89%)
Mutual labels:  modal
react-fusionui
☢️ Nuclear power-up for your UI.
Stars: ✭ 13 (-27.78%)
Mutual labels:  modal
react-native-popup
React Native Animated Popup Modal
Stars: ✭ 19 (+5.56%)
Mutual labels:  modal

react-modal build status Coverage Status

NPM

React Modal

Demo: https://trendmicro-frontend.github.io/react-modal

Installation

  1. Install the latest version of react and react-modal:
npm install --save react @trendmicro/react-modal
  1. At this point you can import @trendmicro/react-modal and its styles in your application as follows:
import Modal from '@trendmicro/react-modal';

// Be sure to include styles at some point, probably during your bootstraping
import '@trendmicro/react-modal/dist/react-modal.css';

Recommended Setup

Create a common components directory including both Buttons and Modal components, as shown below:

components/
  Buttons/
    index.js
  Modal/
    index.js

components/Buttons/index.js

import '@trendmicro/react-buttons/dist/react-buttons.css';

export { Button, ButtonGroup, ButtonToolbar } from '@trendmicro/react-buttons';

components/Modal/index.js

import '@trendmicro/react-modal/dist/react-modal.css';
import Modal from '@trendmicro/react-modal';

export default Modal;

Then, import Modal component in your code:

import Modal from './components/Modal';

Usage

import React from 'react';
import { Button } from './components/Buttons';
import Modal from './components/Modal';

export default ({ size = 'sm', closeModal, ...props }) => (
    <Modal {...props} size={size} onClose={closeModal}>
        <Modal.Header>
            <Modal.Title>
                Modal Title
            </Modal.Title>
        </Modal.Header>
        <Modal.Body padding>
            Modal Body
        </Modal.Body>
        <Modal.Footer>
            <Button
                btnStyle="primary"
                onClick={closeModal}
            >
                Save
            </Button>
            <Button
                btnStyle="default"
                onClick={closeModal}
            >
                Close
            </Button>
        </Modal.Footer>
    </Modal>
);

Examples

Prevent Body From Scrolling

You can create a ModalWrapper component that changes the body style on open and close.

import React, { PureComponent } from 'react';
import Modal from './components/Modal';

let bodyStyle = null;

class ModalWrapper extends PureComponent {
    static propTypes = {
        ...Modal.propTypes
    };

    static defaultProps = {
        ...Modal.defaultProps
    };

    componentWillReceiveProps(nextProps) {
        if (nextProps.show !== this.props.show) {
            if (nextProps.show) {
                this.changeBodyStyle();
            } else {
                this.restoreBodyStyle();
            }
        }
    }

    componentDidMount() {
        this.changeBodyStyle();
    }

    componentWillUnmount() {
        this.restoreBodyStyle();
    }

    changeBodyStyle() {
        if (bodyStyle) {
            return;
        }
        // Prevent body from scrolling when a modal is opened
        const body = document.querySelector('body');
        bodyStyle = {
            overflowY: body.style.overflowY
        };
        body.style.overflowY = 'hidden';
    }

    restoreBodyStyle() {
        if (bodyStyle) {
            const body = document.querySelector('body');
            body.style.overflowY = bodyStyle.overflowY;
            bodyStyle = null;
        }
    }

    render() {
        const { onClose, ...props } = this.props;

        return (
            <Modal
                {...props}
                onClose={() => {
                    this.restoreBodyStyle();
                    onClose();
                }}
            />
        );
    }
}

ModalWrapper.Overlay = Modal.Overlay;
ModalWrapper.Content = Modal.Content;
ModalWrapper.Header = Modal.Header;
ModalWrapper.Title = Modal.Title;
ModalWrapper.Body = Modal.Body;
ModalWrapper.Footer = Modal.Footer;

export default ModalWrapper;

API

Properties

Name Type Default Description
onClose Function A callback fired on clicking the overlay or the close button (x).
show Boolean true Whether the modal is visible.
showCloseButton Boolean true Whether the close button (x) is visible.
showOverlay Boolean true Display an overlay in the background. Defaults to true.
disableOverlayClick Boolean false Don't close the modal on clicking the overlay. Defaults to false.
overlayClassName String className to assign to modal overlay.
overlayStyle Object style to assign to modal overlay.
size String '' One of: 'xs', 'sm', 'md', 'lg', 'extra-small', 'small', 'medium', 'large', or an empty string. Defaults to empty string that will automatically resize to fit contents.

Size

Size Value Dimension
Auto '' 400px (minimum width)
Extra Small 'xs', 'extra-small' 400px (fixed width) x 240 px (minimum height)
Small 'sm', 'small' 544px (fixed width) x 304 px (minimum height)
Medium 'md', 'medium' 688px (fixed width) x 304 px (minimum height)
Large 'lg', 'large' 928px (fixed width) x 304 px (minimum height)

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].