Skip to content

Commit 0161493

Browse files
committed
chore: move to show
1 parent 6064ded commit 0161493

1 file changed

Lines changed: 39 additions & 13 deletions

File tree

src/UniqueProvider/index.tsx

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import TriggerContext, {
77
type UniqueShowOptions,
88
} from '../context';
99
import useDelay from '../hooks/useDelay';
10+
import useAlign from '../hooks/useAlign';
1011
import Popup from '../Popup';
1112

1213
export interface UniqueProviderProps {
@@ -18,6 +19,7 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
1819
const [target, setTarget] = React.useState<HTMLElement | null>(null);
1920
const [currentNode, setCurrentNode] = React.useState<React.ReactNode>(null);
2021
const [options, setOptions] = React.useState<UniqueShowOptions | null>(null);
22+
const [popupEle, setPopupEle] = React.useState<HTMLDivElement>(null);
2123

2224
// ========================== Register ==========================
2325
const delayInvoke = useDelay();
@@ -37,6 +39,31 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
3739
}, delay);
3840
};
3941

42+
// =========================== Align ============================
43+
const [
44+
ready,
45+
offsetX,
46+
offsetY,
47+
offsetR,
48+
offsetB,
49+
arrowX,
50+
arrowY, // scaleX - not used in UniqueProvider
51+
// scaleY - not used in UniqueProvider
52+
,
53+
,
54+
alignInfo,
55+
onAlign,
56+
] = useAlign(
57+
open,
58+
popupEle,
59+
target,
60+
options?.popupPlacement,
61+
options?.builtinPlacements || {},
62+
options?.popupAlign,
63+
undefined, // onPopupAlign
64+
false, // isMobile
65+
);
66+
4067
const contextValue = React.useMemo<UniqueContextProps>(
4168
() => ({
4269
show,
@@ -66,6 +93,7 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
6693
{options && (
6794
<TriggerContext.Provider value={triggerContextValue}>
6895
<Popup
96+
ref={setPopupEle}
6997
portal={Portal}
7098
prefixCls={options.prefixCls || 'rc-trigger-popup'}
7199
popup={currentNode}
@@ -76,20 +104,18 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
76104
keepDom={false}
77105
fresh={true}
78106
onVisibleChanged={() => {}}
79-
ready={true}
80-
offsetX={0}
81-
offsetY={0}
82-
offsetR={0}
83-
offsetB={0}
84-
onAlign={() => {}}
107+
ready={ready}
108+
offsetX={offsetX}
109+
offsetY={offsetY}
110+
offsetR={offsetR}
111+
offsetB={offsetB}
112+
onAlign={onAlign}
85113
onPrepare={() => Promise.resolve()}
86-
arrowPos={{}}
87-
align={
88-
options.popupAlign || {
89-
points: ['tl', 'bl'],
90-
offset: [0, 4],
91-
}
92-
}
114+
arrowPos={{
115+
x: arrowX,
116+
y: arrowY,
117+
}}
118+
align={alignInfo}
93119
zIndex={options.zIndex}
94120
mask={options.mask}
95121
arrow={options.arrow}

0 commit comments

Comments
 (0)