Skip to content

Commit

Permalink
Updated custom comp in samples
Browse files Browse the repository at this point in the history
  • Loading branch information
salmenus committed May 15, 2024
1 parent 93ee88d commit fd7017e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/react/core/src/exports/messageOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type ResponseComponentProps<AiMsg> = {
uid: string;
status: 'streaming' | 'complete';
response?: AiMsg;
containerRef: RefObject<unknown>;
containerRef: RefObject<never>;
};

export type ResponseComponent<AiMsg> = FunctionComponent<ResponseComponentProps<AiMsg>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const createMessageRenderer: <AiMsg>(
status,
// We only pass the response to custom renderer when the status is 'complete'.
response: status === 'complete' ? message as AiMsg : undefined,
containerRef: containerRefToUse,
containerRef: containerRefToUse as RefObject<never>,
});
}

Expand Down
25 changes: 23 additions & 2 deletions samples/aiChat/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,31 @@ function App() {
syntaxHighlighter: highlighter,
// showCodeBlockCopyButton: false,
// streamingAnimationSpeed: 100,
responseComponent: ({response}) => {
promptComponent: ({prompt}) => {
return (
<div>
<div>{response}</div>
<div>{prompt}</div>
<div style={{
backgroundColor: 'lightgreen',
padding: 10,
borderRadius: 10,
marginTop: 10,
fontSize: '0.8em',
textAlign: 'center',
}}>Custom Prompt Component
</div>
</div>
);
},
responseComponent: ({
response,
status,
containerRef,
}) => {
console.log(status);
return (
<div>
{response ? <div>{response}</div> : <div ref={containerRef}/>}
<div style={{
backgroundColor: 'lightblue',
padding: 10,
Expand Down
4 changes: 3 additions & 1 deletion samples/components/react/src/comp/AiChatReactExpo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ type MessageObjectType = {txt: string, color: string, bg: string};
const possibleColors = ['red', 'green', 'blue', 'yellow', 'purple'];
const possibleBackgrounds = ['white', 'black', 'gray', 'lightgray', 'darkgray'];

const CustomMessageComponent: FunctionComponent<ResponseComponentProps<MessageObjectType>> = (
const CustomMessageComponent: FunctionComponent<
ResponseComponentProps<MessageObjectType>
> = (
{response},
) => {
const color = useMemo(() => possibleColors[Math.floor(Math.random() * possibleColors.length)], []);
Expand Down

0 comments on commit fd7017e

Please sign in to comment.