• 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={}

  • 相关阅读:
    Python+Appium移动端自动化测试框架实现
    Go 学习之 channel 篇
    关于redis的一主三从三哨兵的实现
    01-JavaScript-数据类型
    助听器算法研究开发源码介绍
    开学季蓝牙耳机怎么选?高性价比学生蓝牙耳机推荐
    MySQL运维15-一主一从读写分离
    pytorch lightning最简上手
    【实战项目之个人博客】
    SSTI服务端模板注入漏洞原理详解及利用姿势集锦
  • 原文地址:https://blog.csdn.net/wangdanYL/article/details/133694913