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

new(Overlay): Add enableMouseInteraction prop #391

Merged
merged 2 commits into from
Jul 23, 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
16 changes: 13 additions & 3 deletions packages/core/src/components/Overlay/Portal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { styleSheetPortal } from './styles';

export type PortalProps = {
children?: React.ReactNode;
/** Enable userSelect and pointer events. */
enableMouseInteraction?: boolean;
/** True removes the background. */
noBackground: boolean;
/** Callback for when the overlay should be closed. */
Expand Down Expand Up @@ -86,21 +88,29 @@ export class Portal extends React.Component<PortalProps & WithStylesProps, Porta
);

render() {
const { cx, children, styles, x, y, noBackground } = this.props;
const { cx, children, enableMouseInteraction, styles, x, y, noBackground } = this.props;
const { height } = this.state;

return (
<BasePortal>
<FocusTrap>
<div
ref={this.ref}
className={cx(styles.container, noBackground ? styles.noBg : styles.opaque)}
className={cx(
styles.container,
!enableMouseInteraction && styles.noUserSelect,
noBackground ? styles.noBg : styles.opaque,
)}
role="presentation"
onClick={this.handleClick}
onScroll={this.handleScrollThrottled}
>
<div
className={cx(styles.content, { paddingTop: y, marginLeft: x, minHeight: height })}
className={cx(
styles.content,
{ paddingTop: y, marginLeft: x, minHeight: height },
enableMouseInteraction && styles.withPointerEvents,
)}
>
{children}
</div>
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/components/Overlay/Portal/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ export const styleSheetPortal: StyleSheet = ({ color }) => ({
right: 0,
bottom: 0,
overflow: 'auto',
userSelect: 'none',
},

withPointerEvents: {
pointerEvents: 'all',
},

noBg: {
pointerEvents: 'none',
overflow: 'hidden',
},

noUserSelect: {
userSelect: 'none',
},

opaque: {
backgroundColor: color.accent.blackout,
},
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/components/Overlay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Portal from './Portal';
export type OverlayProps = {
/** Content to display within the overlay. */
children?: React.ReactNode;
/** Enable userSelect and pointer events. */
enableMouseInteraction?: boolean;
/** True to be visible. */
open?: boolean;
/** True for non-modal appearance. */
Expand All @@ -24,6 +26,7 @@ export type OverlayState = {
/** An overlay that masks the entire viewport and displays a chunk of content over it. */
export default class Overlay extends React.PureComponent<OverlayProps, OverlayState> {
static defaultProps = {
enableMouseInteraction: false,
noBackground: false,
open: false,
};
Expand Down Expand Up @@ -98,13 +101,15 @@ export default class Overlay extends React.PureComponent<OverlayProps, OverlaySt
private handleScroll = throttle(() => this.props.onClose(), 100);

render() {
const { onClose, open, children, noBackground } = this.props as Required<OverlayProps>;
const { onClose, enableMouseInteraction, open, children, noBackground } = this
.props as Required<OverlayProps>;
const { x, y, targetRectReady } = this.state;

return (
<div ref={this.ref}>
{open && targetRectReady && (
<Portal
enableMouseInteraction={enableMouseInteraction}
x={x}
y={y}
noBackground={noBackground}
Expand Down