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 SnackbarContainer containerRoot class #263

Merged
merged 3 commits into from
May 8, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Thanks to all contributers who improved notistack by opening an issue/PR.
* **@iinitz**: Enforce white text for dark theme [#241](https://github.com/iamhosseindhv/notistack/pull/241)
* **@fbarbare**: Let Mat UI handle the font and border-radius [#262](https://github.com/iamhosseindhv/notistack/pull/262)
* **@tomohiro-iwana @JuanmaMenendez**: Fix bug with snackbar not being centered on `xs` screens [#232](https://github.com/iamhosseindhv/notistack/issues/232)
* Add new `containerRoot` class to `SnackbarContainer` [#263](https://github.com/iamhosseindhv/notistack/pull/263)

<br />

Expand Down
6 changes: 5 additions & 1 deletion src/SnackbarProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import { createPortal } from 'react-dom';
import clsx from 'clsx';
import SnackbarContext from './SnackbarContext';
import { MESSAGES, REASONS, originKeyExtractor, omitContainerKeys } from './utils/constants';
import SnackbarItem from './SnackbarItem';
Expand Down Expand Up @@ -278,7 +279,10 @@ class SnackbarProvider extends Component<SnackbarProviderProps, State> {
key={origin}
dense={dense}
anchorOrigin={snacks[0].anchorOrigin}
className={classes[`containerAnchorOrigin${origin}` as ContainerClassKey]}
className={clsx(
classes.containerRoot,
classes[`containerAnchorOrigin${origin}` as ContainerClassKey],
)}
>
{snacks.map(snack => (
<SnackbarItem
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type TransitionEnterHandler = (node: HTMLElement, isAppearing: boolean, k
export type TransitionHandler = (node: HTMLElement, key: SnackbarKey) => void;

export type ContainerClassKey =
| 'containerRoot'
| 'containerAnchorOriginTopCenter'
| 'containerAnchorOriginBottomCenter'
| 'containerAnchorOriginTopRight'
Expand Down
3 changes: 2 additions & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const allClasses: {
anchorOriginBottomLeft: {},
},
container: {
containerRoot: {},
containerAnchorOriginTopCenter: {},
containerAnchorOriginBottomCenter: {},
containerAnchorOriginTopRight: {},
Expand Down Expand Up @@ -44,7 +45,7 @@ export const originKeyExtractor = (anchor: Snack['anchorOrigin']): string => (
/**
* Omit SnackbarContainer class keys that are not needed for SnackbarItem
*/
export const omitContainerKeys = (classes: SnackbarProviderProps['classes'] = {}): SnackbarItemProps['classes'] => (
export const omitContainerKeys = (classes: SnackbarProviderProps['classes']): SnackbarItemProps['classes'] => (
// @ts-ignore
Object.keys(classes).filter(key => !allClasses.container[key]).reduce((obj, key) => ({ ...obj, [key]: classes[key] }), {})
);
Expand Down
Loading