Skip to content

Commit

Permalink
Improve type def file (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmckenna authored and iamhosseindhv committed Dec 10, 2018
1 parent 9ab3ed4 commit 5dd6588
Show file tree
Hide file tree
Showing 2 changed files with 3,948 additions and 3 deletions.
18 changes: 15 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import * as React from 'react';
import { TransitionActions } from 'react-transition-group/Transition';
import { SvgIconProps } from '@material-ui/core/SvgIcon';
import { SnackbarProps } from '@material-ui/core/Snackbar';
import { SnackbarProps, SnackbarClassKey } from '@material-ui/core/Snackbar';

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>

export type VariantType = 'default' | 'error' | 'success' | 'warning' | 'info';

export interface OptionsObject extends Omit<SnackbarProps, 'open'|'message'> {
export interface OptionsObject extends Omit<SnackbarProps, 'open' | 'message'> {
variant?: VariantType;
onClickAction?: Function;
}

type NotistackClassKey = 'variantSuccess'
| 'variantError'
| 'variantInfo'
| 'variantWarning';

// class keys for both MUI and notistack
export type CombinedClassKey = NotistackClassKey | SnackbarClassKey;

export interface InjectedNotistackProps {
onPresentSnackbar: (variant: VariantType, message: string) => void;
enqueueSnackbar: (message: string, options?: OptionsObject) => void;
Expand All @@ -20,8 +28,12 @@ export interface InjectedNotistackProps {
export function withSnackbar<P extends InjectedNotistackProps>(component: React.ComponentType<P>):
React.ComponentClass<Omit<P, keyof InjectedNotistackProps>> & { WrappedComponent: React.ComponentType<P> };

export type ClassNameMap<ClassKey extends string = string> = Record<ClassKey, string>;

export interface SnackbarProviderProps extends Omit<SnackbarProps, 'open'|'message'> {
/** all MUI props, including class keys for notistack and MUI with additional notistack props */
export interface SnackbarProviderProps
extends Omit<SnackbarProps, 'open' | 'message' | 'classes'> {
classes?: Partial<ClassNameMap<CombinedClassKey>>;
maxSnack: number;
iconVariant?: React.ComponentType<SvgIconProps>;
hideIconVariant?: boolean;
Expand Down
Loading

0 comments on commit 5dd6588

Please sign in to comment.