[关闭]
@zhangning16 2018-03-18T11:54:56.000000Z 字数 1176 阅读 275

组件库文档

Modal对话框

模态对话框。

How to use?

  1. import React, { Component } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import { modal } from 'ceshi-stone';
  4. class App extends Component {
  5. openModal = () => {
  6. const myModal = modal.open({
  7. "size": 'sm',
  8. "template": this.getContentComponent(),
  9. "onCancel": this.closeModal,
  10. "onOk": this.okModal
  11. });
  12. // 该组件提供代码关闭弹框的手段,调用close方法即可!
  13. setTimeout(() => {
  14. myModal.close()
  15. }, 2000);
  16. }
  17. getContentComponent = () => {
  18. return (
  19. <div>
  20. <div className="modal-header">
  21. <span>提示</span>
  22. </div>
  23. <div className="modal-body">
  24. <p>如果没有保存,数据将会丢失,确认取消吗?</p>
  25. </div>
  26. </div>
  27. )
  28. }
  29. render(){
  30. return (
  31. <div>
  32. <Button onClick={this.openModal}>Open Modal</Button>
  33. </div>
  34. )
  35. }
  36. }
  37. ReactDOM.render(<App />, document.getElementById('root'));

组件方法

方法名 参数 说明
open 接受一个对象,包含所有的参数 目前调用modal组件的唯一方法,调用后会返回这个组件本身,可用于后期手动移除!
close 无需传递参数 关闭modal组件

Options

属性名 类型 默认值 说明
mask Boolean true 是否需要蒙层
closeable Boolean true 是否展示右上角关闭按钮
footer Boolean true 是否展示底部按钮(确认、取消)
cancelBtn Boolean true 是否显示取消按钮
okText String '确定' 定义确定按钮文字
cancelText String '取消' 定义取消按钮文字
template JSX 无默认值 Component 模态框内部内容
size String 'sm' ['sm','','lg']或false 模态框的大小 默认'sm' 'sm' {width:'400px',height:'300px'}, size 为空或false时 大小为{width:'600px',height:'400px'} 'lg' {width:'900px',height:'600px'}

Events

方法名称 说明 参数
onCancel 传入模态框的回调函数,关闭时触发 待确认
onOK 传入模态框的回调函数,点击确认时触发 待确认
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注