-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Easybuoy/feature/create-toaster-169776716
Create toaster
- Loading branch information
Showing
8 changed files
with
134 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,24 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
const StyledAlert = styled.div` | ||
.toast { | ||
position: fixed; | ||
top: 10px; | ||
right: 10px; | ||
width: 250px; | ||
border-radius: 4px; | ||
box-shadow: #310808 1px 1px 5px; | ||
background-color: rgba(177, 7, 15, 0.78); | ||
padding: 10px; | ||
color: #f5bfbf; | ||
opacity: 1; | ||
animation: toast 500ms cubic-bezier(0.23, 0.82, 0.16, 1.46); | ||
animation-iteration-count: 1; | ||
} | ||
@keyframes toast { | ||
0% { | ||
opacity: 0; | ||
transform: translateY(200px); | ||
} | ||
100% { | ||
opacity: 1; | ||
transform: translateY(0px); | ||
} | ||
} | ||
`; | ||
|
||
function Alert() { | ||
let hideMessage = false; | ||
|
||
setTimeout(() => { | ||
hideMessage = true; | ||
}, 4000); | ||
import React, { useState, useEffect } from 'react'; | ||
import { Alert as StyledAlert } from '../../styles'; | ||
|
||
const Alert = ({ message }) => { | ||
const [hideMessage, setHideMessage] = useState(false); | ||
useEffect(() => { | ||
const timeout = setTimeout(() => { | ||
setHideMessage('none'); | ||
}, 3000); | ||
return () => { | ||
clearTimeout(timeout); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<StyledAlert> | ||
<div class="toast" style={{ display: hideMessage }}> | ||
<p>Your message</p> | ||
<div className="toast" style={{ display: hideMessage }}> | ||
<p>{message}</p> | ||
</div> | ||
</StyledAlert> | ||
); | ||
} | ||
}; | ||
|
||
export default Alert; |
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,15 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import Alert from './Alert'; | ||
|
||
describe('<Alert />', () => { | ||
const props = { | ||
message: 'Error' | ||
}; | ||
|
||
it('renders the Alert component correctly', () => { | ||
const wrapper = shallow(<Alert {...props} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
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,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<Alert /> renders the Alert component correctly 1`] = ` | ||
<styled.div> | ||
<div | ||
className="toast" | ||
style={ | ||
Object { | ||
"display": false, | ||
} | ||
} | ||
> | ||
<p> | ||
Error | ||
</p> | ||
</div> | ||
</styled.div> | ||
`; |
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