Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100936441
Overlay.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Feb 4, 02:54
Size
2 KB
Mime Type
text/x-java
Expires
Thu, Feb 6, 02:54 (2 d)
Engine
blob
Format
Raw Data
Handle
24056791
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
Overlay.js
View Options
import
*
as
React
from
'react'
;
import
ReactDOM
from
'react-dom'
;
import
useCallbackRef
from
'@restart/hooks/useCallbackRef'
;
import
useMergedRefs
from
'@restart/hooks/useMergedRefs'
;
import
{
useState
}
from
'react'
;
import
usePopper
from
'./usePopper'
;
import
useRootClose
from
'./useRootClose'
;
import
useWaitForDOMRef
from
'./useWaitForDOMRef'
;
import
mergeOptionsWithPopperConfig
from
'./mergeOptionsWithPopperConfig'
;
import
{
jsx
as
_jsx
}
from
"react/jsx-runtime"
;
/**
* Built on top of `Popper.js`, the overlay component is
* great for custom tooltip overlays.
*/
const
Overlay
=
/*#__PURE__*/
React
.
forwardRef
((
props
,
outerRef
)
=>
{
const
{
flip
,
offset
,
placement
,
containerPadding
,
popperConfig
=
{},
transition
:
Transition
}
=
props
;
const
[
rootElement
,
attachRef
]
=
useCallbackRef
();
const
[
arrowElement
,
attachArrowRef
]
=
useCallbackRef
();
const
mergedRef
=
useMergedRefs
(
attachRef
,
outerRef
);
const
container
=
useWaitForDOMRef
(
props
.
container
);
const
target
=
useWaitForDOMRef
(
props
.
target
);
const
[
exited
,
setExited
]
=
useState
(
!
props
.
show
);
const
popper
=
usePopper
(
target
,
rootElement
,
mergeOptionsWithPopperConfig
({
placement
,
enableEvents
:
!!
props
.
show
,
containerPadding
:
containerPadding
||
5
,
flip
,
offset
,
arrowElement
,
popperConfig
}));
if
(
props
.
show
)
{
if
(
exited
)
setExited
(
false
);
}
else
if
(
!
props
.
transition
&&
!
exited
)
{
setExited
(
true
);
}
const
handleHidden
=
(...
args
)
=>
{
setExited
(
true
);
if
(
props
.
onExited
)
{
props
.
onExited
(...
args
);
}
};
// Don't un-render the overlay while it's transitioning out.
const
mountOverlay
=
props
.
show
||
Transition
&&
!
exited
;
useRootClose
(
rootElement
,
props
.
onHide
,
{
disabled
:
!
props
.
rootClose
||
props
.
rootCloseDisabled
,
clickTrigger
:
props
.
rootCloseEvent
});
if
(
!
mountOverlay
)
{
// Don't bother showing anything if we don't have to.
return
null
;
}
let
child
=
props
.
children
(
Object
.
assign
({},
popper
.
attributes
.
popper
,
{
style
:
popper
.
styles
.
popper
,
ref
:
mergedRef
}),
{
popper
,
placement
,
show
:
!!
props
.
show
,
arrowProps
:
Object
.
assign
({},
popper
.
attributes
.
arrow
,
{
style
:
popper
.
styles
.
arrow
,
ref
:
attachArrowRef
})
});
if
(
Transition
)
{
const
{
onExit
,
onExiting
,
onEnter
,
onEntering
,
onEntered
}
=
props
;
child
=
/*#__PURE__*/
_jsx
(
Transition
,
{
in
:
props
.
show
,
appear
:
true
,
onExit
:
onExit
,
onExiting
:
onExiting
,
onExited
:
handleHidden
,
onEnter
:
onEnter
,
onEntering
:
onEntering
,
onEntered
:
onEntered
,
children
:
child
});
}
return
container
?
/*#__PURE__*/
ReactDOM
.
createPortal
(
child
,
container
)
:
null
;
});
Overlay
.
displayName
=
'Overlay'
;
export
default
Overlay
;
Event Timeline
Log In to Comment