From 94a9b304546dd1213ef2f15e57f5966ab88b80b7 Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Tue, 12 May 2020 23:08:20 -0700 Subject: abstract err show logic --- frontend/src/components/Err.js | 50 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'frontend/src/components/Err.js') 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 ( - {msg} - ); +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 ( + {msg} + ); + } } export default Error \ No newline at end of file -- cgit v1.2.3