Skip to content

Commit

Permalink
refactor(ts): use AttrString for text instead of string (#2049)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuLaValva authored Jan 23, 2024
1 parent e653d7e commit 658ef38
Show file tree
Hide file tree
Showing 37 changed files with 129 additions and 105 deletions.
8 changes: 4 additions & 4 deletions src/components/components/ebay-dialog-base/component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as keyboardTrap from "makeup-keyboard-trap";
import * as screenReaderTrap from "makeup-screenreader-trap";
import type { AttrClass } from "marko/tags-html";
import type { AttrClass, AttrString } from "marko/tags-html";
import * as bodyScroll from "../../../common/body-scroll";
import * as eventUtils from "../../../common/event-utils";
import transition from "../../../common/transition";
Expand All @@ -17,9 +17,9 @@ interface DialogBaseInput extends Omit<Marko.Input<"div">, `on${string}`> {
}
>;
"class-prefix"?: string;
"close-button-text"?: string;
"close-button-text"?: AttrString;
"close-button-class"?: AttrClass;
"a11y-close-text"?: string;
"a11y-close-text"?: AttrString;
"close-button"?: Marko.Renderable;
"is-modal"?: boolean;
"ignore-escape"?: boolean;
Expand All @@ -42,7 +42,7 @@ interface DialogBaseInput extends Omit<Marko.Input<"div">, `on${string}`> {
focus?: string;
prevButton?: WithNormalizedProps<
Omit<Marko.Input<"button">, `on${string}`> & {
"a11y-text"?: string;
"a11y-text"?: AttrString;
}
>;
"on-open"?: (event: Event) => void;
Expand Down
9 changes: 5 additions & 4 deletions src/components/components/ebay-notice-base/component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AttrString } from "marko/tags-html";
import type { WithNormalizedProps } from "../../../global";

interface NoticeBaseInput
Expand All @@ -12,15 +13,15 @@ interface NoticeBaseInput
"prefix-class"?: string;
root?: Marko.Renderable;
"no-a11y-label"?: boolean;
"a11y-role-description"?: string;
"a11y-role-description"?: AttrString;
icon?: "none";
"icon-class"?: string;
"header-root"?: Marko.Renderable;
"a11y-text"?: string;
"a11y-icon-text"?: string;
"a11y-text"?: AttrString;
"a11y-icon-text"?: AttrString;
"main-root"?: Marko.Renderable;
footer?: Marko.Renderable;
"a11y-dismiss-text"?: string;
"a11y-dismiss-text"?: AttrString;
title?: Marko.Input<"title"> & {
as?: Marko.Renderable;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AttrClass } from "marko/tags-html";
import type { AttrClass, AttrString } from "marko/tags-html";
import { typeRoles } from "./constants";
import type { WithNormalizedProps } from "../../../global";

Expand All @@ -15,7 +15,7 @@ interface TooltipOverlayInput {
id?: string;
type: keyof typeof typeRoles;
content?: Marko.AttrTag<Marko.Input<"span">>;
"a11y-close-text"?: string;
"a11y-close-text"?: AttrString;
footer?: Marko.AttrTag<
Marko.Renderable & {
class?: AttrClass;
Expand Down
10 changes: 5 additions & 5 deletions src/components/ebay-3d-viewer/component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { AttrClass } from "marko/tags-html";
import type { AttrClass, AttrString } from "marko/tags-html";
import { CDNLoader } from "../../common/cdn";
import type { WithNormalizedProps } from "../../global";

interface ViewerInput {
"cdn-url"?: string;
version?: string;
class?: AttrClass;
"a11y-text"?: string;
"a11y-text"?: AttrString;
src?: string;
"error-text"?: string;
"a11y-start-text"?: string;
"a11y-load-text"?: string;
"error-text"?: AttrString;
"a11y-start-text"?: AttrString;
"a11y-load-text"?: AttrString;
// TODO: import types from @google/model-viewer instead of
// listing manually from https://modelviewer.dev/docs
poster?: string;
Expand Down
3 changes: 2 additions & 1 deletion src/components/ebay-alert-dialog/index.marko
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Input as BaseInput } from "<ebay-dialog-base>";
import type { WithNormalizedProps } from "../../global";
import type { AttrString } from "marko/tags-html";

static interface AlertDialogInput extends Omit<BaseInput, `on${string}`> {
"confirm-text"?: string;
"confirm-text"?: AttrString;
"on-open"?: () => void;
"on-close"?: () => void;
"on-confirm"?: () => void;
Expand Down
3 changes: 2 additions & 1 deletion src/components/ebay-avatar/index.marko
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { processHtmlAttributes } from "../../common/html-attributes";
import { getColorForText } from "./util";
import type { WithNormalizedProps } from "../../global";
import type { AttrString } from "marko/tags-html";

static type Size = 32 | 40 | 48 | 56 | 64 | 96 | 128;

static interface AvatarInput extends Omit<Marko.Input<"div">, `on${string}`> {
username?: string;
color?: string;
"a11y-text"?: string;
"a11y-text"?: AttrString;
size?: Size | `${Size}`;
img?: Marko.AttrTag<Omit<Marko.Input<"img">, `on${string}`>>;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ebay-breadcrumbs/component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as eventUtils from "../../common/event-utils";
import { getMaxWidth } from "../../common/dom";
import type { AttrClass } from "marko/tags-html";
import type { AttrClass, AttrString } from "marko/tags-html";
import type { MenuEvent } from "../ebay-menu/component";
import type { WithNormalizedProps } from "../../global";

interface BreadcrumbsInput extends Omit<Marko.Input<"nav">, `on${string}`> {
"a11y-heading-tag"?: keyof Marko.NativeTags;
"a11y-heading-text"?: string;
"a11y-menu-button-text"?: string;
"a11y-heading-text"?: AttrString;
"a11y-menu-button-text"?: AttrString;
class?: AttrClass;
items: Marko.RepeatableAttrTag<
Marko.Input<"a"> | (Marko.Input<"button"> & { href: never })
Expand Down
5 changes: 3 additions & 2 deletions src/components/ebay-button/index.marko
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AttrString } from "marko/tags-html";
import { processHtmlAttributes } from "../../common/html-attributes"
import type { WithNormalizedProps } from "../../global";

Expand All @@ -24,8 +25,8 @@ export interface ButtonInput extends Omit<Marko.Input<"button">, `on${string}`>
"fixed-height"?: boolean;
truncate?: boolean;
split?: string;
"a11y-text"?: string;
"aria-label"?: string;
"a11y-text"?: AttrString;
"aria-label"?: AttrString;
"on-click"?: (event: ButtonEvent<MouseEvent>) => void;
"on-escape"?: (event: ButtonEvent<KeyboardEvent>) => void;
"on-focus"?: (event: ButtonEvent<FocusEvent>) => void;
Expand Down
13 changes: 7 additions & 6 deletions src/components/ebay-calendar/component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AttrString } from "marko/tags-html";
import type { WithNormalizedProps } from "../../global";
import {
dateArgToISO,
Expand Down Expand Up @@ -29,12 +30,12 @@ interface CalendarInput {
"disable-list"?: (Date | number | string)[];
"link-builder"?: (iso: string) => string | false | null | undefined;
"get-a11y-show-month-text"?: (monthName: string) => string;
"a11y-selected-text"?: string;
"a11y-range-start-text"?: string;
"a11y-in-range-text"?: string;
"a11y-range-end-text"?: string;
"a11y-today-text"?: string;
"a11y-disabled-text"?: string;
"a11y-selected-text"?: AttrString;
"a11y-range-start-text"?: AttrString;
"a11y-in-range-text"?: AttrString;
"a11y-range-end-text"?: AttrString;
"a11y-today-text"?: AttrString;
"a11y-disabled-text"?: AttrString;
"a11y-separator"?: string;
"on-select"?: (event: { iso: DayISO }) => void;
"on-focus"?: (event: { iso: DayISO }) => void;
Expand Down
12 changes: 6 additions & 6 deletions src/components/ebay-calendar/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ $ var monthDates = [...Array(numMonths)].map((_, i) => component.getMonthDate(st
$ var isRangeEnd = dayISO === state.rangeEnd;
$ var isDisabled = component.isDisabled(dayISO);
$ var a11yTexts = [""];
$ if (isSelected) a11yTexts.push(a11ySelectedText);
$ if (isRangeStart) a11yTexts.push(a11yRangeStartText);
$ if (!isRangeStart && !isRangeEnd && isInRange) a11yTexts.push(a11yInRangeText);
$ if (isRangeEnd) a11yTexts.push(a11yRangeEndText);
$ if (a11ySelectedText && isSelected) a11yTexts.push(a11ySelectedText);
$ if (a11yRangeStartText && isRangeStart) a11yTexts.push(a11yRangeStartText);
$ if (a11yInRangeText && !isRangeStart && !isRangeEnd && isInRange) a11yTexts.push(a11yInRangeText);
$ if (a11yRangeEndText && isRangeEnd) a11yTexts.push(a11yRangeEndText);

<td class={
"calendar__cell--selected": isSelected,
Expand All @@ -111,8 +111,8 @@ $ var monthDates = [...Array(numMonths)].map((_, i) => component.getMonthDate(st
</button>
</if>
<else>
$ if (isToday) a11yTexts.push(a11yTodayText);
$ if (isDisabled) a11yTexts.push(a11yDisabledText);
$ if (a11yTodayText && isToday) a11yTexts.push(a11yTodayText);
$ if (a11yDisabledText && isDisabled) a11yTexts.push(a11yDisabledText);
$ var link = !isDisabled && linkBuilder && linkBuilder(dayISO);
<${link ? "a" : "span"}
class={
Expand Down
10 changes: 5 additions & 5 deletions src/components/ebay-carousel/component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import focusables from "makeup-focusables";
import type { AttrClass, AttrStyle } from "marko/tags-html";
import type { AttrClass, AttrString, AttrStyle } from "marko/tags-html";
// TODO check carousel
import { resizeUtil } from "../../common/event-utils";
import { processHtmlAttributes } from "../../common/html-attributes";
Expand Down Expand Up @@ -34,10 +34,10 @@ interface CarouselInput {
"no-peek"?: boolean;
class?: AttrClass;
style?: AttrStyle;
"a11y-previous-text"?: string;
"a11y-next-text"?: string;
"a11y-pause-text"?: string;
"a11y-play-text"?: string;
"a11y-previous-text"?: AttrString;
"a11y-next-text"?: AttrString;
"a11y-pause-text"?: AttrString;
"a11y-play-text"?: AttrString;
"aria-roledescription"?: string;
"on-move"?: (event: { visibleIndexes: number[] }) => void;
"on-scroll"?: (event: { index: number }) => void;
Expand Down
3 changes: 2 additions & 1 deletion src/components/ebay-character-count/component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AttrString } from "marko/tags-html";
import type { WithNormalizedProps } from "../../global";

export interface CharacterCountEvent {
Expand All @@ -9,7 +10,7 @@ interface CharacterCountInput extends Omit<Marko.Input<"span">, `on${string}`> {
renderBody?: Marko.Body;
value?: string | number;
max: number;
"clipped-text"?: string;
"clipped-text"?: AttrString;
"on-change"?: (event?: CharacterCountEvent) => void;
}

Expand Down
5 changes: 3 additions & 2 deletions src/components/ebay-confirm-dialog/index.marko
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Input as BaseInput } from "<ebay-dialog-base>";
import type { WithNormalizedProps } from "../../global";
import type { AttrString } from "marko/tags-html";

static interface ConfirmDialogInput extends Omit<BaseInput, `on${string}`> {
"reject-text"?: string;
"confirm-text"?: string;
"reject-text"?: AttrString;
"confirm-text"?: AttrString;
"on-open"?: () => void;
"on-reject"?: () => void;
"on-confirm"?: () => void;
Expand Down
11 changes: 6 additions & 5 deletions src/components/ebay-date-textbox/component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Expander from "makeup-expander";
import { toISO, type DayISO, dateArgToISO } from "../ebay-calendar/date-utils";
import type { WithNormalizedProps } from "../../global";
import type { AttrString } from "marko/tags-html";

const MIN_WIDTH_FOR_DOUBLE_PANE = 600;

Expand All @@ -16,11 +17,11 @@ interface DateTextboxInput {
"input-placeholder-text"?: string | [string, string];
"collapse-on-select"?: boolean;
"get-a11y-show-month-text"?: (monthName: string) => string;
"a11y-open-popover-text"?: string;
"a11y-selected-text"?: string;
"a11y-range-start-text"?: string;
"a11y-in-range-text"?: string;
"a11y-range-end-text"?: string;
"a11y-open-popover-text"?: AttrString;
"a11y-selected-text"?: AttrString;
"a11y-range-start-text"?: AttrString;
"a11y-in-range-text"?: AttrString;
"a11y-range-end-text"?: AttrString;
"a11y-separator"?: string;
"on-change"?: (
event:
Expand Down
5 changes: 3 additions & 2 deletions src/components/ebay-drawer-dialog/component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { AttrString } from "marko/tags-html";
import type { WithNormalizedProps } from "../../global";
import DialogBase, {
type Input as BaseInput,
} from "../components/ebay-dialog-base/component";

interface DrawerDialogInput extends BaseInput {
"a11y-maximize-text"?: string;
"a11y-minimize-text"?: string;
"a11y-maximize-text"?: AttrString;
"a11y-minimize-text"?: AttrString;
"no-handle"?: boolean;
expanded?: boolean;
"on-expanded"?: () => void;
Expand Down
5 changes: 3 additions & 2 deletions src/components/ebay-fake-menu-button/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import type {
Item as FakeMenuItem,
} from "../ebay-fake-menu/component";
import type { WithNormalizedProps } from "../../global";
import type { AttrString } from "marko/tags-html";

interface FakeMenuButtonInput extends Omit<Marko.Input<"span">, `on${string}`> {
text?: string;
text?: AttrString;
size?: "none" | "large";
"prefix-id"?: string;
variant?: "overflow" | "form" | "button" | "icon";
priority?: "primary" | "secondary" | "delete" | "tertiary" | "none";
borderless?: boolean;
transparent?: boolean;
icon?: Marko.Renderable;
"a11y-text"?: string;
"a11y-text"?: AttrString;
disabled?: boolean;
"no-toggle-icon"?: boolean;
label?: { renderBody?: Marko.Body };
Expand Down
11 changes: 6 additions & 5 deletions src/components/ebay-filter-menu-button/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import setupMenu, {
} from "../../common/menu-utils";
import type { FilterMenuEvent } from "../ebay-filter-menu/component";
import type { WithNormalizedProps } from "../../global";
import type { AttrString } from "marko/tags-html";

export interface FilterMenuButtonEvent {
el?: Element;
Expand All @@ -19,20 +20,20 @@ export interface FilterMenuButtonEvent {
interface FilterMenuButtonInput
extends BaseMenuInput,
Omit<Marko.Input<"span">, `on${string}`> {
text?: string;
"footer-text"?: string;
"a11y-footer-text"?: string;
text?: AttrString;
"footer-text"?: AttrString;
"a11y-footer-text"?: AttrString;
footer?: WithNormalizedProps<
Omit<Marko.Input<"button">, `on${string}`> & {
"a11y-footer-text"?: string;
"a11y-footer-text"?: AttrString;
}
>;
variant?: "form";
"form-name"?: string;
"form-action"?: string;
"form-method"?: string;
disabled?: boolean;
"a11y-text"?: string;
"a11y-text"?: AttrString;
"on-expand"?: () => void;
"on-change"?: (event: FilterMenuButtonEvent) => void;
"on-collapse"?: (event: FilterMenuButtonEvent) => void;
Expand Down
7 changes: 4 additions & 3 deletions src/components/ebay-filter-menu/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import setupMenu, {
} from "../../common/menu-utils";
import type { RadioEvent } from "../ebay-radio/component-browser";
import type { WithNormalizedProps } from "../../global";
import type { AttrString } from "marko/tags-html";

export interface FilterMenuEvent<T extends Event = Event> {
el?: Element;
Expand All @@ -26,11 +27,11 @@ interface FilterMenuInput
"form-name"?: string;
"form-action"?: string;
"form-method"?: string;
"footer-text"?: string;
"a11y-footer-text"?: string;
"footer-text"?: AttrString;
"a11y-footer-text"?: AttrString;
footer?: WithNormalizedProps<
Omit<Marko.Input<"button">, `on${string}`> & {
"a11y-footer-text"?: string;
"a11y-footer-text"?: AttrString;
}
>;
"render-body"?: Marko.Body;
Expand Down
3 changes: 2 additions & 1 deletion src/components/ebay-filter/component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { AttrString } from "marko/tags-html";
import type { WithNormalizedProps } from "../../global";

export interface FilterInput
extends Omit<Marko.Input<"button">, `on${string}`> {
selected?: boolean;
href?: string;
"use-aria-pressed"?: boolean;
"a11y-selected-text"?: string;
"a11y-selected-text"?: AttrString;
"on-click"?: (event: {
selected: boolean;
originalEvent: MouseEvent;
Expand Down
3 changes: 2 additions & 1 deletion src/components/ebay-icon-button/component-browser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AttrString } from "marko/tags-html";
import * as eventUtils from "../../common/event-utils";
import type { WithNormalizedProps } from "../../global";

Expand All @@ -8,7 +9,7 @@ interface IconButtonInput extends Omit<Marko.Input<"button">, `on${string}`> {
transparent?: boolean;
size?: "small" | "large";
"partially-disabled"?: boolean;
"badge-aria-label"?: string;
"badge-aria-label"?: AttrString;
"on-click"?: (event: { originalEvent: MouseEvent }) => void;
"on-escape"?: (event: { originalEvent: KeyboardEvent }) => void;
"on-focus"?: (event: { originalEvent: FocusEvent }) => void;
Expand Down
Loading

0 comments on commit 658ef38

Please sign in to comment.