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

[pickers] Migrate PickersPopper to emotion #26391

Merged
merged 4 commits into from
May 21, 2021
Merged
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
52 changes: 24 additions & 28 deletions packages/material-ui-lab/src/internal/pickers/PickersPopper.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as React from 'react';
import clsx from 'clsx';
import Grow from '@material-ui/core/Grow';
import Paper, { PaperProps as MuiPaperProps } from '@material-ui/core/Paper';
import Popper, { PopperProps as MuiPopperProps } from '@material-ui/core/Popper';
import TrapFocus, {
TrapFocusProps as MuiTrapFocusProps,
} from '@material-ui/core/Unstable_TrapFocus';
import { useForkRef, useEventCallback, ownerDocument } from '@material-ui/core/utils';
import { MuiStyles, StyleRules, WithStyles, withStyles } from '@material-ui/core/styles';
import { experimentalStyled as styled } from '@material-ui/core/styles';
import { TransitionProps as MuiTransitionProps } from '@material-ui/core/transitions';

export interface ExportedPickerPopperProps {
Expand All @@ -30,22 +29,19 @@ export interface PickerPopperProps extends ExportedPickerPopperProps, MuiPaperPr
onClose: () => void;
}

export type PickersPopperClassKey = 'root' | 'paper' | 'topTransition';

export const styles: MuiStyles<PickersPopperClassKey> = (
theme,
): StyleRules<PickersPopperClassKey> => ({
root: {
zIndex: theme.zIndex.modal,
},
paper: {
transformOrigin: 'top center',
outline: 0,
},
topTransition: {
const PickersPopperRoot = styled(Popper, { skipSx: true })(({ theme }) => ({
zIndex: theme.zIndex.modal,
}));

const PickersPopperPaper = styled(Paper, { skipSx: true })<{
styleProps: Pick<MuiPopperProps, 'placement'>;
}>(({ styleProps }) => ({
transformOrigin: 'top center',
outline: 0,
...(styleProps.placement === 'top' && {
transformOrigin: 'bottom center',
},
});
}),
}));

function clickedRootScrollbar(event: MouseEvent, doc: Document) {
return (
Expand Down Expand Up @@ -188,11 +184,10 @@ function useClickAwayListener(
return [nodeRef, handleSynthetic, handleSynthetic];
}

const PickersPopper: React.FC<PickerPopperProps & WithStyles<typeof styles>> = (props) => {
const PickersPopper = (props: PickerPopperProps) => {
const {
anchorEl,
children,
classes,
containerRef = null,
onClose,
open,
Expand Down Expand Up @@ -238,13 +233,16 @@ const PickersPopper: React.FC<PickerPopperProps & WithStyles<typeof styles>> = (
const handleRef = useForkRef(paperRef, containerRef);
const handlePaperRef = useForkRef(handleRef, clickAwayRef as React.Ref<HTMLDivElement>);

// TODO: convert to simple assignment after the type error in defaultPropsHandler.js:60:6 is fixed
const styleProps = { ...props };

return (
<Popper
<PickersPopperRoot
transition
role={role}
open={open}
anchorEl={anchorEl}
className={clsx(classes.root, PopperProps?.className)}
styleProps={styleProps}
{...PopperProps}
>
{({ TransitionProps, placement }) => (
Expand All @@ -257,23 +255,21 @@ const PickersPopper: React.FC<PickerPopperProps & WithStyles<typeof styles>> = (
{...TrapFocusProps}
>
<TransitionComponent {...TransitionProps}>
<Paper
<PickersPopperPaper
tabIndex={-1}
elevation={8}
ref={handlePaperRef}
className={clsx(classes.paper, {
[classes.topTransition]: placement === 'top',
})}
onClick={onPaperClick}
onTouchStart={onPaperTouchStart}
styleProps={{ ...styleProps, placement }}
Copy link
Member Author

Choose a reason for hiding this comment

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

placement is not from props.

>
{children}
</Paper>
</PickersPopperPaper>
</TransitionComponent>
</TrapFocus>
)}
</Popper>
</PickersPopperRoot>
);
};

export default withStyles(styles, { name: 'PrivatePickersPopper' })(PickersPopper);
export default PickersPopper;