2.2.17 • Published 4 years ago

bee-modal v2.2.17

Weekly downloads
605
License
MIT
Repository
github
Last release
4 years ago

bee-modal

npm version Build Status Coverage Status

Browser Support

IEChromeFirefoxOperaSafari
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是否弹出遮罩层booleantrue
backdropClosable遮罩层点击是否触发关闭booleantrue
keyboardesc触发关闭boolean-
animation显隐时是否使用动画booleantrue
dialogComponentClass传递给模态框使用的元素string/element-
dialogClassName传递给模态框的样式class-
autoFocus自动设置焦点booleantrue
enforceFocus防止打开时焦点离开模态框booleantrue
show是否打开模态框boolean-
width模态框宽度,如只传数字则会拼接默认单位 px。例如 100px/100/100%/100rem/100emstring/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添加到背景元素的styleobject-
backdropClassName添加到背景元素的classstring-
transition动画组件function-
dialogTransitionTimeout设置动画超时时间function-
backdropTransitionTimeout设置背景动画超时时间function-
manager管理模态框状态的组件required-
draggable设置模态框是否可拖拽boolfalse
resizable设置模态框是否可resizeboolfalse
resizeClassName设置拖拽dom的class名称string-
onResizeStartresize开始时的回调function-
onResizeresize时的回调function-
onResizeStopresize结束时的回调function-
minWidthresize时模态框的最小宽度number/string200
minHeightresize时模态框的最小高度number/string150
maxWidthresize时模态框的最大宽度number/string-
maxHeightresize时模态框的最大高度number/string-

Modal.Header

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

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关闭模态框

开发调试

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

4 years ago

2.2.16

4 years ago

2.2.15

4 years ago

2.2.14

4 years ago

2.2.14-beta.1

4 years ago

2.2.13

4 years ago

2.2.12

4 years ago

2.2.11

4 years ago

2.2.10

4 years ago

2.2.9

4 years ago

2.2.8

5 years ago

2.2.7

5 years ago

2.2.6

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.1.19

5 years ago

2.2.1

5 years ago

2.1.16

5 years ago

2.2.0

5 years ago

2.1.18

5 years ago

2.1.17

5 years ago

2.1.15

5 years ago

2.1.14

5 years ago

2.1.13

5 years ago

2.1.12

5 years ago

2.1.11

5 years ago

2.1.10

5 years ago

2.1.9

5 years ago

2.1.9-alpha.0

5 years ago

2.1.8

5 years ago

2.1.7

5 years ago

2.1.6

5 years ago

2.1.5-alpha.0

6 years ago

2.1.4

6 years ago

2.1.5

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.2-alpha.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.1.0-beta.0

6 years ago

2.0.22

6 years ago

2.0.22-alpha.0

6 years ago

2.0.21

6 years ago

2.0.21-beta.0

6 years ago

2.0.20

6 years ago

2.0.19

6 years ago

2.0.18

6 years ago

2.0.17

6 years ago

2.0.16

6 years ago

2.0.15

6 years ago

2.0.14

6 years ago

2.0.13

6 years ago

2.0.12

6 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.9-alpha.0

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.7-alpha.3

6 years ago

2.0.7-alpha.2

6 years ago

2.0.7-alpha.1

6 years ago

2.0.7-alpha.0

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.2.8

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago