2
0
Files
bot/apps/builder/components/editor/StepsSideBar/StepCard.tsx

79 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-01-19 09:44:21 +01:00
import { Flex, HStack, StackProps, Text } from '@chakra-ui/react'
import { StepType, DraggableStepType } from 'models'
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,
}: {
type: DraggableStepType
onMouseDown: (e: React.MouseEvent, type: DraggableStepType) => void
2021-12-16 10:43:49 +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"
2022-03-31 09:49:23 +02:00
borderColor="gray.200"
2021-12-16 10:43:49 +01:00
rounded="lg"
flex="1"
cursor={'grab'}
opacity={isMouseDown ? '0.4' : '1'}
onMouseDown={handleMouseDown}
2022-03-31 09:49:23 +02:00
bgColor="gray.50"
2022-01-19 09:44:21 +01:00
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
)
}