import React from 'react'; import { AttributeValue } from '../Utils/WdkModel'; /** * React Component utils */ interface AnyObject { [key: string]: any; } /** * Stateless function component decorator that prevents rerendering * when props are equal use shallow comparison. */ export declare function pure

(Component: React.StatelessComponent

): { new (props: P | Readonly

): { render(): JSX.Element; context: any; setState(state: {} | ((prevState: Readonly<{}>, props: Readonly

) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void; forceUpdate(callback?: (() => void) | undefined): void; readonly props: Readonly

& Readonly<{ children?: React.ReactNode; }>; state: Readonly<{}>; refs: { [key: string]: React.ReactInstance; }; componentDidMount?(): void; shouldComponentUpdate?(nextProps: Readonly

, nextState: Readonly<{}>, nextContext: any): boolean; componentWillUnmount?(): void; componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; getSnapshotBeforeUpdate?(prevProps: Readonly

, prevState: Readonly<{}>): any; componentDidUpdate?(prevProps: Readonly

, prevState: Readonly<{}>, snapshot?: any): void; componentWillMount?(): void; UNSAFE_componentWillMount?(): void; componentWillReceiveProps?(nextProps: Readonly

, nextContext: any): void; UNSAFE_componentWillReceiveProps?(nextProps: Readonly

, nextContext: any): void; componentWillUpdate?(nextProps: Readonly

, nextState: Readonly<{}>, nextContext: any): void; UNSAFE_componentWillUpdate?(nextProps: Readonly

, nextState: Readonly<{}>, nextContext: any): void; }; new (props: P, context: any): { render(): JSX.Element; context: any; setState(state: {} | ((prevState: Readonly<{}>, props: Readonly

) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void; forceUpdate(callback?: (() => void) | undefined): void; readonly props: Readonly

& Readonly<{ children?: React.ReactNode; }>; state: Readonly<{}>; refs: { [key: string]: React.ReactInstance; }; componentDidMount?(): void; shouldComponentUpdate?(nextProps: Readonly

, nextState: Readonly<{}>, nextContext: any): boolean; componentWillUnmount?(): void; componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; getSnapshotBeforeUpdate?(prevProps: Readonly

, prevState: Readonly<{}>): any; componentDidUpdate?(prevProps: Readonly

, prevState: Readonly<{}>, snapshot?: any): void; componentWillMount?(): void; UNSAFE_componentWillMount?(): void; componentWillReceiveProps?(nextProps: Readonly

, nextContext: any): void; UNSAFE_componentWillReceiveProps?(nextProps: Readonly

, nextContext: any): void; componentWillUpdate?(nextProps: Readonly

, nextState: Readonly<{}>, nextContext: any): void; UNSAFE_componentWillUpdate?(nextProps: Readonly

, nextState: Readonly<{}>, nextContext: any): void; }; readonly displayName: string; contextType?: React.Context | undefined; }; export interface ComponentWrapper

extends React.ComponentClass

{ wrapComponent(factory: (Component: React.ComponentType

) => React.ComponentType

): void; } /** * A Component decorator that wraps the Component passed to it and returns a new * Component with a static method `wrapComponent`. Use this method to replace * the wrapped Component. See the docs for `wrapComponent` for more details. * * * Rationale * ========= * * Components in WDK should be customizable by the application. The application * should be able to replace the Component, surround the Component, or modify * the props passed to the Component. By creating a wrapper Component whose * internal Component can be replaced in-place, WDK code does not need to do * any kind of lookup, and implementors are given a nice, convenient syntax for * what will most likely be a common task: modifying a WDK Component. * * There are other approaches that would require a uniform JavaScript build * environment, which would allow the application to perform overriding at * build time (similar to how we do this with JSP tags). We aren't quite at a * point where we can do this, and it might not be desirable. * * * Usage * ===== * * // As a function * let Answer = wrappable(Answer); * * * // As an ES2016 class decorator * @wrappable * class Answer extends React.Component { * // ... * } * * // Using the static wrap method. Note that the function passed to `wrap` * // will receive the currently wrapped Component as an argument. This * // makes it possible to replace or decorate the Component, or to modify * // the props passed to the component. * Answer.wrap(function(Answer) { * return React.createClass({ * render() { * return ( *

*

My Custom title

* *
* ); * } * }); * }); * */ export declare function wrappable

(Component: React.ComponentType

): ComponentWrapper

; interface LazyEnhance { (Component: React.ComponentType): React.ComponentClass; } /** * A higher order component that allows a component to be rendered lazily. * * @example * lazy(function(render) { * loadData('/some/data').then(function(data) { * render({ data }); * }) * })(ComponentThatNeedsData); */ export declare function lazy(load: (props: T) => Promise): LazyEnhance; export declare function delay

(ms: number): LazyEnhance

; interface InstrumentOptions { compareProps?: boolean; } /** * Takes a component and returns an intrumented wrapper component * that will log details about props, etc. * * This should never be used in production code! */ export declare function instrument

(Component: React.ComponentClass

, options: InstrumentOptions): React.ComponentClass

; export declare function instrument

(Component: React.StatelessComponent

, options: InstrumentOptions): React.ComponentClass

; /** Create a React Element using preformatted HTML */ export declare function safeHtml

(str: string, props?: P, Component?: React.ComponentClass

): JSX.Element; export declare function safeHtml

(str: string, props?: P, Component?: React.StatelessComponent

): JSX.Element; export declare function safeHtml

(str: string, props?: P, Component?: string): JSX.Element; /** * Makes a copy of the passed original object, subtracting the properties with * names in the propsToFilter arg, which should be Array[String]. */ export declare function filterOutProps

(orig: P, propsToFilter: string[]): {}; /** * Generates HTML markup for an attribute using duck-typing */ export declare function formatAttributeValue(value?: AttributeValue): string; /** * Creates a React-renderable element using the provided `Component`, or 'span' * by default. * TODO Look up or inject custom formatters */ export declare function renderAttributeValue

(value: AttributeValue, props?: P, Component?: string): JSX.Element; /** * Makes a copy of current, adds value if not present, removes if present, and * returns the copy. * @param {Array} array array to modify * @param {} value to check against * @return {Array} modified copy of original array */ export declare function addOrRemove(array: T[], value: T): T[]; /** * Looks for the property with the passed name in the given object. If the * object or the property is null or undefined, returns default value. * Otherwise returns the value found. */ export declare function getValueOrDefault(object: AnyObject, propertyName: string, defaultValue: T): T; /** * Returns a change handler that will 'bubble' a state change to the * onParentChange function passed in. The value passed to the parent handler is * a copy of previousState with a new value applied to the name this function * was called with. */ export declare function getChangeHandler(inputName: string, onParentChange: (s: S) => S, previousState: S): (newValue: T) => void; /** * For each property in propertyNameList, examines each property in both * oldProps and newProps to check for referential equality. If any prop differs * returns true, else returns false. * * @param {Object} oldProps props object * @param {Object} newProps another props object * @param {Array} propertyNameList list of properties to examine * @return {boolean} false if all properties are referentially identical, else true */ export declare function propsDiffer

(oldProps: P, newProps: P, propertyNameList: string[]): boolean; interface HandlerSetObject { [key: string]: (...args: any[]) => any; } /** * Bind a collection of action functions to a dispatchAction function. * * @param {Function} dispatchAction * @param {Object} actions */ export declare function wrapActions(dispatchAction: Function, ...actionObjects: HandlerSetObject[]): HandlerSetObject; /** * Takes an object containing named functions and an object (usually 'this') * and returns a new object containing copies of the original functions that * are bound to objectToBind. * * @param {Object} handlerSetObject set of named functions * @param {Object} objectToBind object to which copies of named functions will be bound * @return {Object} copy of handlerSetObject with newly bound copies of original functions */ export declare function bindEventHandlers(handlerSetObject: HandlerSetObject, objectToBind: any): HandlerSetObject; /** * Create a helper for generating classNames that follow a BEM-inspired naming * convention. * * @example * ``` * let makeClassName = makeClassNameHelper('wdk-Page'); * makeClassName(); //=> 'wdk-Page' * makeClassName('Title'); //=> 'wdk-PageTitle' * makeClassName('Title', 'muted'); //=> 'wdk-PageTitle wdk-PageTitle__muted' * makeClassName('Title', 'muted', 'blue'); //=> 'wdk-PageTitle wdk-PageTitle__muted wdk-PageTitle__blue' * ``` */ export declare function makeClassNameHelper(baseClassName: string): (suffix?: string, ...modifiers: any[]) => string; /** * Type guard that narrows an object's type such that the interrogated property value is not null or undefined. */ export declare function propertyIsNonNull(object: T, key: K): object is T & { [Key in K]-?: T[K]; }; export declare function useSetDocumentTitle(title: string): void; export {}; //# sourceMappingURL=ComponentUtils.d.ts.map