Merge pull request #11344 from Smiche/master

react-redux-toastr type declarations
This commit is contained in:
Andy
2016-09-20 08:34:11 -07:00
committed by GitHub
2 changed files with 136 additions and 0 deletions
@@ -0,0 +1,28 @@
///<reference path="react-redux-toastr.d.ts" />
///<reference path="../react/react.d.ts" />
///<reference path="../react/react-dom.d.ts" />
///<reference path="../react-redux/react-redux.d.ts" />
import {toastr, reducer as toastrReducer, actions} from 'react-redux-toastr';
import ReduxToastr from 'react-redux-toastr';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {createStore, combineReducers, bindActionCreators} from 'redux';
import { Provider, connect } from 'react-redux';
function test() {
const store = createStore(combineReducers({ toastr: toastrReducer }));
var toastrFactory = React.createFactory(ReduxToastr);
var element = toastrFactory({ timeOut: 1000, newestOnTop: false });
var providerFactory = React.createFactory(Provider);
var root = providerFactory({ store: store }, element);
function callback() { }
toastr.clean();
toastr.confirm("Test", { onOk: callback, onCancel: callback });
toastr.error("Error", "Error message");
toastr.info("Info", "Info test", { timeOut: 1000, removeOnHover: true, removeOnClick: true, onShowComplete: callback });
toastr.success("Test", "Test message", { component: new React.Component() });
}
test();
+108
View File
@@ -0,0 +1,108 @@
// Type definitions for react-redux-toastr 3.7.0
// Project: https://github.com/diegoddox/react-redux-toastr
// Definitions by: Aleksandar Ivanov <https://github.com/Smiche>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///<reference path="../react/react.d.ts" />
///<reference path="../redux/redux.d.ts"/>
declare module "react-redux-toastr" {
import R = __React;
import _Redux = Redux;
interface ToastrOptions {
/**
* Timeout in miliseconds.
*/
timeOut?: number,
/**
* Show newest on top or bottom.
*/
newestOnTop?: boolean,
/**
* Position of the toastr: top-left, top-center, top-right, bottom-left, bottom-center and bottom-right
*/
position?: string,
confirmText?: ConfirmText
}
interface ConfirmText {
okText: string,
cancelText: string
}
/**
* Toastr react component.
*/
export default class ReduxToastr extends R.Component<ToastrOptions, any>{ }
interface EmitterOptions {
/**
* Notification popup icon.
* icon-close-round, icon-information-circle, icon-check-1, icon-exclamation-triangle, icon-exclamation-alert
*/
icon?: string,
/**
* Timeout in miliseconds.
*/
timeOut?: number,
removeOnHover?: boolean,
removeOnClick?: boolean,
component?: R.Component<any, any>,
onShowComplete?(): void;
onHideComplete?(): void;
}
interface ToastrConfirmOptions {
onOk(): void;
onCancel(): void;
}
interface ToastrEmitter {
/**
* Used to provide a large amount of information.
* It will not close unless a timeOut is provided.
*/
message(title: string, message: string, options?: EmitterOptions): void;
info(title: string, message: string, options?: EmitterOptions): void;
success(title: string, message: string, options?: EmitterOptions): void;
warning(title: string, message: string, options?: EmitterOptions): void;
error(title: string, message: string, options?: EmitterOptions): void;
/**
* Clear all notifications
*/
clean(): void;
/**
* Hook confirmation toastr with callback.
*/
confirm(message: string, options: ToastrConfirmOptions): void;
}
/**
* Possible actions to dispatch.
*/
interface Actions {
addToastrAction: Redux.Action,
clean: Redux.Action,
remove: Redux.Action,
success: Redux.Action,
info: Redux.Action,
warning: Redux.Action,
error: Redux.Action,
showConfirm: Redux.Action,
hideConfirm: Redux.Action
}
/**
* Action creator for toastr.
*/
export var actions: Redux.ActionCreator<Actions>;
/**
* Reducer for the toastr state.
* Combine with your reducers.
*/
export var reducer: Redux.Reducer<any>;
/**
* Used to issue toastr notifications.
*/
export var toastr: ToastrEmitter;
}