@bprogress/next
Version:
NProgress bar like for Next.js compatible with new app directory
79 lines (76 loc) • 3.31 kB
text/typescript
import { AnchorProgressProviderProps, RouterProgressProviderProps, RouterProgressProps, AnchorProgressProps } from '@bprogress/react';
import { NavigateOptions, PrefetchOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';
interface PagesProgressProps extends RouterProgressProps {
}
interface PagesProgressProviderProps extends RouterProgressProviderProps {
}
interface AppProgressProps extends AnchorProgressProps {
}
interface AppProgressProviderProps extends AnchorProgressProviderProps {
}
/**
* Helper type to infer router-specific options from the push method signature.
*/
type InferRouterOptions<T extends AppRouterInstance> = T extends {
push(href: string, options?: infer O): void;
} ? O : NavigateOptions;
/**
* Helper type to infer prefetch-specific options from the push method signature.
*/
type InferPrefetchOptions<T extends AppRouterInstance> = T extends {
prefetch(href: string, options?: infer O): void;
} ? O : PrefetchOptions;
/**
* Options for the progress bar.
*
* @param showProgress Show the progress bar. Default is true.
* @param startPosition Starting position of the progress bar during page load. Default is 0.
* @param disableSameURL Disable triggering progress bar when navigating to the same URL. Default is true.
* @param basePath Base path for the progress bar. Default is ''.
*/
interface RouterActionsProgressOptions {
showProgress?: boolean;
startPosition?: number;
disableSameURL?: boolean;
basePath?: string;
i18nPath?: boolean;
delay?: number;
stopDelay?: number;
}
/**
* Base router interface.
* Here we assume that the imported AppRouterInstance is not generic.
*/
interface AppRouterInstance {
push(href: string, options?: unknown): void;
replace(href: string, options?: unknown): void;
prefetch(href: string, options?: unknown): void;
back(options?: unknown): void;
refresh(options?: unknown): void;
forward(options?: unknown): void;
}
/**
* Options for router progress.
*
* @param customRouter Custom router function. Default is undefined.
*/
interface RouterProgressOptions extends RouterActionsProgressOptions {
customRouter?: () => AppRouterInstance;
}
/**
* Combined options type merging router-specific options with progress options.
*/
type CombinedRouterOptions<ROpts> = ROpts & RouterActionsProgressOptions;
/**
* Extended router interface to include progress bar functionality.
* The push/replace methods now take two parameters: href and combined options.
*/
interface AppRouterProgressInstance<ROpts = NavigateOptions, POtps = PrefetchOptions> {
push(href: string, options?: CombinedRouterOptions<ROpts>): void;
replace(href: string, options?: CombinedRouterOptions<ROpts>): void;
prefetch(href: string, options?: POtps): void;
back(options?: CombinedRouterOptions<ROpts>): void;
refresh(options?: CombinedRouterOptions<ROpts>): void;
forward(options?: CombinedRouterOptions<ROpts>): void;
}
export type { AppProgressProps as A, CombinedRouterOptions as C, InferRouterOptions as I, PagesProgressProps as P, RouterActionsProgressOptions as R, PagesProgressProviderProps as a, AppProgressProviderProps as b, InferPrefetchOptions as c, AppRouterInstance as d, RouterProgressOptions as e, AppRouterProgressInstance as f };