mirror of
https://github.com/MrXujiang/h5-Dooring.git
synced 2026-01-08 12:58:11 +00:00
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
import React, { useMemo, memo, ReactNode, useContext, CSSProperties } from 'react';
|
|
import { useDrag } from 'react-dnd';
|
|
import schema from 'components/BasicShop/schema';
|
|
import styles from './index.less';
|
|
import { dooringContext } from '@/layouts';
|
|
|
|
interface TargetBoxProps {
|
|
item: any;
|
|
children: ReactNode;
|
|
canvasId: string;
|
|
}
|
|
|
|
const TargetBox = memo((props: TargetBoxProps) => {
|
|
const { item } = props;
|
|
|
|
const [{ isDragging }, drag] = useDrag({
|
|
item: {
|
|
type: item.type,
|
|
config: schema[item.type as keyof typeof schema].config,
|
|
h: item.h,
|
|
editableEl: schema[item.type as keyof typeof schema].editData,
|
|
category: item.category,
|
|
x: item.x || 0,
|
|
},
|
|
collect: monitor => ({
|
|
isDragging: monitor.isDragging(),
|
|
}),
|
|
});
|
|
|
|
const containerStyle: CSSProperties = useMemo(
|
|
() => ({
|
|
opacity: isDragging ? 0.4 : 1,
|
|
cursor: 'move',
|
|
height: '140px',
|
|
}),
|
|
[isDragging],
|
|
);
|
|
return (
|
|
<>
|
|
<div className={styles.listWrap}>
|
|
<div className={styles.module} style={{ ...containerStyle }} ref={drag}>
|
|
<div
|
|
style={{
|
|
height: '110px',
|
|
display: 'flex',
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
flexDirection: 'column',
|
|
overflow: 'hidden',
|
|
}}
|
|
>
|
|
{props.children}
|
|
</div>
|
|
<div
|
|
style={{
|
|
height: '30px',
|
|
lineHeight: '30px',
|
|
textAlign: 'center',
|
|
backgroundColor: 'rgba(245, 245, 245, 1)',
|
|
color: 'rgba(118, 118, 118, 1)',
|
|
}}
|
|
>
|
|
{props.item.displayName}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
});
|
|
|
|
export default TargetBox;
|