Skip to content

Commit 21afa1b

Browse files
committed
replace react-toastr with react-s-alert
1 parent 0ae0f9c commit 21afa1b

File tree

5 files changed

+27
-42
lines changed

5 files changed

+27
-42
lines changed

src/BootstrapTable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { TableDataStore } from './store/TableDataStore';
1212
import Util from './util';
1313
import exportCSVUtil from './csv_export_util';
1414
import { Filter } from './Filter';
15+
import Alert from 'react-s-alert';
1516

1617
class BootstrapTable extends Component {
1718

@@ -417,6 +418,7 @@ class BootstrapTable extends Component {
417418
</div>
418419
{ tableFilter }
419420
{ showPaginationOnBottom ? pagination : null }
421+
<Alert stack={ { limit: 3 } } />
420422
</div>
421423
);
422424
}

src/Const.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const CONST_VAR = {
4646
FILTER_COND_LIKE: 'like',
4747
EXPAND_BY_ROW: 'row',
4848
EXPAND_BY_COL: 'column',
49-
CANCEL_TOASTR: 'Pressed ESC can cancel',
5049
REMOTE_SORT: 'sort',
5150
REMOTE_PAGE: 'pagination',
5251
REMOTE_CELL_EDIT: 'cellEdit',

src/Notification.js

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
1-
import React, { Component } from 'react';
1+
import Alert from 'react-s-alert';
22

3-
import { ToastContainer, ToastMessage } from '@allenfang/react-toastr';
3+
const notice = (type, msg, title) => {
4+
const titleHTML = title ? `<h4><strong>${ title }</strong></h4>` : '';
45

6+
const bodyHTML = `
7+
${ titleHTML }
8+
<span>${ msg }</span>
9+
`;
510

6-
const ToastrMessageFactory = React.createFactory(ToastMessage.animation);
11+
Alert.error(bodyHTML, {
12+
position: 'top-right',
13+
timeout: 3500,
14+
html: true
15+
});
16+
};
717

8-
class Notification extends Component {
9-
// allow type is success,info,warning,error
10-
notice(type, msg, title) {
11-
this.refs.toastr[type](
12-
msg, title, {
13-
mode: 'single',
14-
timeOut: 5000,
15-
extendedTimeOut: 1000,
16-
showAnimation: 'animated bounceIn',
17-
hideAnimation: 'animated bounceOut'
18-
});
19-
}
20-
21-
render() {
22-
return (
23-
<ToastContainer ref='toastr'
24-
toastMessageFactory={ ToastrMessageFactory }
25-
id='toast-container'
26-
className='toast-top-right'/>
27-
);
28-
}
29-
}
30-
31-
export default Notification;
18+
export { notice };

src/TableEditColumn.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React, { Component, PropTypes } from 'react';
22
import ReactDOM from 'react-dom';
33
import editor from './Editor';
4-
import Notifier from './Notification.js';
4+
import { notice } from './Notification.js';
55
import classSet from 'classnames';
6-
import Const from './Const';
76

87
class TableEditColumn extends Component {
98
constructor(props) {
@@ -73,7 +72,7 @@ class TableEditColumn extends Component {
7372
const responseType = typeof checkVal;
7473
if (responseType !== 'object' && checkVal !== true) {
7574
valid = false;
76-
this.notifyToastr('error', checkVal, Const.CANCEL_TOASTR);
75+
this.notifyToastr('error', checkVal, '');
7776
} else if (responseType === 'object' && checkVal.isValid !== true) {
7877
valid = false;
7978
this.notifyToastr(checkVal.notification.type,
@@ -106,7 +105,7 @@ class TableEditColumn extends Component {
106105
toastr = beforeShowError(type, message, title);
107106
}
108107
if (toastr) {
109-
this.refs.notifier.notice(type, message, title);
108+
notice(type, message, title);
110109
}
111110
}
112111

@@ -201,7 +200,6 @@ class TableEditColumn extends Component {
201200
className={ className }
202201
onClick={ this.handleClick }>
203202
{ cellEditor }
204-
<Notifier ref='notifier'/>
205203
</td>
206204
);
207205
}

src/toolbar/ToolBar.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Modal from 'react-modal';
55
// import classSet from 'classnames';
66
import Const from '../Const';
77
// import editor from '../Editor';
8-
import Notifier from '../Notification.js';
8+
import { notice } from '../Notification.js';
99
import InsertModal from './InsertModal';
1010
import InsertButton from './InsertButton';
1111
import DeleteButton from './DeleteButton';
@@ -65,10 +65,10 @@ class ToolBar extends Component {
6565
}
6666

6767
displayCommonMessage = () => {
68-
this.refs.notifier.notice(
68+
notice(
6969
'error',
7070
'Form validate errors, please checking!',
71-
'Pressed ESC can cancel');
71+
'');
7272
}
7373

7474
validateNewRow(newRow) {
@@ -93,10 +93,10 @@ class ToolBar extends Component {
9393
isValid = false;
9494
validateState[column.field] = tempMsg;
9595
} else if (responseType === 'object' && tempMsg.isValid !== true) {
96-
this.refs.notifier.notice(
97-
tempMsg.notification.type,
98-
tempMsg.notification.msg,
99-
tempMsg.notification.title);
96+
notice(
97+
tempMsg.notification.type,
98+
tempMsg.notification.msg,
99+
tempMsg.notification.title);
100100
isValid = false;
101101
validateState[column.field] = tempMsg.notification.msg;
102102
}
@@ -122,7 +122,7 @@ class ToolBar extends Component {
122122
}
123123
const msg = this.props.onAddRow(newRow);
124124
if (msg) {
125-
this.refs.notifier.notice('error', msg, 'Pressed ESC can cancel');
125+
notice('error', msg, '');
126126
this.clearTimeout();
127127
// shake form and hack prevent modal hide
128128
this.setState({
@@ -321,7 +321,6 @@ class ToolBar extends Component {
321321
return (
322322
<div className='row'>
323323
{ toolbar }
324-
<Notifier ref='notifier' />
325324
{ modal }
326325
</div>
327326
);

0 commit comments

Comments
 (0)