Skip to content

Commit 7f11590

Browse files
committed
Added contained modal example
1 parent 0622d08 commit 7f11590

4 files changed

Lines changed: 81 additions & 14 deletions

File tree

docs/assets/style.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ body {
7272
margin-top: 10px;
7373
}
7474

75-
.bs-example .modal {
75+
.bs-example .static-modal .modal {
7676
position: relative;
7777
top: auto;
7878
right: auto;
@@ -137,3 +137,12 @@ body {
137137
.code-toggle.open {
138138
background: #f8f5ec;
139139
}
140+
141+
// Minimal CSS Needed for contained modals
142+
.modal-container {
143+
position: relative;
144+
}
145+
.modal-container .modal, .modal-container .modal-backdrop {
146+
position: absolute;
147+
}
148+

docs/examples/ModalContained.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/** @jsx React.DOM */
2+
3+
/**
4+
* You will want to include this bit of css
5+
*
6+
* .modal-container {
7+
* position: relative;
8+
* }
9+
* .modal-container .modal, .modal-container .modal-backdrop {
10+
* position: absolute;
11+
* }
12+
*/
13+
14+
15+
var ContainedModal = React.createClass({
16+
render: function() {
17+
return this.transferPropsTo(
18+
<Modal title='Contained Modal' animation>
19+
<div className="modal-body">
20+
Elit est explicabo ipsum eaque dolorem blanditiis doloribus sed id ipsam, beatae, rem fuga id earum? Inventore et facilis obcaecati.
21+
</div>
22+
<div className="modal-footer">
23+
<Button onClick={this.props.onRequestHide}>Close</Button>
24+
</div>
25+
</Modal>
26+
);
27+
}
28+
});
29+
30+
var Trigger = React.createClass({
31+
render: function() {
32+
return (
33+
<div className='modal-container' style={{height: 200}}>
34+
<ModalTrigger modal={<ContainedModal container={this} />} container={this}>
35+
<Button bsStyle="primary" bsSize="large">Launch contained modal</Button>
36+
</ModalTrigger>
37+
</div>
38+
);
39+
}
40+
});
41+
42+
React.renderComponent(<Trigger />, mountNode);

docs/examples/ModalStatic.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ function handleHide() {
55
}
66

77
var modalInstance = (
8-
<Modal title="Modal title"
9-
backdrop={false}
10-
animation={false}
11-
onRequestHide={handleHide}>
12-
<div className="modal-body">
13-
One fine body...
14-
</div>
15-
<div className="modal-footer">
16-
<Button>Close</Button>
17-
<Button bsStyle="primary">Save changes</Button>
18-
</div>
19-
</Modal>
8+
<div className="static-modal">
9+
<Modal title="Modal title"
10+
backdrop={false}
11+
animation={false}
12+
onRequestHide={handleHide}>
13+
<div className="modal-body">
14+
One fine body...
15+
</div>
16+
<div className="modal-footer">
17+
<Button>Close</Button>
18+
<Button bsStyle="primary">Save changes</Button>
19+
</div>
20+
</Modal>
21+
</div>
2022
);
2123

22-
React.renderComponent(modalInstance, mountNode);
24+
React.renderComponent(modalInstance, mountNode);

docs/src/ComponentsPage.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,20 @@ var ComponentsPage = React.createClass({
218218
<h3 id="modals-custom">Custom trigger</h3>
219219
<p>Use <code>&lt;OverlayMixin /&gt;</code> in a custom component to manage the modal's state yourself.</p>
220220
<ReactPlayground codeText={fs.readFileSync(__dirname + '/../examples/ModalOverlayMixin.js', 'utf8')} />
221+
222+
<h3 id="modals-custom">Contained Modal</h3>
223+
<p>You will need to add the following css to your project and ensure that your container has the <code>modal-container</code> class.</p>
224+
<pre>
225+
{React.DOM.code(null,
226+
".modal-container {\n" +
227+
" position: relative;\n" +
228+
"}\n" +
229+
".modal-container .modal, .modal-container .modal-backdrop {\n" +
230+
" position: absolute;\n" +
231+
"}\n"
232+
)}
233+
</pre>
234+
<ReactPlayground codeText={fs.readFileSync(__dirname + '/../examples/ModalContained.js', 'utf8')} />
221235
</div>
222236

223237
{/* Tooltip */}

0 commit comments

Comments
 (0)