Skip to content

Commit 5f7cab6

Browse files
ajainarayananeddywashere
authored andcommitted
feat(ModalClassName): Adds custom class name for modal-dialogs for namespacing (#111)
Users should be able to style modals and should be able to namespace the same. This will help us have styling specific for modals and the rest be generic.
1 parent 96ecb1f commit 5f7cab6

5 files changed

Lines changed: 34 additions & 5 deletions

File tree

docs/lib/Components/ModalsPage.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ export default class ModalsPage extends React.Component {
1212
<Helmet title="Modals" />
1313
<h3>Modals</h3>
1414
<div className="docs-example">
15-
<ModalExample />
15+
<div className="btn-group">
16+
<div className="btn">
17+
<ModalExample buttonLabel="Launch Modal" />
18+
</div>
19+
<div className="btn">
20+
<ModalExample
21+
buttonLabel="Launch Modal with custom className"
22+
className="my-custom-modal"
23+
/>
24+
</div>
25+
</div>
1626
</div>
1727
<pre>
1828
<PrismCode className="language-jsx">

docs/lib/examples/Modal.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class ModalExample extends React.Component {
2222
render() {
2323
return (
2424
<div>
25-
<Button color="danger" onClick={this.toggle}>Launch Modal</Button>
26-
<Modal isOpen={this.state.modal} toggle={this.toggle}>
25+
<Button color="danger" onClick={this.toggle}>{this.props.buttonLabel}</Button>
26+
<Modal isOpen={this.state.modal} toggle={this.toggle} className={this.props.className}>
2727
<ModalHeader toggle={this.toggle}>Modal title</ModalHeader>
2828
<ModalBody>
2929
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

src/Modal.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const propTypes = {
1010
toggle: PropTypes.func.isRequired,
1111
onEnter: PropTypes.func,
1212
onExit: PropTypes.func,
13-
children: PropTypes.node
13+
children: PropTypes.node,
14+
className: PropTypes.any
1415
};
1516

1617
const defaultProps = {
@@ -155,7 +156,9 @@ class Modal extends React.Component {
155156
tabIndex="-1"
156157
>
157158
<div
158-
className={this.props.size ? `modal-dialog modal-${this.props.size}` : 'modal-dialog'}
159+
className={classNames('modal-dialog', this.props.className, {
160+
[`modal-${this.props.size}`]: this.props.size
161+
})}
159162
role="document"
160163
ref={(c) => (this._dialog = c)}
161164
>

test/Modal.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ describe('Modal', () => {
3333
wrapper.unmount();
3434
});
3535

36+
it('should render with class "modal-dialog" and have custom class name if provided', () => {
37+
isOpen = true;
38+
const wrapper = mount(
39+
<Modal isOpen={isOpen} toggle={toggle} className="my-custom-modal">
40+
Yo!
41+
</Modal>
42+
);
43+
44+
jasmine.clock().tick(300);
45+
expect(wrapper.children().length).toBe(0);
46+
expect(document.getElementsByClassName('modal-dialog').length).toBe(1);
47+
expect(document.getElementsByClassName('my-custom-modal').length).toBe(1);
48+
wrapper.unmount();
49+
});
50+
3651
it('should render with the class "modal-${size}" when size is passed', () => {
3752
isOpen = true;
3853
const wrapper = mount(

webpack.base.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12
const path = require('path');
23
const webpack = require('webpack');
34

0 commit comments

Comments
 (0)