@wordpress/components
Version:
UI components for WordPress.
40 lines • 2.2 kB
TypeScript
/**
* External dependencies
*/
import type { ForwardedRef, ReactChild, ReactNode } from 'react';
import type { WordPressComponentFromProps } from '.';
type AcceptsTwoArgs<F extends (...args: any) => any, ErrorMessage = never> = Parameters<F>['length'] extends 2 ? {} : ErrorMessage;
/**
* Forwards ref (React.ForwardRef) and "Connects" (or registers) a component
* within the Context system under a specified namespace.
*
* @param Component The component to register into the Context system.
* @param namespace The namespace to register the component under.
* @return The connected WordPressComponent
*/
export declare function contextConnect<C extends (props: any, ref: ForwardedRef<any>) => JSX.Element | null>(Component: C & AcceptsTwoArgs<C, 'Warning: Your component function does not take a ref as the second argument. Did you mean to use `contextConnectWithoutRef`?'>, namespace: string): WordPressComponentFromProps<Parameters<C & AcceptsTwoArgs<C, "Warning: Your component function does not take a ref as the second argument. Did you mean to use `contextConnectWithoutRef`?">>[0], true>;
/**
* "Connects" (or registers) a component within the Context system under a specified namespace.
* Does not forward a ref.
*
* @param Component The component to register into the Context system.
* @param namespace The namespace to register the component under.
* @return The connected WordPressComponent
*/
export declare function contextConnectWithoutRef<P>(Component: (props: P) => JSX.Element | null, namespace: string): WordPressComponentFromProps<P, false>;
/**
* Attempts to retrieve the connected namespace from a component.
*
* @param Component The component to retrieve a namespace from.
* @return The connected namespaces.
*/
export declare function getConnectNamespace(Component: ReactChild | undefined | {}): string[];
/**
* Checks to see if a component is connected within the Context system.
*
* @param Component The component to retrieve a namespace from.
* @param match The namespace to check.
*/
export declare function hasConnectNamespace(Component: ReactNode, match: string[] | string): boolean;
export {};
//# sourceMappingURL=context-connect.d.ts.map