瀏覽代碼

fix: ts types & promise support in circ. btn icon

Sv443 11 月之前
父節點
當前提交
e878d04075
共有 3 個文件被更改,包括 8 次插入5 次删除
  1. 7 3
      src/components/circularButton.ts
  2. 1 1
      src/components/longButton.ts
  3. 0 1
      src/interface.ts

+ 7 - 3
src/components/circularButton.ts

@@ -4,12 +4,12 @@ import type { ResourceKey } from "../types";
 type CircularBtnOptions = (
   | {
     /** Resource key for the button icon */
-    resourceName: ResourceKey | "_";
+    resourceName: (ResourceKey & `icon-${string}`) | "_";
     /** Tooltip and aria-label of the button */
     title: string;
   }
   | {
-    src: string;
+    src: string | Promise<string>;
     /** Tooltip and aria-label of the button */
     title: string;
   }
@@ -56,7 +56,11 @@ export async function createCircularBtn({
 
   const imgElem = document.createElement("img");
   imgElem.classList.add("bytm-generic-btn-img");
-  imgElem.src = "src" in rest ? rest.src : await getResourceUrl(rest.resourceName);
+  imgElem.src = "src" in rest
+    ? rest.src instanceof Promise
+      ? await rest.src
+      : rest.src
+    : await getResourceUrl(rest.resourceName);
 
   btnElem.appendChild(imgElem);
 

+ 1 - 1
src/components/longButton.ts

@@ -4,7 +4,7 @@ import type { ResourceKey } from "../types";
 type LongBtnOptions = (
   | {
     /** Resource key for the button icon */
-    resourceName: ResourceKey | "_";
+    resourceName: (ResourceKey & `icon-${string}`) | "_";
   }
   | {
     src: string;

+ 0 - 1
src/interface.ts

@@ -130,7 +130,6 @@ const globalFuncs = {
   createHotkeyInput,
   createToggleInput,
   createCircularBtn,
-  // TODO: document
   showToast,
   showIconToast,
   createRipple,