import { Chip, Typography, useTheme } from '@mui/material'; import type { DraggableSyntheticListeners } from '@dnd-kit/core'; import clsx from 'clsx'; import { findIndex, not, propEq } from 'ramda'; import type React from 'react'; import { type CSSProperties, type RefObject, useRef } from 'react'; import type { DraggableSelectEntry, SortableListProps } from './SortableList'; interface ContentProps extends Pick { // biome-ignore lint/suspicious/noExplicitAny: dnd-kit forwards arbitrary HTML attributes attributes: Record; id: string; index: number; isDragging: boolean; itemRef: RefObject; listeners: DraggableSyntheticListeners; style: CSSProperties; } interface Props extends Omit { classes: Record; } const SortableListContent = ({ items, classes, itemHover, itemClick, deleteValue }: Props): ((props: ContentProps) => JSX.Element) => { const Content = ({ attributes, listeners, name, createOption, id, style, itemRef, index, isDragging }: ContentProps): JSX.Element => { const theme = useTheme(); const labelItemRef = useRef(null); const mouseUp = (event: React.MouseEvent): void => { if (not(event.shiftKey)) { return; } const itemIndex = findIndex(propEq(id, 'id'), items); itemHover?.(null); itemClick?.({ index: itemIndex, item: { createOption, id, name } }); }; const mouseLeave = (): void => itemHover?.(null); const mouseEnter = (): void => itemHover?.({ anchorElement: labelItemRef.current, index, item: { createOption, id, name } }); const deleteItem = (): void => deleteValue(id); return (
{name} } onDelete={deleteItem} onMouseEnter={mouseEnter} onMouseLeave={mouseLeave} size="medium" style={{ backgroundColor: isDragging ? theme.palette.grey[300] : undefined }} />
); }; return Content; }; export default SortableListContent;