From be52cd3265f93b09fc400ecaa58cde0a93ed41e6 Mon Sep 17 00:00:00 2001
From: lonkaars <l.leblansch@gmail.com>
Date: Sat, 16 Jan 2021 10:38:15 +0100
Subject: notification be gone

---
 src/components/toast.tsx | 78 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 src/components/toast.tsx

(limited to 'src/components/toast.tsx')

diff --git a/src/components/toast.tsx b/src/components/toast.tsx
new file mode 100644
index 0000000..1d467bd
--- /dev/null
+++ b/src/components/toast.tsx
@@ -0,0 +1,78 @@
+import { CSSProperties, ReactNode, Component } from "react";
+
+import CloseIcon from '@material-ui/icons/Close';
+
+export function ToastArea(props: {
+	style?: CSSProperties
+	children?: ReactNode
+}) {
+	return <div id="ToastArea" style={{
+		position: "fixed",
+		whiteSpace: "nowrap",
+		bottom: 12,
+		left: "50%",
+		transform: "translateX(-50%)",
+		zIndex: 1,
+		maxWidth: 600,
+		width: "calc(100% - 48px - 48px)",
+		margin: "0 24px",
+		...props.style
+	}}>{props.children}</div>
+}
+
+export class Toast extends Component<{
+	text?: string
+	icon?: ReactNode
+	children?: ReactNode
+	type?: "normal"|"confirmation"|"error"
+	style?: CSSProperties
+}> {
+	state = { render: true }
+
+	close = () => this.setState({ render: false })
+
+	render () {
+		if (!this.state.render) return null;
+		return <div style={{
+			padding: 0,
+			marginBottom: 12,
+			borderRadius: 8,
+			color: "var(--text)",
+			boxShadow: "0 8px 12px -4px #00000033",
+			backgroundColor:
+				this.props.type === "normal" ? "var(--background)" :
+				this.props.type === "confirmation" ? "var(--disk-a)" :
+				this.props.type === "error" ? "var(--disk-b)" : "var(--background)",
+			...this.props.style
+		}}>
+		{
+			this.props.children ?
+			this.props.children :
+			<div style={{ lineHeight: 0 }}>
+				<div style={{
+					fontSize: 0,
+					margin: 16,
+					display: "inline-block",
+					verticalAlign: "top",
+					width: 32, height: 32
+				}}>{this.props.icon}</div>
+				<h2 style={{
+					margin: "20px 0",
+					display: "inline-block",
+					width: "calc(100% - 128px)",
+					verticalAlign: "top",
+					fontSize: 20
+				}}>{this.props.text}</h2>
+				<div style={{
+					padding: 20,
+					display: "inline-block",
+					cursor: "pointer"
+				}} onClick={this.close}>
+					<CloseIcon style={{ fontSize: 24 }}/>
+				</div>
+			</div>
+		}
+		</div>
+	}
+}
+
-- 
cgit v1.2.3

