Commit 5fcf2eea authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Use new ModalDialog for use profile modal

parent 78386e60
...@@ -6,9 +6,15 @@ type DialogProps = { ...@@ -6,9 +6,15 @@ type DialogProps = {
closed: boolean; closed: boolean;
children: ComponentChildren; children: ComponentChildren;
onClose: () => void; onClose: () => void;
'data-testid'?: string;
}; };
const NativeDialog = ({ closed, children, onClose }: DialogProps) => { function NativeDialog({
closed,
onClose,
children,
'data-testid': testId,
}: DialogProps) {
const dialogRef = useRef<HTMLDialogElement | null>(null); const dialogRef = useRef<HTMLDialogElement | null>(null);
useEffect(() => { useEffect(() => {
...@@ -32,32 +38,30 @@ const NativeDialog = ({ closed, children, onClose }: DialogProps) => { ...@@ -32,32 +38,30 @@ const NativeDialog = ({ closed, children, onClose }: DialogProps) => {
<dialog <dialog
ref={dialogRef} ref={dialogRef}
className="relative w-full h-full backdrop:bg-black/50" className="relative w-full h-full backdrop:bg-black/50"
data-testid="notebook-outer" data-testid={testId}
> >
{children} {children}
</dialog> </dialog>
); );
}; }
/** /**
* Temporary fallback used in browsers not supporting `dialog` element. * Temporary fallback used in browsers not supporting `dialog` element.
* It can be removed once all browsers we support can use it. * It can be removed once all browsers we support can use it.
*/ */
const FallbackDialog = ({ closed, children }: DialogProps) => { function FallbackDialog({ closed, children, ...rest }: DialogProps) {
return ( return (
<div <div
{...rest}
className={classnames( className={classnames(
'fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50', 'fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50',
{ hidden: closed }, { hidden: closed },
)} )}
data-testid="notebook-outer"
> >
<div className="relative w-full h-full" data-testid="notebook-inner"> <div className="relative w-full h-full">{children}</div>
{children}
</div>
</div> </div>
); );
}; }
/** Checks if the browser supports native modal dialogs */ /** Checks if the browser supports native modal dialogs */
function isModalDialogSupported(document: Document) { function isModalDialogSupported(document: Document) {
......
...@@ -108,7 +108,11 @@ export default function NotebookModal({ ...@@ -108,7 +108,11 @@ export default function NotebookModal({
} }
return ( return (
<ModalDialog closed={isHidden} onClose={onClose}> <ModalDialog
closed={isHidden}
onClose={onClose}
data-testid="notebook-outer"
>
<div className="absolute right-0 m-3"> <div className="absolute right-0 m-3">
<IconButton <IconButton
title="Close the Notebook" title="Close the Notebook"
......
...@@ -3,6 +3,7 @@ import classnames from 'classnames'; ...@@ -3,6 +3,7 @@ import classnames from 'classnames';
import { useEffect, useRef, useState } from 'preact/hooks'; import { useEffect, useRef, useState } from 'preact/hooks';
import type { Emitter, EventBus } from '../util/emitter'; import type { Emitter, EventBus } from '../util/emitter';
import ModalDialog from './ModalDialog';
export type ProfileConfig = { profileAppUrl: string } & Record<string, unknown>; export type ProfileConfig = { profileAppUrl: string } & Record<string, unknown>;
...@@ -37,14 +38,14 @@ export default function ProfileModal({ eventBus, config }: ProfileModalProps) { ...@@ -37,14 +38,14 @@ export default function ProfileModal({ eventBus, config }: ProfileModalProps) {
} }
return ( return (
<div <ModalDialog
className="fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50" closed={isHidden}
onClose={onClose}
data-testid="profile-outer" data-testid="profile-outer"
> >
<div className="relative w-full h-full" data-testid="profile-inner">
<div className="absolute right-0 m-3"> <div className="absolute right-0 m-3">
<IconButton <IconButton
title="Close the Profile" title="Close profile dialog"
onClick={onClose} onClick={onClose}
variant="dark" variant="dark"
classes={classnames( classes={classnames(
...@@ -63,7 +64,6 @@ export default function ProfileModal({ eventBus, config }: ProfileModalProps) { ...@@ -63,7 +64,6 @@ export default function ProfileModal({ eventBus, config }: ProfileModalProps) {
className="h-full w-full border-0" className="h-full w-full border-0"
src={config.profileAppUrl} src={config.profileAppUrl}
/> />
</div> </ModalDialog>
</div>
); );
} }
...@@ -6,13 +6,13 @@ describe('ModalDialog', () => { ...@@ -6,13 +6,13 @@ describe('ModalDialog', () => {
let components; let components;
const createComponent = props => { const createComponent = props => {
const attachTo = document.createElement('div'); const container = document.createElement('div');
document.body.appendChild(attachTo); document.body.appendChild(container);
const component = mount(<ModalDialog open {...props} />, { const component = mount(<ModalDialog open {...props} />, {
attachTo, attachTo: container,
}); });
components.push([component, attachTo]); components.push([component, container]);
return component; return component;
}; };
......
...@@ -12,7 +12,7 @@ describe('NotebookModal', () => { ...@@ -12,7 +12,7 @@ describe('NotebookModal', () => {
let eventBus; let eventBus;
let emitter; let emitter;
const outerSelector = '[data-testid="notebook-outer"]'; const outerSelector = 'dialog[data-testid="notebook-outer"]';
const createComponent = config => { const createComponent = config => {
const attachTo = document.createElement('div'); const attachTo = document.createElement('div');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment