UNPKG

@react-motion-router/core

Version:

Declarative routing library for ReactJS ⚛ with animations baked in ⏮

81 lines (80 loc) 3.57 kB
import NavigationBase, { NavigateEvent, BackEvent } from './NavigationBase'; import { AnimationConfig, AnimationKeyframeEffectConfig, ReducedAnimationConfigSet, SwipeDirection, ScreenChild, PlainObject, RouterEventMap } from './common/types'; import RouterData, { RoutesData } from './RouterData'; import AnimationLayerData from './AnimationLayerData'; import { PageAnimationEndEvent } from './MotionEvents'; import { Component } from 'react'; interface Config { animation?: ReducedAnimationConfigSet | AnimationConfig | AnimationKeyframeEffectConfig; defaultRoute?: string; swipeAreaWidth?: number; minFlingVelocity?: number; hysteresis?: number; basePathname?: string; disableDiscovery?: boolean; swipeDirection?: SwipeDirection; disableBrowserRouting?: boolean; paramsSerializer?(params: PlainObject): string; paramsDeserializer?(queryString: string): PlainObject; } export interface RouterBaseProps { id?: string; config: Config; children: ScreenChild | ScreenChild[]; } export interface RouterBaseState { currentPath: string; backNavigating: boolean; gestureNavigating: boolean; routesData: RoutesData; implicitBack: boolean; defaultDocumentTitle: string; } export default abstract class RouterBase<P extends RouterBaseProps = RouterBaseProps, S extends RouterBaseState = RouterBaseState> extends Component<P, S> { private readonly _id; protected readonly animationLayerData: AnimationLayerData; protected ref: HTMLElement | null; protected abstract _routerData: RouterData; protected config: Config; protected dispatchEvent: ((event: Event) => Promise<boolean>) | null; protected addEventListener: (<K extends keyof RouterEventMap>(type: K, listener: (this: HTMLElement, ev: RouterEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined) => void) | null; protected removeEventListener: (<K extends keyof RouterEventMap>(type: K, listener: (this: HTMLElement, ev: RouterEventMap[K]) => any, options?: boolean | EventListenerOptions | undefined) => void) | null; static defaultProps: { config: { animation: { readonly in: { readonly type: "none"; readonly duration: 0; }; readonly out: { readonly type: "none"; readonly duration: 0; }; }; }; }; constructor(props: RouterBaseProps); state: S; componentDidMount(): void; componentWillUnmount(): void; /** * Initialises current path and routes data from URL search params. */ protected initialise(navigation: NavigationBase): void; get id(): string; protected get parentRouterData(): RouterData<NavigationBase> | null; protected get baseURL(): URL; protected abstract get navigation(): NavigationBase; abstract onAnimationEnd: (e: PageAnimationEndEvent) => void; abstract onGestureNavigationStart: () => void; abstract onGestureNavigationEnd: () => void; protected onPopStateListener(e: Event): void; abstract onBackListener: (e: BackEvent) => void; abstract onNavigateListener: (e: NavigateEvent) => void; onDocumentTitleChange: (title: string | null) => void; addNavigationEventListeners(ref: HTMLElement): void; removeNavigationEventListeners(ref: HTMLElement): void; private setRef; render(): JSX.Element; } export {};