Skip to content

Commit

Permalink
Minor change of types
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhosseindhv committed Mar 8, 2020
1 parent 8d5d13d commit cebd141
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,34 @@ import * as React from 'react';
import { SnackbarProps, SnackbarClassKey } from '@material-ui/core/Snackbar';
import { SnackbarContentProps } from '@material-ui/core/SnackbarContent';

export type OptionalBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
export type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>
export type ClassNameMap<ClassKey extends string = string> = Record<ClassKey, string>;
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

export type RemovedAttributes = 'open' | 'message' | 'classes';
type NonSupportedProps = 'open' | 'message' | 'classes';
export type SnackbarKey = string | number;
export type VariantType = 'default' | 'error' | 'success' | 'warning' | 'info';
export type CloseReason = 'timeout' | 'clickaway' | 'maxsnack' | 'instructed';

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 type CloseReason = 'timeout' | 'clickaway' | 'maxsnack' | 'instructed';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type TransitionCloseHandler = (event: React.SyntheticEvent<any> | null, reason: CloseReason, key: SnackbarKey) => void;
export type TransitionEnterHandler = (node: HTMLElement, isAppearing: boolean, key: SnackbarKey) => void;
export type TransitionHandler = (node: HTMLElement, key: SnackbarKey) => void;
export type TransitionHandlerProps = {
onClose?: TransitionCloseHandler;
onEnter?: TransitionHandler;
onEntering?: TransitionHandler;
onEntered?: TransitionEnterHandler;
onExit?: TransitionHandler;
onExiting?: TransitionHandler;
onExited?: TransitionHandler;
export interface TransitionHandlerProps {
onClose: TransitionCloseHandler;
onEnter: TransitionHandler;
onEntering: TransitionHandler;
onEntered: TransitionEnterHandler;
onExit: TransitionHandler;
onExiting: TransitionHandler;
onExited: TransitionHandler;
}

export type ContainerClassKey =
Expand All @@ -40,6 +43,8 @@ export type ContainerClassKey =
export type VariantClassKey = 'variantSuccess' | 'variantError' | 'variantInfo' | 'variantWarning';
export type CombinedClassKey = VariantClassKey | ContainerClassKey | SnackbarClassKey;

export type IconVariant = Record<VariantType, React.ReactNode>;

export interface ProviderContext {
enqueueSnackbar: (message: SnackbarMessage, options?: OptionsObject) => SnackbarKey;
closeSnackbar: (key?: SnackbarKey) => void;
Expand All @@ -54,7 +59,7 @@ export function useSnackbar(): ProviderContext;
// backwards compatibility
export type WithSnackbarProps = ProviderContext;

export interface SharedProps extends Modify<Omit<SnackbarProps, RemovedAttributes>, TransitionHandlerProps> {
export interface SharedProps extends Modify<Omit<SnackbarProps, NonSupportedProps>, Partial<TransitionHandlerProps>> {
variant?: VariantType;
preventDuplicate?: boolean;
content?: SnackbarContent;
Expand All @@ -73,7 +78,7 @@ export interface SnackbarProviderProps extends SharedProps {
hideIconVariant?: boolean;
domRoot?: HTMLElement;
classes?: Partial<ClassNameMap<CombinedClassKey>>;
iconVariant?: Partial<Record<VariantType, React.ReactNode>>;
iconVariant?: Partial<IconVariant>;
}

export const SnackbarProvider: React.ComponentType<SnackbarProviderProps>;

0 comments on commit cebd141

Please sign in to comment.