2023-04-04 13:43:53 +08:00
|
|
|
import type { AlignType, BuildInPlacements } from '@rc-component/trigger';
|
2023-09-20 19:59:26 +08:00
|
|
|
|
2023-04-07 10:17:00 +08:00
|
|
|
import type { PopupOverflow } from '../config-provider/context';
|
2023-04-04 13:43:53 +08:00
|
|
|
|
2023-04-07 10:17:00 +08:00
|
|
|
const getBuiltInPlacements = (popupOverflow?: PopupOverflow): Record<string, AlignType> => {
|
|
|
|
const htmlRegion: AlignType['htmlRegion'] = popupOverflow === 'scroll' ? 'scroll' : 'visible';
|
|
|
|
|
2023-07-15 10:14:58 +08:00
|
|
|
const sharedConfig: AlignType = {
|
2023-04-07 10:17:00 +08:00
|
|
|
overflow: {
|
|
|
|
adjustX: true,
|
|
|
|
adjustY: true,
|
|
|
|
shiftY: true,
|
|
|
|
},
|
|
|
|
htmlRegion,
|
2023-09-20 19:59:26 +08:00
|
|
|
dynamicInset: true,
|
2023-04-07 10:17:00 +08:00
|
|
|
};
|
2023-04-04 13:43:53 +08:00
|
|
|
|
2023-04-07 10:17:00 +08:00
|
|
|
return {
|
|
|
|
bottomLeft: {
|
|
|
|
...sharedConfig,
|
|
|
|
points: ['tl', 'bl'],
|
|
|
|
offset: [0, 4],
|
|
|
|
},
|
|
|
|
bottomRight: {
|
|
|
|
...sharedConfig,
|
|
|
|
points: ['tr', 'br'],
|
|
|
|
offset: [0, 4],
|
|
|
|
},
|
|
|
|
topLeft: {
|
|
|
|
...sharedConfig,
|
|
|
|
points: ['bl', 'tl'],
|
|
|
|
offset: [0, -4],
|
|
|
|
},
|
|
|
|
topRight: {
|
|
|
|
...sharedConfig,
|
|
|
|
points: ['br', 'tr'],
|
|
|
|
offset: [0, -4],
|
|
|
|
},
|
|
|
|
};
|
2023-04-04 13:43:53 +08:00
|
|
|
};
|
|
|
|
|
2023-04-07 10:17:00 +08:00
|
|
|
export default function useBuiltinPlacements(
|
|
|
|
buildInPlacements?: BuildInPlacements,
|
|
|
|
popupOverflow?: PopupOverflow,
|
|
|
|
) {
|
|
|
|
return buildInPlacements || getBuiltInPlacements(popupOverflow);
|
2023-04-04 13:43:53 +08:00
|
|
|
}
|