Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animate messages and FAQs #26

Merged
merged 1 commit into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/components/GreetingCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default function GreetingCard() {
const animCardStyle = useSpring({
from: { opacity: 0, width: '50%', transform: 'translate3d(0, 300px, 0)' },
to: { opacity: 1, width: '70%', transform: 'translate3d(0, 0px, 0)' },

});

const animTitleStyle = useSpring({
Expand All @@ -21,7 +20,7 @@ export default function GreetingCard() {
});

const animDescStyle = useSpring({
from: { opacity: 0, fontSize: '5px' },
from: { opacity: 0, fontSize: '8px' },
to: { opacity: 1, fontSize: '16px' },
});

Expand Down
18 changes: 15 additions & 3 deletions src/components/MessageBubble.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @jsxImportSource @emotion/react */
import { css } from "@emotion/react";
import { ThumbsUp, ThumbsDown } from "react-feather";
import { useSpring, animated } from '@react-spring/web';

export default function MessageBubble({
text,
Expand All @@ -9,6 +10,16 @@ export default function MessageBubble({
onFeedbackGiven,
timestamp,
}) {
const animWrapperStyle = useSpring({
from: { opacity: 0 },
to: { opacity: 1 },
});

const animTextStyle = useSpring({
from: { opacity: 0, fontSize: '5px' },
to: { opacity: 1, fontSize: '20px' },
});

const messageCss = (theme) =>
css`
display: inline-block;
Expand All @@ -23,6 +34,7 @@ export default function MessageBubble({
border-color: ${alignLeft && "transparent"};
margin-right: ${showFeedback ? "20px" : 0};
`;

const messageWrapperCss = css`
width: max-content;
max-width: 70%;
Expand Down Expand Up @@ -54,8 +66,8 @@ export default function MessageBubble({
`;

return (
<div css={messageWrapperCss}>
<p css={messageCss}>{text}</p>
<animated.div style={animWrapperStyle} css={messageWrapperCss}>
<animated.p style={animTextStyle} css={messageCss}>{text}</animated.p>
{showFeedback && (
<>
<ThumbsDown
Expand All @@ -68,6 +80,6 @@ export default function MessageBubble({
/>
</>
)}
</div>
</animated.div>
);
}
28 changes: 19 additions & 9 deletions src/components/SuggestedOptions.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
/** @jsxImportSource @emotion/react */
import { css } from "@emotion/react";
import { useSpring, useTrail, animated } from '@react-spring/web';
import suggestions from "./suggestions";

export default function SuggestedOptions({ onSend, onSuggestionClick }) {
const trail = useTrail(suggestions.length, {
from: { opacity: 0 },
to: { opacity: 1 },
});

const animContactStyle = useSpring({
from: { opacity: 0},
to: { opacity: 1},
});

const contactText =
"Please send feedback and comments to [email protected]";

Expand Down Expand Up @@ -58,18 +69,17 @@ export default function SuggestedOptions({ onSend, onSuggestionClick }) {
return (
<div css={suggestedOptionsStyle}>
<ul css={suggestionListStyle}>
{suggestions.map((suggestion) => (
<li
{trail.map(({ opacity }, index) => (
<animated.li
style={{ opacity }}
css={suggestionBubbleStyle}
key={suggestion}
onClick={() => sendMessage(suggestion)}
>
{suggestion}
</li>
))}
key={suggestions[index]}
onClick={() => sendMessage(suggestions[index])}
>{suggestions[index]}
</animated.li>))}
</ul>

<p css={contactTextStyle}>{contactText}</p>
<animated.p style={animContactStyle} css={contactTextStyle}>{contactText}</animated.p>
</div>
);
}