diff --git a/types/react-wait/index.d.ts b/types/react-wait/index.d.ts index 0f69864f95..38776082d7 100644 --- a/types/react-wait/index.d.ts +++ b/types/react-wait/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for react-wait 0.3 // Project: https://github.com/f/react-wait#readme // Definitions by: Ifiok Jr. +// Paweł Maciejewski // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -8,12 +9,26 @@ import { ComponentType, FunctionComponent } from 'react'; export const Waiter: FunctionComponent; -export interface WaitProps { +export interface WaitingContextWaitProps { fallback: JSX.Element; +} + +export interface WaitProps extends WaitingContextWaitProps { on: string; } +export interface WaitingContext { + isWaiting(): boolean; + startWaiting(): void; + endWaiting(): void; + Wait: ComponentType; +} + export interface UseWaitAPI { + /** + * Returns an array of waiters. + */ + waiters: string[]; /** * Using Wait Component * @@ -79,6 +94,19 @@ export interface UseWaitAPI { * ``` */ endWaiting(waiter: string): void; + /** + * Creates a waiting context. + * + * ```tsx + * const { startWaiting, endWaiting, isWaiting, Wait } = createWaitingContext("creating user"); + * return ( + * + * ); + * ``` + */ + createWaitingContext(waiter: string): WaitingContext; } export function useWait(): UseWaitAPI; diff --git a/types/react-wait/react-wait-tests.tsx b/types/react-wait/react-wait-tests.tsx index e48edfcda0..59faeacd73 100644 --- a/types/react-wait/react-wait-tests.tsx +++ b/types/react-wait/react-wait-tests.tsx @@ -47,3 +47,25 @@ const MyComponent = () => ( ); + +function testCreateWaitingContext() { + const { createWaitingContext } = useWait(); + const { startWaiting, endWaiting, isWaiting, Wait } = createWaitingContext('creating user'); + return ( +
+ }> + + + +
+ ); +} + +function testWaiters() { + const { waiters } = useWait(); + return ( +
    + {waiters.map((waiter, index) =>
  • {waiter}
  • )} +
+ ); +}