فهرست منبع

feat: added ability for position to be chosen

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan 5 سال پیش
والد
کامیت
911761ae4f
4فایلهای تغییر یافته به همراه153 افزوده شده و 2 حذف شده
  1. 0 0
      dist/toasters.js
  2. 45 0
      example/index.html
  3. 2 2
      src/Toast.vue
  4. 106 0
      src/toasters.js

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/toasters.js


+ 45 - 0
example/index.html

@@ -7,5 +7,50 @@
 <body>
         <div id="toasts-container"></div>
         <script src="../dist/toasters.js"></script>
+        <style>
+        :root {
+                --max-width: 250px;
+        }
+
+        body {
+                padding: 0;
+                margin: 0;
+        }
+
+        .toast {
+                margin-top: 5px;
+                user-select: none;
+                z-index: 10000 !important;
+                animation-duration: 0.60s;
+                animation-fill-mode: both;
+                border-radius: 2px;
+                cursor: pointer;
+                clear: both;
+                position: relative;
+                transform: translateX(20px);
+                height: auto;
+                background-color: #323232;
+                color: #fff;
+                padding: 10px 25px;
+                font-size: 1rem;
+                font-weight: 300;
+                width: var(--max-width);
+                box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
+        }
+
+        .toast-right {
+                transform: translateX(calc(100vw - (var(--max-width) + 50px) - 20px ));
+        }
+
+        .toast-left {
+                transform: translateX(20px);
+        }
+
+        .toast-top {
+        }
+
+        .toast-bottom {
+        }
+        </style>
 </body>
 </html>

+ 2 - 2
src/Toast.vue

@@ -101,11 +101,11 @@
         border-radius: 2px;
         cursor: pointer;
         top: 20px;
-        right: 200px;
+        /* right: 200px; */
         min-width: 225px;
         clear: both;
         margin-top: 10px;
-        position: static;
+        /* position: static; */
         height: auto;
         background-color: #323232;
         padding: 10px 25px;

+ 106 - 0
src/toasters.js

@@ -0,0 +1,106 @@
+document.body.style.backgroundColor = "#eee";
+
+const container = document.getElementById("toasts-container");
+
+let incrementer = 0;
+
+class Toast {
+	// should add type checking
+	constructor(content, persistant, timeout, position) {
+		console.log(position);
+
+		this.identifier = `toast-${incrementer}`;
+		incrementer++;
+
+		this.visible = false;
+
+		this.position = position;
+		this.content = content;
+		this.persistant = persistant;
+		this.timeout = timeout;
+
+		if (!this.persistant) this.startTimer();
+
+		this.dragListener();
+	}
+
+	get content() {
+		return this._content;
+	}
+
+	set content(value) {
+		this._content = value;
+		this.display();
+	}
+
+	startTimer() {
+		setTimeout(this.clear.bind(this), this.timeout);
+	}
+
+	display() {
+		if (!this.visible) {
+			container.insertAdjacentHTML("beforeend", `<div class="toast ${this.identifier} toast-${this.position} toast-bottom">${this.content}</div>`);
+			this.find();
+		} else
+			this.element.innerHTML = this.content;
+
+		this.visible = true;
+	}
+
+	dragListener() {
+		this.element.addEventListener("mousedown", event => {
+
+			// this.element.style.position = "absolute";
+
+			// this.element.ondragstart = () => {
+			// 	return false;
+			// }
+
+			let shiftX = event.clientX - this.element.getBoundingClientRect().x;
+
+			const move = ({ pageX }) => {
+				this.element.style.transform = `translate(${pageX - shiftX}px)`;
+			}
+
+			console.log("Mousedown");
+
+			window.addEventListener("mousemove", move, false);
+
+			window.addEventListener("mouseup", () => {
+				console.log("Mouseup");
+				window.removeEventListener("mousemove", move, false);
+			}, false);
+
+		}, false);
+	}
+
+	find() {
+		for (let i = 0; i < container.childNodes.length; i++)
+			if (container.childNodes[i].classList.contains(this.identifier))
+				return this.element = container.childNodes[i];
+	}
+
+	clear() {
+		this.element.remove();
+	}
+}
+
+// const add = (
+// 	content,
+// 	persistant,
+// 	timeout,
+// ) => {
+// 	const red = new Toast(
+// 		content,
+// 		persistant,
+// 		timeout
+// 	);
+// }
+
+const red = new Toast("This is a test for content", true, 5000, "right");
+const pink = new Toast("ALWAYS HERE AND ALWAYS PINK", true, 5000, "left");
+
+
+export default {
+	
+};

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است