-
-
Notifications
You must be signed in to change notification settings - Fork 236
chore: add css var for calc #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import useOffsetStyle from '../hooks/useOffsetStyle'; | |
import classNames from 'classnames'; | ||
import CSSMotion from '@rc-component/motion'; | ||
import type { CSSMotionProps } from '@rc-component/motion'; | ||
import type { AlignType } from '../interface'; | ||
import type { AlignType, ArrowPos } from '../interface'; | ||
|
||
export interface UniqueBodyProps { | ||
prefixCls: string; // ${prefixCls}-unique-body | ||
|
@@ -15,6 +15,7 @@ export interface UniqueBodyProps { | |
offsetB: number; | ||
offsetX: number; | ||
offsetY: number; | ||
arrowPos?: ArrowPos; | ||
popupSize?: { width: number; height: number }; | ||
motion?: CSSMotionProps; | ||
uniqueBgClassName?: string; | ||
|
@@ -32,6 +33,7 @@ const UniqueBody = (props: UniqueBodyProps) => { | |
offsetB, | ||
offsetX, | ||
offsetY, | ||
arrowPos, | ||
popupSize, | ||
motion, | ||
uniqueBgClassName, | ||
|
@@ -84,11 +86,13 @@ const UniqueBody = (props: UniqueBodyProps) => { | |
<div | ||
className={cls} | ||
style={{ | ||
'--arrow-x': `${arrowPos?.x || 0}px`, | ||
'--arrow-y': `${arrowPos?.y || 0}px`, | ||
...offsetStyle, | ||
...sizeStyle, | ||
...motionStyle, | ||
...uniqueBgStyle, | ||
}} | ||
} as React.CSSProperties} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 使用 你可以在项目中创建一个 import 'react';
declare module 'react' {
interface CSSProperties {
'--arrow-x'?: string;
'--arrow-y'?: string;
}
} 应用此更改后,就可以移除此处的 |
||
/> | ||
); | ||
}} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -236,6 +236,7 @@ describe('Trigger.Unique', () => { | |||||||||
}, | ||||||||||
}, | ||||||||||
}} | ||||||||||
arrow | ||||||||||
> | ||||||||||
<div className="target">click me</div> | ||||||||||
</Trigger> | ||||||||||
|
@@ -246,5 +247,11 @@ describe('Trigger.Unique', () => { | |||||||||
expect(document.querySelector('.rc-trigger-popup-unique-body')).toHaveClass( | ||||||||||
'bamboo', | ||||||||||
); | ||||||||||
|
||||||||||
// Check that arrow position CSS variables are set | ||||||||||
const uniqueBody = document.querySelector('.rc-trigger-popup-unique-body'); | ||||||||||
const computedStyle = getComputedStyle(uniqueBody); | ||||||||||
expect(computedStyle.getPropertyValue('--arrow-x')).not.toBe(''); | ||||||||||
expect(computedStyle.getPropertyValue('--arrow-y')).not.toBe(''); | ||||||||||
Comment on lines
+254
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 当前的测试断言
Suggested change
|
||||||||||
}); | ||||||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议使用空值合并操作符(
??
)代替逻辑或操作符(||
),以更明确地处理null
和undefined
的情况。当arrowPos.x
或arrowPos.y
的值为0
时,||
和??
的行为一致,但??
能更清晰地表达“仅在值为null
或undefined
时提供默认值”的意图,这是更健壮的做法。