From 464e470441287572cfda8d95484f781236b9db35 Mon Sep 17 00:00:00 2001 From: piotrruss Date: Mon, 9 Aug 2021 21:36:03 +0200 Subject: init commit --- components/Popup.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 components/Popup.js (limited to 'components/Popup.js') 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 ? ( +
+
{ content }
+ { + (yes || no) && (
+ {[yes, no].map(a => a && { setVisible(false); a.action() }} value={a.label} />)} +
) + } +
+ ) : null +} + +export default Popup -- cgit v1.2.3