@kitten-science/kitten-scientists
Version:
Add-on for the wonderful incremental browser game: https://kittensgame.com/web/
55 lines • 2.31 kB
TypeScript
import type { KittenScientists } from "../../KittenScientists.js";
export type UiComponentInterface = {
readonly children: Iterable<UiComponentInterface>;
parent: UiComponentInterface | null;
get element(): JQuery<HTMLElement>;
requestRefresh(withChildren?: boolean, depth?: number, trace?: boolean): void;
refresh(force?: boolean, depth?: number): void;
};
export type UiComponentOptions = {
length?: never;
readonly onRefresh?: () => void;
readonly onRefreshRequest?: () => void;
};
export declare abstract class UiComponent<TElement extends HTMLElement = HTMLElement> implements UiComponentInterface {
private static nextComponentId;
readonly componentId: number;
/**
* A reference to the host itself.
*/
readonly host: KittenScientists;
parent: UiComponentInterface | null;
readonly options: UiComponentOptions | undefined;
/**
* The main DOM element for this component, in a JQuery wrapper.
*/
protected _element: JQuery<TElement> | undefined;
protected set element(value: JQuery<TElement>);
get element(): JQuery<TElement>;
/**
* NOTE: It is intentional that all children are of the most fundamental base type.
* If a more specifically typed reference for a child is required, it should be stored
* on construction.
* The 'children' set is intended only for inter-component orchestration.
*/
readonly children: Set<UiComponentInterface>;
/**
* Constructs the base `UiComponent`.
* Subclasses MUST add children from options when `this.element` is constructed.
*
* @param host A reference to the host.
* @param options The options for this component.
*/
constructor(parent: UiComponent | {
host: KittenScientists;
}, options?: UiComponentOptions);
abstract toString(): string;
protected _needsRefresh: boolean;
requestRefresh(withChildren?: boolean, depth?: number, trace?: boolean): void;
refresh(force?: boolean, depth?: number): void;
addChild(child: UiComponentInterface): this;
addChildren(children?: Iterable<UiComponentInterface>): this;
removeChild(child: UiComponentInterface): void;
removeChildren(children: Iterable<UiComponentInterface>): void;
}
//# sourceMappingURL=UiComponent.d.ts.map