Skip to content

Commit

Permalink
feat(editor): 💄 UI bump
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 31, 2022
1 parent c7d5373 commit 7f5d2f4
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 48 deletions.
4 changes: 2 additions & 2 deletions apps/builder/components/editor/StepsSideBar/StepCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export const StepCard = ({
<Flex pos="relative">
<HStack
borderWidth="1px"
borderColor="gray.200"
rounded="lg"
flex="1"
cursor={'grab'}
opacity={isMouseDown ? '0.4' : '1'}
onMouseDown={handleMouseDown}
bgColor="white"
shadow="sm"
bgColor="gray.50"
px="4"
py="2"
_hover={{ shadow: 'md' }}
Expand Down
16 changes: 8 additions & 8 deletions apps/builder/components/editor/StepsSideBar/StepSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ export const StepsSideBar = () => {

return (
<Flex
w="340px"
w="360px"
pos="absolute"
left="0"
h={`calc(100vh - ${headerHeight}px)`}
zIndex="2"
pl="4"
py="4"
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"
>
<Stack
Expand All @@ -92,8 +92,8 @@ export const StepsSideBar = () => {
borderWidth="1px"
pt="2"
pb="10"
px="2"
bgColor="gray.50"
px="4"
bgColor="white"
spacing={6}
userSelect="none"
overflowY="scroll"
Expand All @@ -115,7 +115,7 @@ export const StepsSideBar = () => {
<Text fontSize="sm" fontWeight="semibold" color="gray.600">
Bubbles
</Text>
<SimpleGrid columns={2} spacing="2">
<SimpleGrid columns={2} spacing="3">
{Object.values(BubbleStepType).map((type) => (
<StepCard key={type} type={type} onMouseDown={handleMouseDown} />
))}
Expand All @@ -126,7 +126,7 @@ export const StepsSideBar = () => {
<Text fontSize="sm" fontWeight="semibold" color="gray.600">
Inputs
</Text>
<SimpleGrid columns={2} spacing="2">
<SimpleGrid columns={2} spacing="3">
{Object.values(InputStepType).map((type) => (
<StepCard key={type} type={type} onMouseDown={handleMouseDown} />
))}
Expand All @@ -137,7 +137,7 @@ export const StepsSideBar = () => {
<Text fontSize="sm" fontWeight="semibold" color="gray.600">
Logic
</Text>
<SimpleGrid columns={2} spacing="2">
<SimpleGrid columns={2} spacing="3">
{Object.values(LogicStepType).map((type) => (
<StepCard key={type} type={type} onMouseDown={handleMouseDown} />
))}
Expand All @@ -148,7 +148,7 @@ export const StepsSideBar = () => {
<Text fontSize="sm" fontWeight="semibold" color="gray.600">
Integrations
</Text>
<SimpleGrid columns={2} spacing="2">
<SimpleGrid columns={2} spacing="3">
{Object.values(IntegrationStepType).map((type) => (
<StepCard key={type} type={type} onMouseDown={handleMouseDown} />
))}
Expand Down
3 changes: 2 additions & 1 deletion apps/builder/components/shared/Graph/Edges/DrawingEdge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEventListener } from '@chakra-ui/hooks'
import assert from 'assert'
import { useGraph, ConnectingIds } from 'contexts/GraphContext'
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
import { colors } from 'libs/theme'
import React, { useMemo, useState } from 'react'
import {
computeConnectingEdgePath,
Expand Down Expand Up @@ -91,7 +92,7 @@ export const DrawingEdge = () => {
return (
<path
d={path}
stroke="#1a5fff"
stroke={colors.blue[400]}
strokeWidth="2px"
markerEnd="url(#blue-arrow)"
fill="none"
Expand Down
3 changes: 2 additions & 1 deletion apps/builder/components/shared/Graph/Edges/Edge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Edge as EdgeProps } from 'models'
import { Portal, useDisclosure } from '@chakra-ui/react'
import { useTypebot } from 'contexts/TypebotContext'
import { EdgeMenu } from './EdgeMenu'
import { colors } from 'libs/theme'

export type AnchorsPositionProps = {
sourcePosition: Coordinates
Expand Down Expand Up @@ -124,7 +125,7 @@ export const Edge = ({ edge }: { edge: EdgeProps }) => {
<path
data-testid="edge"
d={path}
stroke={isPreviewing ? '#1a5fff' : '#718096'}
stroke={isPreviewing ? colors.blue[400] : colors.gray[400]}
strokeWidth="2px"
markerEnd={isPreviewing ? 'url(#blue-arrow)' : 'url(#arrow)'}
fill="none"
Expand Down
5 changes: 3 additions & 2 deletions apps/builder/components/shared/Graph/Edges/Edges.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { chakra } from '@chakra-ui/system'
import { colors } from 'libs/theme'
import { Edge as EdgeProps } from 'models'
import React from 'react'
import { AnswersCount } from 'services/analytics'
Expand Down Expand Up @@ -51,7 +52,7 @@ export const Edges = ({
>
<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"
fill="#718096"
fill={colors.gray[400]}
/>
</marker>
<marker
Expand All @@ -66,7 +67,7 @@ export const Edges = ({
>
<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"
fill="#1a5fff"
fill={colors.blue[400]}
/>
</marker>
<marker
Expand Down
35 changes: 28 additions & 7 deletions apps/builder/components/shared/Graph/Endpoints/SourceEndpoint.tsx
Original file line number Diff line number Diff line change
@@ -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 { Source } from 'models'
import React, { MouseEvent, useEffect, useRef, useState } from 'react'
Expand All @@ -10,7 +10,12 @@ export const SourceEndpoint = ({
source: Source
}) => {
const [ranOnce, setRanOnce] = useState(false)
const { setConnectingIds, addSourceEndpoint, blocksCoordinates } = useGraph()
const {
setConnectingIds,
addSourceEndpoint,
blocksCoordinates,
previewingEdge,
} = useGraph()
const ref = useRef<HTMLDivElement | null>(null)

const handleMouseDown = (e: MouseEvent<HTMLDivElement>) => {
Expand All @@ -35,19 +40,35 @@ export const SourceEndpoint = ({
<Flex
ref={ref}
data-testid="endpoint"
boxSize="18px"
boxSize="32px"
rounded="full"
onMouseDownCapture={handleMouseDown}
cursor="copy"
borderWidth="1px"
borderColor="gray.400"
bgColor="white"
justify="center"
align="center"
pointerEvents="all"
{...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>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,11 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
ref={setMultipleRefs([ref, blockRef])}
data-testid="block"
p="4"
rounded="lg"
bgColor="blue.50"
backgroundImage="linear-gradient(rgb(235, 239, 244), rgb(231, 234, 241))"
rounded="xl"
bgColor="#ffffff"
borderWidth="2px"
borderColor={
isConnecting || isOpened || isPreviewing ? 'blue.400' : 'white'
isConnecting || isOpened || isPreviewing ? 'blue.400' : '#ffffff'
}
w="300px"
transition="border 300ms, box-shadow 200ms"
Expand All @@ -134,7 +133,7 @@ export const BlockNode = ({ block, blockIndex }: Props) => {
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
cursor={isMouseDown ? 'grabbing' : 'pointer'}
boxShadow="0px 0px 0px 1px #e9edf3;"
shadow="md"
_hover={{ shadow: 'lg' }}
zIndex={focusedBlockId === block.id ? 10 : 1}
>
Expand Down
20 changes: 16 additions & 4 deletions apps/builder/components/shared/Graph/Nodes/ItemNode/ItemNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { ContextMenu } from 'components/shared/ContextMenu'
import { Coordinates } from 'contexts/GraphContext'
import { NodePosition, useDragDistance } from 'contexts/GraphDndContext'
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 { setMultipleRefs } from 'services/utils'
import { SourceEndpoint } from '../../Endpoints/SourceEndpoint'
Expand Down Expand Up @@ -31,6 +37,11 @@ export const ItemNode = ({
const { typebot } = useTypebot()
const [isMouseOver, setIsMouseOver] = useState(false)
const itemRef = useRef<HTMLDivElement | null>(null)
const isConnectable = !(
typebot?.blocks[indices.blockIndex].steps[
indices.stepIndex
] as ChoiceInputStep
)?.options?.isMultipleChoice
const onDrag = (position: NodePosition) => {
if (!onMouseDown || item.type !== ItemType.BUTTON) return
onMouseDown(position, item)
Expand Down Expand Up @@ -61,8 +72,9 @@ export const ItemNode = ({
transition="box-shadow 200ms"
borderWidth="1px"
rounded="md"
borderColor={isOpened ? 'blue.400' : 'gray.300'}
borderColor={isOpened ? 'blue.400' : 'gray.100'}
pointerEvents={isReadOnly ? 'none' : 'all'}
bgColor="white"
w="full"
>
<ItemNodeContent
Expand All @@ -71,15 +83,15 @@ export const ItemNode = ({
indices={indices}
isLastItem={isLastItem}
/>
{typebot && (
{typebot && isConnectable && (
<SourceEndpoint
source={{
blockId: typebot.blocks[indices.blockIndex].id,
stepId: item.stepId,
itemId: item.id,
}}
pos="absolute"
right="15px"
right="-49px"
pointerEvents="all"
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const ButtonNodeContent = ({
}

return (
<Flex px={4} py={2} justify="center" w="90%">
<Flex px={4} py={2} justify="center" w="90%" pos="relative">
<Editable
ref={editableRef}
flex="1"
Expand All @@ -82,15 +82,20 @@ export const ButtonNodeContent = ({
</Editable>
<Fade
in={isMouseOver}
style={{ position: 'absolute', bottom: '-15px', zIndex: 3 }}
style={{
position: 'absolute',
bottom: '-15px',
zIndex: 3,
left: '90px',
}}
unmountOnExit
>
<IconButton
aria-label="Add item"
icon={<PlusIcon />}
size="xs"
shadow="md"
colorScheme="blue"
colorScheme="gray"
onClick={handlePlusClick}
/>
</Fade>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export const ItemNodesList = ({
(draggedItem && mouseOverBlock?.id === blockId) ?? false
const showPlaceholders = draggedItem && !isReadOnly

const isLastStep =
typebot?.blocks[blockIndex].steps[stepIndex + 1] === undefined

const [position, setPosition] = useState({
x: 0,
y: 0,
Expand Down Expand Up @@ -148,7 +151,7 @@ export const ItemNodesList = ({
/>
</Stack>
))}
<Stack>
{isLastStep && (
<Flex
px="4"
py="2"
Expand All @@ -167,10 +170,10 @@ export const ItemNodesList = ({
stepId: step.id,
}}
pos="absolute"
right="15px"
right="-49px"
/>
</Flex>
</Stack>
)}

{draggedItem && draggedItem.stepId === step.id && (
<Portal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,13 @@ export const StepNode = ({
userSelect="none"
p="3"
borderWidth="1px"
borderColor={isConnecting || isOpened ? 'blue.400' : 'gray.300'}
borderColor={isConnecting || isOpened ? 'blue.400' : 'gray.200'}
rounded="lg"
cursor={'pointer'}
bgColor="white"
bgColor="gray.50"
align="flex-start"
w="full"
transition="border-color 0.2s"
>
<StepIcon
type={step.type}
Expand All @@ -197,8 +198,8 @@ export const StepNode = ({
stepId: step.id,
}}
pos="absolute"
right="15px"
bottom="18px"
right="-34px"
bottom="10px"
/>
)}
</HStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const TextBubbleEditor = ({ initialValue, onClose }: Props) => {
flex="1"
ref={textEditorRef}
borderWidth="2px"
borderColor="blue.500"
borderColor="blue.400"
rounded="md"
onMouseDown={handleMouseDown}
pos="relative"
Expand Down
10 changes: 9 additions & 1 deletion apps/builder/layouts/editor/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ export const Board = () => {
const { rightPanel } = useEditor()

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>
<StepsSideBar />
<GraphProvider blocks={typebot?.blocks ?? []} isReadOnly={isReadOnly}>
Expand Down
Loading

3 comments on commit 7f5d2f4

@vercel
Copy link

@vercel vercel bot commented on 7f5d2f4 Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 7f5d2f4 Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 7f5d2f4 Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

app.typebot.io
builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app

Please sign in to comment.