iterative/vscode-dvc

View on GitHub
webview/src/shared/components/dragDrop/DragDropItemWithTarget.tsx

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import React, { PropsWithChildren } from 'react'
import styles from './styles.module.scss'

interface DragDropItemWithTargetProps {
  dropTarget: JSX.Element | null
  draggable: JSX.Element
  isAfter?: boolean
  shouldShowOnDrag?: boolean
}

export const DragDropItemWithTarget: React.FC<
  PropsWithChildren<DragDropItemWithTargetProps>
> = ({ dropTarget, isAfter, shouldShowOnDrag, draggable, children }) => {
  if (!dropTarget) {
    return <>{children}</>
  }

  const block = isAfter ? [children, dropTarget] : [dropTarget, children]

  return shouldShowOnDrag ? (
    <draggable.type className={styles.newBlockWhenShowingOnDrag}>
      {block}
    </draggable.type>
  ) : (
    block
  )
}