forked from extern/bruno
feat: Toast component
This commit is contained in:
parent
7ee80298f9
commit
c857088e2d
74
renderer/components/Toast/StyledWrapper.js
Normal file
74
renderer/components/Toast/StyledWrapper.js
Normal file
@ -0,0 +1,74 @@
|
||||
import styled from 'styled-components';
|
||||
|
||||
const Wrapper = styled.div`
|
||||
&.grafnode-toast {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.grafnode-toast-card {
|
||||
-webkit-animation-duration: .85s;
|
||||
animation-duration: .85s;
|
||||
-webkit-animation-delay: .1s;
|
||||
animation-delay: .1s;
|
||||
border-radius: var(--border-radius);
|
||||
position: relative;
|
||||
max-width: calc(100% - var(--spacing-base-unit));
|
||||
margin: 3vh 10vw;
|
||||
|
||||
animation: fade-and-slide-in-from-top .50s forwards cubic-bezier(.19,1,.22,1);
|
||||
}
|
||||
|
||||
.notification-toast-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
padding: 5px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.alert {
|
||||
position: relative;
|
||||
padding: .25rem .75rem;
|
||||
border: 1px solid transparent;
|
||||
border-radius: .25rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
color: #721c24;
|
||||
background-color: #f8d7da;
|
||||
border-color: #f5c6cb;
|
||||
}
|
||||
|
||||
.alert-info {
|
||||
color: #004085;
|
||||
background-color: #cce5ff;
|
||||
border-color: #b8daff;
|
||||
}
|
||||
|
||||
.alert-warning {
|
||||
color: #856404;
|
||||
background-color: #fff3cd;
|
||||
border-color: #ffeeba;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
color: #155724;
|
||||
background-color: #d4edda;
|
||||
border-color: #c3e6cb;
|
||||
}
|
||||
|
||||
.closeToast {
|
||||
cursor: pointer;
|
||||
padding-left: 10px;
|
||||
}
|
||||
`;
|
||||
|
||||
export default Wrapper;
|
38
renderer/components/Toast/index.js
Normal file
38
renderer/components/Toast/index.js
Normal file
@ -0,0 +1,38 @@
|
||||
import React, {useEffect} from 'react';
|
||||
import StyledWrapper from './StyledWrapper';
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faTimes } from "@fortawesome/free-solid-svg-icons";
|
||||
|
||||
const ToastContent = ({type, text, handleClose}) => (
|
||||
<div className={`alert alert-${type}`} role="alert">
|
||||
<div> {text} </div>
|
||||
<div onClick={handleClose} className="closeToast">
|
||||
<FontAwesomeIcon size="xs" icon={faTimes}/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const Toast = ({
|
||||
text,
|
||||
type,
|
||||
duration,
|
||||
handleClose
|
||||
}) => {
|
||||
let lifetime = duration ? duration : 3000;
|
||||
|
||||
useEffect(() => {
|
||||
if(text) {
|
||||
setTimeout(handleClose, lifetime);
|
||||
}
|
||||
}, [text]);
|
||||
|
||||
return (
|
||||
<StyledWrapper className='grafnode-toast'>
|
||||
<div className='grafnode-toast-card'>
|
||||
<ToastContent type={type} text={text} handleClose={handleClose}></ToastContent>
|
||||
</div>
|
||||
</StyledWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
export default Toast;
|
Loading…
Reference in New Issue
Block a user