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

feat: Layers #1923

Closed
wants to merge 24 commits 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
1 change: 0 additions & 1 deletion packages/core/.storybook/preview-body.html
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<div id="dropdown-portal"></div>
<div id="tooltips-container"></div>
6 changes: 0 additions & 6 deletions packages/core/.storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
body * {
box-sizing: border-box;
}
#tooltips-container {
position: relative;
white-space: pre-wrap;
z-index: 99999999;
max-width: 50%;
}
.light-app-theme {
background-color: var(--sb-primary-background-color);
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
"@types/lodash-es": "^4.17.6",
"@types/react": "^18.0.25",
"@types/react-dates": "^21.8.3",
"@types/react-dom": "^18.2.18",
"@types/react-is": "^16.7.5",
"@types/react-resizable": "^3.0.7",
"@types/react-test-renderer": "^16.9.0",
Expand Down
17 changes: 13 additions & 4 deletions packages/core/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { VibeComponentProps } from "../../types";
import * as PopperJS from "@popperjs/core";
import styles from "./Dialog.module.scss";
import { ComponentDefaultTestId, getTestId } from "../../tests/test-ids-utils";
import LayerContext from "../LayerProvider/LayerContext";

export interface DialogProps extends VibeComponentProps {
/**
Expand Down Expand Up @@ -92,6 +93,7 @@ export interface DialogProps extends VibeComponentProps {
* Classname to be added to the content container
*/
wrapperClassName?: string;
layerClassName?: string;
/**
* Prevent Animation
*/
Expand Down Expand Up @@ -126,6 +128,7 @@ export interface DialogProps extends VibeComponentProps {
* callback to be called when click on the content is being triggered
*/
onContentClick?: (event: React.MouseEvent) => void;
// TODO: remove in next major
/**
* z-index to add to the dialog
*/
Expand Down Expand Up @@ -199,6 +202,7 @@ export default class Dialog extends PureComponent<DialogProps, DialogState> {
};
private showTimeout: NodeJS.Timeout;
private hideTimeout: NodeJS.Timeout;
context!: React.ContextType<typeof LayerContext>;

constructor(props: DialogProps) {
super(props);
Expand Down Expand Up @@ -282,10 +286,11 @@ export default class Dialog extends PureComponent<DialogProps, DialogState> {

const containerElement = document.querySelector(containerSelector);
if (!containerElement) {
// TODO add env check - if not jest env - trashing the logs - https://monday.monday.com/boards/3532714909/pulses/5570955392
// console.error(
// `Dialog: Container element with selector "${containerSelector}" was not found. Dialog may not be correctly positioned.`
// );
const { layerRef } = this.context;
if (layerRef?.current) {
// Use Vibe layers mechanism if containerElement was not provided, otherwise fallback to document.body
return layerRef.current;
}
return document.body;
}
return containerElement;
Expand Down Expand Up @@ -485,6 +490,7 @@ export default class Dialog extends PureComponent<DialogProps, DialogState> {
render() {
const {
wrapperClassName,
layerClassName,
content,
startingEdge,
children,
Expand Down Expand Up @@ -603,6 +609,7 @@ export default class Dialog extends PureComponent<DialogProps, DialogState> {
animationType={animationTypeCalculated}
position={placement}
wrapperClassName={wrapperClassName}
layerClassName={layerClassName}
startingEdge={startingEdge}
isOpen={this.isShown()}
showDelay={showDelay}
Expand Down Expand Up @@ -637,3 +644,5 @@ function chainOnPropsAndInstance(name: string, instance: Dialog, props: DialogPr
// @ts-ignore
return chainFunctions([props[name], instance[name]], true);
}

Dialog.contextType = LayerContext;
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
}
}

.dialogLayer {
z-index: var(--layer-popover);
}

.contentWrapper[data-popper-reference-hidden="true"] {
visibility: hidden;
pointer-events: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface DialogContentProps extends VibeComponentProps {
children?: ReactElement | ReactElement[];
position?: PopperJS.Placement;
wrapperClassName?: string;
layerClassName?: string;
isOpen?: boolean;
// TODO breaking change convert to enum
startingEdge?: any;
Expand Down Expand Up @@ -54,6 +55,7 @@ export const DialogContent: VibeComponent<DialogContentProps> = React.forwardRef
children,
position,
wrapperClassName,
layerClassName,
isOpen = false,
startingEdge,
animationType = "expand",
Expand Down Expand Up @@ -124,8 +126,14 @@ export const DialogContent: VibeComponent<DialogContentProps> = React.forwardRef
}
return (
<span
// TODO: remove "monday-style-dialog-content-wrapper" class in next major
// don't remove old classname - override from Monolith
className={cx("monday-style-dialog-content-wrapper", styles.contentWrapper, wrapperClassName)}
className={cx(
"monday-style-dialog-content-wrapper",
Copy link
Member Author

Choose a reason for hiding this comment

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

Remove

styles.contentWrapper,
wrapperClassName,
layerClassName || styles.dialogLayer
)}
ref={forwardRef}
data-testid={dataTestId}
style={styleObject}
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/components/LayerProvider/LayerContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

export type LayersContextType = {
layerRef: React.RefObject<HTMLElement>;
};

const LayerContext = React.createContext<LayersContextType>({
layerRef: null
});

export default LayerContext;
13 changes: 13 additions & 0 deletions packages/core/src/components/LayerProvider/LayerProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { FC } from "react";
import LayerContext from "./LayerContext";

interface LayerProviderType {
children: JSX.Element | JSX.Element[];
layerRef: React.RefObject<HTMLElement> | null;
}

const LayerProvider: FC<LayerProviderType> = ({ children, layerRef }) => {
return <LayerContext.Provider value={{ layerRef }}>{children}</LayerContext.Provider>;
};

export default LayerProvider;
3 changes: 2 additions & 1 deletion packages/core/src/components/Modal/Modal.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
}

.container {
--monday-modal-z-index: 10000;
--monday-modal-z-index: var(--layer-modal);
// TODO: use --modal-layer in next major
z-index: var(--monday-modal-z-index);
display: flex;
justify-content: center;
Expand Down
47 changes: 27 additions & 20 deletions packages/core/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { cloneElement, FC, ReactElement, useCallback, useMemo } from "react";
import React, { cloneElement, FC, ReactElement, useCallback, useMemo, useRef } from "react";
import ReactDOM from "react-dom";
import cx from "classnames";
import { useA11yDialog } from "./a11yDialog";
Expand All @@ -12,6 +12,7 @@ import { withStaticProps } from "../../types";
import { getTestId } from "../../tests/test-ids-utils";
import { ComponentDefaultTestId } from "../../tests/constants";
import styles from "./Modal.module.scss";
import LayerProvider from "../LayerProvider/LayerProvider";

export interface ModalProps {
/**
Expand Down Expand Up @@ -72,6 +73,7 @@ export interface ModalProps {
* Dialog content
*/
children?: ReactElement | ReactElement[];
// TODO: remove next major
/**
* z-index attribute of the container
*/
Expand All @@ -97,6 +99,7 @@ const Modal: FC<ModalProps> & { width?: typeof ModalWidth } = ({
zIndex = 10000,
"data-testid": dataTestId
}) => {
const overlayRef = useRef(null);
const childrenArray: ReactElement[] = useMemo(
() => (children ? (React.Children.toArray(children) as ReactElement[]) : []),
[children]
Expand Down Expand Up @@ -162,27 +165,31 @@ const Modal: FC<ModalProps> & { width?: typeof ModalWidth } = ({
{...attr.container}
className={cx(styles.container, classNames.container)}
data-testid={dataTestId || getTestId(ComponentDefaultTestId.MODAL, id)}
// TODO: remove in next major
style={{ "--monday-modal-z-index": zIndex }}
>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
<div
onClick={closeIfNotAlertType}
className={cx(styles.overlay, classNames.overlay)}
data-testid={ComponentDefaultTestId.MODAL_OVERLAY}
/>
<div
{...attr.dialog}
className={cx(styles.dialog, classNames.modal, {
[styles.default]: width === ModalWidth.DEFAULT,
[styles.full]: width === ModalWidth.FULL_WIDTH,
[styles.spacing]: contentSpacing
})}
style={{ width: customWidth ? width : null }}
>
{header}
{content}
{footer}
</div>
<LayerProvider layerRef={overlayRef}>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
<div
onClick={closeIfNotAlertType}
className={cx(styles.overlay, classNames.overlay)}
data-testid={ComponentDefaultTestId.MODAL_OVERLAY}
ref={overlayRef}
/>
<div
{...attr.dialog}
className={cx(styles.dialog, classNames.modal, {
[styles.default]: width === ModalWidth.DEFAULT,
[styles.full]: width === ModalWidth.FULL_WIDTH,
[styles.spacing]: contentSpacing
})}
style={{ width: customWidth ? width : null }}
>
{header}
{content}
{footer}
</div>
</LayerProvider>
</div>,
document.body
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Snapshot Diff:
tabindex="0"
/>
+ <span
+ class="monday-style-dialog-content-wrapper contentWrapper"
+ class="monday-style-dialog-content-wrapper contentWrapper tooltipLayer"
+ data-popper-reference-hidden="false"
+ data-testid="tooltip"
+ style="position: absolute; left: 0px; top: 0px;"
Expand Down Expand Up @@ -83,7 +83,7 @@ Snapshot Diff:
tabindex="0"
/>
- <span
- class="monday-style-dialog-content-wrapper contentWrapper"
- class="monday-style-dialog-content-wrapper contentWrapper tooltipLayer"
- data-popper-reference-hidden="false"
- data-testid="tooltip"
- style="position: absolute; left: 0px; top: 0px;"
Expand Down Expand Up @@ -118,7 +118,7 @@ Snapshot Diff:
tabindex="0"
/>
+ <span
+ class="monday-style-dialog-content-wrapper contentWrapper"
+ class="monday-style-dialog-content-wrapper contentWrapper tooltipLayer"
+ data-popper-reference-hidden="false"
+ data-testid="tooltip"
+ style="position: absolute; left: 0px; top: 0px;"
Expand Down Expand Up @@ -153,7 +153,7 @@ Snapshot Diff:
tabindex="0"
/>
- <span
- class="monday-style-dialog-content-wrapper contentWrapper"
- class="monday-style-dialog-content-wrapper contentWrapper tooltipLayer"
- data-popper-reference-hidden="false"
- data-testid="tooltip"
- style="position: absolute; left: 0px; top: 0px;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Snapshot Diff:
tabindex="0"
/>
+ <span
+ class="monday-style-dialog-content-wrapper contentWrapper"
+ class="monday-style-dialog-content-wrapper contentWrapper tooltipLayer"
+ data-popper-reference-hidden="false"
+ data-testid="tooltip"
+ style="position: absolute; left: 0px; top: 0px;"
Expand Down Expand Up @@ -94,7 +94,7 @@ Snapshot Diff:
tabindex="0"
/>
+ <span
+ class="monday-style-dialog-content-wrapper contentWrapper"
+ class="monday-style-dialog-content-wrapper contentWrapper tooltipLayer"
+ data-popper-reference-hidden="false"
+ data-testid="tooltip"
+ style="position: absolute; left: 0px; top: 0px;"
Expand Down Expand Up @@ -129,7 +129,7 @@ Snapshot Diff:
tabindex="0"
/>
- <span
- class="monday-style-dialog-content-wrapper contentWrapper"
- class="monday-style-dialog-content-wrapper contentWrapper tooltipLayer"
- data-popper-reference-hidden="false"
- data-testid="tooltip"
- style="position: absolute; left: 0px; top: 0px;"
Expand Down Expand Up @@ -164,7 +164,7 @@ Snapshot Diff:
tabindex="0"
/>
+ <span
+ class="monday-style-dialog-content-wrapper contentWrapper"
+ class="monday-style-dialog-content-wrapper contentWrapper tooltipLayer"
+ data-popper-reference-hidden="false"
+ data-testid="tooltip"
+ style="position: absolute; left: 0px; top: 0px;"
Expand Down Expand Up @@ -274,7 +274,7 @@ Snapshot Diff:
tabindex="0"
/>
- <span
- class="monday-style-dialog-content-wrapper contentWrapper"
- class="monday-style-dialog-content-wrapper contentWrapper tooltipLayer"
- data-popper-reference-hidden="false"
- data-testid="tooltip"
- style="position: absolute; left: 0px; top: 0px;"
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/components/Tipseen/Tipseen.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@import "../../styles/typography";

.tipseenLayer {
z-index: var(--layer-popover);
}

.tipseenWrapper {
min-width: 100px;
min-height: 40px;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/components/Tipseen/Tipseen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const Tipseen: VibeComponent<TipseenProps> & {
modifiers={modifiers}
open={defaultDelayOpen ? delayedOpen : undefined}
forceRenderWithoutChildren={floating}
layerClassName={styles.tipseenLayer}
>
{children}
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Array [
onMouseLeave={[Function]}
/>,
<span
className="monday-style-dialog-content-wrapper contentWrapper"
className="monday-style-dialog-content-wrapper contentWrapper tipseenLayer"
data-popper-reference-hidden={false}
data-testid="tooltip"
onClickCapture={[Function]}
Expand Down Expand Up @@ -230,7 +230,7 @@ Array [

exports[`Snapshot tests Tipseen tests renders correctly with floating variation 1`] = `
<span
className="monday-style-dialog-content-wrapper contentWrapper"
className="monday-style-dialog-content-wrapper contentWrapper tipseenLayer"
data-popper-reference-hidden={false}
data-testid="tooltip"
onClickCapture={[Function]}
Expand Down Expand Up @@ -318,7 +318,7 @@ Array [
onMouseLeave={[Function]}
/>,
<span
className="monday-style-dialog-content-wrapper contentWrapper"
className="monday-style-dialog-content-wrapper contentWrapper tipseenLayer"
data-popper-reference-hidden={false}
data-testid="tooltip"
onClickCapture={[Function]}
Expand Down Expand Up @@ -377,7 +377,7 @@ Array [
onMouseLeave={[Function]}
/>,
<span
className="monday-style-dialog-content-wrapper contentWrapper"
className="monday-style-dialog-content-wrapper contentWrapper tipseenLayer"
data-popper-reference-hidden={false}
data-testid="tooltip"
onClickCapture={[Function]}
Expand Down Expand Up @@ -436,7 +436,7 @@ Array [
onMouseLeave={[Function]}
/>,
<span
className="monday-style-dialog-content-wrapper contentWrapper"
className="monday-style-dialog-content-wrapper contentWrapper tipseenLayer"
data-popper-reference-hidden={false}
data-testid="tooltip"
onClickCapture={[Function]}
Expand Down
Loading