-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdb84b9
commit 15497bd
Showing
8 changed files
with
198 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as React from 'react' | ||
import { CSSTransition } from 'react-transition-group' | ||
import classNames from 'classnames' | ||
import { Action } from 'redux' | ||
// import classNames from 'classnames' | ||
import { ToastType } from '../models/store' | ||
|
||
interface ToastProps { | ||
type: ToastType | ||
message: string | ||
isVisible: boolean | ||
timeout: number | ||
onClose: () => Action | ||
} | ||
|
||
const Toast: React.FunctionComponent<ToastProps> = (props: ToastProps) => { | ||
const { type, message, isVisible, timeout, onClose } = props | ||
const icon = type === 'success' | ||
? <span className='icon-inline'>checkmark</span> | ||
: <span className='icon-inline'>warning</span> | ||
|
||
React.useEffect(() => { | ||
// set timeout | ||
if (isVisible === true) { | ||
setTimeout(onClose, timeout) | ||
} | ||
}, [isVisible]) | ||
|
||
return ( | ||
<CSSTransition | ||
in={isVisible} | ||
classNames="toast" | ||
timeout={300} | ||
> | ||
<div className={classNames('toast', { | ||
'success': type === 'success', | ||
'error': type === 'error' | ||
})}> | ||
{icon} | ||
{message} | ||
</div> | ||
</CSSTransition> | ||
) | ||
} | ||
|
||
export default Toast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
.toast { | ||
color: $text; | ||
margin: 0 auto; | ||
max-width: 500px; | ||
padding: 8px 12px; | ||
position: absolute; | ||
bottom: 0; | ||
left: 50%; | ||
right: auto; | ||
border-radius: 2px; | ||
transform: translateX(-50%) translateY(100%); | ||
|
||
.icon-inline { | ||
margin-right: 8px; | ||
position: relative; | ||
top: 2px; | ||
} | ||
|
||
&.success { | ||
background: #a6e2a6; | ||
.icon-inline { | ||
color: #459245 | ||
} | ||
} | ||
|
||
&.error { | ||
background: #dcadad; | ||
.icon-inline { | ||
color: #b9525a | ||
} | ||
} | ||
} | ||
|
||
.toast-enter { | ||
transform: translateX(-50%) translateY(100%); | ||
} | ||
|
||
.toast-enter-active { | ||
transform: translateX(-50%) translateY(-50%); | ||
transition: all 300ms ; | ||
} | ||
|
||
.toast-enter-done { | ||
transform: translateX(-50%) translateY(-50%); | ||
} | ||
|
||
.toast-exit { | ||
transform: translateX(-50%) translateY(-50%); | ||
} | ||
|
||
.toast-exit-active { | ||
transform: translateX(-50%) translateY(100%); | ||
transition: all 300ms ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters