소스 검색

feat: multiple ways of creating a toast (e.g. a toast with no custom options)

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan 4 년 전
부모
커밋
573f4d5057
4개의 변경된 파일29개의 추가작업 그리고 21개의 파일을 삭제
  1. 7 3
      README.md
  2. 0 0
      dist/toasters.js
  3. 10 12
      example/index.js
  4. 12 6
      src/toasters.js

+ 7 - 3
README.md

@@ -23,13 +23,17 @@
 ```js
 import Toast from "toasters";
 
-new Toast(options);
-
 // example
 new Toast({
   content: "Hello World",
-  persistent: true
+  interactable: false
 });
+
+// or
+new Toast("Hello World");
+
+// or
+new Toast("Hello World", { persistent: true, timeout: 9000 });
 ```
 
 **Preview:**

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/toasters.js


+ 10 - 12
example/index.js

@@ -6,25 +6,23 @@ import Toast from "../dist/toasters.js";
 // 	interactable: false
 // });
 
+const TestNotification1 = new Toast("1", { timeout: 1000 });
+
+
 const TestNotification2 = new Toast({
 	content: "2",
 	persistent: true,
 	interactable: true
 });
 
-
-setTimeout(() => {
-	TestNotification2.show();
-}, 2000);
+// setTimeout(() => {
+// 	TestNotification2.show();
+// }, 2000);
 
 
-setTimeout(() => {
-	TestNotification2.visible = false;
-}, 4000);
+// setTimeout(() => {
+// 	TestNotification2.visible = false;
+// }, 4000);
 
-// const TestNotification3 = new Toast({
-// 	content: "lorem ispum lorem hello my name is lorem ispum lorem ispum lorem ispum lorem ispum ",
-// 	persistent: true,
-// 	interactable: true
-// });
+const TestNotification3 = new Toast("lorem ispum lorem hello my name is lorem ispum lorem ispum lorem ispum lorem ispum ", { interactable: false });
 

+ 12 - 6
src/toasters.js

@@ -4,17 +4,23 @@ let incrementer = 0;
 
 export default class Toast {
 	// should add type checking
-	constructor({ content, persistent, interactable, timeout, visible }) {
+	constructor(...args) {
+		let options = {};
+
+		if (typeof args[0] === "object") options = args[0];
+		else if (typeof args[0] === "string" && typeof args[1] === "object") options = { ...args[1], content: args[0] };
+		else if (typeof args[0] === "string") options.content = args[0];
+
 		this.identifier = `toast-${incrementer}`;
 		incrementer++;
 
-		this.persistent = persistent !== undefined ? persistent : false;
-		this.timeout = timeout ? timeout : 6000;
-		this.interactable = interactable !== undefined ? interactable : true;
+		this.persistent = options.persistent !== undefined ? options.persistent : false;
+		this.timeout = options.timeout ? options.timeout : 6000;
+		this.interactable = options.interactable !== undefined ? options.interactable : true;
 
-		this.content = content;
+		this.content = options.content;
 
-		this.visible = visible !== undefined ? visible : true;
+		this.visible = options.visible !== undefined ? options.visible : true;
 
 		if (!this.persistent) this.startTimer();
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.