-
Notifications
You must be signed in to change notification settings - Fork 112
/
index.js
129 lines (106 loc) · 2.8 KB
/
index.js
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
import createReactClass from "create-react-class";
import {
default as React,
} from "react";
import {
default as update,
} from "react-addons-update";
import {
default as classNames,
} from "classnames";
import {
default as animationMixin,
} from "./animationMixin";
import {
default as jQueryMixin,
} from "./jQueryMixin";
function noop() {}
const ToastMessageSpec = {
displayName: `ToastMessage`,
getDefaultProps() {
const iconClassNames = {
error: `toast-error`,
info: `toast-info`,
success: `toast-success`,
warning: `toast-warning`,
};
return {
className: `toast`,
iconClassNames,
titleClassName: `toast-title`,
messageClassName: `toast-message`,
tapToDismiss: true,
closeButton: false,
};
},
handleOnClick(event) {
this.props.handleOnClick(event);
if (this.props.tapToDismiss) {
this.hideToast(true);
}
},
_handle_close_button_click(event) {
event.stopPropagation();
this.hideToast(true);
},
_handle_remove() {
this.props.handleRemove(this.props.toastId);
},
_render_close_button() {
return this.props.closeButton ? (
<button
className="toast-close-button"
onClick={this._handle_close_button_click}
dangerouslySetInnerHTML={{ __html: `×` }}
/>
) : false;
},
_render_title_element() {
return this.props.title ? (
<div className={this.props.titleClassName}>
{this.props.title}
</div>
) : false;
},
_render_message_element() {
return this.props.message ? (
<div className={this.props.messageClassName}>
{this.props.message}
</div>
) : false;
},
render() {
const iconClassName = this.props.iconClassName || this.props.iconClassNames[this.props.type];
return (
<div
className={classNames(this.props.className, iconClassName)}
style={this.props.style}
onClick={this.handleOnClick}
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
>
{this._render_close_button()}
{this._render_title_element()}
{this._render_message_element()}
</div>
);
},
};
export const animation = createReactClass(update(ToastMessageSpec, {
displayName: { $set: `ToastMessage.animation` },
mixins: { $set: [animationMixin] },
}));
export const jQuery = createReactClass(update(ToastMessageSpec, {
displayName: { $set: `ToastMessage.jQuery` },
mixins: { $set: [jQueryMixin] },
}));
/*
* assign default noop functions
*/
ToastMessageSpec.handleMouseEnter = noop;
ToastMessageSpec.handleMouseLeave = noop;
ToastMessageSpec.hideToast = noop;
const ToastMessage = createReactClass(ToastMessageSpec);
ToastMessage.animation = animation;
ToastMessage.jQuery = jQuery;
export default ToastMessage;