UNPKG

2.87 kBJSXView Raw
1/* global $ */
2
3import React from 'react'
4
5var BootstrapButton = React.createClass({
6 getInitialState () {
7 return {'loading': false}
8 },
9 render () {
10 if (this.state.loading) {
11 return (<button type="button" className="btn btn-primary" disabled="disabled">
12 <span className="glyphicon glyphicon-refresh glyphicon-refresh-animate" />
13 </button>)
14 } else {
15 return (<button type="button" {...this.props} className="btn btn-primary">{this.props.children}</button>)
16 }
17 },
18 setLoading (isLoading, callback) {
19 this.setState({'loading': isLoading})
20 }
21})
22
23var BootstrapInput = React.createClass({
24 getInitialState () {
25 return { error: null, loading: null }
26 },
27 render () {
28 var classes = 'form-group '
29 let subView
30 if (this.state.loading) {
31 subView = (<span className="help-block"><span className="glyphicon glyphicon-refresh glyphicon-refresh-animate" /> {this.state.loading}</span>)
32 } else if (this.state.error) {
33 subView = (<span className="help-block">{this.state.error}</span>)
34 classes += 'has-error'
35 }
36 return (
37 <div className="{classes}">
38 <input ref="input" onKeyPress={this.onKeyPress} {...this.props} />
39 {subView}
40 </div>)
41 },
42 onKeyPress (e) {
43 if (this.props.onKeyPress) {
44 this.props.onKeyPress(e)
45 }
46 },
47 value () {
48 return this.refs.input.value
49 }
50})
51
52var BootstrapModal = React.createClass({
53 getInitialState () {
54 return {'title': this.props.title}
55 },
56 componentDidMount () {
57 $(this.refs.root).modal({backdrop: 'static', keyboard: false, show: true})
58 $(this.refs.root).on('hidden.bs.modal', this.handleHidden)
59 },
60 componentWillUnmount () {
61 $(this.refs.root).off('hidden.bs.modal', this.handleHidden)
62 },
63 close () {
64 $(this.refs.root).modal('hide')
65 },
66 open () {
67 $(this.refs.root).modal('show')
68 },
69 render () {
70 return (
71 <div className="modal fade" ref="root">
72 <div className="modal-dialog modal-lg">
73 <div className="modal-content">
74 <div className="modal-header">
75 <button
76 type="button"
77 className="close"
78 onClick={this.handleCancel}>
79 &times;
80 </button>
81 <h4>{this.state.title}</h4>
82 </div>
83 <div className="modal-body">
84 {this.props.children}
85 </div>
86 </div>
87 </div>
88 </div>
89 )
90 },
91 handleCancel () {
92 if (this.props.onClose) {
93 // Parent will take care of closing the modal
94 this.props.onClose()
95 } else {
96 this.close()
97 }
98 },
99 handleHidden () {
100 if (this.props.onHidden) {
101 this.props.onHidden()
102 }
103 }
104})
105
106exports.BootstrapButton = BootstrapButton
107exports.BootstrapModal = BootstrapModal
108exports.BootstrapInput = BootstrapInput