Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add toJSON to icon and cast as any #2094

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spotty-schools-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ebay/ebayui-core": patch
---

optimize icons with toJSON
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { WithNormalizedProps } from "../../../global";

interface TooptipBaseInput {
open?: boolean;
toJSON?: () => Object;
type: string;
offset?: number;
"no-hover"?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/components/ebay-tooltip-base/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ static function toJSON(this: any) {
}
}

$ input.toJSON = toJSON;
$ (input as any).toJSON = toJSON;

$ const {
overlayStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { typeRoles } from "./constants";
import type { WithNormalizedProps } from "../../../global";

interface TooltipOverlayInput {
toJSON?: any;
"style-top"?: string;
"style-left"?: string;
"style-right"?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/components/ebay-tooltip-overlay/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { typeRoles } from "./constants";

static function noop() {}

$ input.toJSON = noop;
$ (input as any).toJSON = noop;

$ const {
id,
Expand Down
3 changes: 1 addition & 2 deletions src/components/ebay-button/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export interface ButtonEvent<T extends Event> {

export interface ButtonInput extends Omit<Marko.Input<"button">, `on${string}`> {
href?: string;
toJSON?: () => Object;
size?: (typeof validSizes)[number];
priority?: "primary" | "secondary" | "tertiary" | "none";
variant?: "standard" | "destructive" | "form";
Expand Down Expand Up @@ -68,7 +67,7 @@ static var validPriorities = [
];

$ {
input.toJSON = toJSON;
(input as any).toJSON = toJSON;
var size = inputSize && validSizes.includes(inputSize) ? inputSize : null;

var priority = inputPriority || "secondary";
Expand Down
1 change: 0 additions & 1 deletion src/components/ebay-checkbox/component-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export interface CheckboxEvent {
checked: boolean;
}
interface CheckboxInput extends Omit<Marko.Input<"input">, `on${string}`> {
toJSON?: any;
"icon-style"?: "rounded" | "square";
"on-change"?: (e: CheckboxEvent) => void;
"on-focus"?: (e: CheckboxEvent) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ebay-checkbox/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ const {
...htmlInput
} = input;

$ input.toJSON = noop;
$ (input as any).toJSON = noop;

<span class=["checkbox", inputClass] style=style>
<input
Expand Down
1 change: 0 additions & 1 deletion src/components/ebay-details/component-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { WithNormalizedProps } from "../../global";

export interface DetailsInput
extends Omit<Marko.Input<"details">, `on${string}`> {
toJSON?: any;
text: string;
size?: "regular" | "small";
alignment?: "regular" | "center";
Expand Down
3 changes: 1 addition & 2 deletions src/components/ebay-details/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ $ const {
text,
renderBody,
as: inputAs,
toJSON,
...htmlInput
} = input;

$ input.toJSON = noop;
$ (input as any).toJSON = noop;

<details
...processHtmlAttributes(htmlInput)
Expand Down
14 changes: 5 additions & 9 deletions src/components/ebay-details/test/test.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,27 @@ use(require("chai-dom"));

describe("details", () => {
it("renders basic version", async () => {
const input = mock.Default_Details;
const input = { ...mock.Default_Details };
await htmlSnap(template, input);
});

it("renders as div version", async () => {
const input = Object.assign({}, mock.Default_Details, { as: "div" });
const input = { ...mock.Default_Details, as: "div" };
await htmlSnap(template, input);
});

it("renders in open state", async () => {
const input = mock.Open_Details;
const input = { ...mock.Default_Details };
await htmlSnap(template, input);
});

it("renders small version", async () => {
const input = Object.assign({}, mock.Default_Details, {
size: "small",
});
const input = { ...mock.Default_Details, size: "small" };
await htmlSnap(template, input);
});

it("renders center version", async () => {
const input = Object.assign({}, mock.Default_Details, {
alignment: "center",
});
const input = { ...mock.Default_Details, alignment: "center" };
await htmlSnap(template, input);
});

Expand Down
1 change: 0 additions & 1 deletion src/components/ebay-eek/eek-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const validRanges = {
};

interface EekInput extends Omit<Marko.Input<"div">, `on${string}`> {
toJSON?: any;
max: string;
min: string;
rating: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ebay-eek/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $ const {
...htmlInput
} = input;

$ input.toJSON = noop;
$ (input as any).toJSON = noop;
$ const eekRating = eekUtil(input);
<div
...processHtmlAttributes(htmlInput)
Expand Down
1 change: 0 additions & 1 deletion src/components/ebay-fake-link/component-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as eventUtils from "../../common/event-utils";
import type { WithNormalizedProps } from "../../global";

interface FakeLinkInput extends Omit<Marko.Input<"button">, `on${string}`> {
toJSON?: any;
variant?: "inline" | "standalone";
"on-click"?: (event: { originalEvent: MouseEvent }) => void;
"on-escape"?: (event: { originalEvent: KeyboardEvent }) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ebay-fake-link/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $ const {
...htmlInput
} = input;

$ input.toJSON = toJSON;
$ (input as any).toJSON = toJSON;

<button
...processHtmlAttributes(htmlInput)
Expand Down
1 change: 0 additions & 1 deletion src/components/ebay-icon-button/component-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as eventUtils from "../../common/event-utils";
import type { WithNormalizedProps } from "../../global";

interface IconButtonInput extends Omit<Marko.Input<"button">, `on${string}`> {
toJSON?: any;
"badge-number"?: number | string;
href?: string;
transparent?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ebay-icon-button/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $ const {
...htmlInput
} = input;

$ input.toJSON = toJSON;
$ (input as any).toJSON = toJSON;
$ const tagType = href ? "a" : "button";

<${tagType}
Expand Down
4 changes: 4 additions & 0 deletions src/components/ebay-icon/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ static var isBrowser = typeof window !== "undefined";

static var browserLookup: Record<string, unknown> = {};

static function noop() {}

$ const {
_name,
_type,
Expand All @@ -16,6 +18,8 @@ $ const {
...htmlInput
} = input;

$ (input as any).toJSON = noop;

static function getIconClass(type: string, name: string) {
if (type === "icon") {
return `icon icon--${name}`;
Expand Down
1 change: 0 additions & 1 deletion src/components/ebay-radio/component-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export interface RadioEvent {
value: string;
}
interface RadioInput extends Omit<Marko.Input<"input">, `on${string}`> {
toJSON?: any;
"icon-style"?: "rounded" | "square";
"on-change"?: (e: RadioEvent, el: HTMLInputElement) => void;
"on-focus"?: (e: RadioEvent, el: HTMLInputElement) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ebay-radio/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $ const {
...htmlInput
} = input;

$ input.toJSON = noop;
$ (input as any).toJSON = noop;

<span class=["radio", inputClass] style=style>
<input
Expand Down
1 change: 0 additions & 1 deletion src/components/ebay-switch/component-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface SwitchEvent {
}

interface SwitchInput extends Omit<Marko.Input<"input">, `on${string}`> {
toJSON?: any;
"on-change"?: (event: SwitchEvent) => void;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/ebay-switch/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $ const {
...htmlInput
} = input;

$ input.toJSON = noop;
$ (input as any).toJSON = noop;

<span class=["switch", inputClass] style=style>
<input
Expand Down
1 change: 0 additions & 1 deletion src/components/ebay-textbox/component-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface TextboxEvent {
}

interface TextboxInput extends Omit<Marko.Input<"textarea">, `on${string}`> {
toJSON?: any;
multiline?: boolean;
type?: Marko.Input<"input">["type"];
"input-size"?: "regular" | "large";
Expand Down
2 changes: 1 addition & 1 deletion src/components/ebay-textbox/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $ const {
...htmlInput
} = input;

$ input.toJSON = toJSON;
$ (input as any).toJSON = toJSON;
$ var isPostfix = !!postfixIcon;
$ var hasIcon = prefixIcon || isPostfix;
$ var isLarge = inputSize === "large";
Expand Down
Loading