2022-01-19 09:44:21 +01:00
|
|
|
import { Flex, HStack, StackProps, Text } from '@chakra-ui/react'
|
2022-01-18 18:25:18 +01:00
|
|
|
import { StepType, DraggableStepType } from 'models'
|
2022-02-04 19:00:08 +01:00
|
|
|
import { useStepDnd } from 'contexts/GraphDndContext'
|
2021-12-16 10:43:49 +01:00
|
|
|
import React, { useEffect, useState } from 'react'
|
|
|
|
import { StepIcon } from './StepIcon'
|
2022-01-08 07:40:55 +01:00
|
|
|
import { StepTypeLabel } from './StepTypeLabel'
|
2021-12-16 10:43:49 +01:00
|
|
|
|
|
|
|
export const StepCard = ({
|
|
|
|
type,
|
|
|
|
onMouseDown,
|
|
|
|
}: {
|
2022-01-18 18:25:18 +01:00
|
|
|
type: DraggableStepType
|
|
|
|
onMouseDown: (e: React.MouseEvent, type: DraggableStepType) => void
|
2021-12-16 10:43:49 +01:00
|
|
|
}) => {
|
2022-01-28 09:42:31 +01:00
|
|
|
const { draggedStepType } = useStepDnd()
|
2021-12-16 10:43:49 +01:00
|
|
|
const [isMouseDown, setIsMouseDown] = useState(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setIsMouseDown(draggedStepType === type)
|
|
|
|
}, [draggedStepType, type])
|
|
|
|
|
|
|
|
const handleMouseDown = (e: React.MouseEvent) => onMouseDown(e, type)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Flex pos="relative">
|
2022-01-19 09:44:21 +01:00
|
|
|
<HStack
|
2021-12-16 10:43:49 +01:00
|
|
|
borderWidth="1px"
|
|
|
|
rounded="lg"
|
|
|
|
flex="1"
|
|
|
|
cursor={'grab'}
|
|
|
|
opacity={isMouseDown ? '0.4' : '1'}
|
|
|
|
onMouseDown={handleMouseDown}
|
2022-01-19 09:44:21 +01:00
|
|
|
bgColor="white"
|
|
|
|
shadow="sm"
|
|
|
|
px="4"
|
|
|
|
py="2"
|
|
|
|
_hover={{ shadow: 'md' }}
|
|
|
|
transition="box-shadow 200ms"
|
2021-12-16 10:43:49 +01:00
|
|
|
>
|
2022-01-19 09:44:21 +01:00
|
|
|
{!isMouseDown ? (
|
2021-12-16 10:43:49 +01:00
|
|
|
<>
|
|
|
|
<StepIcon type={type} />
|
2022-01-08 07:40:55 +01:00
|
|
|
<StepTypeLabel type={type} />
|
2021-12-16 10:43:49 +01:00
|
|
|
</>
|
2022-01-19 09:44:21 +01:00
|
|
|
) : (
|
|
|
|
<Text color="white" userSelect="none">
|
|
|
|
Placeholder
|
|
|
|
</Text>
|
2021-12-16 10:43:49 +01:00
|
|
|
)}
|
2022-01-19 09:44:21 +01:00
|
|
|
</HStack>
|
2021-12-16 10:43:49 +01:00
|
|
|
</Flex>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const StepCardOverlay = ({
|
|
|
|
type,
|
|
|
|
...props
|
2022-01-19 09:44:21 +01:00
|
|
|
}: StackProps & { type: StepType }) => {
|
2021-12-16 10:43:49 +01:00
|
|
|
return (
|
2022-01-19 09:44:21 +01:00
|
|
|
<HStack
|
2021-12-16 10:43:49 +01:00
|
|
|
borderWidth="1px"
|
|
|
|
rounded="lg"
|
2022-01-19 09:44:21 +01:00
|
|
|
cursor={'grabbing'}
|
2021-12-16 10:43:49 +01:00
|
|
|
w="147px"
|
|
|
|
transition="none"
|
|
|
|
pointerEvents="none"
|
2022-01-19 09:44:21 +01:00
|
|
|
px="4"
|
|
|
|
py="2"
|
|
|
|
bgColor="white"
|
|
|
|
shadow="xl"
|
|
|
|
zIndex={2}
|
2021-12-16 10:43:49 +01:00
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
<StepIcon type={type} />
|
2022-01-08 07:40:55 +01:00
|
|
|
<StepTypeLabel type={type} />
|
2022-01-19 09:44:21 +01:00
|
|
|
</HStack>
|
2021-12-16 10:43:49 +01:00
|
|
|
)
|
|
|
|
}
|