-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #958 from GluuFederation/admin-ui-issue-745-extend
feat(admin-ui): make admin-ui compatible with latest version node and npm
- Loading branch information
Showing
110 changed files
with
6,406 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import * as CommonDashboardFuncs from '@miltonbo/dashboard-style-airframe' | ||
import * as CommonDashboardFuncs from './components/dashboard-style-airframe' | ||
|
||
export default CommonDashboardFuncs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
import React, { useState, useRef, useEffect } from "react"; | ||
import DefaultLoader from "./DefaultLoader"; | ||
import safeActiveElement from "./safeActiveElement"; | ||
|
||
export default function BlockUi(props) { | ||
const { | ||
tag: Tag = "div", | ||
blocking, | ||
className, | ||
children, | ||
message, | ||
loader: Loader = DefaultLoader, | ||
renderChildren = true, | ||
keepInView, | ||
ariaLabel = "loading", | ||
...attributes | ||
} = props; | ||
|
||
const classes = blocking ? `block-ui ${className}` : className; | ||
const renderChilds = !blocking || renderChildren; | ||
|
||
const [top] = useState("50%"); | ||
const [focused, setFocused] = useState(null); | ||
|
||
const helper = useRef(null); | ||
const blocker = useRef(null); | ||
const topFocus = useRef(null); | ||
const container = useRef(null); | ||
const messageContainer = useRef(null); | ||
|
||
useEffect(() => { | ||
if (blocking) { | ||
if ( | ||
helper.current && | ||
helper.current.parentNode && | ||
helper.current.parentNode.contains && | ||
helper.current.parentNode.contains(safeActiveElement()) | ||
) { | ||
setFocused(safeActiveElement()); | ||
if (focused && focused !== document.body) { | ||
(window.setImmediate || setTimeout)( | ||
() => | ||
focused && typeof focused.blur === "function" && focused.blur() | ||
); | ||
} | ||
} | ||
} else { | ||
detachListeners(); | ||
const ae = safeActiveElement(); | ||
if (focused && (!ae || ae === document.body || ae === topFocus.current)) { | ||
if (typeof focused.focus === "function") { | ||
focused.focus(); | ||
} | ||
setFocused(null); | ||
} | ||
} | ||
if ( | ||
keepInView && | ||
(keepInView !== props.keepInView || | ||
(blocking && blocking !== props.blocking)) | ||
) { | ||
attachListeners(); | ||
keepInViewFunc(); | ||
} | ||
return () => { | ||
detachListeners(); | ||
}; | ||
}, [blocking, keepInView, focused]); | ||
|
||
const blockingTab = (e, withShift = false) => { | ||
return ( | ||
blocking && | ||
(e.key === "Tab" || e.keyCode === 9) && | ||
e.shiftKey == withShift | ||
); | ||
}; | ||
|
||
const tabbedUpTop = (e) => { | ||
if (blockingTab(e)) { | ||
blocker.current.focus(); | ||
} | ||
}; | ||
|
||
const tabbedDownTop = (e) => { | ||
if (blockingTab(e)) { | ||
e.preventDefault(); | ||
blocker.current.focus(); | ||
} | ||
}; | ||
|
||
const tabbedUpBottom = (e) => { | ||
if (blockingTab(e, true)) { | ||
topFocus.current.focus(); | ||
} | ||
}; | ||
|
||
const tabbedDownBottom = (e) => { | ||
if (blockingTab(e, true)) { | ||
e.preventDefault(); | ||
topFocus.current.focus(); | ||
} | ||
}; | ||
|
||
const attachListeners = () => { | ||
window.addEventListener("scroll", handleScroll); | ||
}; | ||
|
||
const detachListeners = () => { | ||
window.removeEventListener("scroll", handleScroll); | ||
}; | ||
|
||
const keepInViewFunc = () => { | ||
if (props.blocking && props.keepInView && container.current) { | ||
const containerBounds = container.current.getBoundingClientRect(); | ||
const windowHeight = window.innerHeight; | ||
if (containerBounds.top > windowHeight || containerBounds.bottom < 0) | ||
return; | ||
if (containerBounds.top >= 0 && containerBounds.bottom <= windowHeight) | ||
return; | ||
const topDelta = Math.min(containerBounds.top, 0); | ||
const bottomDelta = Math.max(containerBounds.bottom - windowHeight, 0); | ||
const scrollDelta = topDelta || bottomDelta; | ||
window.scrollBy({ | ||
top: scrollDelta, | ||
left: 0, | ||
behavior: "smooth", | ||
}); | ||
} | ||
}; | ||
|
||
function handleScroll() { | ||
keepInView(); | ||
} | ||
|
||
return ( | ||
<Tag {...attributes} className={classes} aria-busy={blocking}> | ||
{blocking && ( | ||
<div | ||
tabIndex="0" | ||
onKeyUp={tabbedUpTop} | ||
onKeyDown={tabbedDownTop} | ||
ref={topFocus} | ||
> | ||
<div className="sr-only">{message || ariaLabel}</div> | ||
</div> | ||
)} | ||
{renderChilds && children} | ||
{blocking && ( | ||
<div | ||
className="block-ui-container" | ||
tabIndex="0" | ||
ref={blocker} | ||
onKeyUp={tabbedUpBottom} | ||
onKeyDown={tabbedDownBottom} | ||
> | ||
<div className="block-ui-overlay" ref={container} /> | ||
<div | ||
className="block-ui-message-container" | ||
ref={messageContainer} | ||
style={{ top: keepInView ? top : undefined }} | ||
> | ||
<div className="block-ui-message"> | ||
{message || <span className="sr-only">{ariaLabel}</span>} | ||
<div aria-hidden> | ||
{React.isValidElement(Loader) ? Loader : <Loader />} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
<span ref={helper} /> | ||
</Tag> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react" | ||
|
||
function Loader() { | ||
return ( | ||
<div className="loading-indicator"> | ||
<span className="loading-bullet">•</span> | ||
<span className="loading-bullet">•</span> | ||
<span className="loading-bullet">•</span> | ||
</div> | ||
); | ||
} | ||
|
||
export default Loader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// https://gist.github.com/Alex1990/046a6553dc83e22dd6f4 | ||
/** | ||
* Get the current active element safely. | ||
* Ref: https://github.com/jquery/jquery-ui/blob/2b84531ae9331f60e4d739fabca6d78abde89ae1/ui/safe-active-element.js | ||
*/ | ||
export default function safeActiveElement(doc) { | ||
doc = doc || document; | ||
let activeElement; | ||
|
||
try { | ||
activeElement = document.activeElement; | ||
if (!activeElement || !activeElement.nodeName) { | ||
activeElement = doc.body; | ||
} | ||
} catch (error) { | ||
activeElement = doc.body; | ||
} | ||
|
||
return activeElement; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import SideMenuAnimate from './side-menu-animate' | ||
import SidebarEntryAnimate from './sidebar-entry-animate' | ||
import SlimSidebarAnimate from './slim-sidebar-animate' | ||
import SlimMenuAnimate from './slim-menu-animate' | ||
|
||
export { | ||
SideMenuAnimate, | ||
SidebarEntryAnimate, | ||
SlimSidebarAnimate, | ||
SlimMenuAnimate, | ||
}; |
Oops, something went wrong.