Skip to content

Commit e5a6910

Browse files
authored
refactor: retire deprecated api (#511)
* refactor: Remove deprecated props and related code * refactor: Remove deprecated motion-related utility functions and props * fix: lint fix * chore: demo fix
1 parent a53c077 commit e5a6910

File tree

9 files changed

+29
-219
lines changed

9 files changed

+29
-219
lines changed

docs/examples/body-overflow.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ export default () => {
4040

4141
<Trigger
4242
arrow
43-
// forceRender
44-
// action="click"
4543
popupVisible={open}
4644
onPopupVisibleChange={(next) => {
4745
console.log('Visible Change:', next);
4846
setOpen(next);
4947
}}
50-
popupTransitionName="rc-trigger-popup-zoom"
48+
popupMotion={{
49+
motionName: 'rc-trigger-popup-zoom',
50+
}}
5151
popup={
5252
<div
5353
style={{
@@ -104,7 +104,9 @@ export default () => {
104104
console.log('Visible Change:', next);
105105
setOpen1(next);
106106
}}
107-
popupTransitionName="rc-trigger-popup-zoom"
107+
popupMotion={{
108+
motionName: 'rc-trigger-popup-zoom',
109+
}}
108110
popup={
109111
<div
110112
style={{
@@ -158,7 +160,9 @@ export default () => {
158160
console.log('Visible Change:', next);
159161
setOpen2(next);
160162
}}
161-
popupTransitionName="rc-trigger-popup-zoom"
163+
popupMotion={{
164+
motionName: 'rc-trigger-popup-zoom',
165+
}}
162166
popup={
163167
<div
164168
style={{
@@ -205,7 +209,9 @@ export default () => {
205209
console.log('Visible Change:', next);
206210
setOpen3(next);
207211
}}
208-
popupTransitionName="rc-trigger-popup-zoom"
212+
popupMotion={{
213+
motionName: 'rc-trigger-popup-zoom',
214+
}}
209215
popup={
210216
<div
211217
style={{

docs/examples/case.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ const Demo = () => {
202202
},
203203
}}
204204
popupPlacement={placement}
205-
destroyPopupOnHide={destroyPopupOnHide}
205+
autoDestroy={destroyPopupOnHide}
206206
mask={mask}
207207
maskMotion={motion ? MaskMotion : null}
208208
maskClosable={maskClosable}

docs/examples/container.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ export default () => {
160160
Popup
161161
</div>
162162
}
163-
popupTransitionName="rc-trigger-popup-zoom"
163+
popupMotion={{
164+
motionName: 'rc-trigger-popup-zoom',
165+
}}
164166
popupStyle={{ boxShadow: '0 0 5px red' }}
165167
popupVisible={visible}
166168
onPopupVisibleChange={(nextVisible) => {

docs/examples/simple.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,14 @@ class Test extends React.Component<any, TestState> {
353353
getPopupContainer={getPopupContainer}
354354
popupAlign={this.getPopupAlign()}
355355
popupPlacement={state.placement}
356-
destroyPopupOnHide={this.state.destroyPopupOnHide}
357356
autoDestroy={this.state.autoDestroy}
358357
// zIndex={40}
359358
mask={this.state.mask}
360359
maskClosable={this.state.maskClosable}
361360
stretch={this.state.stretch}
362-
maskAnimation="fade"
361+
maskMotion={{
362+
motionName: 'rc-trigger-mask-fade',
363+
}}
363364
// mouseEnterDelay={0.1}
364365
// mouseLeaveDelay={0.1}
365366
action={actions}
@@ -372,7 +373,9 @@ class Test extends React.Component<any, TestState> {
372373
boxSizing: 'border-box',
373374
}}
374375
popup={<div>i am a popup</div>}
375-
popupTransitionName={state.transitionName}
376+
popupMotion={{
377+
motionName: state.transitionName,
378+
}}
376379
>
377380
<RefTarget />
378381
</Trigger>

src/index.tsx

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ import useWinClick from './hooks/useWinClick';
2020
import type {
2121
ActionType,
2222
AlignType,
23-
AnimationType,
2423
ArrowPos,
2524
ArrowTypeOuter,
2625
BuildInPlacements,
27-
TransitionNameType,
2826
} from './interface';
29-
import { getAlignPopupClassName, getMotion } from './util';
27+
import { getAlignPopupClassName } from './util';
3028

3129
export type {
3230
ActionType,
@@ -72,9 +70,6 @@ export interface TriggerProps {
7270
forceRender?: boolean;
7371
autoDestroy?: boolean;
7472

75-
/** @deprecated Please use `autoDestroy` instead */
76-
destroyPopupOnHide?: boolean;
77-
7873
// ==================== Mask =====================
7974
mask?: boolean;
8075
maskClosable?: boolean;
@@ -85,15 +80,6 @@ export interface TriggerProps {
8580
/** Set mask motion. You can ref `rc-motion` for more info. */
8681
maskMotion?: CSSMotionProps;
8782

88-
/** @deprecated Please us `popupMotion` instead. */
89-
popupTransitionName?: TransitionNameType;
90-
/** @deprecated Please us `popupMotion` instead. */
91-
popupAnimation?: AnimationType;
92-
/** @deprecated Please us `maskMotion` instead. */
93-
maskTransitionName?: TransitionNameType;
94-
/** @deprecated Please us `maskMotion` instead. */
95-
maskAnimation?: AnimationType;
96-
9783
// ==================== Delay ====================
9884
mouseEnterDelay?: number;
9985
mouseLeaveDelay?: number;
@@ -123,10 +109,6 @@ export interface TriggerProps {
123109
// ==================== Arrow ====================
124110
arrow?: boolean | ArrowTypeOuter;
125111

126-
// ================= Deprecated ==================
127-
/** @deprecated Add `className` on `children`. Please add `className` directly instead. */
128-
className?: string;
129-
130112
// =================== Private ===================
131113
/**
132114
* @private Get trigger DOM node.
@@ -174,7 +156,6 @@ export function generateTrigger(
174156
getPopupContainer,
175157
forceRender,
176158
autoDestroy,
177-
destroyPopupOnHide,
178159

179160
// Popup
180161
popup,
@@ -200,21 +181,14 @@ export function generateTrigger(
200181
// Motion
201182
popupMotion,
202183
maskMotion,
203-
popupTransitionName,
204-
popupAnimation,
205-
maskTransitionName,
206-
maskAnimation,
207-
208-
// Deprecated
209-
className,
210184

211185
// Private
212186
getTriggerDOMNode,
213187

214188
...restProps
215189
} = props;
216190

217-
const mergedAutoDestroy = autoDestroy || destroyPopupOnHide || false;
191+
const mergedAutoDestroy = autoDestroy || false;
218192

219193
// =========================== Mobile ===========================
220194
const [mobile, setMobile] = React.useState(false);
@@ -289,21 +263,6 @@ export function generateTrigger(
289263
);
290264
});
291265

292-
// =========================== Motion ===========================
293-
const mergePopupMotion = getMotion(
294-
prefixCls,
295-
popupMotion,
296-
popupAnimation,
297-
popupTransitionName,
298-
);
299-
300-
const mergeMaskMotion = getMotion(
301-
prefixCls,
302-
maskMotion,
303-
maskAnimation,
304-
maskTransitionName,
305-
);
306-
307266
// ============================ Open ============================
308267
const [internalOpen, setInternalOpen] = React.useState(
309268
defaultPopupVisible || false,
@@ -639,11 +598,6 @@ export function generateTrigger(
639598
};
640599
}
641600

642-
// ========================= ClassName ==========================
643-
if (className) {
644-
cloneProps.className = classNames(originChildProps.className, className);
645-
}
646-
647601
// =========================== Render ===========================
648602
const mergedChildrenProps = {
649603
...originChildProps,
@@ -726,8 +680,8 @@ export function generateTrigger(
726680
// Mask
727681
mask={mask}
728682
// Motion
729-
motion={mergePopupMotion}
730-
maskMotion={mergeMaskMotion}
683+
motion={popupMotion}
684+
maskMotion={maskMotion}
731685
onVisibleChanged={onVisibleChanged}
732686
onPrepare={onPrepare}
733687
// Portal

src/util.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import type { CSSMotionProps } from 'rc-motion';
21
import type {
32
AlignType,
4-
AnimationType,
53
BuildInPlacements,
6-
TransitionNameType,
74
} from './interface';
85

96
function isPointsEq(
@@ -39,32 +36,6 @@ export function getAlignPopupClassName(
3936
return '';
4037
}
4138

42-
/** @deprecated We should not use this if we can refactor all deps */
43-
export function getMotion(
44-
prefixCls: string,
45-
motion: CSSMotionProps,
46-
animation: AnimationType,
47-
transitionName: TransitionNameType,
48-
): CSSMotionProps {
49-
if (motion) {
50-
return motion;
51-
}
52-
53-
if (animation) {
54-
return {
55-
motionName: `${prefixCls}-${animation}`,
56-
};
57-
}
58-
59-
if (transitionName) {
60-
return {
61-
motionName: transitionName,
62-
};
63-
}
64-
65-
return null;
66-
}
67-
6839
export function getWin(ele: HTMLElement) {
6940
return ele.ownerDocument.defaultView;
7041
}

tests/basic.test.jsx

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -384,25 +384,6 @@ describe('Trigger.Basic', () => {
384384
trigger(container, '.target');
385385
expect(document.querySelector('.rc-trigger-popup-hidden')).toBeTruthy();
386386
});
387-
388-
it('set true will destroy tooltip on hide', () => {
389-
const { container } = render(
390-
<Trigger
391-
action={['click']}
392-
destroyPopupOnHide
393-
popupAlign={placementAlignMap.topRight}
394-
popup={<strong>trigger</strong>}
395-
>
396-
<div className="target">click</div>
397-
</Trigger>,
398-
);
399-
400-
trigger(container, '.target');
401-
expect(document.querySelector('.rc-trigger-popup')).toBeTruthy();
402-
403-
trigger(container, '.target');
404-
expect(document.querySelector('.rc-trigger-popup')).toBeFalsy();
405-
});
406387
});
407388

408389
describe('support autoDestroy', () => {
@@ -603,47 +584,6 @@ describe('Trigger.Basic', () => {
603584
expect(container.querySelector('div')).not.toHaveAttribute('class');
604585
});
605586

606-
it('support className', () => {
607-
const { container } = render(
608-
<Trigger
609-
action={['click']}
610-
popupAlign={placementAlignMap.left}
611-
popup={<strong className="x-content">tooltip2</strong>}
612-
className="className-in-trigger"
613-
>
614-
<div className="target">click</div>
615-
</Trigger>,
616-
);
617-
618-
expect(container.querySelector('div')).toHaveClass(
619-
'target className-in-trigger',
620-
);
621-
});
622-
623-
it('support className in nested Trigger', () => {
624-
const { container } = render(
625-
<Trigger
626-
action={['click']}
627-
popupAlign={placementAlignMap.left}
628-
popup={<strong className="x-content">tooltip2</strong>}
629-
className="className-in-trigger-2"
630-
>
631-
<Trigger
632-
action={['click']}
633-
popupAlign={placementAlignMap.left}
634-
popup={<strong className="x-content">tooltip2</strong>}
635-
className="className-in-trigger-1"
636-
>
637-
<div className="target">click</div>
638-
</Trigger>
639-
</Trigger>,
640-
);
641-
642-
expect(container.querySelector('div').className).toBe(
643-
'target className-in-trigger-1 className-in-trigger-2',
644-
);
645-
});
646-
647587
it('support function component', () => {
648588
const NoRef = React.forwardRef((props, ref) => {
649589
React.useImperativeHandle(ref, () => null);

tests/mask.test.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ describe('Trigger.Mask', () => {
2121
popupAlign={placementAlignMap.left}
2222
popup={<strong className="x-content" />}
2323
mask
24-
maskTransitionName="bamboo"
24+
maskMotion={{
25+
motionName: 'bamboo',
26+
}}
2527
>
2628
<div className="target">click</div>
2729
</Trigger>,

0 commit comments

Comments
 (0)