- { items.map(item => (
+
setOpen(false)}>
+ {open && (
+
+ {items.map((item) => (
{
- item.onClick(e);
+ key={item.label}
+ onClick={(e) => {
+ item.onClick(e);
setOpen(false);
}}
- className={ cn("flex items-center justify-end color-green bg-white uppercase overflow-hidden", cls.menuItemButton) }
+ className={cn(
+ 'flex items-center justify-end color-green bg-white uppercase overflow-hidden',
+ cls.menuItemButton
+ )}
>
- { item.label }
-
+ {item.label}
+
))}
- }
-
+ )}
+
setOpen(o => !o) }
- className={ cn("bg-teal flex items-center justify-center", cls.addStepButton, {[cls.openMenuBtn] : open }) }
+ onClick={() => setOpen((o) => !o)}
+ className={cn('bg-teal flex items-center justify-center', cls.addStepButton, {
+ [cls.openMenuBtn]: open,
+ })}
>
-
+
-
+
);
});
diff --git a/frontend/app/components/ui/Popover/Popover.tsx b/frontend/app/components/ui/Popover/Popover.tsx
new file mode 100644
index 000000000..f3fc2dffd
--- /dev/null
+++ b/frontend/app/components/ui/Popover/Popover.tsx
@@ -0,0 +1,86 @@
+import React, { cloneElement, useMemo, useState } from 'react';
+import {
+ Placement,
+ offset,
+ flip,
+ shift,
+ autoUpdate,
+ useFloating,
+ useInteractions,
+ useRole,
+ useDismiss,
+ useId,
+ useClick,
+ FloatingFocusManager,
+} from '@floating-ui/react-dom-interactions';
+import { mergeRefs } from 'react-merge-refs';
+import { INDEXES } from 'App/constants/zindex';
+
+interface Props {
+ render: (data: { close: () => void; labelId: string; descriptionId: string }) => React.ReactNode;
+ placement?: Placement;
+ children: JSX.Element;
+}
+
+const Popover = ({ children, render, placement }: Props) => {
+ const [open, setOpen] = useState(false);
+
+ const { x, y, reference, floating, strategy, context } = useFloating({
+ open,
+ onOpenChange: setOpen,
+ middleware: [offset(5), flip(), shift()],
+ placement,
+ whileElementsMounted: autoUpdate,
+ });
+
+ const id = useId();
+ const labelId = `${id}-label`;
+ const descriptionId = `${id}-description`;
+
+ const { getReferenceProps, getFloatingProps } = useInteractions([
+ useClick(context),
+ useRole(context),
+ useDismiss(context),
+ ]);
+
+ // Preserve the consumer's ref
+ const ref = useMemo(() => mergeRefs([reference, (children as any).ref]), [reference, children]);
+
+ return (
+ <>
+ {cloneElement(children, getReferenceProps({ ref, ...children.props }))}
+ {open && (
+
+
+ {render({
+ labelId,
+ descriptionId,
+ close: () => {
+ setOpen(false);
+ },
+ })}
+
+
+ )}
+ >
+ );
+};
+
+export default Popover;
diff --git a/frontend/app/components/ui/Popover/index.ts b/frontend/app/components/ui/Popover/index.ts
new file mode 100644
index 000000000..44c04deaf
--- /dev/null
+++ b/frontend/app/components/ui/Popover/index.ts
@@ -0,0 +1 @@
+export { default } from './Popover';
diff --git a/frontend/app/components/ui/Popup/Popup.stories.js b/frontend/app/components/ui/Popup/Popup.stories.js
deleted file mode 100644
index 022c84731..000000000
--- a/frontend/app/components/ui/Popup/Popup.stories.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import { storiesOf } from '@storybook/react';
-import Popup from '.';
-
-storiesOf('Popup', module)
- .add('Pure', () => (
-
- ))
-
diff --git a/frontend/app/components/ui/Popup/Popup.tsx b/frontend/app/components/ui/Popup/Popup.tsx
deleted file mode 100644
index 0bf9258af..000000000
--- a/frontend/app/components/ui/Popup/Popup.tsx
+++ /dev/null
@@ -1,57 +0,0 @@
-import React from 'react';
-import { Tooltip, Theme, Trigger, Position, Animation } from 'react-tippy';
-
-interface Props {
- content?: any;
- title?: any;
- trigger?: Trigger;
- position?: Position;
- className?: string;
- delay?: number;
- hideDelay?: number;
- disabled?: boolean;
- arrow?: boolean;
- style?: any;
- theme?: Theme;
- interactive?: boolean;
- children?: any;
- animation?: Animation;
- // [x:string]: any;
-}
-export default ({
- position = 'top',
- title = '',
- className = '',
- trigger = 'mouseenter',
- delay = 0,
- hideDelay = 0,
- content = '',
- disabled = false,
- arrow = false,
- theme = 'dark',
- style = {},
- interactive = false,
- children,
- animation = 'fade',
-}: // ...props
-Props) => (
- // @ts-ignore
-
- {children}
-
-);
diff --git a/frontend/app/components/ui/Popup/index.js b/frontend/app/components/ui/Popup/index.js
deleted file mode 100644
index ab5f1602c..000000000
--- a/frontend/app/components/ui/Popup/index.js
+++ /dev/null
@@ -1 +0,0 @@
-export { default } from './Popup';
\ No newline at end of file
diff --git a/frontend/app/components/ui/QuestionMarkHint/QuestionMarkHint.js b/frontend/app/components/ui/QuestionMarkHint/QuestionMarkHint.js
index 793edf95d..6cc7981b7 100644
--- a/frontend/app/components/ui/QuestionMarkHint/QuestionMarkHint.js
+++ b/frontend/app/components/ui/QuestionMarkHint/QuestionMarkHint.js
@@ -1,16 +1,11 @@
import React from 'react';
-import cn from "classnames";
-import { Icon, Popup } from 'UI';
+import cn from 'classnames';
+import { Icon, Tooltip } from 'UI';
-export default function QuestionMarkHint({ onHover = false, content, ...props }) {
- return (
-
-
-
- );
-}
\ No newline at end of file
+export default function QuestionMarkHint({ content, ...props }) {
+ return (
+
+
+
+ );
+}
diff --git a/frontend/app/components/ui/SegmentSelection/SegmentSelection.js b/frontend/app/components/ui/SegmentSelection/SegmentSelection.js
index 97db6cef1..d3c71b6cf 100644
--- a/frontend/app/components/ui/SegmentSelection/SegmentSelection.js
+++ b/frontend/app/components/ui/SegmentSelection/SegmentSelection.js
@@ -1,44 +1,62 @@
import React from 'react';
-import { Icon, Popup } from 'UI';
+import { Icon, Tooltip } from 'UI';
import cn from 'classnames';
import styles from './segmentSelection.module.css';
class SegmentSelection extends React.Component {
setActiveItem = (item) => {
this.props.onSelect(null, { name: this.props.name, value: item.value });
- }
+ };
render() {
- const { className, list, small = false, extraSmall = false, primary = false, size = "normal", icons = false, disabled = false, disabledMessage = 'Not Allowed', outline } = this.props;
+ const {
+ className,
+ list,
+ small = false,
+ extraSmall = false,
+ primary = false,
+ size = 'normal',
+ icons = false,
+ disabled = false,
+ disabledMessage = 'Not Allowed',
+ outline,
+ } = this.props;
return (
-
-
+
- { list.map(item => (
-
!item.disabled && this.setActiveItem(item) }
- >
- { item.icon &&
}
-
{ item.name }
-
- ))
- }
+ {list.map((item) => (
+
!item.disabled && this.setActiveItem(item)}
+ >
+ {item.icon && (
+
+ )}
+
{item.name}
+
+ ))}
-
+
);
}
}
diff --git a/frontend/app/components/ui/SideMenuitem/SideMenuitem.js b/frontend/app/components/ui/SideMenuitem/SideMenuitem.js
index 7c8e8272a..8538a9a63 100644
--- a/frontend/app/components/ui/SideMenuitem/SideMenuitem.js
+++ b/frontend/app/components/ui/SideMenuitem/SideMenuitem.js
@@ -1,5 +1,5 @@
import React from 'react';
-import { Icon, Popup } from 'UI';
+import { Icon, Tooltip } from 'UI';
import cn from 'classnames';
import stl from './sideMenuItem.module.css';
@@ -18,12 +18,10 @@ function SideMenuitem({
...props
}) {
return (
-
}
-
+
)
}
diff --git a/frontend/app/components/ui/TextEllipsis/TextEllipsis.js b/frontend/app/components/ui/TextEllipsis/TextEllipsis.js
index 036d12d46..7cd51e39f 100644
--- a/frontend/app/components/ui/TextEllipsis/TextEllipsis.js
+++ b/frontend/app/components/ui/TextEllipsis/TextEllipsis.js
@@ -1,10 +1,10 @@
import React from 'react';
import { useState, useRef, useEffect, forwardRef } from 'react';
import cn from 'classnames';
-import { Popup } from 'UI';
+import { Tooltip } from 'UI';
import styles from './textEllipsis.module.css';
-/** calculates text width in pixels
+/** calculates text width in pixels
* by creating a hidden element with
* text and counting its width
* @param text String - text string
@@ -12,96 +12,100 @@ import styles from './textEllipsis.module.css';
* @returns width number
*/
function findTextWidth(text, fontProp) {
- const tag = document.createElement('div')
+ const tag = document.createElement('div');
- tag.style.position = 'absolute'
- tag.style.left = '-99in'
- tag.style.whiteSpace = 'nowrap'
- tag.style.font = fontProp
- tag.innerHTML = text
+ tag.style.position = 'absolute';
+ tag.style.left = '-99in';
+ tag.style.whiteSpace = 'nowrap';
+ tag.style.font = fontProp;
+ tag.innerHTML = text;
- document.body.appendChild(tag)
- const result = tag.clientWidth
- document.body.removeChild(tag)
+ document.body.appendChild(tag);
+ const result = tag.clientWidth;
+ document.body.removeChild(tag);
- return result;
+ return result;
}
const Trigger = forwardRef(({ textOrChildren, maxWidth, style, className, ...rest }, ref) => (
-
- { textOrChildren }
-
-))
+
+ {textOrChildren}
+
+));
-const TextEllipsis = ({
- text,
- hintText = text,
- children = null,
- maxWidth="auto",
- style = {},
- className="",
- noHint=false,
- popupProps={},
- hintProps={},
- ...props
+const TextEllipsis = ({
+ text,
+ hintText = text,
+ children = null,
+ maxWidth = 'auto',
+ style = {},
+ className = '',
+ noHint = false,
+ popupProps = {},
+ hintProps = {},
+ ...props
}) => {
- const [showPopup, setShowPopup] = useState(false)
- const [computed, setComputed] = useState(false)
- const textRef = useRef(null);
+ const [showPopup, setShowPopup] = useState(false);
+ const [computed, setComputed] = useState(false);
+ const textRef = useRef(null);
- const textOrChildren = text || children;
-
- const popupId = (Math.random() + 1).toString(36).substring(2);
+ const textOrChildren = text || children;
- useEffect(() => {
- if (computed) return;
- if (textRef.current) {
- const element = textRef.current;
+ const popupId = (Math.random() + 1).toString(36).substring(2);
- const fontSize = window.getComputedStyle(element, null).getPropertyValue('font-size');
-
- const textWidth = findTextWidth(element.innerText, fontSize)
- if (textWidth > element.clientWidth) setShowPopup(true)
- else setShowPopup(false)
- setComputed(true)
- }
-
- }, [textRef.current, computed])
+ useEffect(() => {
+ if (computed) return;
+ if (textRef.current) {
+ const element = textRef.current;
- if (noHint || !showPopup) return (
-
- )
+ const fontSize = window.getComputedStyle(element, null).getPropertyValue('font-size');
- return (
-
{ hintText || textOrChildren } }
- { ...popupProps }
- >
-
-
- );
+ const textWidth = findTextWidth(element.innerText, fontSize);
+ if (textWidth > element.clientWidth) setShowPopup(true);
+ else setShowPopup(false);
+ setComputed(true);
+ }
+ }, [textRef.current, computed]);
+
+ if (noHint || !showPopup)
+ return (
+