-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#103 - Improves metrics and layouts UX
Details: - Adds Transition.tsx and _transition.scss to handle mount and unmount transitions for React components - Adds MessageTooltip as a generic component to display tooltip messages - Fixes various minor issues - In layouts and metrics panels, adds a success tooltip message on the left of the footer when data has properly been saved to the graph - Replaces warning messages for metric attributes by a tooltip message on the right of the attribute name input
- Loading branch information
Showing
10 changed files
with
246 additions
and
54 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { FC, ReactNode, useEffect, useRef, useState } from "react"; | ||
import { AiFillWarning, AiOutlineCheckCircle, AiOutlineInfoCircle } from "react-icons/ai"; | ||
import { IconType } from "react-icons"; | ||
import cx from "classnames"; | ||
|
||
import Tooltip, { TooltipAPI } from "./Tooltip"; | ||
|
||
const DEFAULT_ICONS = { | ||
success: AiOutlineCheckCircle, | ||
info: AiOutlineInfoCircle, | ||
warning: AiFillWarning, | ||
error: AiFillWarning, | ||
} as const; | ||
type MessageType = keyof typeof DEFAULT_ICONS; | ||
|
||
const MessageTooltip: FC<{ | ||
message: ReactNode; | ||
type?: MessageType; | ||
icon?: IconType; | ||
openOnMount?: number; | ||
className?: string; | ||
iconClassName?: string; | ||
}> = ({ message, type = "info", icon: IconComponent = DEFAULT_ICONS[type], openOnMount, className, iconClassName }) => { | ||
const tooltipRef = useRef<TooltipAPI>(null); | ||
const [timeout, setTimeout] = useState<null | number>(null); | ||
|
||
useEffect(() => { | ||
let timeoutID: number | undefined; | ||
if (tooltipRef.current && openOnMount && !tooltipRef.current.isOpened()) { | ||
tooltipRef.current.open(); | ||
timeoutID = window.setTimeout(() => { | ||
tooltipRef.current?.close(); | ||
}, openOnMount); | ||
|
||
setTimeout(timeoutID); | ||
} | ||
|
||
return () => { | ||
if (timeoutID) window.clearTimeout(timeoutID); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return ( | ||
<Tooltip ref={tooltipRef} attachment="top middle" targetAttachment="bottom middle" targetClassName={className}> | ||
<button | ||
type="button" | ||
className="btn p-0 text" | ||
onMouseEnter={() => { | ||
if (timeout) window.clearTimeout(timeout); | ||
}} | ||
> | ||
<IconComponent className={cx(`text-${type}`, iconClassName)} /> | ||
</button> | ||
<div | ||
className="tooltip show bs-tooltip-top p-0 mx-2" | ||
role="tooltip" | ||
onMouseEnter={() => { | ||
if (timeout) window.clearTimeout(timeout); | ||
}} | ||
> | ||
<div className={cx("tooltip-inner", `bg-${type} text-bg-${type}`)}>{message}</div> | ||
</div> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export default MessageTooltip; |
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,28 @@ | ||
import React, { forwardRef, PropsWithChildren, useEffect, useState } from "react"; | ||
import { Property } from "csstype"; | ||
|
||
const Transition = forwardRef< | ||
HTMLDivElement, | ||
PropsWithChildren<{ show: unknown; mountTransition?: Property.Animation; unmountTransition?: Property.Animation }> | ||
>(({ children, show, mountTransition, unmountTransition }, ref) => { | ||
const [shouldRender, setRender] = useState(show); | ||
|
||
useEffect(() => { | ||
if (show) setRender(true); | ||
else if (!show && !unmountTransition) setRender(false); | ||
}, [show, unmountTransition]); | ||
|
||
return show || shouldRender ? ( | ||
<div | ||
ref={ref} | ||
style={{ animation: show ? mountTransition : unmountTransition }} | ||
// onAnimationEnd={() => { | ||
// if (!show) setRender(false); | ||
// }} | ||
> | ||
{children} | ||
</div> | ||
) : null; | ||
}); | ||
|
||
export default Transition; |
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
File renamed without changes.
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,16 @@ | ||
@keyframes fade-in { | ||
0% { | ||
opacity: 0; | ||
} | ||
100% { | ||
opacity: 1; | ||
} | ||
} | ||
@keyframes fade-out { | ||
0% { | ||
opacity: 1; | ||
} | ||
100% { | ||
opacity: 0; | ||
} | ||
} |
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
Oops, something went wrong.