From eac4b9b92df1274410046e6a8142593b6bbbe17d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com>
Date: Sat, 15 Feb 2025 16:41:41 +0800
Subject: [PATCH 1/4] refactor: Remove deprecated props and related code
---
src/index.tsx | 18 +------------
tests/basic.test.jsx | 60 --------------------------------------------
2 files changed, 1 insertion(+), 77 deletions(-)
diff --git a/src/index.tsx b/src/index.tsx
index ac4b841e..726bde73 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -72,9 +72,6 @@ export interface TriggerProps {
forceRender?: boolean;
autoDestroy?: boolean;
- /** @deprecated Please use `autoDestroy` instead */
- destroyPopupOnHide?: boolean;
-
// ==================== Mask =====================
mask?: boolean;
maskClosable?: boolean;
@@ -123,10 +120,6 @@ export interface TriggerProps {
// ==================== Arrow ====================
arrow?: boolean | ArrowTypeOuter;
- // ================= Deprecated ==================
- /** @deprecated Add `className` on `children`. Please add `className` directly instead. */
- className?: string;
-
// =================== Private ===================
/**
* @private Get trigger DOM node.
@@ -174,7 +167,6 @@ export function generateTrigger(
getPopupContainer,
forceRender,
autoDestroy,
- destroyPopupOnHide,
// Popup
popup,
@@ -205,16 +197,13 @@ export function generateTrigger(
maskTransitionName,
maskAnimation,
- // Deprecated
- className,
-
// Private
getTriggerDOMNode,
...restProps
} = props;
- const mergedAutoDestroy = autoDestroy || destroyPopupOnHide || false;
+ const mergedAutoDestroy = autoDestroy || false;
// =========================== Mobile ===========================
const [mobile, setMobile] = React.useState(false);
@@ -639,11 +628,6 @@ export function generateTrigger(
};
}
- // ========================= ClassName ==========================
- if (className) {
- cloneProps.className = classNames(originChildProps.className, className);
- }
-
// =========================== Render ===========================
const mergedChildrenProps = {
...originChildProps,
diff --git a/tests/basic.test.jsx b/tests/basic.test.jsx
index 071878b6..58b912b8 100644
--- a/tests/basic.test.jsx
+++ b/tests/basic.test.jsx
@@ -384,25 +384,6 @@ describe('Trigger.Basic', () => {
trigger(container, '.target');
expect(document.querySelector('.rc-trigger-popup-hidden')).toBeTruthy();
});
-
- it('set true will destroy tooltip on hide', () => {
- const { container } = render(
- trigger}
- >
- click
- ,
- );
-
- trigger(container, '.target');
- expect(document.querySelector('.rc-trigger-popup')).toBeTruthy();
-
- trigger(container, '.target');
- expect(document.querySelector('.rc-trigger-popup')).toBeFalsy();
- });
});
describe('support autoDestroy', () => {
@@ -603,47 +584,6 @@ describe('Trigger.Basic', () => {
expect(container.querySelector('div')).not.toHaveAttribute('class');
});
- it('support className', () => {
- const { container } = render(
- tooltip2}
- className="className-in-trigger"
- >
- click
- ,
- );
-
- expect(container.querySelector('div')).toHaveClass(
- 'target className-in-trigger',
- );
- });
-
- it('support className in nested Trigger', () => {
- const { container } = render(
- tooltip2}
- className="className-in-trigger-2"
- >
- tooltip2}
- className="className-in-trigger-1"
- >
- click
-
- ,
- );
-
- expect(container.querySelector('div').className).toBe(
- 'target className-in-trigger-1 className-in-trigger-2',
- );
- });
-
it('support function component', () => {
const NoRef = React.forwardRef((props, ref) => {
React.useImperativeHandle(ref, () => null);
From 95b0ef22b66e6d6957f9e83ed405addf120683ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com>
Date: Sat, 15 Feb 2025 16:47:01 +0800
Subject: [PATCH 2/4] refactor: Remove deprecated motion-related utility
functions and props
---
src/index.tsx | 36 ++----------------------
src/util.ts | 26 -----------------
tests/mask.test.jsx | 4 ++-
tests/util.test.jsx | 68 ---------------------------------------------
4 files changed, 6 insertions(+), 128 deletions(-)
delete mode 100644 tests/util.test.jsx
diff --git a/src/index.tsx b/src/index.tsx
index 726bde73..49e4cbfb 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -20,13 +20,11 @@ import useWinClick from './hooks/useWinClick';
import type {
ActionType,
AlignType,
- AnimationType,
ArrowPos,
ArrowTypeOuter,
BuildInPlacements,
- TransitionNameType,
} from './interface';
-import { getAlignPopupClassName, getMotion } from './util';
+import { getAlignPopupClassName } from './util';
export type {
ActionType,
@@ -82,15 +80,6 @@ export interface TriggerProps {
/** Set mask motion. You can ref `rc-motion` for more info. */
maskMotion?: CSSMotionProps;
- /** @deprecated Please us `popupMotion` instead. */
- popupTransitionName?: TransitionNameType;
- /** @deprecated Please us `popupMotion` instead. */
- popupAnimation?: AnimationType;
- /** @deprecated Please us `maskMotion` instead. */
- maskTransitionName?: TransitionNameType;
- /** @deprecated Please us `maskMotion` instead. */
- maskAnimation?: AnimationType;
-
// ==================== Delay ====================
mouseEnterDelay?: number;
mouseLeaveDelay?: number;
@@ -192,10 +181,6 @@ export function generateTrigger(
// Motion
popupMotion,
maskMotion,
- popupTransitionName,
- popupAnimation,
- maskTransitionName,
- maskAnimation,
// Private
getTriggerDOMNode,
@@ -278,21 +263,6 @@ export function generateTrigger(
);
});
- // =========================== Motion ===========================
- const mergePopupMotion = getMotion(
- prefixCls,
- popupMotion,
- popupAnimation,
- popupTransitionName,
- );
-
- const mergeMaskMotion = getMotion(
- prefixCls,
- maskMotion,
- maskAnimation,
- maskTransitionName,
- );
-
// ============================ Open ============================
const [internalOpen, setInternalOpen] = React.useState(
defaultPopupVisible || false,
@@ -710,8 +680,8 @@ export function generateTrigger(
// Mask
mask={mask}
// Motion
- motion={mergePopupMotion}
- maskMotion={mergeMaskMotion}
+ motion={popupMotion}
+ maskMotion={maskMotion}
onVisibleChanged={onVisibleChanged}
onPrepare={onPrepare}
// Portal
diff --git a/src/util.ts b/src/util.ts
index 5170d86b..b21ab703 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -39,32 +39,6 @@ export function getAlignPopupClassName(
return '';
}
-/** @deprecated We should not use this if we can refactor all deps */
-export function getMotion(
- prefixCls: string,
- motion: CSSMotionProps,
- animation: AnimationType,
- transitionName: TransitionNameType,
-): CSSMotionProps {
- if (motion) {
- return motion;
- }
-
- if (animation) {
- return {
- motionName: `${prefixCls}-${animation}`,
- };
- }
-
- if (transitionName) {
- return {
- motionName: transitionName,
- };
- }
-
- return null;
-}
-
export function getWin(ele: HTMLElement) {
return ele.ownerDocument.defaultView;
}
diff --git a/tests/mask.test.jsx b/tests/mask.test.jsx
index f4e9e129..f27d239d 100644
--- a/tests/mask.test.jsx
+++ b/tests/mask.test.jsx
@@ -21,7 +21,9 @@ describe('Trigger.Mask', () => {
popupAlign={placementAlignMap.left}
popup={}
mask
- maskTransitionName="bamboo"
+ maskMotion={{
+ motionName: 'bamboo',
+ }}
>
click
,
diff --git a/tests/util.test.jsx b/tests/util.test.jsx
deleted file mode 100644
index efa899d6..00000000
--- a/tests/util.test.jsx
+++ /dev/null
@@ -1,68 +0,0 @@
-import { getMotion } from '../src/util';
-// import MockTrigger from '../src/mock';
-
-/**
- * dom-align internal default position is `-999`.
- * We do not need to simulate full position, check offset only.
- */
-describe('Trigger.Util', () => {
- describe('getMotion', () => {
- const prefixCls = 'test';
- const motion = {
- motionName: 'motion',
- };
- const transitionName = 'transition';
- const animation = 'animation';
-
- it('motion is first', () => {
- expect(getMotion(prefixCls, motion, animation, transitionName)).toEqual({
- motionName: 'motion',
- });
- });
-
- it('animation is second', () => {
- expect(getMotion(prefixCls, null, animation, transitionName)).toEqual({
- motionName: 'test-animation',
- });
- });
-
- it('transition is last', () => {
- expect(getMotion(prefixCls, null, null, transitionName)).toEqual({
- motionName: 'transition',
- });
- });
- });
-
- // describe('mock', () => {
- // it('close', () => {
- // const { container } = render(
- // bamboo}
- // >
- // light
- // ,
- // );
-
- // expect(container.innerHTML).toEqual('light
');
- // });
-
- // it('open', () => {
- // const { container } = render(
- // bamboo}
- // popupVisible
- // >
- // light
- // ,
- // );
-
- // expect(container.innerHTML).toEqual(
- // 'light
',
- // );
- // });
- // });
-});
From 4d2010ea600d2715fe6da3cbdba4927ac831b2e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com>
Date: Mon, 17 Feb 2025 11:25:28 +0800
Subject: [PATCH 3/4] fix: lint fix
---
src/util.ts | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/util.ts b/src/util.ts
index b21ab703..cc13eb60 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -1,9 +1,6 @@
-import type { CSSMotionProps } from 'rc-motion';
import type {
AlignType,
- AnimationType,
BuildInPlacements,
- TransitionNameType,
} from './interface';
function isPointsEq(
From 4430f35f0c84b661d2f2ef57e06030cc6d5ef76a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com>
Date: Mon, 17 Feb 2025 17:15:56 +0800
Subject: [PATCH 4/4] chore: demo fix
---
docs/examples/body-overflow.tsx | 18 ++++++++++++------
docs/examples/case.tsx | 2 +-
docs/examples/container.tsx | 4 +++-
docs/examples/simple.tsx | 9 ++++++---
4 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/docs/examples/body-overflow.tsx b/docs/examples/body-overflow.tsx
index 744e86a3..d4b272ea 100644
--- a/docs/examples/body-overflow.tsx
+++ b/docs/examples/body-overflow.tsx
@@ -40,14 +40,14 @@ export default () => {
{
console.log('Visible Change:', next);
setOpen(next);
}}
- popupTransitionName="rc-trigger-popup-zoom"
+ popupMotion={{
+ motionName: 'rc-trigger-popup-zoom',
+ }}
popup={
{
console.log('Visible Change:', next);
setOpen1(next);
}}
- popupTransitionName="rc-trigger-popup-zoom"
+ popupMotion={{
+ motionName: 'rc-trigger-popup-zoom',
+ }}
popup={
{
console.log('Visible Change:', next);
setOpen2(next);
}}
- popupTransitionName="rc-trigger-popup-zoom"
+ popupMotion={{
+ motionName: 'rc-trigger-popup-zoom',
+ }}
popup={
{
console.log('Visible Change:', next);
setOpen3(next);
}}
- popupTransitionName="rc-trigger-popup-zoom"
+ popupMotion={{
+ motionName: 'rc-trigger-popup-zoom',
+ }}
popup={
{
},
}}
popupPlacement={placement}
- destroyPopupOnHide={destroyPopupOnHide}
+ autoDestroy={destroyPopupOnHide}
mask={mask}
maskMotion={motion ? MaskMotion : null}
maskClosable={maskClosable}
diff --git a/docs/examples/container.tsx b/docs/examples/container.tsx
index 3a00aa00..9ea1ff09 100644
--- a/docs/examples/container.tsx
+++ b/docs/examples/container.tsx
@@ -160,7 +160,9 @@ export default () => {
Popup
}
- popupTransitionName="rc-trigger-popup-zoom"
+ popupMotion={{
+ motionName: 'rc-trigger-popup-zoom',
+ }}
popupStyle={{ boxShadow: '0 0 5px red' }}
popupVisible={visible}
onPopupVisibleChange={(nextVisible) => {
diff --git a/docs/examples/simple.tsx b/docs/examples/simple.tsx
index aa4c7033..5e85d544 100644
--- a/docs/examples/simple.tsx
+++ b/docs/examples/simple.tsx
@@ -353,13 +353,14 @@ class Test extends React.Component
{
getPopupContainer={getPopupContainer}
popupAlign={this.getPopupAlign()}
popupPlacement={state.placement}
- destroyPopupOnHide={this.state.destroyPopupOnHide}
autoDestroy={this.state.autoDestroy}
// zIndex={40}
mask={this.state.mask}
maskClosable={this.state.maskClosable}
stretch={this.state.stretch}
- maskAnimation="fade"
+ maskMotion={{
+ motionName: 'rc-trigger-mask-fade',
+ }}
// mouseEnterDelay={0.1}
// mouseLeaveDelay={0.1}
action={actions}
@@ -372,7 +373,9 @@ class Test extends React.Component {
boxSizing: 'border-box',
}}
popup={i am a popup
}
- popupTransitionName={state.transitionName}
+ popupMotion={{
+ motionName: state.transitionName,
+ }}
>