Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

feat: add animations to proactive messages (COR-4271) #471

Closed
wants to merge 2 commits into from
Closed
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
33 changes: 33 additions & 0 deletions apps/documentation/src/pages/ProactiveMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useState } from 'react';

const inputStyle = {
border: 'solid 1px black',
borderRadius: '4px',
padding: '2px',
};

const sendButtonStyle = {
background: '#e8e8e8',
borderRadius: '4px',
padding: '4px 8px',
marginLeft: '4px',
};

export default function ProactiveMessage() {
const [message, setMessage] = useState('');

const send = () => {
(window as any).voiceflow.chat.proactive.push({ type: 'text', payload: { message } });
setMessage('');
};

return (
<div>
Add proactive message:
<input type="text" style={inputStyle} value={message} onChange={(e) => setMessage(e.target.value)} />
<button type="button" style={sendButtonStyle} onClick={send}>
Send
</button>
</div>
);
}
13 changes: 8 additions & 5 deletions apps/documentation/src/pages/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'regenerator-runtime/runtime';

import { ChatScript } from '@/components/ChatScript';

import ProactiveMessage from './ProactiveMessage';

export const getServerSideProps = async (context: any) => ({
// will be passed to the page component as props
props: {
Expand All @@ -13,12 +15,13 @@ export const getServerSideProps = async (context: any) => ({
export default function ChatPage(props: any) {
return (
<>
<div style={{ position: 'relative' }}>
You can switch projects by changing the URL `projectID=...`
{props.projectID && <ChatScript {...props} />}
</div>

<div style={{ height: '100vh', padding: '30px' }}>
<div style={{ position: 'relative' }}>
You can switch projects by changing the URL `projectID=...`
{props.projectID && <ChatScript {...props} />}
</div>
<ProactiveMessage />

<div style={{ width: '600px', height: '100%', margin: '0 auto' }} id="chat_embed"></div>
</div>
</>
Expand Down
22 changes: 17 additions & 5 deletions packages/chat/src/components/Proactive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ import { useEffect, useMemo, useState } from 'react';
import { match } from 'ts-pattern';

import { ClassName } from '@/constants';
import { fadeInAndUp } from '@/styles/animation-utils.css';

import { Button } from '../Button';
import { Icon } from '../Icon';
import { closeButton, closeButtonIcon, messageContainer, proactiveContainer, singleMessage } from './styles.css';
import {
closeButton,
closeButtonIcon,
closed,
messageContainer,
proactiveContainer,
singleMessage,
} from './styles.css';

interface ProactiveQueueProps {
side: WidgetSettingsWidgetPosition;
Expand All @@ -23,7 +31,7 @@ export const Proactive: React.FC<ProactiveQueueProps> = ({ side, messages }) =>
messages.map((message, index) =>
match(message)
.with({ type: Trace.TraceType.TEXT }, ({ payload }) => (
<div className={singleMessage} key={index}>
<div className={clsx(singleMessage, fadeInAndUp)} key={index}>
{String(payload.message)}
</div>
))
Expand All @@ -37,11 +45,15 @@ export const Proactive: React.FC<ProactiveQueueProps> = ({ side, messages }) =>
setIsClosed(false);
}, [queue]);

if (isClosed || !queue.length) return null;
const close = () => {
setIsClosed(true);
};

if (!queue.length) return null;

return (
<div className={clsx(ClassName.PROACTIVE, proactiveContainer({ side }))}>
<Button round className={closeButton} onClick={() => setIsClosed(true)}>
<div className={clsx(ClassName.PROACTIVE, proactiveContainer({ side }), isClosed && closed)}>
<Button round className={closeButton} onClick={() => close()}>
<Icon className={closeButtonIcon} svg="closeV2" />
</Button>
<div className={messageContainer}>{queue}</div>
Expand Down
8 changes: 8 additions & 0 deletions packages/chat/src/components/Proactive/styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const proactiveContainer = recipe({
width: 256,
display: 'flex',
flexDirection: 'column',
transition: transition(['opacity']),
},

variants: {
Expand Down Expand Up @@ -40,6 +41,8 @@ export const singleMessage = style({
fontSize: 14,
lineHeight: '20px',
fontFamily: THEME.fontFamily,
opacity: 0,
transition: transition(['opacity']),
});

export const messageContainer = style({
Expand Down Expand Up @@ -82,3 +85,8 @@ export const closeButtonIcon = style({
height: 10,
marginBottom: 2,
});

export const closed = style({
opacity: 0,
pointerEvents: 'none',
});
Loading