Skip to content

Commit

Permalink
🚸 (bubble) Add swipe gesture to close preview…
Browse files Browse the repository at this point in the history
Closes #1388
  • Loading branch information
baptisteArno committed Mar 26, 2024
1 parent 798e94a commit 1f158e7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.2.56",
"version": "0.2.57",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ const defaultTextColor = '#303235'
export const PreviewMessage = (props: PreviewMessageProps) => {
const [isPreviewMessageHovered, setIsPreviewMessageHovered] =
createSignal(false)
const [touchStartPosition, setTouchStartPosition] = createSignal({
x: 0,
y: 0,
})

const handleTouchStart = (e: TouchEvent) => {
setTouchStartPosition({ x: e.touches[0].clientX, y: e.touches[0].clientY })
}

const handleTouchEnd = (e: TouchEvent) => {
const x = e.changedTouches[0].clientX
const y = e.changedTouches[0].clientY

if (
Math.abs(x - touchStartPosition().x) > 10 ||
y - touchStartPosition().y > 10
)
props.onCloseClick()

setTouchStartPosition({ x: 0, y: 0 })
}

return (
<div
Expand All @@ -38,6 +59,8 @@ export const PreviewMessage = (props: PreviewMessageProps) => {
}}
onMouseEnter={() => setIsPreviewMessageHovered(true)}
onMouseLeave={() => setIsPreviewMessageHovered(false)}
onTouchStart={handleTouchStart}
onTouchEnd={handleTouchEnd}
>
<CloseButton
isHovered={isPreviewMessageHovered()}
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.2.56",
"version": "0.2.57",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.2.56",
"version": "0.2.57",
"description": "Convenient library to display typebots on your React app",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 1f158e7

Please sign in to comment.