2024-04-08 14:04:08 +08:00
|
|
|
import * as React from 'react';
|
2023-07-08 15:45:28 +08:00
|
|
|
import type { TriggerProps, TriggerRef } from '@rc-component/trigger';
|
2023-06-07 21:59:21 +08:00
|
|
|
import MockTrigger from '@rc-component/trigger/lib/mock';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
import { TriggerMockContext } from '../../shared/demoTestContext';
|
2023-02-15 10:21:28 +08:00
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
let OriginTrigger = jest.requireActual('@rc-component/trigger');
|
|
|
|
OriginTrigger = OriginTrigger.default ?? OriginTrigger;
|
2023-02-15 10:21:28 +08:00
|
|
|
|
2023-07-08 15:45:28 +08:00
|
|
|
const ForwardTrigger = React.forwardRef<TriggerRef, TriggerProps>((props, ref) => {
|
2023-02-15 10:21:28 +08:00
|
|
|
const context = React.useContext(TriggerMockContext);
|
|
|
|
|
|
|
|
const mergedPopupVisible = context?.popupVisible ?? props.popupVisible;
|
2023-06-07 21:59:21 +08:00
|
|
|
(global as any).triggerProps = props;
|
2023-02-15 10:21:28 +08:00
|
|
|
|
2023-07-08 15:45:28 +08:00
|
|
|
const mergedProps: TriggerProps = {
|
2023-02-15 10:21:28 +08:00
|
|
|
...props,
|
2023-07-08 15:45:28 +08:00
|
|
|
popupVisible: mergedPopupVisible,
|
2023-02-15 10:21:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (context?.mock === false) {
|
2023-07-08 15:45:28 +08:00
|
|
|
return <OriginTrigger ref={ref} {...mergedProps} />;
|
2023-02-15 10:21:28 +08:00
|
|
|
}
|
2023-07-08 15:45:28 +08:00
|
|
|
return <MockTrigger ref={ref} {...mergedProps} />;
|
2023-02-15 10:21:28 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export default ForwardTrigger;
|