UNPKG

@ttk/component

Version:

ttk组件库

80 lines (66 loc) 1.74 kB
import React, { PureComponent } from 'react' import { Modal } from 'antd' import localeWrapper from '../localeWrapper'; import classNames from 'classnames' import Drag from '../drag' export class DragTitle extends PureComponent { updateTransform = transformStr => { this.modalDom.style.transform = transformStr; }; componentDidMount() { let modalObj = document.getElementsByClassName("ant-modal") if (modalObj) { let modalCount = modalObj.length if (modalCount == 1) { this.modalDom = document.getElementsByClassName( "ant-modal" //modal的class是ant-modal )[0]; } else if (modalCount > 1) { this.modalDom = document.getElementsByClassName( "ant-modal" //modal的class是ant-modal )[modalCount - 1]; } } } render() { const title = this.props.title if (typeof title == 'string') { return ( <Drag updateTransform={this.updateTransform}> <div title={title}>{title}</div> </Drag> ) } else { return ( <Drag updateTransform={this.updateTransform}> <div >{title}</div> </Drag> ) } } } class ModalComponent extends PureComponent { render() { var { children, title, allowDrag, ...otherProps } = this.props let className = classNames({ 'mk-modal': true }) allowDrag = allowDrag === false ? false : true if (allowDrag) { title = ( <DragTitle title={title} /> ) } return localeWrapper( <Modal visible={true} title={title} className={className} {...otherProps} children={children} /> ) } } export default ModalComponent