Skip to content

Commit

Permalink
feat(index.js): add iconClassNames and toastType to props
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed Oct 12, 2014
1 parent bb87f99 commit 3916c2e
Showing 1 changed file with 54 additions and 12 deletions.
66 changes: 54 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
/** @jsx React.DOM */
var React = require("react/addons");
var {update} = React.addons;

var AlertMessage = React.createClass({
displayName: "AlertMessage",

getDefaultProps () {
var iconClassNames = {
error: "toast-error",
info: "toast-info",
success: "toast-success",
warning: "toast-warning"
};

return {
className: "toast-info",
className: "toast",
iconClassNames: iconClassNames,
titleClassName: "toast-title",
messageClassName: "toast-message",
closeButton: false
Expand Down Expand Up @@ -38,11 +47,12 @@ var AlertMessage = React.createClass({
render () {
var cx = React.addons.classSet;
var props = this.props;
var toastClass = {
toast: true
};
var iconClassName = props.iconClassName || props.iconClassNames[props.type];

var toastClass = {};
toastClass[props.className] = true;

toastClass[iconClassName] = true;

return (
<div className={cx(toastClass)}>
{this._render_close_button(props)}
Expand All @@ -56,20 +66,52 @@ var AlertMessage = React.createClass({
module.exports = React.createClass({
displayName: "Container",

error (message, title, optionsOverride) {
this._notify(this.props.toastType.error, message, title, optionsOverride);
},

info (message, title, optionsOverride) {
this._notify(this.props.toastType.info, message, title, optionsOverride);
},

success (message, title, optionsOverride) {
this._notify(this.props.toastType.success, message, title, optionsOverride);
},

warning (message, title, optionsOverride) {
this._notify(this.props.toastType.warning, message, title, optionsOverride);
},

getDefaultProps () {
return {
toastType: {
error: "error",
info: "info",
success: "success",
warning: "warning"
}
};
},

getInitialState () {
return {
toasts: []
};
},

success(message, title, optionsOverride) {
this.state.toasts.push({
title,
message,
className: "toast-success"// error, info, success, warning
_notify (type, message, title, optionsOverride) {
var newToast = update(optionsOverride || {}, {
$merge: {
type,
title,
message
}
});
this.setState(this.state);
},
var newState = update(this.state, {
toasts: { $push: [newToast] }
});
this.setState(newState);
},

render () {
return this.transferPropsTo(
Expand Down

0 comments on commit 3916c2e

Please sign in to comment.