Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
5fcf2eea
Commit
5fcf2eea
authored
Feb 12, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Feb 12, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new ModalDialog for use profile modal
parent
78386e60
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
40 deletions
+48
-40
ModalDialog.tsx
src/annotator/components/ModalDialog.tsx
+13
-9
NotebookModal.tsx
src/annotator/components/NotebookModal.tsx
+5
-1
ProfileModal.tsx
src/annotator/components/ProfileModal.tsx
+25
-25
ModalDialog-test.js
src/annotator/components/test/ModalDialog-test.js
+4
-4
NotebookModal-test.js
src/annotator/components/test/NotebookModal-test.js
+1
-1
No files found.
src/annotator/components/ModalDialog.tsx
View file @
5fcf2eea
...
...
@@ -6,9 +6,15 @@ type DialogProps = {
closed
:
boolean
;
children
:
ComponentChildren
;
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
);
useEffect
(()
=>
{
...
...
@@ -32,32 +38,30 @@ const NativeDialog = ({ closed, children, onClose }: DialogProps) => {
<
dialog
ref=
{
dialogRef
}
className=
"relative w-full h-full backdrop:bg-black/50"
data
-
testid=
"notebook-outer"
data
-
testid=
{
testId
}
>
{
children
}
</
dialog
>
);
}
;
}
/**
* Temporary fallback used in browsers not supporting `dialog` element.
* It can be removed once all browsers we support can use it.
*/
const
FallbackDialog
=
({
closed
,
children
}:
DialogProps
)
=>
{
function
FallbackDialog
({
closed
,
children
,
...
rest
}:
DialogProps
)
{
return
(
<
div
{
...
rest
}
className=
{
classnames
(
'fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50'
,
{
hidden
:
closed
},
)
}
data
-
testid=
"notebook-outer"
>
<
div
className=
"relative w-full h-full"
data
-
testid=
"notebook-inner"
>
{
children
}
</
div
>
<
div
className=
"relative w-full h-full"
>
{
children
}
</
div
>
</
div
>
);
}
;
}
/** Checks if the browser supports native modal dialogs */
function
isModalDialogSupported
(
document
:
Document
)
{
...
...
src/annotator/components/NotebookModal.tsx
View file @
5fcf2eea
...
...
@@ -108,7 +108,11 @@ export default function NotebookModal({
}
return
(
<
ModalDialog
closed=
{
isHidden
}
onClose=
{
onClose
}
>
<
ModalDialog
closed=
{
isHidden
}
onClose=
{
onClose
}
data
-
testid=
"notebook-outer"
>
<
div
className=
"absolute right-0 m-3"
>
<
IconButton
title=
"Close the Notebook"
...
...
src/annotator/components/ProfileModal.tsx
View file @
5fcf2eea
...
...
@@ -3,6 +3,7 @@ import classnames from 'classnames';
import
{
useEffect
,
useRef
,
useState
}
from
'preact/hooks'
;
import
type
{
Emitter
,
EventBus
}
from
'../util/emitter'
;
import
ModalDialog
from
'./ModalDialog'
;
export
type
ProfileConfig
=
{
profileAppUrl
:
string
}
&
Record
<
string
,
unknown
>
;
...
...
@@ -37,33 +38,32 @@ export default function ProfileModal({ eventBus, config }: ProfileModalProps) {
}
return
(
<
div
className=
"fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50"
<
ModalDialog
closed=
{
isHidden
}
onClose=
{
onClose
}
data
-
testid=
"profile-outer"
>
<
div
className=
"relative w-full h-full"
data
-
testid=
"profile-inner"
>
<
div
className=
"absolute right-0 m-3"
>
<
IconButton
title=
"Close the Profile"
onClick=
{
onClose
}
variant=
"dark"
classes=
{
classnames
(
// Remove the dark variant's background color to avoid
// interfering with modal overlays. Re-activate the dark variant's
// background color on hover.
// See https://github.com/hypothesis/client/issues/3676
'!bg-transparent enabled:hover:!bg-grey-3'
,
)
}
>
<
CancelIcon
className=
"w-4 h-4"
/>
</
IconButton
>
</
div
>
<
iframe
title=
{
'Hypothesis profile'
}
className=
"h-full w-full border-0"
src=
{
config
.
profileAppUrl
}
/>
<
div
className=
"absolute right-0 m-3"
>
<
IconButton
title=
"Close profile dialog"
onClick=
{
onClose
}
variant=
"dark"
classes=
{
classnames
(
// Remove the dark variant's background color to avoid
// interfering with modal overlays. Re-activate the dark variant's
// background color on hover.
// See https://github.com/hypothesis/client/issues/3676
'!bg-transparent enabled:hover:!bg-grey-3'
,
)
}
>
<
CancelIcon
className=
"w-4 h-4"
/>
</
IconButton
>
</
div
>
</
div
>
<
iframe
title=
{
'Hypothesis profile'
}
className=
"h-full w-full border-0"
src=
{
config
.
profileAppUrl
}
/>
</
ModalDialog
>
);
}
src/annotator/components/test/ModalDialog-test.js
View file @
5fcf2eea
...
...
@@ -6,13 +6,13 @@ describe('ModalDialog', () => {
let
components
;
const
createComponent
=
props
=>
{
const
attachTo
=
document
.
createElement
(
'div'
);
document
.
body
.
appendChild
(
attachTo
);
const
container
=
document
.
createElement
(
'div'
);
document
.
body
.
appendChild
(
container
);
const
component
=
mount
(
<
ModalDialog
open
{...
props
}
/>,
{
attachTo
,
attachTo
:
container
,
});
components
.
push
([
component
,
attachTo
]);
components
.
push
([
component
,
container
]);
return
component
;
};
...
...
src/annotator/components/test/NotebookModal-test.js
View file @
5fcf2eea
...
...
@@ -12,7 +12,7 @@ describe('NotebookModal', () => {
let
eventBus
;
let
emitter
;
const
outerSelector
=
'[data-testid="notebook-outer"]'
;
const
outerSelector
=
'
dialog
[data-testid="notebook-outer"]'
;
const
createComponent
=
config
=>
{
const
attachTo
=
document
.
createElement
(
'div'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment