diff options
author | 2021-08-09 21:36:03 +0200 | |
---|---|---|
committer | 2021-08-09 21:37:03 +0200 | |
commit | 464e470441287572cfda8d95484f781236b9db35 (patch) | |
tree | 87177837cb6ee6ee000f0d39fa5ba7ee6bb2943e /components/Popup.js | |
download | my_apps-464e470441287572cfda8d95484f781236b9db35.tar.gz my_apps-464e470441287572cfda8d95484f781236b9db35.tar.bz2 my_apps-464e470441287572cfda8d95484f781236b9db35.zip |
init commit
Diffstat (limited to 'components/Popup.js')
-rw-r--r-- | components/Popup.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/components/Popup.js b/components/Popup.js new file mode 100644 index 0000000..911d2fa --- /dev/null +++ b/components/Popup.js @@ -0,0 +1,32 @@ +import React, {useState, useEffect} from 'react' + +const Popup = ({popup}) => { + const [visible, setVisible] = useState(false) + const { + content = null, + time = null, + error = null, + yes = null, + no = null, + } = popup + + useEffect(() => { + setVisible(true) + time && setTimeout(() => setVisible(false), time) + }, [popup]) + + if (!content) return null + + return visible ? ( + <div className={`window window--popup${error ? ' window--error' : ''}`}> + <div className="window__content--popup">{ content }</div> + { + (yes || no) && (<div className="window__buttons--popup"> + {[yes, no].map(a => a && <input key={a.label} className='window__button' type="button" onClick={() => { setVisible(false); a.action() }} value={a.label} />)} + </div>) + } + </div> + ) : null +} + +export default Popup |