AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
| 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and limitations under the License. |
| 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import React from 'react'; |
| 17 | import ReactDOM from 'react-dom'; |
| 18 | import BootstrapModal from 'react-bootstrap/lib/Modal.js'; |
| 19 | |
| 20 | let nextModalId = 0; |
| 21 | |
| 22 | export default class Modal extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 23 | static Header = BootstrapModal.Header; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 24 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 25 | static Title = BootstrapModal.Title; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 26 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 27 | static Footer = BootstrapModal.Footer; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 28 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 29 | static Body = class ModalBody extends React.Component { |
| 30 | render() { |
| 31 | let { children, ...props } = this.props; |
| 32 | return ( |
| 33 | <BootstrapModal.Body {...props}>{children}</BootstrapModal.Body> |
| 34 | ); |
| 35 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 36 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 37 | componentDidMount() { |
| 38 | let element = ReactDOM.findDOMNode(this); |
| 39 | element.addEventListener('click', event => { |
| 40 | if (event.target.tagName === 'A') { |
| 41 | event.preventDefault(); |
| 42 | } |
| 43 | }); |
| 44 | ['wheel', 'mousewheel', 'DOMMouseScroll'].forEach(eventType => |
| 45 | element.addEventListener(eventType, event => |
| 46 | event.stopPropagation() |
| 47 | ) |
| 48 | ); |
| 49 | } |
| 50 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 51 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 52 | componentWillMount() { |
| 53 | this.modalId = `dox-ui-modal-${nextModalId++}`; |
| 54 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 55 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 56 | componentDidMount() { |
| 57 | this.ensureRootClass(); |
| 58 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 59 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 60 | componentDidUpdate() { |
| 61 | this.ensureRootClass(); |
| 62 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 63 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 64 | ensureRootClass() { |
| 65 | let element = document.getElementById(this.modalId); |
| 66 | while (element && !element.hasAttribute('data-reactroot')) { |
| 67 | element = element.parentElement; |
| 68 | } |
| 69 | if (element && !element.classList.contains('dox-ui')) { |
| 70 | element.classList.add('dox-ui'); |
| 71 | } |
| 72 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 73 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 74 | render() { |
| 75 | let { children, ...props } = this.props; |
| 76 | return ( |
| 77 | <BootstrapModal {...props} id={this.modalId}> |
| 78 | {children} |
| 79 | </BootstrapModal> |
| 80 | ); |
| 81 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 82 | } |