aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/Err.js
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-12 23:08:20 -0700
committerjackyzha0 <[email protected]>2020-05-12 23:08:20 -0700
commit94a9b304546dd1213ef2f15e57f5966ab88b80b7 (patch)
tree6d583219cb9bcf04ca521d35a9edfb8c6838fe1b /frontend/src/components/Err.js
parentMerge branch 'master' of https://github.com/jackyzha0/ctrl-v into pass-rendering (diff)
downloadctrl-v-94a9b304546dd1213ef2f15e57f5966ab88b80b7.tar.xz
ctrl-v-94a9b304546dd1213ef2f15e57f5966ab88b80b7.zip
abstract err show logic
Diffstat (limited to 'frontend/src/components/Err.js')
-rw-r--r--frontend/src/components/Err.js50
1 files changed, 43 insertions, 7 deletions
diff --git a/frontend/src/components/Err.js b/frontend/src/components/Err.js
index 8562a74..dc78398 100644
--- a/frontend/src/components/Err.js
+++ b/frontend/src/components/Err.js
@@ -1,18 +1,54 @@
import React from 'react';
-import styled from 'styled-components'
+import styled, { css } from 'styled-components'
const ErrMsg = styled.p`
display: inline;
font-weight: 700;
margin-left: 2em;
- color: #ff3333
+ color: #ff3333;
+ opacity: 0;
+ transition: opacity 0.3s cubic-bezier(.25,.8,.25,1);
+
+ ${props =>
+ (props.active) && css`
+ opacity: 1
+ `
+ };
`
-const Error = (props) => {
- const msg = props.msg.toString().toLowerCase()
- return (
- <ErrMsg> {msg} </ErrMsg>
- );
+class Error extends React.Component {
+
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ active: false,
+ msg: '',
+ };
+
+ this.showMessage = this.showMessage.bind(this);
+ }
+
+ showMessage(msg, duration = 3000) {
+ this.setState({
+ active: true,
+ msg: msg
+ })
+
+ // fadeout after duration ms if duration != -1
+ if (duration !== -1) {
+ setTimeout(() => {
+ this.setState({ active: false })
+ }, duration);
+ }
+ }
+
+ render() {
+ const msg = this.state.msg.toString().toLowerCase()
+ return (
+ <ErrMsg active={this.state.active}> {msg} </ErrMsg>
+ );
+ }
}
export default Error \ No newline at end of file