Skip to content

Commit

Permalink
Fix various typescript inconsistencies (#319)
Browse files Browse the repository at this point in the history
* Add ref types to SnackbarProvider

* Rename SnackbarContent callback type

* Better name for SnackbarContent props
  • Loading branch information
iamhosseindhv authored Oct 6, 2020
1 parent ad36b59 commit 490bee9
Show file tree
Hide file tree
Showing 3 changed files with 2,165 additions and 190 deletions.
4 changes: 2 additions & 2 deletions src/SnackbarContent/SnackbarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const styles = (theme: Theme) => createStyles({
}
});

export interface SnackbarContent extends WithStyles<typeof styles>, React.HTMLAttributes<HTMLDivElement> { }
interface SnackbarContentProps extends WithStyles<typeof styles>, React.HTMLAttributes<HTMLDivElement> { }

const SnackbarContent: React.FC<SnackbarContent> = forwardRef<HTMLDivElement, SnackbarContent>(({ classes, className, ...props }, ref) => (
const SnackbarContent = forwardRef<HTMLDivElement, SnackbarContentProps>(({ classes, className, ...props }, ref) => (
<div ref={ref} className={clsx(classes.root, className)} {...props} />
))

Expand Down
13 changes: 10 additions & 3 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type CloseReason = 'timeout' | 'clickaway' | 'maxsnack' | 'instructed';

export type SnackbarMessage = string | React.ReactNode;
export type SnackbarAction = React.ReactNode | ((key: SnackbarKey) => React.ReactNode);
export type SnackbarContent = React.ReactNode | ((key: SnackbarKey, message: SnackbarMessage) => React.ReactNode);
export type SnackbarContentCallback = React.ReactNode | ((key: SnackbarKey, message: SnackbarMessage) => React.ReactNode);


// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -192,7 +192,7 @@ export interface SharedProps extends Omit<SnackbarProps, 'classes'>, Partial<Tra
* Replace the snackbar. Callback used for displaying entirely customized snackbar.
* @param {string|number} key key of a snackbar
*/
content?: SnackbarContent;
content?: SnackbarContentCallback;
/**
* Callback used for getting action(s). actions are mostly buttons displayed in Snackbar.
* @param {string|number} key key of a snackbar
Expand Down Expand Up @@ -253,9 +253,16 @@ export interface SnackbarProviderProps extends SharedProps {
* Little icon that is displayed at left corner of a snackbar.
*/
iconVariant?: Partial<IconVariant>;
/**
* SnackbarProvider's ref
*/
ref?: React.Ref<SnackbarProvider>;
}

export const SnackbarProvider: React.ComponentType<SnackbarProviderProps>;
export class SnackbarProvider extends React.Component<SnackbarProviderProps> {
enqueueSnackbar: ProviderContext['enqueueSnackbar'];
closeSnackbar: ProviderContext['closeSnackbar'];
}

export interface ProviderContext {
enqueueSnackbar: (message: SnackbarMessage, options?: OptionsObject) => SnackbarKey;
Expand Down
Loading

0 comments on commit 490bee9

Please sign in to comment.