-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
/
trigger.tsx
28 lines (22 loc) · 860 Bytes
/
trigger.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { TriggerProps } from '@rc-component/trigger';
import MockTrigger from '@rc-component/trigger/es/mock';
import * as React from 'react';
import { TriggerMockContext } from '../../tests/shared/demoTestContext';
const { default: OriginTrigger } = await vi.importActual<typeof import('@rc-component/trigger')>(
'@rc-component/trigger',
);
const ForwardTrigger = React.forwardRef<any, TriggerProps>((props, ref) => {
const context = React.useContext(TriggerMockContext);
const mergedPopupVisible = context?.popupVisible ?? props.popupVisible;
globalThis.triggerProps = props;
const mergedProps = {
...props,
ref,
popupVisible: mergedPopupVisible as boolean,
};
if (context?.mock === false) {
return <OriginTrigger {...mergedProps} />;
}
return <MockTrigger {...mergedProps} />;
});
export default ForwardTrigger;