-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.html
306 lines (275 loc) · 15.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://use.fontawesome.com/13f77c8bf7.js"></script>
<!-- <link rel="stylesheet" href="../dist/ReactReduxNotify.css" /> -->
<link rel="stylesheet" href="https://unpkg.com/react-redux-notify/dist/ReactReduxNotify.min.css" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w"
crossorigin="anonymous">
<title>React Redux Notify</title>
<style>
.customContent {
background: pink;
}
.containerTopCenter {
z-index: 1;
position: fixed;
overflow-y: auto;
max-height: 100vh;
left: 50%;
transform: translate3d(-50%, 0, 0);
flex-direction: column;
top: 0;
}
.containerTopCenter::-webkit-scrollbar {
display: none;
}
</style>
</head>
<body>
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/prop-types/prop-types.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/redux.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/react-redux.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.1/es6-sham.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.js"></script>
<!-- <script src="../dist/ReactReduxNotify.js"></script> -->
<script src="https://unpkg.com/react-redux-notify/dist/ReactReduxNotify.min.js"></script>
<script type="text/babel">
'use strict';
const { createStore, combineReducers } = Redux
const { Provider, connect } = ReactRedux
const { reducer, Notify, createNotification, removeNotification, removeAllNotifications,
NOTIFICATION_TYPE_SUCCESS, NOTIFICATION_TYPE_WARNING, NOTIFICATION_TYPE_INFO, NOTIFICATION_TYPE_ERROR,
NOTIFICATIONS_POS_TOP_RIGHT, NOTIFICATIONS_POS_BOT_RIGHT, NOTIFICATIONS_POS_BOT_LEFT, NOTIFICATIONS_POS_TOP_LEFT } = ReactReduxNotify
const reducers = combineReducers({ notifications: reducer })
const store = createStore(reducers, {})
const icons = {
[NOTIFICATION_TYPE_ERROR]: <i className="fa fa-fire" />,
[NOTIFICATION_TYPE_SUCCESS]: <i className="fa fa-check" />,
[NOTIFICATION_TYPE_INFO]: <i className="fa fa-info" />,
[NOTIFICATION_TYPE_WARNING]: <i className="fa fa-warning" />,
}
//See styles definition in head.
const customNotificationStyles = {
'content': 'customContent'
}
const CUSTOM_POSITION = 'TopCenter';
const customNotifyStyles = {
'containerTopCenter': 'containerTopCenter'
}
const MyCustomNotificationComponent = ({message, type, canDismiss, acceptBtn, denyBtn,
icon, customStyles, id, isFirst, handleDismiss, handleDismissAll}) => {
let styles = {
margin:'5px 0',
padding: '2px 5px',
border: '1px solid #333',
float:'right',
clear: 'right',
width: '330px',
boxSizing: 'border-box',
}
if (canDismiss) {
styles = Object.assign({}, styles, {cursor: 'pointer'})
}
return (
<div onClick={(e)=>{if(canDismiss){handleDismiss(id)}}} style={styles}>
{message}
</div>
)
}
class ExampleNotifications extends React.Component {
constructor(props){
super(props);
this.state = {
message: 'Hello There!',
type: NOTIFICATION_TYPE_ERROR,
icon: icons[NOTIFICATION_TYPE_ERROR],
duration: 0,
acceptBtn: {
handler: (e, notification) => {
alert('Ayyyyy :)');
notification.handleDismiss(notification.id);
},
title: 'Accept',
icon: 'fa fa-thumbs-up'
},
denyBtn: {
handler: (e, notification) => {
alert('Get Lost. -.-');
notification.handleDismiss(notification.id);
},
title: 'Deny',
icon: 'fa fa-thumbs-down'
},
localization: {
closeAllBtnText: "Close dem all",
acceptBtnText: "Yes",
denyBtnText: "No",
},
customLocalization: false,
canDismiss: true,
globalCustomNotification: false,
position: NOTIFICATIONS_POS_TOP_RIGHT,
forceClose: false,
showCloseAllBtn: false
}
this.createNotification = this._createNotification.bind(this);
this.handleFieldChange = this._handleFieldChange.bind(this);
}
_handleFieldChange(field){
return (e) => {
if (field == 'canDismiss' || field == 'globalCustomNotification' || field == 'forceClose' || field == 'customLocalization' || field == 'showCloseAllBtn'){
const fieldVal = e.target.checked
if(field == 'customLocalization' && e.target.checked){
return this.setState((prevState, props) => {
return {
...prevState,
acceptBtn: {
...prevState.acceptBtn,
title: '',
},
denyBtn: {
...prevState.denyBtn,
title: '',
},
[field]: fieldVal
}
})
} else if (field == 'customLocalization' && !e.target.checked){
return this.setState((prevState, props) => {
return {
...prevState,
acceptBtn: {
...prevState.acceptBtn,
title: 'Accept',
},
denyBtn: {
...prevState.denyBtn,
title: 'Deny',
},
[field]: fieldVal
}
})
}
return this.setState({[field]: fieldVal});
} else if (field == 'customComponent') {
const componentToUse = (e.target.checked) ? MyCustomNotificationComponent: undefined
this.setState({[field]: componentToUse});
} else if (field == 'customStyles'){
const styles = (e.target.checked) ? customNotificationStyles : undefined
this.setState({customStyles:styles});
} else {
if(field == 'duration'){
return this.setState({[field]: parseInt(e.target.value, 10)});
}
if (field == 'type'){
this.setState({icon: icons[e.target.value]});
}
this.setState({[field]: e.target.value});
}
}
}
_createNotification(e){
e.preventDefault();
const {createNotification} = this.props;
const nProps = Object.assign({}, this.state);
delete nProps['localization']
delete nProps['showCloseAllBtn']
createNotification(nProps);
}
render(){
const NotificationComponentProp = this.state.globalCustomNotification ? MyCustomNotificationComponent:undefined;
let notifyProps = {
notificationComponent: NotificationComponentProp,
position: this.state.position,
forceClose: this.state.forceClose,
customStyles: customNotifyStyles,
localization: this.state.customLocalization ? this.state.localization : undefined,
showCloseAllBtn: this.state.showCloseAllBtn
}
return (
<div>
<Notify
{...notifyProps}
/>
<form className="pure-form pure-form-stacked" style={
{width: '300px', height: '500px', top:'50%', left:'50%', position: 'relative', transform: 'translate3d(-50%, 50%, 0)', textAlign: 'center'}}>
<label><strong>Message: </strong></label>
<input style={{display:'inline-block'}} type="text" value={this.state.message} onChange={this.handleFieldChange('message')} />
<label><strong>Duration: </strong></label>
<input style={{display:'inline-block'}} type="number" value={this.state.duration} onChange={this.handleFieldChange('duration')} />
<label><strong>Type: </strong></label>
<input type="radio" value={NOTIFICATION_TYPE_SUCCESS} checked={this.state.type==NOTIFICATION_TYPE_SUCCESS} onChange={this.handleFieldChange('type')} /> Success <br />
<input type="radio" value={NOTIFICATION_TYPE_WARNING} checked={this.state.type==NOTIFICATION_TYPE_WARNING} onChange={this.handleFieldChange('type')} /> Warning <br />
<input type="radio" value={NOTIFICATION_TYPE_ERROR} checked={this.state.type==NOTIFICATION_TYPE_ERROR} onChange={this.handleFieldChange('type')} /> Error <br />
<input type="radio" value={NOTIFICATION_TYPE_INFO} checked={this.state.type==NOTIFICATION_TYPE_INFO} onChange={this.handleFieldChange('type')} /> Info <br />
<label><strong>Can Dismiss: </strong></label>
<input type="checkbox" defaultChecked={this.state.canDismiss} onChange={this.handleFieldChange('canDismiss')} />
<label><strong>Custom Localization Text: </strong></label>
<input type="checkbox" defaultChecked={this.state.customLocalization} onChange={this.handleFieldChange('customLocalization')} />
<label><strong>Custom Global Notification Component: </strong></label>
<input type="checkbox" defaultChecked={this.state.globalCustomNotification} onChange={this.handleFieldChange('globalCustomNotification')} />
<label><strong>Custom Notification Component: </strong></label>
<input type="checkbox" defaultChecked={false} onChange={this.handleFieldChange('customComponent')} />
<label><strong>Container Position: </strong></label>
<input type="radio" value={NOTIFICATIONS_POS_TOP_RIGHT} checked={this.state.position==NOTIFICATIONS_POS_TOP_RIGHT} onChange={this.handleFieldChange('position')} /> Top Right <br />
<input type="radio" value={NOTIFICATIONS_POS_BOT_RIGHT} checked={this.state.position==NOTIFICATIONS_POS_BOT_RIGHT} onChange={this.handleFieldChange('position')} /> Bottom Right <br />
<input type="radio" value={NOTIFICATIONS_POS_BOT_LEFT} checked={this.state.position==NOTIFICATIONS_POS_BOT_LEFT} onChange={this.handleFieldChange('position')} /> Bottom Left <br />
<input type="radio" value={NOTIFICATIONS_POS_TOP_LEFT} checked={this.state.position==NOTIFICATIONS_POS_TOP_LEFT} onChange={this.handleFieldChange('position')} /> Top Left <br />
<input type="radio" value={CUSTOM_POSITION} checked={this.state.position==CUSTOM_POSITION} onChange={this.handleFieldChange('position')} /> Custom Position - Top Center <br />
<label><strong>Custom Notification Styles: </strong></label>
<input type="checkbox" defaultChecked={false} onChange={this.handleFieldChange('customStyles')} />
<label><strong>Force Close Notifications: </strong></label>
<input type="checkbox" defaultChecked={this.state.forceClose} onChange={this.handleFieldChange('forceClose')} />
<label><strong>Show Close All Button: </strong></label>
<input type="checkbox" defaultChecked={this.state.showCloseAllBtn} onChange={this.handleFieldChange('showCloseAllBtn')} />
<div style={{paddingTop:'10px'}}>
<button onClick={(e) => this.createNotification(e)}
style={{margin: '0 auto'}}
className="pure-button pure-button-primary">
Create Notification!
</button>
</div>
</form>
</div>
)
}
}
const mapDispatchToProps = (dispatch) => {
return {
createNotification: (config) => {
dispatch(createNotification(config))
},
removeNotification: (id) => {
dispatch(removeNotification(id))
},
removeAllNotifications: () => {
dispatch(removeAllNotifications())
}
}
}
ExampleNotifications = connect(
null,
mapDispatchToProps
)(ExampleNotifications)
class App extends React.Component {
render(){
return (
<Provider store={store}>
<ExampleNotifications />
</Provider>
)
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
</script>
</body>
</html>