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

fix: do not use css selector for collapse styles #396

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 0 additions & 19 deletions src/SnackbarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { makeStyles } from '@material-ui/core/styles';
import { SNACKBAR_INDENTS } from './utils/constants';
import { SnackbarProviderProps } from '.';

const collapse = {
container: '& > .MuiCollapse-container',
wrapper: '& > .MuiCollapse-container > .MuiCollapse-wrapper',
};

const xsWidthMargin = 16;

const useStyle = makeStyles((theme) => ({
Expand All @@ -23,24 +18,12 @@ const useStyle = makeStyles((theme) => ({
transition: 'top 300ms ease 0ms, right 300ms ease 0ms, bottom 300ms ease 0ms, left 300ms ease 0ms, margin 300ms ease 0ms, max-width 300ms ease 0ms',
// container itself is invisible and should not block clicks, clicks should be passed to its children
pointerEvents: 'none',
[collapse.container]: {
pointerEvents: 'all',
},
[collapse.wrapper]: {
padding: `${SNACKBAR_INDENTS.snackbar.default}px 0px`,
transition: 'padding 300ms ease 0ms',
},
maxWidth: `calc(100% - ${SNACKBAR_INDENTS.view.default * 2}px)`,
[theme.breakpoints.down('xs')]: {
width: '100%',
maxWidth: `calc(100% - ${xsWidthMargin * 2}px)`,
},
},
rootDense: {
[collapse.wrapper]: {
padding: `${SNACKBAR_INDENTS.snackbar.dense}px 0px`,
},
},
top: {
top: SNACKBAR_INDENTS.view.default - SNACKBAR_INDENTS.snackbar.default,
flexDirection: 'column',
Expand Down Expand Up @@ -76,7 +59,6 @@ const useStyle = makeStyles((theme) => ({
},
}));


interface SnackbarContainerProps {
children: JSX.Element | JSX.Element[];
className?: string;
Expand All @@ -91,7 +73,6 @@ const SnackbarContainer: React.FC<SnackbarContainerProps> = (props) => {
const combinedClassname = clsx(
classes[anchorOrigin.vertical],
classes[anchorOrigin.horizontal],
{ [classes.rootDense]: dense },
classes.root, // root should come after others to override maxWidth
className,
);
Expand Down
16 changes: 15 additions & 1 deletion src/SnackbarItem/SnackbarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { withStyles, WithStyles, createStyles, Theme, emphasize } from '@materia
import Collapse from '@material-ui/core/Collapse';
import SnackbarContent from '../SnackbarContent';
import { getTransitionDirection } from './SnackbarItem.util';
import { allClasses, REASONS, objectMerge, DEFAULTS, transformer } from '../utils/constants';
import { allClasses, REASONS, objectMerge, DEFAULTS, transformer, SNACKBAR_INDENTS } from '../utils/constants';
import { SharedProps, RequiredBy, TransitionHandlerProps, SnackbarProviderProps as ProviderProps } from '../index';
import defaultIconVariants from '../utils/defaultIconVariants';
import createChainedFunction from '../utils/createChainedFunction';
Expand Down Expand Up @@ -65,6 +65,16 @@ const styles = (theme: Theme) => {
bottom: 0,
left: 0,
},
collapseContainer: {
pointerEvents: 'all',
},
collapseWrapper: {
padding: `${SNACKBAR_INDENTS.snackbar.default}px 0px`,
transition: 'padding 300ms ease 0ms',
},
collapseWrapperDense: {
padding: `${SNACKBAR_INDENTS.snackbar.dense}px 0px`,
},
});
}

Expand Down Expand Up @@ -194,6 +204,10 @@ const SnackbarItem: React.FC<SnackbarItemProps> = ({ classes, ...props }) => {
timeout={175}
in={collapsed}
onExited={callbacks.onExited}
classes={{
wrapper: clsx(classes.collapseWrapper, { [classes.collapseWrapperDense]: dense }),
container: classes.collapseContainer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI with @material-ui/core 4.12.1 this wants to be

    root: classes.collapseContainer

rather than container.

}}
>
{/* @ts-ignore */}
<Snackbar
Expand Down