diff --git a/assets/index.less b/assets/index.less index 092d32a2..e13a1256 100644 --- a/assets/index.less +++ b/assets/index.less @@ -41,35 +41,35 @@ } &-arrow { + z-index: 1; width: 0px; height: 0px; background: #000; border-radius: 100vw; box-shadow: 0 0 0 3px black; - z-index: 1; } @keyframes rcTriggerZoomIn { 0% { transform: scale(0, 0); - transform-origin: 50% 50%; + transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%); opacity: 0; } 100% { transform: scale(1, 1); - transform-origin: 50% 50%; + transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%); opacity: 1; } } @keyframes rcTriggerZoomOut { 0% { transform: scale(1, 1); - transform-origin: 50% 50%; + transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%); opacity: 1; } 100% { transform: scale(0, 0); - transform-origin: 50% 50%; + transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%); opacity: 0; } } diff --git a/docs/examples/container.tsx b/docs/examples/container.tsx index dd6fbb45..70b84585 100644 --- a/docs/examples/container.tsx +++ b/docs/examples/container.tsx @@ -55,7 +55,7 @@ const builtinPlacements = { }, }; -const popupPlacement = 'right'; +const popupPlacement = 'top'; export default () => { console.log('Demo Render!'); @@ -136,7 +136,7 @@ export default () => { }} > { Popup } + popupTransitionName="rc-trigger-popup-zoom" popupStyle={{ boxShadow: '0 0 5px red' }} // popupVisible // getPopupContainer={() => popHolderRef.current} popupPlacement={popupPlacement} builtinPlacements={builtinPlacements} stretch="minWidth" + onPopupAlign={(domNode, align) => { + console.log('onPopupAlign:', domNode, align); + }} > (); @@ -53,6 +55,12 @@ export default function Arrow(props: ArrowProps) { } return ( -
+
+ {content} +
); } diff --git a/src/Popup/index.tsx b/src/Popup/index.tsx index d20a6ff9..106fd798 100644 --- a/src/Popup/index.tsx +++ b/src/Popup/index.tsx @@ -6,7 +6,7 @@ import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; import { composeRef } from 'rc-util/lib/ref'; import * as React from 'react'; import type { TriggerProps } from '../'; -import type { AlignType, ArrowType } from '../interface'; +import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface'; import Arrow from './Arrow'; import Mask from './Mask'; import PopupContent from './PopupContent'; @@ -26,7 +26,8 @@ export interface PopupProps { // Arrow align?: AlignType; - arrow?: ArrowType; + arrow?: ArrowTypeOuter; + arrowPos: ArrowPos; // Open open: boolean; @@ -81,6 +82,7 @@ const Popup = React.forwardRef((props, ref) => { // Arrow arrow, + arrowPos, align, // Motion @@ -206,14 +208,18 @@ const Popup = React.forwardRef((props, ref) => {
((props, ref) => { )} diff --git a/src/index.tsx b/src/index.tsx index a2541450..252b926b 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,7 +18,7 @@ import type { ActionType, AlignType, AnimationType, - ArrowType, + ArrowPos, ArrowTypeOuter, BuildInPlacements, TransitionNameType, @@ -650,12 +650,15 @@ export function generateTrigger( ...passedProps, }); - const innerArrow: ArrowType = arrow + const arrowPos: ArrowPos = { + x: arrowX, + y: arrowY, + }; + + const innerArrow: ArrowTypeOuter = arrow ? { // true and Object likely ...(arrow !== true ? arrow : {}), - x: arrowX, - y: arrowY, } : null; @@ -702,6 +705,7 @@ export function generateTrigger( // Arrow align={alignInfo} arrow={innerArrow} + arrowPos={arrowPos} // Align ready={ready} offsetX={offsetX} diff --git a/src/interface.ts b/src/interface.ts index 5da4b31d..bcd591c3 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -74,12 +74,13 @@ export interface AlignType { export interface ArrowTypeOuter { className?: string; + content?: React.ReactNode; } -export type ArrowType = ArrowTypeOuter & { +export type ArrowPos = { x?: number; y?: number; -} +}; export type BuildInPlacements = Record; @@ -106,4 +107,4 @@ export interface MobileConfig { popupClassName?: string; popupStyle?: React.CSSProperties; popupRender?: (originNode: React.ReactNode) => React.ReactNode; -} \ No newline at end of file +} diff --git a/tests/arrow.test.jsx b/tests/arrow.test.jsx index 9947b268..80be36ad 100644 --- a/tests/arrow.test.jsx +++ b/tests/arrow.test.jsx @@ -187,4 +187,26 @@ describe('Trigger.Arrow', () => { expect(arrowDom.classList.contains('abc')).toBeTruthy(); }); }); + + it('content', async () => { + render( + trigger} + arrow={{ + content: , + }} + > +
+ , + ); + + await awaitFakeTimer(); + + expect(document.querySelector('.my-content')).toBeTruthy(); + }); });