2
0

feat(editor): 💄 UI bump

This commit is contained in:
Baptiste Arnaud
2022-03-31 09:49:23 +02:00
parent c7d5373127
commit 7f5d2f4173
16 changed files with 105 additions and 48 deletions

View File

@@ -25,13 +25,13 @@ export const StepCard = ({
<Flex pos="relative"> <Flex pos="relative">
<HStack <HStack
borderWidth="1px" borderWidth="1px"
borderColor="gray.200"
rounded="lg" rounded="lg"
flex="1" flex="1"
cursor={'grab'} cursor={'grab'}
opacity={isMouseDown ? '0.4' : '1'} opacity={isMouseDown ? '0.4' : '1'}
onMouseDown={handleMouseDown} onMouseDown={handleMouseDown}
bgColor="white" bgColor="gray.50"
shadow="sm"
px="4" px="4"
py="2" py="2"
_hover={{ shadow: 'md' }} _hover={{ shadow: 'md' }}

View File

@@ -74,7 +74,7 @@ export const StepsSideBar = () => {
return ( return (
<Flex <Flex
w="340px" w="360px"
pos="absolute" pos="absolute"
left="0" left="0"
h={`calc(100vh - ${headerHeight}px)`} h={`calc(100vh - ${headerHeight}px)`}
@@ -82,7 +82,7 @@ export const StepsSideBar = () => {
pl="4" pl="4"
py="4" py="4"
onMouseLeave={handleMouseLeave} onMouseLeave={handleMouseLeave}
transform={isExtended ? 'translateX(0)' : 'translateX(-340px)'} transform={isExtended ? 'translateX(0)' : 'translateX(-350px)'}
transition="transform 350ms cubic-bezier(0.075, 0.82, 0.165, 1) 0s" transition="transform 350ms cubic-bezier(0.075, 0.82, 0.165, 1) 0s"
> >
<Stack <Stack
@@ -92,8 +92,8 @@ export const StepsSideBar = () => {
borderWidth="1px" borderWidth="1px"
pt="2" pt="2"
pb="10" pb="10"
px="2" px="4"
bgColor="gray.50" bgColor="white"
spacing={6} spacing={6}
userSelect="none" userSelect="none"
overflowY="scroll" overflowY="scroll"
@@ -115,7 +115,7 @@ export const StepsSideBar = () => {
<Text fontSize="sm" fontWeight="semibold" color="gray.600"> <Text fontSize="sm" fontWeight="semibold" color="gray.600">
Bubbles Bubbles
</Text> </Text>
<SimpleGrid columns={2} spacing="2"> <SimpleGrid columns={2} spacing="3">
{Object.values(BubbleStepType).map((type) => ( {Object.values(BubbleStepType).map((type) => (
<StepCard key={type} type={type} onMouseDown={handleMouseDown} /> <StepCard key={type} type={type} onMouseDown={handleMouseDown} />
))} ))}
@@ -126,7 +126,7 @@ export const StepsSideBar = () => {
<Text fontSize="sm" fontWeight="semibold" color="gray.600"> <Text fontSize="sm" fontWeight="semibold" color="gray.600">
Inputs Inputs
</Text> </Text>
<SimpleGrid columns={2} spacing="2"> <SimpleGrid columns={2} spacing="3">
{Object.values(InputStepType).map((type) => ( {Object.values(InputStepType).map((type) => (
<StepCard key={type} type={type} onMouseDown={handleMouseDown} /> <StepCard key={type} type={type} onMouseDown={handleMouseDown} />
))} ))}
@@ -137,7 +137,7 @@ export const StepsSideBar = () => {
<Text fontSize="sm" fontWeight="semibold" color="gray.600"> <Text fontSize="sm" fontWeight="semibold" color="gray.600">
Logic Logic
</Text> </Text>
<SimpleGrid columns={2} spacing="2"> <SimpleGrid columns={2} spacing="3">
{Object.values(LogicStepType).map((type) => ( {Object.values(LogicStepType).map((type) => (
<StepCard key={type} type={type} onMouseDown={handleMouseDown} /> <StepCard key={type} type={type} onMouseDown={handleMouseDown} />
))} ))}
@@ -148,7 +148,7 @@ export const StepsSideBar = () => {
<Text fontSize="sm" fontWeight="semibold" color="gray.600"> <Text fontSize="sm" fontWeight="semibold" color="gray.600">
Integrations Integrations
</Text> </Text>
<SimpleGrid columns={2} spacing="2"> <SimpleGrid columns={2} spacing="3">
{Object.values(IntegrationStepType).map((type) => ( {Object.values(IntegrationStepType).map((type) => (
<StepCard key={type} type={type} onMouseDown={handleMouseDown} /> <StepCard key={type} type={type} onMouseDown={handleMouseDown} />
))} ))}

View File

@@ -2,6 +2,7 @@ import { useEventListener } from '@chakra-ui/hooks'
import assert from 'assert' import assert from 'assert'
import { useGraph, ConnectingIds } from 'contexts/GraphContext' import { useGraph, ConnectingIds } from 'contexts/GraphContext'
import { useTypebot } from 'contexts/TypebotContext/TypebotContext' import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
import { colors } from 'libs/theme'
import React, { useMemo, useState } from 'react' import React, { useMemo, useState } from 'react'
import { import {
computeConnectingEdgePath, computeConnectingEdgePath,
@@ -91,7 +92,7 @@ export const DrawingEdge = () => {
return ( return (
<path <path
d={path} d={path}
stroke="#1a5fff" stroke={colors.blue[400]}
strokeWidth="2px" strokeWidth="2px"
markerEnd="url(#blue-arrow)" markerEnd="url(#blue-arrow)"
fill="none" fill="none"

View File

@@ -10,6 +10,7 @@ import { Edge as EdgeProps } from 'models'
import { Portal, useDisclosure } from '@chakra-ui/react' import { Portal, useDisclosure } from '@chakra-ui/react'
import { useTypebot } from 'contexts/TypebotContext' import { useTypebot } from 'contexts/TypebotContext'
import { EdgeMenu } from './EdgeMenu' import { EdgeMenu } from './EdgeMenu'
import { colors } from 'libs/theme'
export type AnchorsPositionProps = { export type AnchorsPositionProps = {
sourcePosition: Coordinates sourcePosition: Coordinates
@@ -124,7 +125,7 @@ export const Edge = ({ edge }: { edge: EdgeProps }) => {
<path <path
data-testid="edge" data-testid="edge"
d={path} d={path}
stroke={isPreviewing ? '#1a5fff' : '#718096'} stroke={isPreviewing ? colors.blue[400] : colors.gray[400]}
strokeWidth="2px" strokeWidth="2px"
markerEnd={isPreviewing ? 'url(#blue-arrow)' : 'url(#arrow)'} markerEnd={isPreviewing ? 'url(#blue-arrow)' : 'url(#arrow)'}
fill="none" fill="none"

View File

@@ -1,4 +1,5 @@
import { chakra } from '@chakra-ui/system' import { chakra } from '@chakra-ui/system'
import { colors } from 'libs/theme'
import { Edge as EdgeProps } from 'models' import { Edge as EdgeProps } from 'models'
import React from 'react' import React from 'react'
import { AnswersCount } from 'services/analytics' import { AnswersCount } from 'services/analytics'
@@ -51,7 +52,7 @@ export const Edges = ({
> >
<path <path
d="M7.07138888,5.50174526 L2.43017246,7.82235347 C1.60067988,8.23709976 0.592024983,7.90088146 0.177278692,7.07138888 C0.0606951226,6.83822174 0,6.58111307 0,6.32042429 L0,1.67920787 C0,0.751806973 0.751806973,0 1.67920787,0 C1.93989666,0 2.19700532,0.0606951226 2.43017246,0.177278692 L7,3 C7.82949258,3.41474629 8.23709976,3.92128809 7.82235347,4.75078067 C7.6598671,5.07575341 7.39636161,5.33925889 7.07138888,5.50174526 Z" d="M7.07138888,5.50174526 L2.43017246,7.82235347 C1.60067988,8.23709976 0.592024983,7.90088146 0.177278692,7.07138888 C0.0606951226,6.83822174 0,6.58111307 0,6.32042429 L0,1.67920787 C0,0.751806973 0.751806973,0 1.67920787,0 C1.93989666,0 2.19700532,0.0606951226 2.43017246,0.177278692 L7,3 C7.82949258,3.41474629 8.23709976,3.92128809 7.82235347,4.75078067 C7.6598671,5.07575341 7.39636161,5.33925889 7.07138888,5.50174526 Z"
fill="#718096" fill={colors.gray[400]}
/> />
</marker> </marker>
<marker <marker
@@ -66,7 +67,7 @@ export const Edges = ({
> >
<path <path
d="M7.07138888,5.50174526 L2.43017246,7.82235347 C1.60067988,8.23709976 0.592024983,7.90088146 0.177278692,7.07138888 C0.0606951226,6.83822174 0,6.58111307 0,6.32042429 L0,1.67920787 C0,0.751806973 0.751806973,0 1.67920787,0 C1.93989666,0 2.19700532,0.0606951226 2.43017246,0.177278692 L7,3 C7.82949258,3.41474629 8.23709976,3.92128809 7.82235347,4.75078067 C7.6598671,5.07575341 7.39636161,5.33925889 7.07138888,5.50174526 Z" d="M7.07138888,5.50174526 L2.43017246,7.82235347 C1.60067988,8.23709976 0.592024983,7.90088146 0.177278692,7.07138888 C0.0606951226,6.83822174 0,6.58111307 0,6.32042429 L0,1.67920787 C0,0.751806973 0.751806973,0 1.67920787,0 C1.93989666,0 2.19700532,0.0606951226 2.43017246,0.177278692 L7,3 C7.82949258,3.41474629 8.23709976,3.92128809 7.82235347,4.75078067 C7.6598671,5.07575341 7.39636161,5.33925889 7.07138888,5.50174526 Z"
fill="#1a5fff" fill={colors.blue[400]}
/> />
</marker> </marker>
<marker <marker

View File

@@ -1,4 +1,4 @@
import { Box, BoxProps, Flex } from '@chakra-ui/react' import { BoxProps, Flex } from '@chakra-ui/react'
import { useGraph } from 'contexts/GraphContext' import { useGraph } from 'contexts/GraphContext'
import { Source } from 'models' import { Source } from 'models'
import React, { MouseEvent, useEffect, useRef, useState } from 'react' import React, { MouseEvent, useEffect, useRef, useState } from 'react'
@@ -10,7 +10,12 @@ export const SourceEndpoint = ({
source: Source source: Source
}) => { }) => {
const [ranOnce, setRanOnce] = useState(false) const [ranOnce, setRanOnce] = useState(false)
const { setConnectingIds, addSourceEndpoint, blocksCoordinates } = useGraph() const {
setConnectingIds,
addSourceEndpoint,
blocksCoordinates,
previewingEdge,
} = useGraph()
const ref = useRef<HTMLDivElement | null>(null) const ref = useRef<HTMLDivElement | null>(null)
const handleMouseDown = (e: MouseEvent<HTMLDivElement>) => { const handleMouseDown = (e: MouseEvent<HTMLDivElement>) => {
@@ -35,19 +40,35 @@ export const SourceEndpoint = ({
<Flex <Flex
ref={ref} ref={ref}
data-testid="endpoint" data-testid="endpoint"
boxSize="18px" boxSize="32px"
rounded="full" rounded="full"
onMouseDownCapture={handleMouseDown} onMouseDownCapture={handleMouseDown}
cursor="copy" cursor="copy"
borderWidth="1px"
borderColor="gray.400"
bgColor="white"
justify="center" justify="center"
align="center" align="center"
pointerEvents="all" pointerEvents="all"
{...props} {...props}
> >
<Box bgColor="gray.400" rounded="full" boxSize="6px" /> <Flex
boxSize="20px"
justify="center"
align="center"
bgColor="gray.100"
rounded="full"
>
<Flex
boxSize="13px"
rounded="full"
borderWidth="3.5px"
shadow={`sm`}
borderColor={
previewingEdge?.from.stepId === source.stepId &&
previewingEdge.from.itemId === source.itemId
? 'blue.300'
: 'blue.200'
}
/>
</Flex>
</Flex> </Flex>
) )
} }

View File

@@ -115,12 +115,11 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
ref={setMultipleRefs([ref, blockRef])} ref={setMultipleRefs([ref, blockRef])}
data-testid="block" data-testid="block"
p="4" p="4"
rounded="lg" rounded="xl"
bgColor="blue.50" bgColor="#ffffff"
backgroundImage="linear-gradient(rgb(235, 239, 244), rgb(231, 234, 241))"
borderWidth="2px" borderWidth="2px"
borderColor={ borderColor={
isConnecting || isOpened || isPreviewing ? 'blue.400' : 'white' isConnecting || isOpened || isPreviewing ? 'blue.400' : '#ffffff'
} }
w="300px" w="300px"
transition="border 300ms, box-shadow 200ms" transition="border 300ms, box-shadow 200ms"
@@ -134,7 +133,7 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
onMouseEnter={handleMouseEnter} onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave} onMouseLeave={handleMouseLeave}
cursor={isMouseDown ? 'grabbing' : 'pointer'} cursor={isMouseDown ? 'grabbing' : 'pointer'}
boxShadow="0px 0px 0px 1px #e9edf3;" shadow="md"
_hover={{ shadow: 'lg' }} _hover={{ shadow: 'lg' }}
zIndex={focusedBlockId === block.id ? 10 : 1} zIndex={focusedBlockId === block.id ? 10 : 1}
> >

View File

@@ -3,7 +3,13 @@ import { ContextMenu } from 'components/shared/ContextMenu'
import { Coordinates } from 'contexts/GraphContext' import { Coordinates } from 'contexts/GraphContext'
import { NodePosition, useDragDistance } from 'contexts/GraphDndContext' import { NodePosition, useDragDistance } from 'contexts/GraphDndContext'
import { useTypebot } from 'contexts/TypebotContext' import { useTypebot } from 'contexts/TypebotContext'
import { ButtonItem, Item, ItemIndices, ItemType } from 'models' import {
ButtonItem,
ChoiceInputStep,
Item,
ItemIndices,
ItemType,
} from 'models'
import React, { useRef, useState } from 'react' import React, { useRef, useState } from 'react'
import { setMultipleRefs } from 'services/utils' import { setMultipleRefs } from 'services/utils'
import { SourceEndpoint } from '../../Endpoints/SourceEndpoint' import { SourceEndpoint } from '../../Endpoints/SourceEndpoint'
@@ -31,6 +37,11 @@ export const ItemNode = ({
const { typebot } = useTypebot() const { typebot } = useTypebot()
const [isMouseOver, setIsMouseOver] = useState(false) const [isMouseOver, setIsMouseOver] = useState(false)
const itemRef = useRef<HTMLDivElement | null>(null) const itemRef = useRef<HTMLDivElement | null>(null)
const isConnectable = !(
typebot?.blocks[indices.blockIndex].steps[
indices.stepIndex
] as ChoiceInputStep
)?.options?.isMultipleChoice
const onDrag = (position: NodePosition) => { const onDrag = (position: NodePosition) => {
if (!onMouseDown || item.type !== ItemType.BUTTON) return if (!onMouseDown || item.type !== ItemType.BUTTON) return
onMouseDown(position, item) onMouseDown(position, item)
@@ -61,8 +72,9 @@ export const ItemNode = ({
transition="box-shadow 200ms" transition="box-shadow 200ms"
borderWidth="1px" borderWidth="1px"
rounded="md" rounded="md"
borderColor={isOpened ? 'blue.400' : 'gray.300'} borderColor={isOpened ? 'blue.400' : 'gray.100'}
pointerEvents={isReadOnly ? 'none' : 'all'} pointerEvents={isReadOnly ? 'none' : 'all'}
bgColor="white"
w="full" w="full"
> >
<ItemNodeContent <ItemNodeContent
@@ -71,7 +83,7 @@ export const ItemNode = ({
indices={indices} indices={indices}
isLastItem={isLastItem} isLastItem={isLastItem}
/> />
{typebot && ( {typebot && isConnectable && (
<SourceEndpoint <SourceEndpoint
source={{ source={{
blockId: typebot.blocks[indices.blockIndex].id, blockId: typebot.blocks[indices.blockIndex].id,
@@ -79,7 +91,7 @@ export const ItemNode = ({
itemId: item.id, itemId: item.id,
}} }}
pos="absolute" pos="absolute"
right="15px" right="-49px"
pointerEvents="all" pointerEvents="all"
/> />
)} )}

View File

@@ -62,7 +62,7 @@ export const ButtonNodeContent = ({
} }
return ( return (
<Flex px={4} py={2} justify="center" w="90%"> <Flex px={4} py={2} justify="center" w="90%" pos="relative">
<Editable <Editable
ref={editableRef} ref={editableRef}
flex="1" flex="1"
@@ -82,7 +82,12 @@ export const ButtonNodeContent = ({
</Editable> </Editable>
<Fade <Fade
in={isMouseOver} in={isMouseOver}
style={{ position: 'absolute', bottom: '-15px', zIndex: 3 }} style={{
position: 'absolute',
bottom: '-15px',
zIndex: 3,
left: '90px',
}}
unmountOnExit unmountOnExit
> >
<IconButton <IconButton
@@ -90,7 +95,7 @@ export const ButtonNodeContent = ({
icon={<PlusIcon />} icon={<PlusIcon />}
size="xs" size="xs"
shadow="md" shadow="md"
colorScheme="blue" colorScheme="gray"
onClick={handlePlusClick} onClick={handlePlusClick}
/> />
</Fade> </Fade>

View File

@@ -30,6 +30,9 @@ export const ItemNodesList = ({
(draggedItem && mouseOverBlock?.id === blockId) ?? false (draggedItem && mouseOverBlock?.id === blockId) ?? false
const showPlaceholders = draggedItem && !isReadOnly const showPlaceholders = draggedItem && !isReadOnly
const isLastStep =
typebot?.blocks[blockIndex].steps[stepIndex + 1] === undefined
const [position, setPosition] = useState({ const [position, setPosition] = useState({
x: 0, x: 0,
y: 0, y: 0,
@@ -148,7 +151,7 @@ export const ItemNodesList = ({
/> />
</Stack> </Stack>
))} ))}
<Stack> {isLastStep && (
<Flex <Flex
px="4" px="4"
py="2" py="2"
@@ -167,10 +170,10 @@ export const ItemNodesList = ({
stepId: step.id, stepId: step.id,
}} }}
pos="absolute" pos="absolute"
right="15px" right="-49px"
/> />
</Flex> </Flex>
</Stack> )}
{draggedItem && draggedItem.stepId === step.id && ( {draggedItem && draggedItem.stepId === step.id && (
<Portal> <Portal>

View File

@@ -171,12 +171,13 @@ export const StepNode = ({
userSelect="none" userSelect="none"
p="3" p="3"
borderWidth="1px" borderWidth="1px"
borderColor={isConnecting || isOpened ? 'blue.400' : 'gray.300'} borderColor={isConnecting || isOpened ? 'blue.400' : 'gray.200'}
rounded="lg" rounded="lg"
cursor={'pointer'} cursor={'pointer'}
bgColor="white" bgColor="gray.50"
align="flex-start" align="flex-start"
w="full" w="full"
transition="border-color 0.2s"
> >
<StepIcon <StepIcon
type={step.type} type={step.type}
@@ -197,8 +198,8 @@ export const StepNode = ({
stepId: step.id, stepId: step.id,
}} }}
pos="absolute" pos="absolute"
right="15px" right="-34px"
bottom="18px" bottom="10px"
/> />
)} )}
</HStack> </HStack>

View File

@@ -103,7 +103,7 @@ export const TextBubbleEditor = ({ initialValue, onClose }: Props) => {
flex="1" flex="1"
ref={textEditorRef} ref={textEditorRef}
borderWidth="2px" borderWidth="2px"
borderColor="blue.500" borderColor="blue.400"
rounded="md" rounded="md"
onMouseDown={handleMouseDown} onMouseDown={handleMouseDown}
pos="relative" pos="relative"

View File

@@ -14,7 +14,15 @@ export const Board = () => {
const { rightPanel } = useEditor() const { rightPanel } = useEditor()
return ( return (
<Flex flex="1" pos="relative" bgColor="gray.50" h="full"> <Flex
flex="1"
pos="relative"
h="full"
background="#f4f5f8"
backgroundImage="radial-gradient(#c6d0e1 1px, transparent 0)"
backgroundSize="40px 40px"
backgroundPosition="-19px -19px"
>
<GraphDndContext> <GraphDndContext>
<StepsSideBar /> <StepsSideBar />
<GraphProvider blocks={typebot?.blocks ?? []} isReadOnly={isReadOnly}> <GraphProvider blocks={typebot?.blocks ?? []} isReadOnly={isReadOnly}>

View File

@@ -5,7 +5,7 @@ const fonts = {
body: 'Open Sans', body: 'Open Sans',
} }
const colors = { export const colors = {
gray: { gray: {
50: '#F9FAFB', 50: '#F9FAFB',
100: '#F3F4F6', 100: '#F3F4F6',

View File

@@ -2,7 +2,7 @@ import React from 'react'
import { AppProps } from 'next/app' import { AppProps } from 'next/app'
import { SessionProvider } from 'next-auth/react' import { SessionProvider } from 'next-auth/react'
import { ChakraProvider } from '@chakra-ui/react' import { ChakraProvider } from '@chakra-ui/react'
import { customTheme } from 'libs/chakra' import { customTheme } from 'libs/theme'
import { useRouterProgressBar } from 'libs/routerProgressBar' import { useRouterProgressBar } from 'libs/routerProgressBar'
import 'assets/styles/routerProgressBar.css' import 'assets/styles/routerProgressBar.css'
import 'assets/styles/plate.css' import 'assets/styles/plate.css'

View File

@@ -9,6 +9,8 @@ import {
} from 'contexts/GraphContext' } from 'contexts/GraphContext'
import { roundCorners } from 'svg-round-corners' import { roundCorners } from 'svg-round-corners'
const roundSize = 20
export const computeDropOffPath = ( export const computeDropOffPath = (
sourcePosition: Coordinates, sourcePosition: Coordinates,
sourceTop: number sourceTop: number
@@ -18,7 +20,10 @@ export const computeDropOffPath = (
x: sourceCoord.x + 20, x: sourceCoord.x + 20,
y: sourceCoord.y + 80, y: sourceCoord.y + 80,
}) })
return roundCorners(`M${sourceCoord.x},${sourceCoord.y} ${segments}`, 10).path return roundCorners(
`M${sourceCoord.x},${sourceCoord.y} ${segments}`,
roundSize
).path
} }
export const computeSourceCoordinates = ( export const computeSourceCoordinates = (
@@ -222,7 +227,7 @@ export const computeEdgePath = ({
}) })
return roundCorners( return roundCorners(
`M${sourcePosition.x},${sourcePosition.y} ${segments}`, `M${sourcePosition.x},${sourcePosition.y} ${segments}`,
10 roundSize
).path ).path
} }
@@ -268,7 +273,7 @@ export const computeEdgePathToMouse = ({
) )
return roundCorners( return roundCorners(
`M${sourcePosition.x},${sourcePosition.y} ${segments}`, `M${sourcePosition.x},${sourcePosition.y} ${segments}`,
10 roundSize
).path ).path
} }
@@ -280,7 +285,7 @@ export const getEndpointTopOffset = (
if (!endpointId) return if (!endpointId) return
const endpointRef = endpoints[endpointId]?.ref const endpointRef = endpoints[endpointId]?.ref
if (!endpointRef?.current) return if (!endpointRef?.current) return
const endpointHeight = 18 const endpointHeight = 28
return ( return (
endpointRef.current.getBoundingClientRect().top + endpointRef.current.getBoundingClientRect().top +
endpointHeight / 2 - endpointHeight / 2 -