Refactor utils/html

This commit is contained in:
redphx 2024-10-18 16:54:29 +07:00
parent 1e644504ec
commit b27cfc8215
2 changed files with 5 additions and 6 deletions

View File

@ -1,3 +1,4 @@
// Credit: https://phosphoricons.com
import iconBetterXcloud from "@assets/svg/better-xcloud.svg" with { type: "text" };
import iconTrueAchievements from "@assets/svg/true-achievements.svg" with { type: "text" };
import iconClose from "@assets/svg/close.svg" with { type: "text" };

View File

@ -101,16 +101,14 @@ function createElement<T=HTMLElement>(elmName: string, props: CreateElementOptio
export const CE = createElement;
// Credit: https://phosphoricons.com
const svgParser = (svg: string) => new DOMParser().parseFromString(svg, 'image/svg+xml').documentElement;
export const createSvgIcon = (icon: typeof BxIcon) => {
return svgParser(icon.toString());
const domParser = new DOMParser();
export function createSvgIcon(icon: typeof BxIcon) {
return domParser.parseFromString(icon.toString(), 'image/svg+xml').documentElement;
}
const ButtonStyleIndices = Object.keys(ButtonStyleClass).map(i => parseInt(i));
export const createButton = <T=HTMLButtonElement>(options: BxButton): T => {
export function createButton<T=HTMLButtonElement>(options: BxButton): T {
let $btn;
if (options.url) {
$btn = CE('a', {'class': 'bx-button'}) as HTMLAnchorElement;