presentation/renderers/element.renderer.ts

presentation/renderers/element.renderer.ts is a file in Bane's Lab Site. 22 lines of code and 5 definitions.

import { ANIMATE_ATTRIBUTE, ANIMATE_DELAY_ATTRIBUTE } from "#configuration/constants/element.constants";
import type { ElementSpec, ElementTag } from "#types/element.types";
import { TITLE_SEPARATOR } from "#configuration/strings/page.strings";
import { createElement } from "#core/factories/element.factory";

const CONTEXT_CLASS = "visually-hidden";

export const contextOf = function contextOf(context: string): HTMLElement {
    return createElement("span", { className: CONTEXT_CLASS, text: TITLE_SEPARATOR + context });
};

export const namedFor = function namedFor(label: string, context: string): string {
    return label + TITLE_SEPARATOR + context;
};

export const animated = function animated<T extends ElementTag>(
    tag: T,
    spec: ElementSpec,
    effect: string,
    delay = 0,
): HTMLElementTagNameMap[T] {
    const element = createElement(tag, spec);
    element.setAttribute(ANIMATE_ATTRIBUTE, effect);
    element.setAttribute(ANIMATE_DELAY_ATTRIBUTE, String(delay));
    return element;
};