パッケージの詳細

bee-modal

tinper-bee897MIT2.2.17

ModalDialogl ui component for react

react, react-component, bee-modal, iuap-design

readme

bee-modal

npm version Build Status Coverage Status

Browser Support

IE Chrome Firefox Opera Safari
IE 9+ ✔ Chrome 31.0+ ✔ Firefox 31.0+ ✔ Opera 30.0+ ✔ Safari 7.0+ ✔

react bee-modal component for tinper-bee

模态框组件

使用方法

import Modal from 'bee-modal';

class ModalDemo extends Component {
    constructor(props) {
        super(props);
        this.state = {
            showModal: false
        };
        this.close = this.close.bind(this);
        this.open = this.open.bind(this);
    }

    close() {
        this.setState({ showModal: false });
    }

    open() {
        this.setState({ showModal: true });
    }
    render () {
        return (
            <div>
              <Button color="primary" size="large" onClick={this.open}>
                点击打开模态框
              </Button>
              <Modal show = {
                  this.state.showModal
              }
              onHide = {
                  this.close
              }>
                <Modal.Header>
                  <Modal.Title>标题</Modal.Title>
                </Modal.Header>

                <Modal.Body>
                  正文描述。。。
                </Modal.Body>

                <Modal.Footer>
                  <Button>关闭</Button>
                  <Button color="primary">确认</Button>
                </Modal.Footer>

              </Modal>
            </div>
        )
    }
}

);

ReactDOM.render(
        <ModalDemo />
        , document.getElementById('target'));

样式引入

  • 可以使用link引入build目录下Modal.css
    <link rel="stylesheet" href="./node_modules/bee-modal/build/Modal.css">
  • 可以在js中import样式
    import "./node_modules/bee-modal/src/Modal.scss"
    //或是
    import "./node_modules/bee-modal/build/Modal.css"

API

Modal

参数 说明 类型 默认值
backdrop 是否弹出遮罩层 boolean true
backdropClosable 遮罩层点击是否触发关闭 boolean true
keyboard esc触发关闭 boolean -
animation 显隐时是否使用动画 boolean true
dialogComponentClass 传递给模态框使用的元素 string/element -
dialogClassName 传递给模态框的样式 class -
autoFocus 自动设置焦点 boolean true
enforceFocus 防止打开时焦点离开模态框 boolean true
show 是否打开模态框 boolean -
width 模态框宽度,如只传数字则会拼接默认单位 px。例如 100px/100/100%/100rem/100em string/number -
onHide 关闭时的钩子函数 function -
size 模态框尺寸 sm/lg/xlg -
width 自定义模态框尺寸 string/number -
onEnter 开始显示时的钩子函数 function -
onEntering 显示时的钩子函数 function -
onEntered 显示完成后的钩子函数 function -
onExit 隐藏开始时的钩子函数 function -
onExiting 隐藏进行时的钩子函数 function -
onExited 隐藏结束时的钩子函数 function -
container 容器 DOM元素\React组件\或者返回React组件的函数 -
onShow 当模态框显示时的钩子函数 function -
renderBackdrop 返回背景元素的函数 function -
onEscapeKeyUp 响应ESC键时的钩子函数 function -
onBackdropClick 点击背景元素的函数 function -
backdropStyle 添加到背景元素的style object -
backdropClassName 添加到背景元素的class string -
transition 动画组件 function -
dialogTransitionTimeout 设置动画超时时间 function -
backdropTransitionTimeout 设置背景动画超时时间 function -
manager 管理模态框状态的组件 required -
draggable 设置模态框是否可拖拽 bool false
resizable 设置模态框是否可resize bool false
resizeClassName 设置拖拽dom的class名称 string -
onResizeStart resize开始时的回调 function -
onResize resize时的回调 function -
onResizeStop resize结束时的回调 function -
minWidth resize时模态框的最小宽度 number/string 200
minHeight resize时模态框的最小高度 number/string 150
maxWidth resize时模态框的最大宽度 number/string -
maxHeight resize时模态框的最大高度 number/string -

Modal.Header

参数 说明 类型 默认值
closeButton 是否显示关闭按钮 boolean false

Modal.method()

包括:

  • Modal.info
  • Modal.success
  • Modal.error
  • Modal.warning
  • Modal.confirm

以上均为一个函数,参数为 object,具体属性如下: |参数|说明|类型|默认值| |:---|:-----|:----|:------| |cancelText|取消按钮文字|string|取消| |okText|确认按钮文字|string|确定| |okType|确认按钮类型,取值范围(primary/secondary/success/info/warning/danger/dark/light)|string|primary| |title|标题|string/ReactNode|-| |content|内容|string/ReactNode|-| |className|容器类名|string|-| |icon|自定义图标|ReactNode|<Icon type="uf-qm-c"/>| |backdrop|是否弹出遮罩层/点击遮罩层是否触发关闭|boolean/"static"|true| |width|宽度|string/number|400| |onCancel|取消回调,参数为关闭函数,返回 promise 时 resolve 后自动关闭|function|-| |onOk|点击确定回调,参数为关闭函数,返回 promise 时 resolve 后自动关闭|function|-|

以上函数调用后,会返回一个引用,可以通过该引用更新和关闭弹窗。

const modal = Modal.info();

modal.update({
  title: '修改的标题',
  content: '修改的内容',
});

