-
Notifications
You must be signed in to change notification settings - Fork 187
/
alert-service.examples.tsx
97 lines (78 loc) · 2.36 KB
/
alert-service.examples.tsx
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
import React from 'react';
import reactDecorator from '../../.storybook/react-decorator';
import Button from '../button/button';
import ButtonToolbar from '../button-toolbar/button-toolbar';
import Theme from '../global/theme';
import alert from './alert-service';
import styles from './alert-service.examples.css';
export default {
title: 'Services/Alert Service',
decorators: [reactDecorator()],
parameters: {
notes: 'Service for managing a stack of alerts.',
hermione: {skip: true}
}
};
export const alertService = () => {
const MSG_TIMEOUT = 5000;
const MSG_LONG_TIMEOUT = 30000;
class AlertServiceDemo extends React.Component {
componentDidMount() {
setTimeout(() => {
alert.message('A initial message', MSG_TIMEOUT);
alert.error('Error message');
this.showCustomMessage();
});
}
componentWillUnmount() {
alert._getShowingAlerts().forEach(item => alert.removeWithoutAnimation(item.key));
}
lastKey?: string | number;
showCustomMessage = () => {
this.lastKey = alert.addAlert(
<div className={styles.customAlert}>
<h1>Hello!</h1>
<p>{'This is a custom message'}</p>
</div>,
undefined,
0,
{
className: styles.customAlert,
closeButtonClassName: styles.closeButton,
theme: Theme.LIGHT
}
);
};
showError = () => {
this.lastKey = alert.error('Something wrong happened');
};
showRandomWarning = () => {
this.lastKey = alert.warning(
`Warning! Something bad is going to happen (${Math.random()})`,
MSG_LONG_TIMEOUT
);
};
showMessage = () => {
this.lastKey = alert.message('This is just a message', MSG_TIMEOUT);
};
removeLastAlert = () => {
alert.remove(this.lastKey);
};
render() {
return (
<ButtonToolbar>
<Button onClick={this.showError}>Show error</Button>
<Button onClick={this.showMessage} primary>
Show message
</Button>
<Button onClick={this.showCustomMessage}>
Show custom message
</Button>
<Button onClick={this.showRandomWarning}>Show warning</Button>
<Button onClick={this.removeLastAlert}>Remove last alert</Button>
</ButtonToolbar>
);
}
}
return <AlertServiceDemo/>;
};