Skip to content

Commit

Permalink
chore: checkpoint more progress
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSisb committed May 17, 2024
1 parent 5c21b5b commit 6a8f9de
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 58 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Avatar } from "@twilio-paste/avatar";
import type { BoxElementProps } from "@twilio-paste/box";
import { ArtificialIntelligenceIcon } from "@twilio-paste/icons/esm/ArtificialIntelligenceIcon";
import type { ThemeShape } from "@twilio-paste/theme";
import type { HTMLPasteProps } from "@twilio-paste/types";
import * as React from "react";
import { AIChatMessageMeta } from "./AIChatMessageMeta";

export interface AIChatMessageAuthorProps extends HTMLPasteProps<"div"> {
/**
* The name of the author of the chat message
*
* @type {string}
* @memberof AIChatMessageAuthorProps
*/
children: string;
/**
* Overrides the default element name to apply unique styles with the Customization Provider
*
* @default "AI_CHAT_MESSAGE_AUTHOR"
* @type {BoxProps["element"]}
* @memberof AIChatMessageAuthorProps
*/
element?: BoxElementProps["element"];
/**
* Screen reader label for the author
*
* @type {string}
* @memberof AIChatMessageAuthorProps
*/
"aria-label": string;
/**
* Whether the author is a bot or not
*
* @default false
* @type {boolean}
* @memberof AIChatMessageAuthorProps
*/
bot?: boolean;
}

export const AIChatMessageAuthor = React.forwardRef<HTMLDivElement, AIChatMessageAuthorProps>(
({ children, bot = false, element = "AI_CHAT_MESSAGE_AUTHOR", ...props }, ref) => {
return (
<AIChatMessageMeta {...props} ref={ref} aria-label={props["aria-label"]} element={element}>
{bot ? (
<Avatar name={children} size="sizeIcon50" icon={ArtificialIntelligenceIcon} element={`${element}_AVATAR}`} />
) : (
<Avatar name={children} size="sizeIcon50" color="decorative30" element={`${element}_AVATAR}`} />
)}
{children}
</AIChatMessageMeta>
);
},
);

AIChatMessageAuthor.displayName = "AIChatMessageAuthor";
4 changes: 2 additions & 2 deletions packages/paste-core/components/ai-chat-log/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export { AIChatMessageMeta } from "./AIChatMessageMeta";
export type { AIChatMessageMetaProps } from "./AIChatMessageMeta";
export { AIChatMessageBody } from "./AIChatMessageBody";
export type { AIChatMessageBodyProps } from "./AIChatMessageBody";
export { AIChatMessageActions } from "./AIChatMessageActions";
export type { AIChatMessageActionsProps } from "./AIChatMessageActions";
export { AIChatMessageAuthor } from "./AIChatMessageAuthor";
export type { AIChatMessageAuthorProps } from "./AIChatMessageAuthor";
export { AIChatMessageFeedback } from "./AIChatMessageFeedback";
export type { AIChatMessageFeedbackProps } from "./AIChatMessageFeedback";
export { AIChatMessageLoading } from "./AIChatMessageLoading";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type PushAIChat = (chat: PartialIDChat) => void;
type PopAIChat = (id?: string) => void;

