Skip to content

Commit

Permalink
Removed rest of inline styles from fa-layers.svelte
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic authored and Cweili committed Jan 16, 2024
1 parent 7f3f58f commit da615de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/layers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ test("basic", async () => {

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

test("color", async () => {
mountFaLayers({}, { color: "red" });
expect(getFaLayersText().querySelector("span")?.getAttribute("style")).toContain("color:red");
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 Down
9 changes: 5 additions & 4 deletions src/lib/fa-layers-text.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@
let containerElement: HTMLElement;
$: containerElement && size && setCutomFontSize(containerElement, size);
$: containerElement && color && (containerElement.style.color = color);
$: transform = getTransform(scale, translateX, translateY, rotate, flip, 1, "em", "deg");
$: fullStyle =
`transform: ${transform}` + (color ? `; color:${color}` : "") + (style ? `; ${style}` : "");
$: containerElement && transform && (containerElement.style.transform = transform);
</script>

<span {id} class="svelte-fa-layers-text {clazz}">
<!-- eslint-disable svelte/no-inline-styles -- Only styles passed to this component should be included -->
<span
class="svelte-fa-base container"
class:svelte-fa-size-lg={size === "lg"}
class:svelte-fa-size-sm={size === "sm"}
class:svelte-fa-size-xs={size === "xs"}
bind:this={containerElement}
style={fullStyle}
{style}
>
<!-- eslint-enable -->
<slot />
</span>
</span>
Expand Down

0 comments on commit da615de

Please sign in to comment.