onChange(e.target.innerText)}
- />
+ >
+
onChange(e.target.innerText)}
+ />
+
)
}
diff --git a/src/bubble.css b/src/bubble.css
index 17792ea..c6d24f4 100644
--- a/src/bubble.css
+++ b/src/bubble.css
@@ -1,20 +1,25 @@
.bubble {
+ max-width: 600px;
+}
+
+.bubble-content {
+ max-width: 600px;
+ display: inline-block;
border-radius: 30px;
padding: 12px 20px;
margin-top: 5px;
margin-bottom: 5px;
- display: inline-block;
- max-width: 600px;
+ hyphens: auto;
}
-.bubble {
+.bubble-content {
margin-right: 25%;
background-color: #eee;
position: relative;
}
-.bubble:last-child:before,
-.bubble:nth-last-child(2):before {
+.bubble:last-child .bubble-content:before,
+.bubble:nth-last-child(2) .bubble-content:before {
content: '';
position: absolute;
z-index: 0;
@@ -26,8 +31,8 @@
border-bottom-right-radius: 20px;
}
-.bubble:last-child:after,
-.bubble:nth-last-child(2):after {
+.bubble:last-child .bubble-content:after,
+.bubble:nth-last-child(2) .bubble-content:after {
content: '';
position: absolute;
z-index: 1;
diff --git a/src/bubble.jsx b/src/bubble.jsx
index 4ee286c..3ae2c5e 100644
--- a/src/bubble.jsx
+++ b/src/bubble.jsx
@@ -1,17 +1,38 @@
import React from 'react'
-import { motion } from 'framer-motion'
+import { motion, usePresence } from 'framer-motion'
import './bubble.css'
-const Bubble = ({ id, children, sender }) => {
+const transition = {
+ type: 'spring',
+ stiffness: 500,
+ damping: 50,
+ default: {
+ duration: 1
+ }
+}
+
+const Bubble = ({ id, children, sender, dy }) => {
+ const [isPresent, safeToRemove] = usePresence()
+
+ const animations = {
+ layout: true,
+ initial: 'out',
+ style: {
+ position: 'static'
+ },
+ animate: 'in',
+ variants: {
+ in: { opacity: 1, translateY: 0 },
+ out: { opacity: 1, translateY: `${dy}px` }
+ },
+ exit: { opacity: 0, translateY: 0 },
+ onAnimationComplete: () => !isPresent && safeToRemove(),
+ transition
+ }
+
return (
-
- {children}
+
+ {children}
)
}
diff --git a/src/chat.css b/src/chat.css
index 71fbd51..f39d36e 100644
--- a/src/chat.css
+++ b/src/chat.css
@@ -7,4 +7,5 @@
align-items: flex-start;
font-size: 32px;
+ position: relative;
}