export type UseAIChatLogger = (...initialChats: PartialIDChat[]) => {
aiChats: AIChat[];
chats: AIChat[];
push: PushAIChat;
pop: PopAIChat;
clear: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Text } from "@twilio-paste/text";
import {
AIChatLog,
AIChatMessage,
AIChatMessageAuthor,
AIChatMessageBody,
AIChatMessageFeedback,
AIChatMessageLoading,
Expand All @@ -28,22 +29,17 @@ export const StandardUsage = (): React.ReactNode => {
return (
<AIChatLog>
<AIChatMessage>
<AIChatMessageMeta aria-label="You said">
<Avatar name="Gibby Radki" size="sizeIcon50" color="decorative30" />
You
</AIChatMessageMeta>
<AIChatMessageAuthor aria-label="You said at 2:36pm">Gibby Radki</AIChatMessageAuthor>
<AIChatMessageBody variant="default">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Deserunt delectus fuga, necessitatibus eligendi iure
adipisci facilis exercitationem officiis dolorem laborum, ex fugiat quisquam itaque, earum sit nesciunt
impedit repellat assumenda.
</AIChatMessageBody>
</AIChatMessage>

<AIChatMessage>
<AIChatMessageMeta aria-label="AI said">
<Avatar name="AI" size="sizeIcon50" icon={ArtificialIntelligenceIcon} />
AI Bot
</AIChatMessageMeta>
<AIChatMessageAuthor aria-label="AI said" bot>
Good Bot
</AIChatMessageAuthor>
<AIChatMessageBody variant="default">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Deserunt delectus fuga, necessitatibus eligendi iure
adipisci facilis exercitationem officiis dolorem laborum, ex fugiat quisquam itaque, earum sit nesciunt
Expand All @@ -66,24 +62,18 @@ export const StandardUsage = (): React.ReactNode => {
<AIChatMessageFeedback onLike={() => {}} onDislike={() => {}} />
</AIChatMessageMeta>
</AIChatMessage>

<AIChatMessage>
<AIChatMessageMeta aria-label="You said">
<Avatar name="Gibby Radki" size="sizeIcon50" color="decorative30" />
You
</AIChatMessageMeta>
<AIChatMessageAuthor aria-label="You said">Gibby Radki</AIChatMessageAuthor>
<AIChatMessageBody>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Deserunt delectus fuga, necessitatibus eligendi iure
adipisci facilis exercitationem officiis dolorem laborum, ex fugiat quisquam itaque, earum sit nesciunt
impedit repellat assumenda.
</AIChatMessageBody>
</AIChatMessage>

<AIChatMessage>
<AIChatMessageMeta aria-label="AI said">
<Avatar name="AI" size="sizeIcon50" icon={ArtificialIntelligenceIcon} />
AI Bot
</AIChatMessageMeta>
<AIChatMessageAuthor aria-label="AI said" bot>
Good Bot
</AIChatMessageAuthor>
<AIChatMessageBody>
<AIChatMessageLoading onStopLoading={() => {}} />
</AIChatMessageBody>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import type { StoryFn } from "@storybook/react";
import { Box } from "@twilio-paste/box";
import { Button } from "@twilio-paste/button";
import { Input } from "@twilio-paste/input";
import { Label } from "@twilio-paste/label";
import { ListItem, OrderedList } from "@twilio-paste/list";
import { RadioButton, RadioButtonGroup } from "@twilio-paste/radio-button-group";
import { Stack } from "@twilio-paste/stack";
import { useUID } from "@twilio-paste/uid-library";
import * as React from "react";



import { Avatar } from "@twilio-paste/avatar";
import { ButtonGroup } from "@twilio-paste/button-group";
import { ArtificialIntelligenceIcon } from "@twilio-paste/icons/esm/ArtificialIntelligenceIcon";


import {
AIChatLog
AIChatLoggergerger,
AIChatMessage,
AIChatMessageBody,
AIChatMessageFeedback,
AIChatMessageLoading,
AIChatMessageMeta,
useAIChatLogger
} from "../src";


// eslint-disable-next-line import/no-default-export
export default {
title: "Components/AI Chat Log/useAIChatLogger",
};






export const UseChatLogger: StoryFn = () => {
const pushID = useUID();
const popID = useUID();
const messageID = useUID();
const variantId = useUID();

const { chats, push, pop, clear } = useAIChatLogger(
{
content: (
<AIChatMessage>
<AIChatMessageBody>Hi my name is Jane Doe how can I help you?</AIChatMessageBody>
</AIChatMessage>
),
},
{
content: (
<AIChatMessage>
<AIChatMessageBody>I need some help with the Twilio API</AIChatMessageBody>
</AIChatMessage>
),
},
{
content: (
<AIChatMessage>
<AIChatMessageBody>Of course! Can you provide more detail?</AIChatMessageBody>
</AIChatMessage>
),
},
);
console.log(chats, push, pop);

const handlePushSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
e.preventDefault();
const form = e.currentTarget;
const data = new FormData(form);
const message = data.get("message");
const variant = (data.get("variant") || "inbound") as MessageVariants;
const id = data.get("id");

const chat: PartialIDChat = {
variant,
content: (
<AIChatMessage variant={variant}>
<AIChatMessageBody>{message}</AIChatMessageBody>
</AIChatMessage>
),
};

if (id) {
chat.id = id?.toString();
}

push(chat);
form.reset();
};

const handlePopSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
e.preventDefault();
const form = e.currentTarget;
const data = new FormData(form);
const id = data.get("id")?.toString();

pop(id);
form.reset();
};

return (
<Stack orientation="vertical" spacing="space80">
<Box display="flex" columnGap="space80" alignItems="flex-start">
<form onSubmit={handlePushSubmit}>
<Stack orientation="vertical" spacing="space40">
<legend>Push</legend>
<div>
<Label required htmlFor={messageID}>
Message
</Label>
<Input required name="message" id={messageID} type="text" />
</div>
<div>
<Label htmlFor={pushID}>Push ID</Label>
<Input name="id" id={pushID} type="text" />
</div>
<RadioButtonGroup required id={variantId} attached name="variant" legend="variant">
<RadioButton value="inbound">inbound</RadioButton>
<RadioButton value="outbound">outbound</RadioButton>
</RadioButtonGroup>
<Button type="submit" variant="secondary">
Submit Push
</Button>
</Stack>
</form>
<form onSubmit={handlePopSubmit}>
<Stack orientation="vertical" spacing="space40">
<legend>Pop</legend>
<div>
<Label htmlFor={popID}>Pop ID</Label>
<Input name="id" id={popID} type="text" />
</div>
<Button type="submit" variant="secondary">
Submit Pop
</Button>
</Stack>
</form>
<Stack orientation="vertical" spacing="space40">
<legend>Clear</legend>
<Button type="submit" variant="secondary" onClick={clear}>
Clear All History
</Button>
</Stack>
<OrderedList aria-label="ordered list">
{chats.map(({ id }) => (
<ListItem key={id}>
<code>{id}</code>
</ListItem>
))}
</OrderedList>
</Box>
<AIChatLogger chats={chats} />
</Stack>
);
};
UseChatLogger.parameters = {
a11y: {
// no need to a11y check composition of a11y checked components
disable: true,
},
};

0 comments on commit 6a8f9de

Please sign in to comment.