import { forwardRef, ForwardedRef } from 'react'; import styles from '../styles/rt-list.module.css'; import { RtFrame } from '@dpa/react-frame-intro'; import classNames from 'classnames/bind'; import { RtListItem, RtListProps } from '../types/rt-list.types'; import { DndContext, closestCenter } from '@dnd-kit/core'; import { SortableContext, verticalListSortingStrategy, } from '@dnd-kit/sortable'; import { useRtBaseProps } from '@dpa/react-hoc'; import { useDndList } from '../hooks/useDndList'; import { RtGrid } from '@dpa/react-grid'; const cn = classNames.bind(styles); const RtInternalList = ( props: RtListProps, ref: ForwardedRef ) => { const { children, items, getId, renderItem, onReorder, useGrid, ariaLabel, use, ...otherProps } = props; const baseProps = useRtBaseProps(props, '0.2.2'); const { handleDragEnd, sensors, idGetter, getRenderItemFn } = useDndList( items, onReorder, getId, renderItem ); const renderItemFn = getRenderItemFn(use); return ( {useGrid ? ( {items.map((item) => (
  • {renderItemFn(item)}
  • ))}
    ) : (
      {items.map((item) => (
    • {renderItemFn(item)}
    • ))}
    )}
    ); }; /** * Компонент для отображения списка с DnD. * Может использовать RtGrid. В качестве единицы списка может использовать RtItem * {@link RtListProps} */ export const RtList = forwardRef(RtInternalList); RtList.displayName = 'RtList';