Skip to content

Commit

Permalink
spike: wrap tile content in dialog modal
Browse files Browse the repository at this point in the history
  • Loading branch information
lublagg committed Nov 21, 2024
1 parent 3d00012 commit 2e92a76
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 29 deletions.
19 changes: 19 additions & 0 deletions v3/src/components/codap-component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
$border-drag-width: 8px;
$corner-drag-size: calc($border-drag-width * 2);

.dialog-wrapper-container {
position: absolute;
margin: 0;
width: inherit;
height: inherit;
}

.dialog-wrapper {
width: inherit;
height: inherit;
margin: 0;
}

.codap-component {
position: relative;
width: 100%;
Expand All @@ -12,6 +25,12 @@ $corner-drag-size: calc($border-drag-width * 2);
box-shadow: 0 1px 20px 0 rgba(0, 0, 0, 0.4);
}

&.dialogWrapper {
position: absolute;
width: inherit;
height: inherit;
}

input {
&:focus {
background-color: white !important;
Expand Down
124 changes: 96 additions & 28 deletions v3/src/components/codap-component.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { clsx } from "clsx"
import { observer } from "mobx-react-lite"
import { isAlive } from "mobx-state-tree"
import React, { useRef } from "react"
import React, { useEffect, useRef, useState } from "react"
import { CodapComponentContext } from "../hooks/use-codap-component-context"
import { TileModelContext } from "../hooks/use-tile-model-context"
import { InspectorPanelWrapper } from "./inspector-panel-wrapper"
import { ITileBaseProps } from "./tiles/tile-base-props"
import { getTileComponentInfo } from "../models/tiles/tile-component-info"
import { ITileModel } from "../models/tiles/tile-model"
import { uiState } from "../models/ui-state"
import { urlParams } from "../utilities/url-params"
import { isWebViewModel } from "./web-view/web-view-model"
import ResizeHandle from "../assets/icons/icon-corner-resize-handle.svg"

import "./codap-component.scss"
Expand All @@ -29,8 +31,33 @@ export const CodapComponent = observer(function CodapComponent({
tile, isMinimized, onMinimizeTile, onCloseTile, onBottomRightPointerDown, onBottomLeftPointerDown,
onRightPointerDown, onBottomPointerDown, onLeftPointerDown
}: IProps) {
const {dialogWrapper} = urlParams
const dialogRef = useRef<HTMLDialogElement>(null)
const dialogWrapperRef = useRef<HTMLDivElement>(null)
const info = getTileComponentInfo(tile.content.type)
const codapComponentRef = useRef<HTMLDivElement | null>(null)
const [showDialog, setShowDialog] = useState(false)

useEffect(() => {
if (dialogWrapper && dialogRef.current && isWebViewModel(tile.content)) {
setShowDialog(true)

Check warning on line 43 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L43

Added line #L43 was not covered by tests
const wrapperPos = dialogWrapperRef.current?.getBoundingClientRect()
const wrapperOffsetLeft = wrapperPos?.left
const wrapperOffsetTop = wrapperPos?.top
dialogRef.current.style.left = `${wrapperOffsetLeft}px`
dialogRef.current.style.top = `${wrapperOffsetTop}px`

Check warning on line 48 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L47-L48

Added lines #L47 - L48 were not covered by tests
}
}, [tile.content, dialogWrapper])

useEffect(() => {
if (dialogRef.current) {
if (showDialog) {
dialogRef.current.showModal()
} else {
dialogRef.current.close()

Check warning on line 57 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L55-L57

Added lines #L55 - L57 were not covered by tests
}
}
}, [showDialog])

function handleFocusTile() {
if (isAlive(tile)) {
Expand All @@ -44,34 +71,75 @@ export const CodapComponent = observer(function CodapComponent({
if (!info) return null

const { TitleBar, Component, tileEltClass, isFixedWidth, isFixedHeight } = info
const classes = clsx("codap-component", tileEltClass, { minimized: isMinimized },
const classes = clsx("codap-component", tileEltClass, {dialogWrapper}, { minimized: isMinimized },
{ shadowed: uiState.isFocusedTile(tile.id) || uiState.isHoveredTile(tile.id) })
return (
<TileModelContext.Provider value={tile}>
<CodapComponentContext.Provider value={codapComponentRef}>
<div className={classes} ref={codapComponentRef} key={tile.id} data-testid={tileEltClass}
onFocus={handleFocusTile} onPointerDownCapture={handleFocusTile}>
<TitleBar tile={tile} onMinimizeTile={onMinimizeTile} onCloseTile={onCloseTile}/>
<Component tile={tile} isMinimized={isMinimized} />
{onRightPointerDown && !isFixedWidth && !isMinimized &&
<div className="codap-component-border right" onPointerDown={onRightPointerDown}/>}
{onBottomPointerDown && !isFixedHeight && !isMinimized &&
<div className="codap-component-border bottom" onPointerDown={onBottomPointerDown}/>}
{onLeftPointerDown && !isFixedWidth && !isMinimized &&
<div className="codap-component-border left" onPointerDown={onLeftPointerDown}/>}
{onBottomLeftPointerDown && !(isFixedWidth && isFixedHeight) && !isMinimized &&
<div className="codap-component-corner bottom-left" onPointerDown={onBottomLeftPointerDown}/>
}
{onBottomRightPointerDown && !(isFixedWidth && isFixedHeight) && !isMinimized &&
<div className="codap-component-corner bottom-right" onPointerDown={onBottomRightPointerDown}>
{(uiState.isFocusedTile(tile.id)) && !isMinimized &&
<ResizeHandle className="component-resize-handle"/>}

if (dialogWrapper && isWebViewModel(tile.content)) {
return (

Check warning on line 78 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L78

Added line #L78 was not covered by tests
<TileModelContext.Provider value={tile}>
<CodapComponentContext.Provider value={codapComponentRef}>
<div className={classes} ref={codapComponentRef} key={tile.id} data-testid={tileEltClass}
onFocus={handleFocusTile} onPointerDownCapture={handleFocusTile}>
<TitleBar tile={tile} onMinimizeTile={onMinimizeTile} onCloseTile={onCloseTile}/>
{ !showDialog &&
<button onClick={() => setShowDialog(true)}>

Check warning on line 85 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L85

Added line #L85 was not covered by tests
open dialog
</button>
}
<div ref={dialogWrapperRef} className="dialog-wrapper-container">
<dialog onClose={() => setShowDialog(false)} className={"dialog-wrapper"} ref={dialogRef}>
<button onClick={() => setShowDialog(false)}>close dialog</button>

Check warning on line 91 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L90-L91

Added lines #L90 - L91 were not covered by tests
<Component tile={tile} isMinimized={isMinimized} />
{onRightPointerDown && !isFixedWidth && !isMinimized &&
<div className="codap-component-border right" onPointerDown={onRightPointerDown}/>}

Check warning on line 94 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L94

Added line #L94 was not covered by tests
{onBottomPointerDown && !isFixedHeight && !isMinimized &&
<div className="codap-component-border bottom" onPointerDown={onBottomPointerDown}/>}

Check warning on line 96 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L96

Added line #L96 was not covered by tests
{onLeftPointerDown && !isFixedWidth && !isMinimized &&
<div className="codap-component-border left" onPointerDown={onLeftPointerDown}/>}

Check warning on line 98 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L98

Added line #L98 was not covered by tests
{onBottomLeftPointerDown && !(isFixedWidth && isFixedHeight) && !isMinimized &&
<div className="codap-component-corner bottom-left" onPointerDown={onBottomLeftPointerDown}/>

Check warning on line 100 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L100

Added line #L100 was not covered by tests
}
</dialog>
</div>
}
{onBottomRightPointerDown && !(isFixedWidth && isFixedHeight) && !isMinimized &&
<div className="codap-component-corner bottom-right" onPointerDown={onBottomRightPointerDown}>

Check warning on line 105 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L105

Added line #L105 was not covered by tests
{(uiState.isFocusedTile(tile.id)) && !isMinimized &&
<ResizeHandle className="component-resize-handle" />}

Check warning on line 107 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L107

Added line #L107 was not covered by tests
</div>
}
</div>
<InspectorPanelWrapper tile={tile} isMinimized={isMinimized} />
</CodapComponentContext.Provider>
</TileModelContext.Provider>
)
} else {

Check warning on line 115 in v3/src/components/codap-component.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/codap-component.tsx#L115

Added line #L115 was not covered by tests
return (
<TileModelContext.Provider value={tile}>
<CodapComponentContext.Provider value={codapComponentRef}>
<div className={classes} ref={codapComponentRef} key={tile.id} data-testid={tileEltClass}
onFocus={handleFocusTile} onPointerDownCapture={handleFocusTile}>
<TitleBar tile={tile} onMinimizeTile={onMinimizeTile} onCloseTile={onCloseTile}/>
<Component tile={tile} isMinimized={isMinimized} />
{onRightPointerDown && !isFixedWidth && !isMinimized &&
<div className="codap-component-border right" onPointerDown={onRightPointerDown}/>}
{onBottomPointerDown && !isFixedHeight && !isMinimized &&
<div className="codap-component-border bottom" onPointerDown={onBottomPointerDown}/>}
{onLeftPointerDown && !isFixedWidth && !isMinimized &&
<div className="codap-component-border left" onPointerDown={onLeftPointerDown}/>}
{onBottomLeftPointerDown && !(isFixedWidth && isFixedHeight) && !isMinimized &&
<div className="codap-component-corner bottom-left" onPointerDown={onBottomLeftPointerDown}/>
}
{onBottomRightPointerDown && !(isFixedWidth && isFixedHeight) && !isMinimized &&
<div className="codap-component-corner bottom-right" onPointerDown={onBottomRightPointerDown}>
{(uiState.isFocusedTile(tile.id)) && !isMinimized &&
<ResizeHandle className="component-resize-handle"/>}
</div>
}

</div>
<InspectorPanelWrapper tile={tile} isMinimized={isMinimized} />
</CodapComponentContext.Provider>
</TileModelContext.Provider>
)
</div>
<InspectorPanelWrapper tile={tile} isMinimized={isMinimized} />
</CodapComponentContext.Provider>
</TileModelContext.Provider>
)
}
})
6 changes: 5 additions & 1 deletion v3/src/utilities/url-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export interface UrlParams {
*/
di?: string | null
/*
* [v3] Wrap the iframe plugin in a dialog element.
*/
dialogWrapper?: string | null
/*
* [v2] When present enables the gaussian fit feature of the normal curve adornment.
* value: ignored
*/
Expand All @@ -42,7 +46,7 @@ export interface UrlParams {
*/
ICI?: string | null
/*
* Indicates CODAP is running in the Activity Player. Used by the CFM and to configure
* Indicates CODAP is running in the Activity Player. Used by the CFM and to configure
* the CFM.
* value: ignored
*/
Expand Down

0 comments on commit 2e92a76

Please sign in to comment.