Skip to content

Commit

Permalink
refactor: props defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Cweili committed Jan 16, 2024
1 parent e2bfa64 commit b4cc08e
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- run: npm run check
- run: npm run lint
- run: npm run build
- run: npm test -- --coverage.enabled --coverage.include=src/lib/**
- run: npm test

- uses: coverallsapp/github-action@master
with:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"prepublishOnly": "npm run package",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test": "vitest --typecheck",
"test": "vitest --typecheck --coverage.enabled",
"lint": "prettier --check . && eslint --ignore-path .gitignore .",
"format": "prettier --write ."
},
Expand Down
14 changes: 7 additions & 7 deletions src/lib/fa-layers-text.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<script lang="ts">
import { getTransform, setCutomFontSize } from "./utils.js";
import { getTransform, setCustomFontSize } from "./utils.js";
import type { FlipDir, IconSize } from "./types.js";
let clazz = "";
let clazz: string | undefined = undefined;
export { clazz as class };
export let id = "";
export let style = "";
export let size: IconSize | "" = "";
export let id: string | undefined = undefined;
export let style: string | undefined = undefined;
export let size: IconSize | undefined = undefined;
export let color = "";
export let scale: number | string = 1;
export let translateX: number | string = 0;
export let translateY: number | string = 0;
export let rotate: number | string = "";
export let rotate: number | undefined = undefined;
export let flip: FlipDir | undefined = undefined;
let containerElement: HTMLElement;
$: containerElement && size && setCutomFontSize(containerElement, size);
$: containerElement && size && setCustomFontSize(containerElement, size);
$: containerElement && color && (containerElement.style.color = color);
$: transform = getTransform(scale, translateX, translateY, rotate, flip, 1, "em", "deg");
$: containerElement && transform && (containerElement.style.transform = transform);
Expand Down
14 changes: 7 additions & 7 deletions src/lib/fa-layers.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<script lang="ts">
import { setCutomFontSize } from "./utils.js";
import { setCustomFontSize } from "./utils.js";
import type { IconSize, PullDir } from "./types.js";
let clazz = "";
let clazz: string | undefined = undefined;
export { clazz as class };
export let id = "";
export let style = "";
export let size: IconSize | "" = "";
export let id: string | undefined = undefined;
export let style: string | undefined = undefined;
export let size: IconSize | undefined = undefined;
export let pull: PullDir | undefined = undefined;
let containerElement: HTMLElement;
$: containerElement && size && setCutomFontSize(containerElement, size);
$: containerElement && size && setCustomFontSize(containerElement, size);
</script>

<!-- eslint-disable svelte/no-inline-styles -- Only styles passed to this component should be included -->
Expand All @@ -23,7 +23,7 @@
class:svelte-fa-size-sm={size === "sm"}
class:svelte-fa-size-xs={size === "xs"}
bind:this={containerElement}
style={style !== "" ? style : null}
{style}
>
<!-- eslint-enable -->
<slot />
Expand Down
20 changes: 10 additions & 10 deletions src/lib/fa.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<script lang="ts">
import type { IconDefinition } from "@fortawesome/fontawesome-common-types";
import { getTransform, setCutomFontSize } from "./utils.js";
import { getTransform, setCustomFontSize } from "./utils.js";
import type { FlipDir, IconSize, PullDir } from "./types.js";
let clazz = "";
let clazz: string | undefined = undefined;
export { clazz as class };
export let id = "";
export let style = "";
export let id: string | undefined = undefined;
export let style: string | undefined = undefined;
export let icon: IconDefinition;
export let size: IconSize | "" = "";
export let color = "";
export let size: IconSize | undefined = undefined;
export let color: string | undefined = undefined;
export let fw = false;
export let pull: PullDir | undefined = undefined;
export let scale: number | string = 1;
export let translateX: number | string = 0;
export let translateY: number | string = 0;
export let rotate: number | string = "";
export let rotate: number | string | undefined = undefined;
export let flip: FlipDir | undefined = undefined;
export let spin = false;
Expand All @@ -32,7 +32,7 @@
export let swapOpacity = false;
let svgElement: HTMLElement | SVGElement;
$: svgElement && size && setCutomFontSize(svgElement, size);
$: svgElement && size && setCustomFontSize(svgElement, size);
$: i = (icon && icon.icon) || [0, 0, "", [], ""];
Expand All @@ -42,7 +42,7 @@
{#if i[4]}
<!-- eslint-disable svelte/no-inline-styles -- Only styles passed to this component should be included -->
<svg
id={id || undefined}
{id}
class="svelte-fa svelte-fa-base {clazz}"
class:pulse
class:svelte-fa-size-lg={size === "lg"}
Expand All @@ -53,7 +53,7 @@
class:svelte-fa-pull-right={pull === "right"}
class:spin
bind:this={svgElement}
style={style !== "" ? style : null}
{style}
viewBox="0 0 {i[0]} {i[1]}"
aria-hidden="true"
role="img"
Expand Down
6 changes: 3 additions & 3 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IconSize } from "./types.js";

export function setCutomFontSize(element: HTMLElement | SVGElement, size: IconSize | ""): void {
export function setCustomFontSize(element: HTMLElement | SVGElement, size?: IconSize): void {
if (size && size !== "lg" && size !== "sm" && size !== "xs") {
element.style.fontSize = size.replace("x", "em");
} else {
Expand All @@ -12,8 +12,8 @@ export function getTransform(
scale: number | string,
translateX: number | string,
translateY: number | string,
rotate: number | string,
flip: string | undefined,
rotate?: number | string,
flip?: string | undefined,
translateTimes = 1,
translateUnit = "",
rotateUnit = "",
Expand Down
2 changes: 1 addition & 1 deletion src/basic.test.ts → test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, test, afterEach } from "vitest";
// @ts-expect-error No typings available
import { fasFlag, fasInfo } from "@cweili/fa-test-util";
import { render, screen, cleanup } from "@testing-library/svelte";
import Fa from "./lib/index.js";
import Fa from "../src/lib/index.js";

function mountFa(props: Partial<ComponentProps<Fa>>) {
cleanup();
Expand Down
2 changes: 1 addition & 1 deletion src/duotone.test.ts → test/duotone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test, afterEach } from "vitest";
// @ts-expect-error No typings available
import { fasFlag, fadFlag, fadInfo } from "@cweili/fa-test-util";
import { render, screen, cleanup } from "@testing-library/svelte";
import Fa from "./lib/index.js";
import Fa from "../src/lib/index.js";

function mountFa(props: Partial<ComponentProps<Fa>>) {
cleanup();
Expand Down
2 changes: 1 addition & 1 deletion src/layers.test.ts → test/layers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, test, afterEach } from "vitest";
import { render, screen, cleanup, configure } from "@testing-library/svelte";
import type { ComponentProps } from "svelte";

import { FaLayers, FaLayersText } from "./lib/index.js";
import { FaLayers, FaLayersText } from "../src/lib/index.js";

configure({ testIdAttribute: "id" });
afterEach(cleanup);
Expand Down
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
plugins: [sveltekit()],
test: {
include: ["src/**/*.{test,spec}.{js,ts}"],
include: ["test/**/*.{test,spec}.{js,ts}"],
environment: "jsdom",
coverage: {
include: ["src/lib/**/*"],
reporter: ["lcov"],
},
},
Expand Down

0 comments on commit b4cc08e

Please sign in to comment.