Skip to content

Commit

Permalink
Correct types for transition handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhosseindhv committed Feb 23, 2020
1 parent a23b5b8 commit f2e68a4
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SnackbarContentProps } from '@material-ui/core/SnackbarContent';

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
type ClassNameMap<ClassKey extends string = string> = Record<ClassKey, string>;
type Modify<T, R> = Pick<T, Exclude<keyof T, keyof R>> & R

type RemovedAttributes = 'open' | 'message' | 'classes';
export type SnackbarKey = string | number;
Expand All @@ -13,7 +14,20 @@ export type SnackbarMessage = string | React.ReactNode;
export type SnackbarAction = SnackbarContentProps['action'] | ((key: SnackbarKey) => React.ReactNode);
export type SnackbarContent = React.ReactNode | ((key: SnackbarKey, message: SnackbarMessage) => React.ReactNode);

export interface OptionsObject extends Omit<SnackbarProps, RemovedAttributes> {
export type TransitionCloseHandler = (event: React.SyntheticEvent<any>, reason: string, key: SnackbarKey) => void;
export type TransitionEnterHandler = (node: HTMLElement, isAppearing: boolean, key: SnackbarKey) => void;
export type TransitionExitHandler = (node: HTMLElement, key: SnackbarKey) => void;
export type TransitionHandlerProps = {
onClose?: TransitionCloseHandler;
onEnter?: TransitionEnterHandler;
onEntering?: TransitionEnterHandler;
onEntered?: TransitionEnterHandler;
onExit?: TransitionExitHandler;
onExiting?: TransitionExitHandler;
onExited?: TransitionExitHandler;
}

export interface OptionsObject extends Modify<Omit<SnackbarProps, RemovedAttributes>, TransitionHandlerProps> {
key?: SnackbarKey;
variant?: VariantType;
persist?: boolean;
Expand Down Expand Up @@ -46,7 +60,7 @@ export function withSnackbar<P extends WithSnackbarProps>(component: React.Compo
export function useSnackbar(): WithSnackbarProps;

// all material-ui props, including class keys for notistack and material-ui with additional notistack props
export interface SnackbarProviderProps extends Omit<SnackbarProps, RemovedAttributes> {
export interface SnackbarProviderProps extends Modify<Omit<SnackbarProps, RemovedAttributes>, TransitionHandlerProps> {
classes?: Partial<ClassNameMap<CombinedClassKey>>;
maxSnack?: number;
iconVariant?: Partial<Record<VariantType, React.ReactNode>>;
Expand Down

0 comments on commit f2e68a4

Please sign in to comment.