Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Typings for Classes #37

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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