import _ from 'lodash'; import classnames from 'classnames'; import createFragment from 'react-addons-create-fragment'; import React from 'react'; import CustomScrollbars from '../ui/CustomScrollbars'; import ModalActions from './ModalActions'; import ModalTabs from './ModalTabs'; const METHODS_TO_BIND = ['handleTabChange']; export default class Modal extends React.Component { constructor() { super(); this.state = { activeTabId: null }; METHODS_TO_BIND.forEach((method) => { this[method] = this[method].bind(this); }); } getActiveTabId() { if (this.state.activeTabId) { return this.state.activeTabId; } return Object.keys(this.props.tabs)[0]; } handleTabChange(tab) { this.setState({activeTabId: tab.id}); } handleMenuWrapperClick(event) { event.stopPropagation(); } render() { let footer = null; let contentClasses = classnames('modal__content__wrapper', `modal--align-${this.props.alignment}`, `modal--size-${this.props.size}`, { 'modal--horizontal': this.props.orientation === 'horizontal', 'modal--vertical': this.props.orientation === 'vertical', 'modal--tabs-in-header': !this.props.tabsInBody, 'modal--tabs-in-body': this.props.tabsInBody }, this.props.classNames); let modalBody = [createFragment({'modal-body': this.props.content})]; let modalHeader = [createFragment({'modal-header': this.props.heading})]; let headerClasses = classnames('modal__header', { 'has-tabs': this.props.tabs }); let tabs = null; if (this.props.tabs) { let activeTabId = this.getActiveTabId(); let activeTab = this.props.tabs[activeTabId]; let ModalContentComponent = activeTab.content; let modalContentData = activeTab.props; let tabs = ( ); if (this.props.tabsInBody) { modalBody = [tabs]; } else { modalHeader.push(tabs); } modalBody.push(
); } if (this.props.actions) { footer = (
); } return (
{modalHeader}
{modalBody} {footer}
); } } Modal.defaultProps = { alignment: 'left', classNames: null, size: 'medium', orientation: 'horizontal', tabsInBody: false };