Skip to content

Commit

Permalink
Fixed type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Jan 15, 2024
1 parent d440022 commit dbf3bc0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe("size", () => {
size: "2x",
});
const style = getComputedStyle(getFa());
expect(style["font-size"]).toBe("2em");
expect(style.getPropertyValue("font-size")).toBe("2em");
});

test("lg", async () => {
Expand Down
12 changes: 7 additions & 5 deletions src/layers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ test("basic", async () => {

expect(getFaLayersText("b").getAttribute("id")).toBe("b");
expect(getFaLayersText("b").getAttribute("class")).toContain("class-b");
expect(getComputedStyle(getFaLayersText("b").querySelector("span"))["color"]).toBe(
expect(getComputedStyle(getFaLayersText("b").querySelector("span")!)["color"]).toBe(
"rgb(0, 0, 255)",
);
});

test("color", async () => {
mountFaLayers({}, { color: "red" });
expect(getComputedStyle(getFaLayersText().querySelector("span"))["color"]).toBe("rgb(255, 0, 0)");
expect(getComputedStyle(getFaLayersText().querySelector("span")!)["color"]).toBe(
"rgb(255, 0, 0)",
);
mountFaLayers({}, { color: undefined });
expect(getFaLayersText().querySelector("span")?.getAttribute("style")).not.toContain("color:red");
});
Expand All @@ -80,9 +82,9 @@ describe("size", () => {
mountFaLayers({ size: "2x" }, { size: "2x" });

const style = getComputedStyle(getFaLayers());
const styleText = getComputedStyle(getFaLayersText().querySelector("span"));
expect(style["font-size"]).toBe("2em");
expect(styleText["font-size"]).toBe("2em");
const styleText = getComputedStyle(getFaLayersText().querySelector("span")!);
expect(style.getPropertyValue("font-size")).toBe("2em");
expect(styleText.getPropertyValue("font-size")).toBe("2em");
});

test("lg", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/fa.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
export let secondaryOpacity: number | string = 0.4;
export let swapOpacity = false;
let svgElement: HTMLElement;
let svgElement: HTMLElement | SVGElement;
$: svgElement && size && setCutomFontSize(svgElement, size);
$: i = (icon && icon.icon) || [0, 0, "", [], ""];
Expand Down
8 changes: 5 additions & 3 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export function setCutomFontSize(element: HTMLElement, size: IconSize | ""): void {
if (size && size !== "lg" && size !== "sm" && size !== "xs" && size !== "") {
import type { IconSize } from "./types.js";

export function setCutomFontSize(element: HTMLElement | SVGElement, size: IconSize | ""): void {
if (size && size !== "lg" && size !== "sm" && size !== "xs") {
element.style.fontSize = size.replace("x", "em");
} else {
element.style.fontSize = undefined;
element.style.fontSize = "";
}
}

Expand Down

0 comments on commit dbf3bc0

Please sign in to comment.