Skip to content

Commit

Permalink
feat: expose chat container
Browse files Browse the repository at this point in the history
  • Loading branch information
sofly committed Nov 25, 2024
1 parent 881c88e commit 6fe41cb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@vanilla-extract/css": "1.15.5",
"@vanilla-extract/recipes": "0.5.5",
"@voiceflow/base-types": "2.113.1",
"@voiceflow/dtos-interact": "1.1.0",
"@voiceflow/dtos-interact": "1.9.0",
"@voiceflow/sdk-runtime": "workspace:*",
"@voiceflow/slate-serializer": "1.5.5",
"@voiceflow/voiceflow-types": "3.32.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { assignInlineVars } from '@vanilla-extract/dynamic';
import type { WidgetSettingsColorPalette } from '@voiceflow/dtos-interact';

import { PALETTE } from '@/styles/colors.css';

import { chatWindowStyle } from './ChatContainer.css';

export interface IChatContainer {
palette: WidgetSettingsColorPalette;
children?: React.ReactNode;
isMobile?: boolean;
}

export const ChatContainer: React.FC<IChatContainer> = ({ palette, children, isMobile = false }) => {
return (
<div style={assignInlineVars(PALETTE, { colors: palette })} className={chatWindowStyle({ mobile: isMobile })}>
{children}
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { recipe } from '@vanilla-extract/recipes';

export const chatWindow = recipe({
export const chatWindowStyle = recipe({
base: {
height: '100%',
maxHeight: '800px',
Expand Down
7 changes: 6 additions & 1 deletion packages/chat/src/components/NewChat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { type INewFooter, NewFooter } from '../NewFooter';
import { Prompt } from '../Prompt';
import { Separator } from '../Separator';
import { type IWelcomeMessage, WelcomeMessage } from '../WelcomeMessage';
import { ChatContainer } from './ChatContainer/ChatContainer.component';
import { bottomSpacer, chatContainer, chatEndedContainer, dialogContainer } from './NewChat.css';

export interface INewChat
Expand Down Expand Up @@ -56,7 +57,7 @@ export interface INewChat
onStart?: (() => Promise<void>) | undefined;
}

export const NewChat: React.FC<INewChat> = ({
const Chat: React.FC<INewChat> = ({
buttons,
showPoweredBy,
messageInputProps,
Expand Down Expand Up @@ -138,3 +139,7 @@ export const NewChat: React.FC<INewChat> = ({
</div>
);
};

export const NewChat = Object.assign(Chat, {
Container: ChatContainer,
});
8 changes: 2 additions & 6 deletions packages/chat/src/views/ChatWindow/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import '../../styles.css';

import { assignInlineVars } from '@vanilla-extract/dynamic';
import React, { useCallback, useContext } from 'react';
import * as R from 'remeda';
import { match } from 'ts-pattern';
Expand All @@ -11,12 +10,9 @@ import { UserResponse } from '@/components/UserResponse';
import { RuntimeStateAPIContext, RuntimeStateContext } from '@/contexts/RuntimeContext';
import type { FeedbackName } from '@/contexts/RuntimeContext/useRuntimeAPI';
import { usePalette } from '@/hooks/usePalette';
import { PALETTE } from '@/styles/colors.css';
import type { UserTurnProps } from '@/types';
import { SessionStatus, TurnType } from '@/types';

import { chatWindow } from './styles.css';

export interface ChatWindowProps {
className?: string;
isMobile?: boolean;
Expand Down Expand Up @@ -45,7 +41,7 @@ export const ChatWindow: React.FC<ChatWindowProps> = ({ isMobile }) => {
if (!palette) return null;

return (
<div style={assignInlineVars(PALETTE, { colors: palette })} className={chatWindow({ mobile: isMobile })}>
<NewChat.Container isMobile={isMobile} palette={palette}>
<NewChat
title={assistant.title}
description={assistant.description}
Expand Down Expand Up @@ -94,6 +90,6 @@ export const ChatWindow: React.FC<ChatWindowProps> = ({ isMobile }) => {
})}
{state.indicator && <Indicator avatar={assistant.avatar} isLast={true} />}
</NewChat>
</div>
</NewChat.Container>
);
};
11 changes: 10 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7480,6 +7480,15 @@ __metadata:
languageName: node
linkType: hard

"@voiceflow/dtos-interact@npm:1.9.0":
version: 1.9.0
resolution: "@voiceflow/dtos-interact@npm:1.9.0"
peerDependencies:
zod: ^3
checksum: 676a4d808f5f1191703fdc4b27f0d059774141bf9a4c2294bac16c25786fd2efd0e5a15c9637ae807ee2764db3be6a14c259e686b03beac04df341aee2795694
languageName: node
linkType: hard

"@voiceflow/eslint-config@npm:7.5.0":
version: 7.5.0
resolution: "@voiceflow/eslint-config@npm:7.5.0"
Expand Down Expand Up @@ -7651,7 +7660,7 @@ __metadata:
"@vanilla-extract/vite-plugin": 4.0.15
"@vitejs/plugin-react": 4.2.1
"@voiceflow/base-types": 2.113.1
"@voiceflow/dtos-interact": 1.1.0
"@voiceflow/dtos-interact": 1.9.0
"@voiceflow/sdk-runtime": "workspace:*"
"@voiceflow/slate-serializer": 1.5.5
"@voiceflow/test-common": 1.10.3
Expand Down

0 comments on commit 6fe41cb

Please sign in to comment.