-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into use-snackbar
- Loading branch information
Showing
9 changed files
with
120 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
## `[email protected].0` | ||
## `[email protected].2` | ||
###### to be published | ||
|
||
Thanks to all contributers who improved notistack by opening an issue/PR. | ||
|
||
**@martinmckenna** | ||
**@Lukas-Kullmann** | ||
* Add `displayName` to components exported by `withSnackbar` HOC [#100](https://github.com/iamhosseindhv/notistack/issues/100) | ||
|
||
|
||
## `[email protected]` | ||
###### Mar 15, 2019 | ||
|
||
Thanks to all contributers who improved notistack by opening an issue/PR. | ||
|
||
**@amakhrov** | ||
* Fix typing for `iconVariant` props [#91](https://github.com/iamhosseindhv/notistack/issues/91) | ||
|
||
|
||
|
||
## `[email protected]` | ||
###### Mar 5, 2019 | ||
|
||
Thanks to all contributers who improved notistack by opening an issue/PR. | ||
|
||
**@cwbuecheler @mpash @khhan1993 @Fs00 @martinmckenna** | ||
* Rename `InjectedSnackbarProps` to `withSnackbarProps` in type definitions [#59](https://github.com/iamhosseindhv/notistack/issues/59) | ||
* Add new prop `dense` to allow dense margins for snackbars (suitable for mobiles) [#58](https://github.com/iamhosseindhv/notistack/issues/58) | ||
* Improve performance and prevent unnecessary child re-rendering [#39](https://github.com/iamhosseindhv/notistack/issues/39) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,46 @@ | ||
import * as React from 'react'; | ||
import { SvgIconProps } from '@material-ui/core/SvgIcon'; | ||
import { SnackbarProps, SnackbarClassKey } from '@material-ui/core/Snackbar'; | ||
|
||
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> | ||
type ClassNameMap<ClassKey extends string = string> = Record<ClassKey, string>; | ||
|
||
export type VariantType = 'default' | 'error' | 'success' | 'warning' | 'info'; | ||
|
||
export interface OptionsObject extends Omit<SnackbarProps, 'open' | 'message' | 'classes'> { | ||
key?: string | number; | ||
variant?: VariantType; | ||
persist?: boolean; | ||
persist?: boolean; | ||
onClickAction?: Function; | ||
preventDuplicate?: boolean; | ||
} | ||
|
||
type NotistackClassKey = 'variantSuccess' | ||
| 'variantError' | ||
| 'variantInfo' | ||
| 'variantWarning'; | ||
export type NotistackClassKey = 'variantSuccess' | 'variantError' | 'variantInfo' | 'variantWarning'; | ||
|
||
// class keys for both MUI and notistack | ||
export type CombinedClassKey = NotistackClassKey | SnackbarClassKey; | ||
type CombinedClassKey = NotistackClassKey | SnackbarClassKey; | ||
|
||
export interface InjectedNotistackProps { | ||
export interface withSnackbarProps { | ||
onPresentSnackbar: (variant: VariantType, message: string) => void; | ||
enqueueSnackbar: (message: string | React.ReactNode, options?: OptionsObject) => string | number | null; | ||
closeSnackbar: (key: string | number) => void | ||
} | ||
|
||
export function withSnackbar<P extends InjectedNotistackProps>(component: React.ComponentType<P>): | ||
React.ComponentClass<Omit<P, keyof InjectedNotistackProps>> & { WrappedComponent: React.ComponentType<P> }; | ||
export function withSnackbar<P extends withSnackbarProps>(component: React.ComponentType<P>): | ||
React.ComponentClass<Omit<P, keyof withSnackbarProps>> & { WrappedComponent: React.ComponentType<P> }; | ||
|
||
|
||
export function useSnackbar(): InjectedNotistackProps; | ||
|
||
export type ClassNameMap<ClassKey extends string = string> = Record<ClassKey, string>; | ||
|
||
/** all MUI props, including class keys for notistack and MUI with additional notistack props */ | ||
export interface SnackbarProviderProps | ||
extends Omit<SnackbarProps, 'open' | 'message' | 'classes'> { | ||
// all material-ui props, including class keys for notistack and material-ui with additional notistack props | ||
export interface SnackbarProviderProps extends Omit<SnackbarProps, 'open' | 'message' | 'classes'> { | ||
classes?: Partial<ClassNameMap<CombinedClassKey>>; | ||
maxSnack: number; | ||
iconVariant?: React.ComponentType<SvgIconProps>; | ||
maxSnack?: number; | ||
iconVariant?: Partial<Record<VariantType, React.ReactNode>>; | ||
hideIconVariant?: boolean; | ||
onClickAction?: Function; | ||
preventDuplicate?: boolean; | ||
dense?: boolean; | ||
} | ||
|
||
export const SnackbarProvider: React.ComponentType<SnackbarProviderProps>; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
import React from 'react'; | ||
import { SnackbarContext, SnackbarContextNext } from './SnackbarContext'; | ||
|
||
const withSnackbar = Component => props => ( | ||
<SnackbarContext.Consumer> | ||
{handlePresentSnackbar => ( | ||
<SnackbarContextNext.Consumer> | ||
{context => ( | ||
<Component | ||
{...props} | ||
onPresentSnackbar={handlePresentSnackbar} | ||
enqueueSnackbar={context.handleEnqueueSnackbar} | ||
closeSnackbar={context.handleCloseSnackbar} | ||
/> | ||
)} | ||
</SnackbarContextNext.Consumer> | ||
)} | ||
</SnackbarContext.Consumer> | ||
); | ||
const withSnackbar = (Component) => { | ||
const WrappedComponent = props => ( | ||
<SnackbarContext.Consumer> | ||
{handlePresentSnackbar => ( | ||
<SnackbarContextNext.Consumer> | ||
{context => ( | ||
<Component | ||
{...props} | ||
onPresentSnackbar={handlePresentSnackbar} | ||
enqueueSnackbar={context.handleEnqueueSnackbar} | ||
closeSnackbar={context.handleCloseSnackbar} | ||
/> | ||
)} | ||
</SnackbarContextNext.Consumer> | ||
)} | ||
</SnackbarContext.Consumer> | ||
); | ||
|
||
WrappedComponent.displayName = `withSnackbar(${Component.displayName || Component.name || 'Component'})`; | ||
|
||
return WrappedComponent; | ||
}; | ||
|
||
export default withSnackbar; |