Skip to content

Commit

Permalink
chore: replace T generic
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanVor committed Feb 9, 2024
1 parent ce6f78e commit 2dc1fc2
Showing 1 changed file with 46 additions and 43 deletions.
89 changes: 46 additions & 43 deletions src/components/TreeSelect/DndTreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function DndTreeSelect<T extends DndTreeSelectItem>({
() => initialDroppableId || `default-droppable-id-${dndTreeSelectCount++}`,
);

const renderContainer = React.useCallback<RenderContainerType<T>>(
const renderContainer = React.useCallback<RenderContainerType<DndTreeSelectItem>>(
({renderItem, visibleFlattenIds, items: _items, containerRef, id}) => {
const handleDrugEnd: OnDragEndResponder = ({destination, source}) => {
if (destination?.index !== undefined && destination?.index !== source.index) {
Expand Down Expand Up @@ -86,48 +86,51 @@ export function DndTreeSelect<T extends DndTreeSelectItem>({
[items, setItems, propsRenderContainer, droppableId],
);

const renderDndItem = React.useCallback<RenderItem<T>>((item, state, _, idx) => {
const endSlot =
item.endSlot ?? (item.isDragDisabled ? undefined : <Icon data={Grip} size={16} />);

const commonProps = {
...state,
...item,
endSlot,
};

return (
<Draggable
draggableId={state.id}
index={Number(idx)}
key={`item-key-${state.id}`}
isDragDisabled={item.isDragDisabled}
>
{(provided, snapshot) => {
const style: React.CSSProperties = {
...provided.draggableProps.style,
};

// not expected offset appears, one way to fix - remove this offsets explicitly
if (snapshot.isDragging) {
style.left = undefined;
style.top = undefined;
}

return (
<TreeSelectItem
ref={provided.innerRef}
{...commonProps}
{...provided.draggableProps}
{...provided.dragHandleProps}
style={style}
active={snapshot.isDragging}
/>
);
}}
</Draggable>
);
}, []);
const renderDndItem = React.useCallback<RenderItem<DndTreeSelectItem>>(
(item, state, _, idx) => {
const endSlot =
item.endSlot ?? (item.isDragDisabled ? undefined : <Icon data={Grip} size={16} />);

const commonProps = {
...state,
...item,
endSlot,
};

return (
<Draggable
draggableId={state.id}
index={Number(idx)}
key={`item-key-${state.id}`}
isDragDisabled={item.isDragDisabled}
>
{(provided, snapshot) => {
const style: React.CSSProperties = {
...provided.draggableProps.style,
};

// not expected offset appears, one way to fix - remove this offsets explicitly
if (snapshot.isDragging) {
style.left = undefined;
style.top = undefined;
}

return (
<TreeSelectItem
ref={provided.innerRef}
{...commonProps}
{...provided.draggableProps}
{...provided.dragHandleProps}
style={style}
active={snapshot.isDragging}
/>
);
}}
</Draggable>
);
},
[],
);

return (
<TreeSelect
Expand Down

0 comments on commit 2dc1fc2

Please sign in to comment.