mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 13:00:19 +00:00
Add react-toast-notifications (#40194)
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
7222741787
commit
c73034d2af
+84
@@ -0,0 +1,84 @@
|
||||
// Type definitions for react-toast-notifications 2.0
|
||||
// Project: https://github.com/jossmac/react-toast-notifications
|
||||
// Definitions by: Spencer Elliott <https://github.com/elliottsj>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { ReactNode, ComponentType } from 'react';
|
||||
|
||||
export type AppearanceTypes = 'error' | 'info' | 'success' | 'warning';
|
||||
|
||||
export type Placement = 'bottom-left' | 'bottom-center' | 'bottom-right' | 'top-left' | 'top-center' | 'top-right';
|
||||
|
||||
export type TransitionState = 'entering' | 'entered' | 'exiting' | 'exited';
|
||||
|
||||
export interface ToastProps {
|
||||
appearance: AppearanceTypes;
|
||||
autoDismiss: boolean | number;
|
||||
autoDismissTimeout: number; // inherited from ToastProvider
|
||||
children: ReactNode;
|
||||
isRunning: boolean;
|
||||
onDismiss: (id?: string) => void;
|
||||
onMouseEnter: () => void;
|
||||
onMouseLeave: () => void;
|
||||
placement: Placement;
|
||||
transitionDuration: number; // inherited from ToastProvider
|
||||
transitionState: TransitionState; // inherited from ToastProvider
|
||||
}
|
||||
|
||||
export interface ToastConsumerContext {
|
||||
add: AddToast;
|
||||
remove: RemoveToast;
|
||||
toasts: Array<{
|
||||
content: ReactNode;
|
||||
id: string;
|
||||
appearance: AppearanceTypes;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface ToastConsumerProps {
|
||||
children: (context: ToastConsumerContext) => ReactNode;
|
||||
}
|
||||
|
||||
export interface ToastContainerProps {
|
||||
children: ReactNode;
|
||||
hasToasts: boolean;
|
||||
placement: Placement;
|
||||
}
|
||||
|
||||
export interface ToastProviderProps {
|
||||
autoDismissTimeout?: number;
|
||||
children: ReactNode;
|
||||
components?: {
|
||||
ToastContainer?: ComponentType<ToastContainerProps>;
|
||||
Toast?: ComponentType<ToastProps>;
|
||||
};
|
||||
placement?: Placement;
|
||||
transitionDuration?: number;
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
appearance: AppearanceTypes;
|
||||
autoDismiss?: boolean;
|
||||
onDismiss?: (id: string) => void;
|
||||
pauseOnHover?: boolean;
|
||||
}
|
||||
|
||||
export type AddToast = (content: ReactNode, options?: Options, callback?: (id: string) => void) => void;
|
||||
|
||||
export type RemoveToast = (id: string, callback: () => void) => void;
|
||||
|
||||
export const DefaultToastContainer: ComponentType<ToastContainerProps>;
|
||||
export const DefaultToast: ComponentType<ToastProps>;
|
||||
export const ToastConsumer: ComponentType<ToastConsumerProps>;
|
||||
export const ToastProvider: ComponentType<ToastProviderProps>;
|
||||
export function withToastManager(...args: any[]): any;
|
||||
export function useToasts(): {
|
||||
addToast: AddToast;
|
||||
removeToast: RemoveToast;
|
||||
toastStack: Array<{
|
||||
content: ReactNode;
|
||||
id: string;
|
||||
appearance: AppearanceTypes;
|
||||
}>;
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
import * as React from 'react';
|
||||
import { DefaultToast, ToastProps, ToastProvider, useToasts, ToastConsumer } from 'react-toast-notifications';
|
||||
|
||||
const CustomToast: React.FC<ToastProps> = ({ children, ...props }) => (
|
||||
<DefaultToast {...props}>
|
||||
<div className="custom">{children}</div>
|
||||
</DefaultToast>
|
||||
);
|
||||
|
||||
const MyApp: React.FC = () => (
|
||||
<ToastProvider>
|
||||
<Main1 />
|
||||
<Main2 />
|
||||
</ToastProvider>
|
||||
);
|
||||
|
||||
const Main1: React.FC = () => (
|
||||
<ToastConsumer>
|
||||
{context => (
|
||||
<div>
|
||||
<button onClick={() => context.add('Toast')}>Add</button>
|
||||
</div>
|
||||
)}
|
||||
</ToastConsumer>
|
||||
);
|
||||
|
||||
const Main2: React.FC = () => {
|
||||
const { addToast, removeToast, toastStack } = useToasts();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button onClick={() => addToast('Toast')}>Add</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"jsx": "react",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-toast-notifications-tests.tsx"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user