mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 17:19:11 +08:00
2777d2c39f
* fix: Fixed an issue where the z-index setting of the pop-up component was abnormal in the pop-up container * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * Update components/popconfirm/index.tsx Signed-off-by: kiner-tang(文辉) <1127031143@qq.com> --------- Signed-off-by: kiner-tang(文辉) <1127031143@qq.com>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import React from 'react';
|
|
|
|
import useToken from '../../theme/useToken';
|
|
import zIndexContext from '../zindexContext';
|
|
|
|
export type ZIndexContainer = 'Modal' | 'Drawer' | 'Popover' | 'Popconfirm' | 'Tooltip' | 'Tour';
|
|
|
|
export type ZIndexConsumer = 'SelectLike' | 'Dropdown' | 'DatePicker' | 'Menu';
|
|
|
|
export const containerBaseZIndexOffset: Record<ZIndexContainer, number> = {
|
|
Modal: 0,
|
|
Drawer: 0,
|
|
Popover: 70,
|
|
Popconfirm: 70,
|
|
Tooltip: 70,
|
|
Tour: 70,
|
|
};
|
|
export const consumerBaseZIndexOffset: Record<ZIndexConsumer, number> = {
|
|
SelectLike: 50,
|
|
Dropdown: 50,
|
|
DatePicker: 50,
|
|
Menu: 50,
|
|
};
|
|
|
|
function isContainerType(type: ZIndexContainer | ZIndexConsumer): type is ZIndexContainer {
|
|
return type in containerBaseZIndexOffset;
|
|
}
|
|
|
|
export function useZIndex(
|
|
componentType: ZIndexContainer | ZIndexConsumer,
|
|
customZIndex?: number,
|
|
): [zIndex: number | undefined, contextZIndex: number] {
|
|
const [, token] = useToken();
|
|
const parentZIndex = React.useContext(zIndexContext);
|
|
const isContainer = isContainerType(componentType);
|
|
let zIndex = parentZIndex ?? 0;
|
|
if (isContainer) {
|
|
zIndex += token.zIndexPopupBase + containerBaseZIndexOffset[componentType];
|
|
} else {
|
|
zIndex += consumerBaseZIndexOffset[componentType];
|
|
}
|
|
return [parentZIndex === undefined ? customZIndex : zIndex, zIndex];
|
|
}
|