在react-boostrap模态上指定/设置宽度和高度

时间:2015-09-17 07:22:26

标签: size jsx react-bootstrap

如何将动态宽度和高度应用于react-bootstrap模态窗口? 我已经检查了react-bootstrap文档here,但无法弄清楚如何做到这一点。 实际上,宽度和高度道具的值将是动态的(可以是任何值),因为这将是我的应用程序中的可重用组件(在许多页面上使用),因此无法通过某些CSS类应用宽度/高度。

文档中提到的'bsSize'属性也不起作用,虽然xs,md,lg的预定义大小不是我想要的,而是我需要通过道具在模态上设置宽度和高度。

这是我的示例JSX代码:

var MyWindow = React.createClass({
    getInitialState() {
        return { show: true };
    },
    close() {
        this.setState({ show: false });
    },
    open() {
        this.setState({ show: true });
    },
    save() {

    },
    render: function () {

        var Button = ReactBootstrap.Button,
            Modal = ReactBootstrap.Modal,
            ModalBody = ReactBootstrap.ModalBody,
            ModalHeader = ReactBootstrap.ModalHeader,
            ModalFooter = ReactBootstrap.ModalFooter,
            ModalTitle = ReactBootstrap.ModalTitle;

        return (
            <Modal show={this.state.show} onHide={this.close}>
                <ModalHeader closeButton>
                    <ModalTitle>My Cool Window</ModalTitle>
                </ModalHeader>
                <ModalBody>
                    <h4>Text in a modal</h4>
                    <p>Duis mollis, est non commodo luctus</p>
                </ModalBody>
                <ModalFooter>
                    <Button onClick={this.close}>Cancel</Button>
                    <Button bsStyle="primary" onClick={this.save}>Save</Button>
                </ModalFooter>
            </Modal>
        );

    }
});

React.render(<MyWindow width={700} height={400} />, mountNode);

1 个答案:

答案 0 :(得分:9)

根据它的documentation,你必须自定义你自己的css类,通过modal的prop dialogClassName来实现你想要的风格。

因此我们可能会在下面提供my.jsx代码:

<Modal dialogClassName="my-modal">
</Modal>

下面有my.css

.my-modal {
    width: 90vw    /* Occupy the 90% of the screen width */
    max-width: 90vw;
} 

然后你将获得你的习惯模式!