Skip to content

Commit

Permalink
Allow passing an alert class in alert.show
Browse files Browse the repository at this point in the history
  • Loading branch information
askvortsov1 committed May 16, 2020
1 parent 5f345da commit 2432b4d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion js/src/common/components/AlertManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export default class AlertManager extends Component {
return (
<div className="AlertManager">
{Object.entries(this.state.activeAlerts).map(([key, state]) => (
<div className="AlertManager-alert">{Alert.component({ ...state.attrs, ondismiss: this.state.dismiss.bind(this.state, key) })}</div>
<div className="AlertManager-alert">
{state.alertClass.component({ ...state.attrs, ondismiss: this.state.dismiss.bind(this.state, key) })}
</div>
))}
</div>
);
Expand Down
5 changes: 3 additions & 2 deletions js/src/common/states/AlertManagerState.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Alert from '../components/Alert';
import AlertState from './AlertState';

export default class AlertManagerState {
Expand All @@ -8,8 +9,8 @@ export default class AlertManagerState {
/**
* Show an Alert in the alerts area.
*/
show(attrs, key = AlertManagerState.genAlertId()) {
const state = new AlertState(attrs);
show(attrs, alertClass = Alert, key = AlertManagerState.genAlertId()) {
const state = new AlertState(attrs, alertClass);

this.activeAlerts[key] = state;
m.redraw();
Expand Down
5 changes: 4 additions & 1 deletion js/src/common/states/AlertState.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Alert from '../components/Alert';

export default class AlertState {
constructor(attrs = {}) {
constructor(attrs = {}, alertClass = Alert) {
this.attrs = attrs;
this.alertClass = alertClass;
}
}

0 comments on commit 2432b4d

Please sign in to comment.