Skip to content

Commit 46600c0

Browse files
authored
chore: add css var for calc (#577)
* chore: add css var for calc * chore: fix ts
1 parent 70d31f3 commit 46600c0

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/UniqueProvider/UniqueBody.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import useOffsetStyle from '../hooks/useOffsetStyle';
33
import classNames from 'classnames';
44
import CSSMotion from '@rc-component/motion';
55
import type { CSSMotionProps } from '@rc-component/motion';
6-
import type { AlignType } from '../interface';
6+
import type { AlignType, ArrowPos } from '../interface';
77

88
export interface UniqueBodyProps {
99
prefixCls: string; // ${prefixCls}-unique-body
@@ -15,6 +15,7 @@ export interface UniqueBodyProps {
1515
offsetB: number;
1616
offsetX: number;
1717
offsetY: number;
18+
arrowPos?: ArrowPos;
1819
popupSize?: { width: number; height: number };
1920
motion?: CSSMotionProps;
2021
uniqueBgClassName?: string;
@@ -32,6 +33,7 @@ const UniqueBody = (props: UniqueBodyProps) => {
3233
offsetB,
3334
offsetX,
3435
offsetY,
36+
arrowPos,
3537
popupSize,
3638
motion,
3739
uniqueBgClassName,
@@ -84,11 +86,13 @@ const UniqueBody = (props: UniqueBodyProps) => {
8486
<div
8587
className={cls}
8688
style={{
89+
'--arrow-x': `${arrowPos?.x || 0}px`,
90+
'--arrow-y': `${arrowPos?.y || 0}px`,
8791
...offsetStyle,
8892
...sizeStyle,
8993
...motionStyle,
9094
...uniqueBgStyle,
91-
}}
95+
} as React.CSSProperties}
9296
/>
9397
);
9498
}}

src/UniqueProvider/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
214214
offsetB={offsetB}
215215
offsetX={offsetX}
216216
offsetY={offsetY}
217+
arrowPos={{
218+
x: arrowX,
219+
y: arrowY,
220+
}}
217221
popupSize={popupSize}
218222
motion={options.popupMotion}
219223
uniqueBgClassName={classNames(

tests/unique.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ describe('Trigger.Unique', () => {
236236
},
237237
},
238238
}}
239+
arrow
239240
>
240241
<div className="target">click me</div>
241242
</Trigger>
@@ -246,5 +247,11 @@ describe('Trigger.Unique', () => {
246247
expect(document.querySelector('.rc-trigger-popup-unique-body')).toHaveClass(
247248
'bamboo',
248249
);
250+
251+
// Check that arrow position CSS variables are set
252+
const uniqueBody = document.querySelector('.rc-trigger-popup-unique-body');
253+
const computedStyle = getComputedStyle(uniqueBody);
254+
expect(computedStyle.getPropertyValue('--arrow-x')).not.toBe('');
255+
expect(computedStyle.getPropertyValue('--arrow-y')).not.toBe('');
249256
});
250257
});

0 commit comments

Comments
 (0)