@ima/react-page-renderer
Version:
IMA.js React page renderer.
124 lines • 5.67 kB
TypeScript
import type { DictionaryMap, Utils } from '@ima/core';
import classnames from 'classnames';
import { ComponentType, ContextType } from 'react';
import { AbstractComponent } from './component/AbstractComponent';
import { AbstractPureComponent } from './component/AbstractPureComponent';
import { PageContext } from './PageContext';
/**
* Retrieves the view utilities from the component's current context or
* properties (preferring the context).
*
* @param props The component's current properties.
* @param context The component's current context.
* @return The retrieved view utilities.
* @throws Error Throw if the view utils cannot be located in the provided
* properties nor context.
*/
export declare function getUtils(props: {
$Utils?: Utils;
}, context: ContextType<typeof PageContext>): Utils | undefined;
/**
* Returns the localized phrase identified by the specified key. The
* placeholders in the localization phrase will be replaced by the provided
* values.
*
* @param component The component
* requiring the localization.
* @param key Localization key.
* @param params Values for replacing the
* placeholders in the localization phrase.
* @return Localized phrase.
*/
export declare function localize(component: AbstractComponent | AbstractPureComponent, key: keyof DictionaryMap, params: {
[key: string]: string | number;
}): string;
/**
* Generates an absolute URL using the provided route name (see the
* <code>app/config/routes.js</code> file). The provided parameters will
* replace the placeholders in the route pattern, while the extraneous
* parameters will be appended to the generated URL's query string.
*
* @param component The component
* requiring the generating of the URL.
* @param name The route name.
* @param params Router parameters and
* extraneous parameters to add to the URL as a query string.
* @return The generated URL.
*/
export declare function link(component: AbstractComponent | AbstractPureComponent, name: string, params: {
[key: string]: string;
}): string;
/**
* Generate a string of CSS classes from the properties of the passed-in
* object that resolve to `true`.
*
* @example
* this.cssClasses('my-class my-class-modifier', true);
* @example
* this.cssClasses({
* 'my-class': true,
* 'my-class-modifier': this.props.modifier
* }, true);
* @param component The component
* requiring the composition of the CSS class names.
* @param classRules CSS classes in a
* string separated by whitespace, or a map of CSS class names to
* boolean values. The CSS class name will be included in the result
* only if the value is `true`.
* @param includeComponentClassName
* @return String of CSS classes that had their property resolved
* to `true`.
*/
export declare function cssClasses(component: AbstractComponent | AbstractPureComponent, classRules: string | {
[key: string]: boolean;
} | string[], includeComponentClassName: boolean): string;
/**
* Generate a string of CSS classes from the properties of the passed-in
* object that resolve to `true`.
*
* @param classRules CSS classes in a
* string separated by whitespace, or a map of CSS class names to
* boolean values. The CSS class name will be included in the result
* only if the value is `true`.
* @param component The component
* requiring the composition of the CSS class names, if it has the
* `className` property set and requires its inclusion this time.
* @return String of CSS classes that had their property resolved
* to `true`.
*/
export declare function defaultCssClasses(classRules: classnames.Argument, component?: string | ComponentType): string;
/**
* Creates and sends a new IMA.js DOM custom event from the provided component.
*
* @param component The component
* at which's root element the event will originate.
* @param eventName The name of the event.
* @param data Data to send within the event.
*/
export declare function fire(component: AbstractComponent | AbstractPureComponent, eventTarget: EventTarget, eventName: string, data?: unknown): import("@ima/core").EventBus;
/**
* Registers the provided event listener for execution whenever an IMA.js
* DOM custom event of the specified name occurs at the specified event
* target.
*
* @param component The component
* requesting the registration of the event listener.
* @param eventTarget The react component or
* event target at which the listener should listen for the event.
* @param eventName The name of the event for which to listen.
* @param listener The listener for event to register.
*/
export declare function listen(component: AbstractComponent | AbstractPureComponent, eventTarget: EventTarget, eventName: string, listener: (event: Event) => void): import("@ima/core").EventBus;
/**
* Deregisters the provided event listener for an IMA.js DOM custom event
* of the specified name at the specified event target.
*
* @param component The component
* that requested the registration of the event listener.
* @param eventTarget The react component or
* event target at which the listener should listen for the event.
* @param eventName The name of the event for which to listen.
* @param listener The listener for event to register.
*/
export declare function unlisten(component: AbstractComponent | AbstractPureComponent, eventTarget: EventTarget, eventName: string, listener: (event: Event) => void): import("@ima/core").EventBus;
//# sourceMappingURL=componentHelpers.d.ts.map