Skip to content

Commit

Permalink
feat(ToastMessage): rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed Oct 28, 2017
1 parent e5fa767 commit b8a3b29
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/components/ToastMessage/ToastMessage.jsx
@@ -0,0 +1,65 @@
// @flow
import _ from "lodash"
import cx from "classnames"
import React from "react"

export type IconClassNames = {
error: string,
info: string,
success: string,
warning: string,
}

const defaultIconClassNames: IconClassNames = {
error: "toast-error",
info: "toast-info",
success: "toast-success",
warning: "toast-warning",
}

export type Props = {
className?: string,
type: string,
iconClassNames?: IconClassNames,
iconClassName?: string,
/**
* Show or hide an optional close button.
*/
closeButton?: boolean,
onCloseClick?: func,
title?: any,
titleClassName?: string,
message?: any,
messageClassName?: string,
}

/**
* Base component for displaying a toast message.
*/
export const ToastMessage = ({
className = "toast",
type,
iconClassNames = defaultIconClassNames,
iconClassName = iconClassNames[type],
closeButton = false,
onCloseClick = _.noop,
title = false,
titleClassName = "toast-title",
message = false,
messageClassName = "toast-message",
...restProps
}: Props) => (
<div {...restProps} className={cx(className, iconClassName)}>
{!!closeButton && (
<button
className="toast-close-button"
onClick={onCloseClick}
dangerouslySetInnerHTML={{ __html: "&times;" }}
/>
)}
{!!title && <div className={titleClassName}>{title}</div>}
{!!message && <div className={messageClassName}>{message}</div>}
</div>
)

export default ToastMessage
9 changes: 9 additions & 0 deletions src/components/ToastMessage/ToastMessage.md
@@ -0,0 +1,9 @@
### Usage

```jsx static
import { ToastMessage } from "react-toastr";

```

### Simple message

0 comments on commit b8a3b29

Please sign in to comment.