modal.destroy();
  • Modal.destroyAll 使用 Modal.destroyAll() 可以销毁弹出的确认窗(即上述的 Modal.info、Modal.success、Modal.error、Modal.warning、Modal.confirm)。通常用于路由监听当中,处理路由前进、后退不能销毁确认对话框的问题,而不用各处去使用实例的返回值进行关闭(modal.destroy() 适用于主动关闭,而不是路由这样被动关闭) ``` import { browserHistory } from 'react-router';

// router change browserHistory.listen(() => { Modal.destroyAll(); });



## 已支持的键盘操作

|按键|功能|
|:---|:----|
|esc |关闭模态框|


#### 开发调试

```sh
$ npm install -g bee-tools
$ git clone https://github.com/tinper-bee/bee-modal
$ cd bee-modal
$ npm install
$ npm run dev

更新履歴

2.2.13 (2021-02-20)

Bug Fixes

  • Modal停止拖动的时候处理坐标的小数位 (e6b08f3)

2.2.12 (2021-02-20)

Bug Fixes

  • 先resize再拖动时有闪动 (9e95f70)

2.2.11 (2021-01-29)

Bug Fixes

  • 火狐浏览器拖拽问题兼容 (a2aa4e2)

2.2.10 (2021-01-15)

Bug Fixes

  • 弹框拖动的时候阻止事件冒泡 (36c4b21)

2.2.9 (2021-01-07)

Bug Fixes

2.2.8 (2020-12-10)

Bug Fixes

  • 拖拽模态框点击头部会定位到左上角 (a141b5d)

2.2.7 (2020-12-09)

Bug Fixes

  • 含有拖拽的模态框点击时会向左上角抖动一下 (4407a0a)

2.2.6 (2020-11-12)

Bug Fixes

  • resiable draggable centered 共用时不能向上拖拽 (4ec5a05)

2.2.5 (2020-11-10)

Bug Fixes

  • 修复IE11的高度异常问题 (0c0423a)

2.2.4 (2020-08-15)

Features

  • confirm字体改为12px (476457b)

2.2.3 (2020-08-06)

2.2.2 (2020-08-05)

2.2.1 (2020-07-31)

2.2.0 (2020-07-30)

2.1.18 (2020-07-07)

Features

  • needScroll支持传入number类型的值 (ad6c103)

2.1.17 (2020-07-07)

Bug Fixes

  • 去掉 pointer-events 影响 (f086dd8)

Features

  • 新增needScroll属性,解决打开模态框滚动到最顶部的问题 (7589392)

2.1.16 (2020-05-28)

Bug Fixes

  • 去掉 pointer-events 影响 (f086dd8)

2.1.15 (2020-04-24)

Bug Fixes

2.1.14 (2020-04-10)

Features

  • bee-modal: 关闭后 还原draging draged 属性 (1f54e74)

2.1.13 (2020-04-07)

Bug Fixes

  • bee-modal: centered属性影响模态框无法向上拖动 (6db1311)

2.1.12 (2020-03-26)

Bug Fixes

  • Confirm 按esc不触发close事件 (7e70b13)

2.1.11 (2020-03-12)

Features

  • bee-modal: confirm2样式修改 (a83c34c)

2.1.10 (2020-03-03)

Features

  • bee-modal: confirm2样式修改 (f0a0001)

2.1.9 (2020-02-28)

Bug Fixes

  • content高度自由伸缩 (1ca1928)

2.1.8 (2020-02-21)

2.1.7 (2020-02-20)

Features

  • bee-modal: api调用方式新增locale属性,设置按钮文字 (e7b5a8a)

2.1.6 (2020-02-15)

Bug Fixes

  • 修复 container 设置无效问题 (2ac3dd0)

2.1.5 (2019-12-18)

2.1.4 (2019-12-17)

2.1.3 (2019-11-25)

2.1.2 (2019-09-24)

2.1.1 (2019-09-16)

2.1.0 (2019-08-31)

2.0.22 (2019-08-20)

2.0.21 (2019-07-30)

2.0.20 (2019-07-11)

2.0.19 (2019-06-27)

2.0.18 (2019-06-26)

Features

  • bee-modal: icon版本修改 (f52c2af)

2.0.17 (2019-06-26)

Features

  • bee-modal: 设置可拖拽范围 (ad1f183)

2.0.16 (2019-06-24)

Features

2.0.14 (2019-05-29)

2.0.13 (2019-05-16)

Features

  • bee-modal: 依赖bee-overlay改为bee-overlay-modal版本 (a77d557)

2.0.12 (2019-05-15)

Features

  • bee-modal: container不传即为body的时候不计算isOverFlowing (d1b9458)

2.0.11 (2019-05-15)

Features

  • bee-modal: 改变窗口大小加判断 (e285dd3)

2.0.10 (2019-05-14)

2.0.9 (2019-05-10)

2.0.8 (2019-04-25)

2.0.7 (2019-04-24)

2.0.6 (2019-04-23)

2.0.5 (2019-04-10)

2.0.4 (2019-04-08)

2.0.3 (2019-04-04)

2.0.2 (2019-04-02)

2.0.1 (2019-04-02)

2.0.0 (2019-03-05)

1.0.10 (2018-12-12)

1.0.9 (2018-11-21)

1.0.8 (2018-11-20)

1.0.7 (2018-11-20)

Features

  • bee-modal: width宽度 px,数字,rem,em,% 适配 (edbe746)

1.0.6 (2018-11-19)

Bug Fixes

1.0.5 (2018-11-16)

Bug Fixes

  • bee-modal: &timer;改为 uf-close (a903897)

1.0.4 (2018-07-04)

Bug Fixes

  • demo (2c58054)
  • demo (3eea95e)
  • firefox显示bug 锁定dom-helpers ver 3.0.0 (a8dfbcd)
  • ie9 transition buf (41a07ef)
  • 修改示例 (c7eb650)
  • bee-modal: Modal组件在react16版本以上时,出现ref获取bug (d423755)