Skip to content

Commit 2620995

Browse files
committed
easily overwrite just the styles you want, v 0.3.0
1 parent f399d6e commit 2620995

File tree

9 files changed

+203
-159
lines changed

9 files changed

+203
-159
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
An incredibly simple modal dialog, because after writing [this post](http://reactjsnews.com/modals-in-react/), I found none of the ones listed let you easily overwrite the css!
1818

1919
~~~js
20-
import Modal, {closeClass} from 'simple-react-modal'
20+
import Modal, {closeStyle} from 'simple-react-modal'
2121

2222
export default class App extends React.Component{
2323

@@ -40,12 +40,14 @@ export default class App extends React.Component{
4040
<div>
4141
<a onClick={this.show.bind(this)}>Open Modal</a>
4242
<Modal
43-
className="test-class" //this will completely overwrite the default css
43+
className="test-class" //this will completely overwrite the default css completely
44+
style={{background: 'red'}} //overwrites the default background
45+
containerStyle={{background: 'blue'}} //changes styling on the inner content area
4446
closeOnOuterClick={true}
4547
show={this.state.show}
4648
onClose={this.close.bind(this)}>
4749

48-
<a style={closeClass} onClick={this.close.bind(this)}>X</a>
50+
<a style={closeStyle} onClick={this.close.bind(this)}>X</a>
4951
<div>hey</div>
5052

5153
</Modal>
@@ -61,8 +63,12 @@ export default class App extends React.Component{
6163
- `show`: true or false
6264
- `onClose`: when the modal is sending the close event (only happens is `closeOnOuterClick` is true)
6365
- `className`: this will allow you to completely change the default css located in the component.
66+
- `containerStyle`: changes styles on the modal content area
6467

65-
Everything else will be merged and you're free to apply any props you want. Minimum required props would be `show`. You can optionally pull in `modalClass` and merge any styles with it and set the style prop on the modal.
68+
Minimum required props would be `show` and `onClose`. You can optionally pull in `closeStyle` to use the default close button.
6669

67-
The big difference is that you can require the css from 'simple-react-modal/dist/modal' and easily add other classes that make it look however you like.
68-
Customizing the style is easy, to target the actual content area it will be `.your-class div`.
70+
###Why this modal?
71+
72+
The big difference is that you can use the default style, overwrite just the things you want with the `style` or `containerStyle` props, or throw on a class name and completely style everything yourself.
73+
74+
Customizing the style via a css class is easy, to target the actual content area it will be `.your-class div`.

build/simple-modal.js

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Object.defineProperty(exports, '__esModule', {
44
value: true
55
});
66

7-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8-
97
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
108

119
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
1210

11+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
12+
1313
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1414

1515
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
@@ -20,48 +20,9 @@ var _react = require('react');
2020

2121
var _react2 = _interopRequireDefault(_react);
2222

23-
var modalClass = {
24-
position: 'fixed',
25-
'font-family': 'Arial, Helvetica, sans-serif',
26-
top: 0,
27-
right: 0,
28-
bottom: 0,
29-
left: 0,
30-
background: 'rgba(0, 0, 0, 0.8)',
31-
'z-index': 99999,
32-
opacity: 0,
33-
transition: 'opacity 400ms ease-in',
34-
opacity: 1,
35-
'pointer-events': 'auto'
36-
};
37-
38-
exports.modalClass = modalClass;
39-
var containerClass = {
40-
width: '400px',
41-
position: 'relative',
42-
margin: '10% auto',
43-
padding: '5px 20px 13px 20px',
44-
background: '#fff'
45-
};
46-
47-
exports.containerClass = containerClass;
48-
var closeClass = {
49-
background: '#606061',
50-
color: '#FFFFFF',
51-
'line-height': '25px',
52-
position: 'absolute',
53-
right: '-12px',
54-
'text-align': 'center',
55-
top: '-10px',
56-
width: '24px',
57-
'text-decoration': 'none',
58-
'font-weight': 'bold',
59-
borderRadius: '12px',
60-
boxDhadow: '1px 1px 3px #000',
61-
cursor: 'pointer'
62-
};
63-
64-
exports.closeClass = closeClass;
23+
var _styles = require('./styles');
24+
25+
var _styles2 = _interopRequireDefault(_styles);
6526

6627
var Modal = (function (_React$Component) {
6728
_inherits(Modal, _React$Component);
@@ -76,27 +37,28 @@ var Modal = (function (_React$Component) {
7637
_createClass(Modal, [{
7738
key: 'hideOnOuterClick',
7839
value: function hideOnOuterClick(event) {
79-
if (!this.props.closeOnOuterClick) return;
40+
if (this.props.closeOnOuterClick === false) return;
8041
if (event.target.dataset.modal) this.props.onClose(event);
8142
}
8243
}, {
8344
key: 'render',
8445
value: function render() {
8546
if (!this.props.show) return null;
86-
var modal = modalClass;
87-
var container = containerClass;
47+
var modalStyle = _extends({}, _styles2['default'].modal, this.props.style);
48+
var containerStyle = _extends({}, _styles2['default'].container, this.props.containerStyle);
8849

50+
//completely overwrite if they use a class
8951
if (this.props.className) {
90-
modal = null;
91-
container = null;
52+
modalStyle = this.props.style;
53+
containerStyle = this.props.containerStyle;
9254
}
9355

9456
return _react2['default'].createElement(
9557
'div',
96-
_extends({}, this.props, { style: modal, onClick: this.hideOnOuterClick, 'data-modal': "true" }),
58+
_extends({}, this.props, { style: modalStyle, onClick: this.hideOnOuterClick, 'data-modal': "true" }),
9759
_react2['default'].createElement(
9860
'div',
99-
{ style: container },
61+
{ style: containerStyle },
10062
this.props.children
10163
)
10264
);
@@ -106,4 +68,6 @@ var Modal = (function (_React$Component) {
10668
return Modal;
10769
})(_react2['default'].Component);
10870

109-
exports['default'] = Modal;
71+
exports['default'] = Modal;
72+
var closeStyle = _styles2['default'].close;
73+
exports.closeStyle = closeStyle;

build/styles.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, '__esModule', {
4+
value: true
5+
});
6+
var modal = {
7+
position: 'fixed',
8+
fontFamily: 'Arial, Helvetica, sans-serif',
9+
top: 0,
10+
right: 0,
11+
bottom: 0,
12+
left: 0,
13+
background: 'rgba(0, 0, 0, 0.8)',
14+
zIndex: 99999,
15+
opacity: 0,
16+
transition: 'opacity 400ms ease-in',
17+
opacity: 1,
18+
pointerEvents: 'auto'
19+
};
20+
21+
var container = {
22+
width: '400px',
23+
position: 'relative',
24+
margin: '10% auto',
25+
padding: '5px 20px 13px 20px',
26+
background: '#fff'
27+
};
28+
29+
var close = {
30+
background: '#606061',
31+
color: '#FFFFFF',
32+
lineHeight: '25px',
33+
position: 'absolute',
34+
right: '-12px',
35+
textAlign: 'center',
36+
top: '-10px',
37+
width: '24px',
38+
textDecoration: 'none',
39+
fontWeight: 'bold',
40+
borderRadius: '12px',
41+
boxShadow: '1px 1px 3px #000',
42+
cursor: 'pointer'
43+
};
44+
45+
exports['default'] = {
46+
modal: modal,
47+
container: container,
48+
close: close
49+
};
50+
module.exports = exports['default'];

dist/simple-react-modal.js

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Object.defineProperty(exports, '__esModule', {
66
value: true
77
});
88

9-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
10-
119
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
1210

1311
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
1412

13+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
14+
1515
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
1616

1717
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
@@ -22,48 +22,9 @@ var _react = (typeof window !== "undefined" ? window['React'] : typeof global !=
2222

2323
var _react2 = _interopRequireDefault(_react);
2424

25-
var modalClass = {
26-
position: 'fixed',
27-
'font-family': 'Arial, Helvetica, sans-serif',
28-
top: 0,
29-
right: 0,
30-
bottom: 0,
31-
left: 0,
32-
background: 'rgba(0, 0, 0, 0.8)',
33-
'z-index': 99999,
34-
opacity: 0,
35-
transition: 'opacity 400ms ease-in',
36-
opacity: 1,
37-
'pointer-events': 'auto'
38-
};
25+
var _styles = require('./styles');
3926

40-
exports.modalClass = modalClass;
41-
var containerClass = {
42-
width: '400px',
43-
position: 'relative',
44-
margin: '10% auto',
45-
padding: '5px 20px 13px 20px',
46-
background: '#fff'
47-
};
48-
49-
exports.containerClass = containerClass;
50-
var closeClass = {
51-
background: '#606061',
52-
color: '#FFFFFF',
53-
'line-height': '25px',
54-
position: 'absolute',
55-
right: '-12px',
56-
'text-align': 'center',
57-
top: '-10px',
58-
width: '24px',
59-
'text-decoration': 'none',
60-
'font-weight': 'bold',
61-
borderRadius: '12px',
62-
boxDhadow: '1px 1px 3px #000',
63-
cursor: 'pointer'
64-
};
65-
66-
exports.closeClass = closeClass;
27+
var _styles2 = _interopRequireDefault(_styles);
6728

6829
var Modal = (function (_React$Component) {
6930
_inherits(Modal, _React$Component);
@@ -78,27 +39,28 @@ var Modal = (function (_React$Component) {
7839
_createClass(Modal, [{
7940
key: 'hideOnOuterClick',
8041
value: function hideOnOuterClick(event) {
81-
if (!this.props.closeOnOuterClick) return;
42+
if (this.props.closeOnOuterClick === false) return;
8243
if (event.target.dataset.modal) this.props.onClose(event);
8344
}
8445
}, {
8546
key: 'render',
8647
value: function render() {
8748
if (!this.props.show) return null;
88-
var modal = modalClass;
89-
var container = containerClass;
49+
var modalStyle = _extends({}, _styles2['default'].modal, this.props.style);
50+
var containerStyle = _extends({}, _styles2['default'].container, this.props.containerStyle);
9051

52+
//completely overwrite if they use a class
9153
if (this.props.className) {
92-
modal = null;
93-
container = null;
54+
modalStyle = this.props.style;
55+
containerStyle = this.props.containerStyle;
9456
}
9557

9658
return _react2['default'].createElement(
9759
'div',
98-
_extends({}, this.props, { style: modal, onClick: this.hideOnOuterClick, 'data-modal': "true" }),
60+
_extends({}, this.props, { style: modalStyle, onClick: this.hideOnOuterClick, 'data-modal': "true" }),
9961
_react2['default'].createElement(
10062
'div',
101-
{ style: container },
63+
{ style: containerStyle },
10264
this.props.children
10365
)
10466
);
@@ -109,7 +71,61 @@ var Modal = (function (_React$Component) {
10971
})(_react2['default'].Component);
11072

11173
exports['default'] = Modal;
74+
var closeStyle = _styles2['default'].close;
75+
exports.closeStyle = closeStyle;
11276

11377
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
78+
},{"./styles":2}],2:[function(require,module,exports){
79+
'use strict';
80+
81+
Object.defineProperty(exports, '__esModule', {
82+
value: true
83+
});
84+
var modal = {
85+
position: 'fixed',
86+
fontFamily: 'Arial, Helvetica, sans-serif',
87+
top: 0,
88+
right: 0,
89+
bottom: 0,
90+
left: 0,
91+
background: 'rgba(0, 0, 0, 0.8)',
92+
zIndex: 99999,
93+
opacity: 0,
94+
transition: 'opacity 400ms ease-in',
95+
opacity: 1,
96+
pointerEvents: 'auto'
97+
};
98+
99+
var container = {
100+
width: '400px',
101+
position: 'relative',
102+
margin: '10% auto',
103+
padding: '5px 20px 13px 20px',
104+
background: '#fff'
105+
};
106+
107+
var close = {
108+
background: '#606061',
109+
color: '#FFFFFF',
110+
lineHeight: '25px',
111+
position: 'absolute',
112+
right: '-12px',
113+
textAlign: 'center',
114+
top: '-10px',
115+
width: '24px',
116+
textDecoration: 'none',
117+
fontWeight: 'bold',
118+
borderRadius: '12px',
119+
boxShadow: '1px 1px 3px #000',
120+
cursor: 'pointer'
121+
};
122+
123+
exports['default'] = {
124+
modal: modal,
125+
container: container,
126+
close: close
127+
};
128+
module.exports = exports['default'];
129+
114130
},{}]},{},[1])(1)
115131
});

0 commit comments

Comments
 (0)