New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@trendmicro/react-modal

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trendmicro/react-modal

Trend Micro Components: React Modal

  • 0.7.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
349
decreased by-44.43%
Maintainers
2
Weekly downloads
 
Created
Source

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';

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, { Component, PropTypes } from 'react';
import { Button } from './components/Buttons';
import Modal from './components/Modal';

class ModalDialog extends Component {
    static propTypes = {
        state: PropTypes.object,
        actions: PropTypes.object
    };

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

        return (
            <Modal
                show={state.showModal}
                onClose={actions.closeModal}
            >
                <Modal.Header>
                    <Modal.Title>
                        Modal Title
                    </Modal.Title>
                </Modal.Header>
                <Modal.Body padding>
                    Modal Body
                </Modal.Body>
                <Modal.Footer>
                    <Button
                        btnStyle="primary"
                        onClick={actions.closeModal}
                    >
                        Save
                    </Button>
                    <Button
                        onClick={actions.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, { Component } from 'react';
import Modal from '@trendmicro/react-modal';
import '@trendmicro/react-modal/dist/react-modal.css';

class ModalWrapper extends Component {
    static propTypes = {
        ...Modal.propTypes
    };
    static defaultProps = {
        ...Modal.defaultProps
    };

    bodyStyle = null;

    componentWillReceiveProps(nextProps) {
        if (nextProps.show !== this.props.show) {
            if (nextProps.show) {
                this.changeBodyStyle();
            } else {
                this.restoreBodyStyle();
            }
        }
    }
    componentWillUnmount() {
        this.restoreBodyStyle();
    }
    changeBodyStyle() {
        if (this.bodyStyle) {
            return;
        }
        // Prevent body from scrolling when a modal is opened
        const body = document.querySelector('body');
        this.bodyStyle = {
            overflowY: body.style.overflowY
        };
        body.style.overflowY = 'hidden';
    }
    restoreBodyStyle() {
        if (this.bodyStyle) {
            const body = document.querySelector('body');
            body.style.overflowY = this.bodyStyle.overflowY;
            this.bodyStyle = null;
        }
    }
    render() {
        const { onOpen, onClose, ...props } = this.props;

        return (
            <Modal
                {...props}
                onOpen={() => {
                    this.changeBodyStyle();
                    onOpen();
                }}
                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

NameTypeDefaultDescription
closeOnOverlayClickBooleantrueBy default the modal is closed when clicking the overlay area. You can pass 'closeOnOverlayClick' prop with 'false' value if you want to prevent this behavior.
onCloseFunctionA callback fired when clicking the close button (x×) or the overlay area.
onOpenFunctionA callback fired after opening a modal.
showBooleantrueSpecify whether to show the modal.
showCloseButtonBooleantrueSpecify whether the modal should contain a close button (x).
showOverlayBooleantruePass 'showOverlay' prop with 'true' value to add an overlay to the background, and 'false' otherwise.
sizeString'xs'
  • Extra Small (400px x 240px): 'xs' or 'extra-small'
  • Small (544px x 304px): 'sm' or 'small'
  • Medium (688px x 304px): 'md' or 'medium'
  • Large (928px x 304px): 'lg' or 'large'

License

MIT

Keywords

FAQs

Package last updated on 17 Jul 2017

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