diff --git a/package.json b/package.json index 04c1d032b..0ebf16911 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "react": "*", "react-dom": "*", "react-is": "^17.0.2", + "react-tiny-popover": "^7.2.3", "rollup": "^2.79.1", "rollup-plugin-multi-input": "^1.3.3", "rollup-plugin-terser": "^7.0.2", @@ -101,6 +102,7 @@ "polished": "^4.2.2", "react": "^16.13.1 || ^17.0.0", "react-dom": "^16.13.1 || ^17.0.0", + "react-tiny-popover": "^7.2.3", "styled-components": "^5.3.6" }, "resolutions": { diff --git a/src/components/TourPoint/TourPoint.tsx b/src/components/TourPoint/TourPoint.tsx index 6899b26fd..69f1ea8e2 100644 --- a/src/components/TourPoint/TourPoint.tsx +++ b/src/components/TourPoint/TourPoint.tsx @@ -1,11 +1,6 @@ -import React, { - cloneElement, - useContext, - useRef, - MouseEvent, -} from 'react'; - -import type { Props } from './TourPoint.types'; +import React, { cloneElement, useContext, MouseEvent } from 'react'; + +import type { Props, Attach } from './TourPoint.types'; import { Footer, Steps, TourPointStyled } from './TourPoint.style'; import { TourContext } from './TourPoint.context'; import { Motion } from './TourPoint.motion'; @@ -13,31 +8,37 @@ import { Caret, buildClipPaths } from './Caret'; import { Header, Paragraph } from '../../typography'; import { Button } from '../Button/Button'; +import { capitalize } from '../../utils'; import { - Anchor, - useAnchor, -} from '../../utils/hooks/useAnchor/useAnchor'; -import { usePortal, capitalize } from '../../utils'; + Popover, + PopoverAlign, + PopoverPosition, +} from 'react-tiny-popover'; TourPoint.Motion = Motion; const lessThan = (a: number, b: number) => a < b && a; const greaterThan = (a: number, b: number) => a > b || a; +type compareFn = (nextIndex, totalSteps) => number | boolean; + export function TourPoint({ - active = true, - alt = null, - attach = 'left', + active, + content, children, + // legacy + attach, + positions, + align, + style, + src, + alt = '', + title, + onClose, confirmation = 'Got it', dismission = 'Dismiss', - content, getStepsTranslation, - onClose, - src, - step, - style, - title, + step = 0, ...props }: Props) { const { @@ -47,23 +48,32 @@ export function TourPoint({ steps, } = useContext(TourContext); - const ref = useRef(null); - const refAnchor = useRef(null); - const childrenClone = cloneElement(children, { ref }); - const propsAnchor = useAnchor(ref, attach, active); + let pos = positions; + let alignment = align; + let clipPaths = {}; + let margin = {}; + const marginSize = '1rem'; + if (attach && !positions) { + [pos, alignment] = convertAttachToPositionAlign(attach); + clipPaths = buildClipPaths(attach); + const [side] = attach.split('-'); + const marginSide = 'margin' + capitalize(side); + margin = { [marginSide]: marginSize }; + } const Image = src && {alt}; const Title = title &&
{title}
; - const Content = slotProgressive(content, ); - function stepFn(direction, increment = 0, compare = null) { - const next = compare ? compare(index + increment, steps) : null; + function stepFn(direction, increment = 0, compare?: compareFn) { + const next = compare + ? compare((index || 0) + increment, steps) + : null; return (event: MouseEvent) => { if (automated) { onClose?.(event, { direction }); - indexSet(next); + indexSet?.(next); } }; } @@ -82,58 +92,89 @@ export function TourPoint({