ant-design/components/tree/utils/dropIndicator.tsx

38 lines
984 B
TypeScript
Raw Normal View History

import React from 'react';
2024-07-29 01:30:35 +08:00
import type { DirectionType } from '../../config-provider';
export const offset = 4;
2024-07-29 01:30:35 +08:00
function dropIndicatorRender(props: {
dropPosition: -1 | 0 | 1;
dropLevelOffset: number;
indent: number;
prefixCls: string;
2024-07-29 01:30:35 +08:00
direction: DirectionType;
}) {
const { dropPosition, dropLevelOffset, prefixCls, indent, direction = 'ltr' } = props;
const startPosition = direction === 'ltr' ? 'left' : 'right';
const endPosition = direction === 'ltr' ? 'right' : 'left';
const style: React.CSSProperties = {
[startPosition]: -dropLevelOffset * indent + offset,
[endPosition]: 0,
};
switch (dropPosition) {
case -1:
style.top = -3;
break;
case 1:
style.bottom = -3;
break;
default:
// dropPosition === 0
style.bottom = -3;
style[startPosition] = indent + offset;
break;
}
return <div style={style} className={`${prefixCls}-drop-indicator`} />;
}
2024-07-29 01:30:35 +08:00
export default dropIndicatorRender;