Skip to content

Commit 98cfa02

Browse files
committed
chore: flying
1 parent 5a53dd6 commit 98cfa02

File tree

7 files changed

+85
-14
lines changed

7 files changed

+85
-14
lines changed

assets/index.less

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
}
8888

8989
&-visible {
90-
transition: all 0.3s;
90+
transition: all 0.1s;
9191
}
9292
}
9393

@@ -97,6 +97,30 @@
9797
background: transparent !important;
9898
z-index: 1;
9999
}
100+
101+
// Motion Content
102+
&-motion-content {
103+
// Fade motion
104+
&-fade-appear {
105+
opacity: 0;
106+
animation-duration: 0.3s;
107+
animation-fill-mode: both;
108+
animation-timing-function: cubic-bezier(0.55, 0, 0.55, 0.2);
109+
}
110+
111+
&-fade-appear&-fade-appear-active {
112+
animation-name: rcTriggerFadeIn;
113+
}
114+
115+
@keyframes rcTriggerFadeIn {
116+
0% {
117+
opacity: 0;
118+
}
119+
100% {
120+
opacity: 1;
121+
}
122+
}
123+
}
100124
}
101125

102126
@import './index/Mask';

docs/examples/two-buttons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Trigger, { UniqueProvider } from '@rc-component/trigger';
22
import React, { useState } from 'react';
33
import '../../assets/index.less';
44

5-
const LEAVE_DELAY = 0.1;
5+
const LEAVE_DELAY = 0.2;
66

77
const builtinPlacements = {
88
left: {

src/Popup/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,12 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
186186
}, [show, getPopupContainerNeedParams, target]);
187187

188188
// ========================= Resize =========================
189-
const onInternalResize: ResizeObserverProps['onResize'] = useEvent((size) => {
190-
onResize?.(size);
191-
onAlign();
192-
});
189+
const onInternalResize: ResizeObserverProps['onResize'] = useEvent(
190+
(size, ele) => {
191+
onResize?.(size, ele);
192+
onAlign();
193+
},
194+
);
193195

194196
// ========================= Styles =========================
195197
const offsetStyle = useOffsetStyle(

src/UniqueProvider/MotionContent.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as React from 'react';
2+
import type { TriggerProps } from '..';
3+
import CSSMotion from '@rc-component/motion';
4+
import classNames from 'classnames';
5+
6+
export interface MotionContentProps {
7+
prefixCls: string; // ${prefixCls}-motion-content apply on root div
8+
children: TriggerProps['popup'];
9+
}
10+
11+
const MotionContent = (props: MotionContentProps) => {
12+
const { prefixCls, children } = props;
13+
14+
const childNode = typeof children === 'function' ? children() : children;
15+
16+
// motion name: `${prefixCls}-motion-content-fade`, apply in index.less
17+
const motionName = `${prefixCls}-motion-content-fade`;
18+
19+
return (
20+
<CSSMotion motionAppear motionLeave={false} visible motionName={motionName}>
21+
{({ className: motionClassName, style: motionStyle }) => {
22+
const cls = classNames(`${prefixCls}-motion-content`, motionClassName);
23+
24+
return (
25+
<div className={cls} style={motionStyle}>
26+
{childNode}
27+
</div>
28+
);
29+
}}
30+
</CSSMotion>
31+
);
32+
};
33+
34+
if (process.env.NODE_ENV !== 'production') {
35+
MotionContent.displayName = 'MotionContent';
36+
}
37+
38+
export default MotionContent;

src/UniqueProvider/index.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import useTargetState from './useTargetState';
1414
import { isDOM } from '@rc-component/util/lib/Dom/findDOMNode';
1515
import FloatBg from './FloatBg';
1616
import classNames from 'classnames';
17+
import MotionContent from './MotionContent';
1718

1819
export interface UniqueProviderProps {
1920
children: React.ReactNode;
@@ -41,13 +42,18 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
4142
});
4243

4344
// ========================== Register ==========================
45+
const [popupId, setPopupId] = React.useState(0);
46+
4447
const delayInvoke = useDelay();
4548

46-
const show = (showOptions: UniqueShowOptions) => {
49+
const show = useEvent((showOptions: UniqueShowOptions) => {
4750
delayInvoke(() => {
51+
if (showOptions.id !== options?.id) {
52+
setPopupId((i) => i + 1);
53+
}
4854
trigger(showOptions);
4955
}, showOptions.delay);
50-
};
56+
});
5157

5258
const hide = (delay: number) => {
5359
delayInvoke(() => {
@@ -60,11 +66,6 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
6066
const onVisibleChanged = useEvent((visible: boolean) => {
6167
// Call useTargetState callback to handle animation state
6268
onTargetVisibleChanged(visible);
63-
// if (!visible) {
64-
// setTarget(null);
65-
// setCurrentNode(null);
66-
// setOptions(null);
67-
// }
6869
});
6970

7071
// =========================== Align ============================
@@ -133,7 +134,11 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
133134
ref={setPopupRef}
134135
portal={Portal}
135136
prefixCls={prefixCls}
136-
popup={options.popup}
137+
popup={
138+
<MotionContent prefixCls={prefixCls} key={popupId}>
139+
{options.popup}
140+
</MotionContent>
141+
}
137142
className={classNames(
138143
options.popupClassName,
139144
`${prefixCls}-unique-controlled`,

src/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default TriggerContext;
1212

1313
// ==================== Unique ====================
1414
export interface UniqueShowOptions {
15+
id: string;
1516
popup: TriggerProps['popup'];
1617
target: HTMLElement;
1718
delay: number;

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ export function generateTrigger(
317317
maskMotion,
318318
arrow,
319319
getPopupContainer,
320+
id,
320321
}));
321322

322323
// Handle controlled state changes for UniqueProvider

0 commit comments

Comments
 (0)