diff --git a/types/rrc/index.d.ts b/types/rrc/index.d.ts new file mode 100644 index 0000000000..5ebf120c74 --- /dev/null +++ b/types/rrc/index.d.ts @@ -0,0 +1,75 @@ +// Type definitions for rrc 0.10 +// Project: https://github.com/pshrmn/rrc#readme +// Definitions by: Deividas Bakanas +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as React from "react"; +import * as H from "history"; +import { RouteProps, RouteComponentProps, match as MatchObject } from "react-router-dom"; + +export interface ScrollIntoViewProps { + alignToTop?: boolean; + id: string; +} + +export class ScrollIntoView extends React.Component { } + +export type PropIdCallback = () => string; + +export interface WithScrollOptions { + propId?: PropIdCallback; + alignToTop?: boolean; +} + +export type ComponentConstructor = React.ComponentClass | React.SFC; + +export function withScroll(component: ComponentConstructor | undefined>, options?: WithScrollOptions) + : ComponentConstructor | undefined>; + +export type RouteConfiguration = RouteProps & { inject?: { [key: string]: any } }; + +export interface SwitchProps { + routes: RouteConfiguration[]; + location: H.LocationDescriptorObject & { pathname: H.Pathname }; +} + +export class ConfigSwitch extends React.Component { } + +export type OnUpdateCall = (location: H.Location) => void; + +export interface OnUpdateProps { + call: OnUpdateCall; + immediate?: boolean; +} + +export class OnUpdate extends React.Component { } + +export type IsActiveCallback = () => boolean; + +export interface WhenActiveOptions { + exact?: boolean; + strict?: boolean; + pathProp?: string; + className?: string; + style?: React.CSSProperties; + isActive?: IsActiveCallback; +} + +export type WhenActiveReturnType = (component: ComponentConstructor) => ComponentConstructor; + +export function whenActive(options?: WhenActiveOptions): WhenActiveReturnType; + +export interface StatusProps { + code: string; +} + +export class Status extends React.Component { } + +export type GetKeyFunction = (match: MatchObject, route: RouteConfiguration, location: H.Location) => string; + +export interface WrapSwitchProps extends SwitchProps { + getKey?: GetKeyFunction; +} + +export function wrapSwitch(Wrapper: ComponentConstructor): + ComponentConstructor & WrapperProps>; diff --git a/types/rrc/rrc-tests.tsx b/types/rrc/rrc-tests.tsx new file mode 100644 index 0000000000..084f921614 --- /dev/null +++ b/types/rrc/rrc-tests.tsx @@ -0,0 +1,122 @@ +import * as React from "react"; +import { Switch, Route, RouteComponentProps, BrowserRouter, Link } from "react-router-dom"; +import { + ScrollIntoView, + ConfigSwitch, + withScroll, + OnUpdate, + whenActive, + Status, + wrapSwitch, + RouteConfiguration, + GetKeyFunction, + OnUpdateCall +} from "rrc"; + +class RouteOne extends React.Component, {}> { + render() { + return
+ +
Main view
+
+ }, + { path: "/one/two", render: () =>
One two route
} + ]} /> +
; + } +} + +class RouteTwo extends React.Component, {}> { + private onUpdate: OnUpdateCall = (location) => { console.log("update"); }; + + render() { + return
+ Route 2 + Go to Route 1 + +
; + } +} + +interface LayoutProps { + title: string; + subtitle?: string; +} + +class Layout extends React.Component { + render() { + return
+
{`Layout ${this.props.title}`}
+
+ Content + {this.props.children} +
+
; + } +} + +const WrappedLayout = wrapSwitch(Layout); + +interface Params { + page: number; +} + +class RouteFour extends React.Component, {}> { + private routes: RouteConfiguration[] = [ + { path: "/four/something/:page", component: RouteTwo } + ]; + + private getKey: GetKeyFunction = (match, route, location) => { + return "my-key-" + match.url; + } + + render() { + return
+
+ Route four +
+
+ +
+
; + } +} + +interface MyContainerProps { + className?: string; + color: number; +} + +class MyContainer extends React.Component { + render() { + return
+ {this.props.children} +
; + } +} + +const ExtendedContainer = whenActive({ className: "active" })(MyContainer); + +const RouteTwoWithScroll = withScroll(RouteTwo); + +export const Routes = + +
+
My page
+ + + + + Route 3} /> + + +
+
; diff --git a/types/rrc/tsconfig.json b/types/rrc/tsconfig.json new file mode 100644 index 0000000000..12588363b6 --- /dev/null +++ b/types/rrc/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "jsx": "react", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "rrc-tests.tsx" + ] +} diff --git a/types/rrc/tslint.json b/types/rrc/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/rrc/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }