@@ -10,6 +10,7 @@ import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
10
10
import Arrow from './Arrow' ;
11
11
import Mask from './Mask' ;
12
12
import PopupContent from './PopupContent' ;
13
+ import useOffsetStyle from '../hooks/useOffsetStyle' ;
13
14
14
15
export interface MobileConfig {
15
16
mask ?: boolean ;
@@ -175,49 +176,23 @@ const Popup = React.forwardRef<HTMLDivElement, PopupProps>((props, ref) => {
175
176
}
176
177
} , [ show , getPopupContainerNeedParams , target ] ) ;
177
178
179
+ // ========================= Styles =========================
180
+ const offsetStyle = useOffsetStyle (
181
+ isMobile ,
182
+ ready ,
183
+ open ,
184
+ align ,
185
+ offsetR ,
186
+ offsetB ,
187
+ offsetX ,
188
+ offsetY ,
189
+ ) ;
190
+
178
191
// ========================= Render =========================
179
192
if ( ! show ) {
180
193
return null ;
181
194
}
182
195
183
- // TODO: Move offsetStyle logic to useOffsetStyle.ts hooks
184
- // >>>>> Offset
185
- const AUTO = 'auto' as const ;
186
-
187
- const offsetStyle : React . CSSProperties = isMobile
188
- ? { }
189
- : {
190
- left : '-1000vw' ,
191
- top : '-1000vh' ,
192
- right : AUTO ,
193
- bottom : AUTO ,
194
- } ;
195
-
196
- // Set align style
197
- if ( ! isMobile && ( ready || ! open ) ) {
198
- const { points } = align ;
199
- const dynamicInset =
200
- align . dynamicInset || ( align as any ) . _experimental ?. dynamicInset ;
201
- const alignRight = dynamicInset && points [ 0 ] [ 1 ] === 'r' ;
202
- const alignBottom = dynamicInset && points [ 0 ] [ 0 ] === 'b' ;
203
-
204
- if ( alignRight ) {
205
- offsetStyle . right = offsetR ;
206
- offsetStyle . left = AUTO ;
207
- } else {
208
- offsetStyle . left = offsetX ;
209
- offsetStyle . right = AUTO ;
210
- }
211
-
212
- if ( alignBottom ) {
213
- offsetStyle . bottom = offsetB ;
214
- offsetStyle . top = AUTO ;
215
- } else {
216
- offsetStyle . top = offsetY ;
217
- offsetStyle . bottom = AUTO ;
218
- }
219
- }
220
-
221
196
// >>>>> Misc
222
197
const miscStyle : React . CSSProperties = { } ;
223
198
if ( stretch ) {
0 commit comments