@enact/ui
Version:
A collection of simplified unstyled cross-platform UI components for Enact
65 lines (59 loc) • 2.27 kB
TypeScript
// Type definitions for ui/Cancelable
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
export interface CancelableConfig extends Object {
/**
* Called when a cancel action is invoked by the user.
*
* If it is a string, the cancel handler will attempt to invoke a function passed as a prop of
that name. If it is a function, that function will be called with the current props as the
only argument.
*
* If the function handles the cancel action, it should call `stopPropagation()` on the provided
event object prevent container or `modal` Cancelable instances from also handling the action.
*/
onCancel: string | Function;
/**
* Subscribes to cancel events globally for this instance.
*
* When `true` , the `Cancelable` instance will handle cancel events globally that successfully
bubble up to `window` regardless of which component is focused.
*
* `modal` cancel handlers are processed in reverse of the order they are created such that the
innermost instance (in terms of the component hierarchy) have the first opportunity to handle
the event before its container components.
*/
modal?: boolean;
/**
* The component that will contain the wrapped component.
*
* When set, the wrapped component will be contained within an instance of `component` . This may
be necessary if the props passed to the wrapped component are not placed on the root element.
*/
component?: React.ComponentType;
}
export interface CancelableProps {
/**
* Called when a cancel action is received.
*
* This callback is invoked for every cancel action before the config or prop handler is
invoked.
*/
onCancel?: Function;
}
export function Cancelable<P>(
config: CancelableConfig,
Component: React.ComponentType<P> | string,
): React.ComponentType<P & CancelableProps>;
export function Cancelable<P>(
Component: React.ComponentType<P> | string,
): React.ComponentType<P & CancelableProps>;
/**
* Adds an event handler to filter cancel events.
*/
export function addCancelHandler(handler: Function): void;
/**
* Removes an event handler to filter cancel events
*/
export function removeCancelHandler(handler: Function): void;
export default Cancelable;