UNPKG

4.58 kBMarkdownView Raw
1react-skylight
2==============
3
4React-SkyLight is a simple react component for modals and dialogs, Powerful, lightweight, and unopinionated in design.
5
6
7Installation
8------------
9
10```sh
11npm install react-skylight
12```
13
14Features
15--------
16
17- Very simple modal/dialog
18- Unopinionated in or design, (CSS is not included, only a template is suggested (see more below).
19- Callback before open
20- Callback after open
21- Callback before close
22- Callback after close
23
24
25How to use
26--------------------
27
28```js
29
30//Require react-skylight
31var SkyLight = require('react-skylight');
32
33var App = React.createClass({
34 showDialogWithCallBacks: function(){
35 this.refs.dialogWithCallBacks.show();
36 },
37 showSimpleDialog: function(){
38 this.refs.simpleDialog.show();
39 },
40 render:function(){
41 return (
42 <div>
43 <p>
44 <button onClick={this.showSimpleDialog}>Modal without callbacks</button>
45 <button onClick={this.showDialogWithCallBacks}>Modal with callbacks</button>
46 </p>
47 <SkyLight ref="dialogWithCallBacks" title="Hello!, I'm a modal with callbacks!"
48 beforeOpen={this._executeBeforeFirstModalOpen}
49 afterOpen={this._executeAfterFirstModalOpen}
50 beforeClose={this._executeBeforeFirstModalClose}
51 afterClose={this._executeAfterFirstModalClose}>I have callbacks!</SkyLight>
52 <SkyLight ref="simpleDialog" title="Hi, I'm a simple modal">
53 Hello, I dont have any callback.
54 </SkyLight>
55 </div>
56 )
57 },
58 _executeBeforeFirstModalOpen: function(){
59 alert('Executed before open');
60 },
61 _executeAfterFirstModalOpen: function(){
62 alert('Executed after open');
63 },
64 _executeBeforeFirstModalClose: function(){
65 alert('Executed before close');
66 },
67 _executeAfterFirstModalClose: function(){
68 alert('Executed after close');
69 }
70});
71
72React.render(<App/>, document.getElementById("content"));
73
74```
75
76
77
78Options
79-------------------
80
81####title: (String)
82A title for your modal.
83``` html
84<SkyLight ref="myModal" title="TITLE FOR MODAL">Modal Content</SkyLight>
85```
86####showOverlay: (Boolean)
87Show modal with an overlay (true) or without an overlay (false).
88
89``` html
90<SkyLight ref="myModal" title="TITLE FOR MODAL" showOverlay={true}>Modal With Overlay</SkyLight>
91
92<SkyLight ref="myModal" title="TITLE FOR MODAL" showOverlay={false}>Modal Without Overlay</SkyLight>
93```
94
95####beforeOpen, afterOpen, beforeClose and afterClose: (Function)
96A callback functions to execute before and after open and before and after close a modal. You can use just the one you want.
97``` html
98<SkyLight ref="myModal" title="TITLE FOR MODAL"
99 beforeOpen={myFunctionToExecuteBeforeOpen}
100 afterOpen={myFunctionToExecuteAfterOpen}
101 beforeClose={myFunctionToExecuteBeforeClose}
102 afterClose={myFunctionToExecuteAfterClose}>Modal Content</SkyLight>
103```
104
105##New in 0.2.0 version
106
107Overlay, dialog and closeButton styles now accept an object that represent your styles.
108
109If you not declare any style, skyLight will apply the default styles, but if you send an object with one or more properties, your object will override the default property.
110
111####overlayStyles: (Object)
112An object that represent the styles of overlay:
113```js
114//Default overlay SkyLight styles:
115overlayStyles: {
116 position: 'fixed',
117 top: 0,
118 left: 0,
119 width: '100%',
120 height: '100%',
121 zIndex: 99,
122 backgroundColor: 'rgba(0,0,0,0.3)'
123}
124```
125
126####dialogStyles: (Object)
127An object that represent the styles of dialog.
128```js
129//Default dialog SkyLight styles:
130dialogStyles: {
131 width: '50%',
132 height: '400px',
133 position: 'fixed',
134 top: '50%',
135 left: '50%',
136 marginTop: '-200px',
137 marginLeft: '-25%',
138 backgroundColor: '#fff',
139 borderRadius: '2px',
140 zIndex: 100,
141 padding: '10px',
142 boxShadow: '0 0 4px rgba(0,0,0,.14),0 4px 8px rgba(0,0,0,.28)'
143}
144```
145
146####closeButtonStyle: (Object)
147An object that represent the styles of close button
148```js
149//Default close button SkyLight styles:
150closeButtonStyle: {
151 cursor: 'pointer',
152 float: 'right',
153 fontSize: '1.6em',
154 margin: '-15px 0'
155}
156```
157
158### An Example with new styles, overriding dialog background color to red
159
160
161```js
162
163var dialogStyles = {
164 backgroundColor: '#f03'
165};
166
167<SkyLight ref="myModal" title="TITLE FOR MODAL" dialogStyles={dialogStyles}>Modal Content</SkyLight>
168```
169
170
171CSS
172--------------------
173
174External css is no more needed!
175
176##Enjoy!
177
178
179
180## Release History
181
182 * 2015-02-03   v0.1.4   Changed skylight.js to skylight.jsx and adjust of namespace