• react-beautiful-dnd拖拽插件指定拖拽元素


    import React, { useMemo } from 'react';

    import { List, Avatar } from 'antd';

    import classNames from 'classnames';

    import { TransferSortProps, TransferItem } from './types';

    import { MenuOutlined } from '@ant-design/icons';

    import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd';

    const SortTableItem = (props: TransferSortProps) => {

        const { target, direction, sort, sourceActive, targetActive, item = {}, rowKey, onActive, onItemDoubleClick, view, getTitle, prefixCls, icon } = props

        const className = useMemo(() => {

            return direction === 'left'

                ? sourceActive.includes(item[rowKey])

                : targetActive.includes(item[rowKey])

        }, [direction, sourceActive, targetActive, item])

        const isChecked = target && target.filter(it => it[rowKey] === item[rowKey]).length > 0;

        const isDisabled = direction === 'left' ? isChecked : false;

        const getAvatar = (item: TransferItem) => {

            const { avatar } = view || {};

            if (!avatar) return null;

            if (typeof avatar === 'function') {

                const avatarProps = avatar(item);

                return avatarProps ? : null;

            } else {

                return item[avatar] ? : null;

            }

        };

        const avatarRender = () => {

            if (sort && direction === 'right') {

                return

    {icon}{getAvatar(item)}

            }

            return getAvatar(item)

        }

        const getDescription = (item: TransferItem) => {

            const { fieldDesc } = view || {};

            if (fieldDesc) {

                return fieldDesc.split(',').map((name, index) =>

                    item[name] && ({item[name]}));

            } else {

                return null;

            }

        };

        const handleClick = (isDisabled: boolean, fn: Function) => {

            return !isDisabled && fn(direction, item)

        }

        return (

           

                className={classNames({

                    [`${prefixCls}-item-active`]: className, [`${prefixCls}-item-disabled`]: isDisabled

                })}

                key={`${item.id}`}

                onClick={() => handleClick(isDisabled, onActive)}

                onDoubleClick={() => handleClick(isDisabled, onItemDoubleClick)}

            >

               

                    avatar={avatarRender()}

                    title={getTitle(item)}

                    description={getDescription(item)}

                />

           

        )

    }

    const SortTable = (props: TransferSortProps) => {

        const { direction, unTarget, target, loading = false, sort, onSortEnd } = props;

        const isLeft = direction === 'left';

        const data = useMemo(() => {

            return isLeft ? unTarget : target

        }, [direction, unTarget, target])

        const listProps = (isLeft && loading) ? { locale: { emptyText: <> } } : {};

        const showLoading = isLeft ? { spinning: loading, tip: '加载中···', wrapperClassName: 'ant-list' } : false;

        return (

           

                {...listProps}

                size="small"

                itemLayout="horizontal"

                loading={showLoading}

                style={{ overflowY: 'auto' }}

            >

               

                   

                        {(droppableProvided: any) => (

                           

                                {data && data.length > 0 && data.map((item: any, index: number) => {

                                    return (

                                       

                                            key={item?.id}

                                            index={index}

                                            draggableId={item?.id}

                                            isDragDisabled={!sort || direction === 'left'}

                                        >

                                            {(provided: any, snapshot: any) => (

                                               

                                                    ref={provided.innerRef}

                                                    {...provided.draggableProps}

                                                    style={{

                                                        ...provided.draggableProps.style,

                                                        opacity: snapshot.isDragging ? 0.7 : 1,

                                                    }}

                                                    className='transfer-sortable-item-avatar'

                                                >

                                                   

                                                        {...props}

                                                        item={item}

                                                        index={index}

                                                        key={`${item.id}_${index}`}

                                                        icon={}

                                                    />

                                               

                                            )}

                                       

                                    )

                                })}

                                {droppableProvided.placeholder}

                           

                        )}

                   

               

           

        )

    }

    export default SortTable;

    主要是  icon={}

  • 相关阅读:
    MySQL高级SQL语句
    机器学习笔记之高斯混合模型(二)模型求解——尝试使用极大似然估计求解模型参数
    L9170 LGCN 原厂直销5A大电流输出DC双向马达驱动电路IC
    盘点 | 2022年上半年国内的电邮安全事件
    IDEA常用快捷键大全
    虚拟机搭建负载均衡,mysql主从复制和读写分离(三、搭建负载均衡)
    华为云HECS服务器下docker可视化(portainer)
    DAO 的具体内涵与概念
    hive笔记(五):查询、排序-join语句/连接/分区/sort by/distribute by/cluster by
    前端入门学习笔记四十九
  • 原文地址:https://blog.csdn.net/wangdanYL/article/details/133694913