Skip to content

chore(docs/chat-composer): Update the documentation for the new Chat Composer elements #3981

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

Merged
merged 31 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a6f0224
feat(composer): wip base elements
krisantrobus Jun 20, 2024
8b934dd
feat(composer): addition of all attatchment components
krisantrobus Jun 20, 2024
0829a26
feat(composer): lint fix
krisantrobus Jun 20, 2024
ea4c801
feat(composer): fix disabled styling
krisantrobus Jun 21, 2024
441ba42
feat(composer): responsive columns and JS doc
krisantrobus Jun 25, 2024
876088c
feat(composer-docs): wip examples
krisantrobus Jun 26, 2024
e76ef9b
feat(composer): add new plugin to access state
krisantrobus Jun 28, 2024
a05ed0c
feat(composer): fix lint issues
krisantrobus Jun 28, 2024
4713bed
feat(docs-composer): added in stories for log types
krisantrobus Jun 28, 2024
405f374
chore(docs): update AI Chat Log page name
krisantrobus Jul 3, 2024
c581489
chore(chat-composer): clenaup unused imports
krisantrobus Jul 10, 2024
e69f614
chore(chat-composer): remove duplicate story
krisantrobus Jul 10, 2024
2534672
chore(docs/chat-composer): content changes for latest component updates
krisantrobus Jul 10, 2024
8af3b51
chore(chat-composer): remove attachment
krisantrobus Jul 10, 2024
1c3ea40
chore(chat-composer): remove unused component
krisantrobus Jul 10, 2024
343632d
chore(chat-composer): pr cleanup
krisantrobus Jul 10, 2024
85bbfeb
chore(docs/ai-chat-log): correct storybook link
krisantrobus Jul 10, 2024
a234e96
chore(docs/chat-composer): type fix
krisantrobus Jul 10, 2024
3453284
chore(docs/chat-composer): formatting fix
krisantrobus Jul 10, 2024
0679fe2
chore(docs/chat-composer): lint fix
krisantrobus Jul 10, 2024
4527247
chore(docs/chat-composer): story update
krisantrobus Jul 11, 2024
76126ca
Update packages/paste-website/src/pages/components/chat-composer/inde…
krisantrobus Jul 11, 2024
7adcb91
Apply suggestions from code review
krisantrobus Jul 11, 2024
f9d5401
chore(docs/chat-composer): remove redundant changeset
krisantrobus Jul 11, 2024
bab674e
chore(docs/chat-composer): update docs AI story example
krisantrobus Jul 11, 2024
8ee5cb9
Merge branch 'docs/chat-composer' of github.com:twilio-labs/paste int…
krisantrobus Jul 11, 2024
9f1b2cc
chore(chat-composer): updated typedoc
krisantrobus Jul 11, 2024
8b6008a
Update packages/paste-website/src/pages/components/chat-composer/inde…
krisantrobus Jul 11, 2024
5720307
chore(docs/chat-composer): show default contained variant
krisantrobus Jul 11, 2024
d75f5f0
Merge branch 'docs/chat-composer' of github.com:twilio-labs/paste int…
krisantrobus Jul 11, 2024
8b24cdc
chore(docs/chat-composer): formatting fix
krisantrobus Jul 11, 2024
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
6 changes: 6 additions & 0 deletions .changeset/quick-yaks-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/chat-composer": patch
"@twilio-paste/core": patch
---

[ChatComposer] removed internal unused imports
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ export const AIChatLogComposer = (): React.ReactNode => {
content: (
<AIChatMessage variant="user">
<AIChatMessageAuthor aria-label="you said at 2:36pm">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>
<AIChatMessageBody>Hi, I am getting errors codes when sending an SMS.</AIChatMessageBody>
</AIChatMessage>
),
},
Expand All @@ -144,9 +140,7 @@ export const AIChatLogComposer = (): React.ReactNode => {
<AIChatMessage variant="bot">
<AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor>
<AIChatMessageBody>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Deserunt delectus fuga, necessitatibus
eligendiiure adipisci facilis exercitationem officiis dolorem laborum, ex fugiat quisquam itaque, earum sit
nesciunt impedit repellat assumenda.
Error codes can be returned from various parts of the process. What error codes are you encountering?
<Box marginTop="space50">
<ButtonGroup>
<Button variant="secondary" onClick={() => {}} size="rounded_small">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,7 @@ export const AIChatLogComposer = (): React.ReactNode => {
content: (
<AIChatMessage variant="user">
<AIChatMessageAuthor aria-label="you said at 2:36pm">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>
<AIChatMessageBody>Hi, I am getting errors codes when sending an SMS.</AIChatMessageBody>
</AIChatMessage>
),
},
Expand All @@ -304,9 +300,7 @@ export const AIChatLogComposer = (): React.ReactNode => {
<AIChatMessage variant="bot">
<AIChatMessageAuthor aria-label="AI said">Good Bot</AIChatMessageAuthor>
<AIChatMessageBody>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Deserunt delectus fuga, necessitatibus
eligendiiure adipisci facilis exercitationem officiis dolorem laborum, ex fugiat quisquam itaque, earum sit
nesciunt impedit repellat assumenda.
Error codes can be returned from various parts of the process. What error codes are you encountering?
<Box marginTop="space50">
<ButtonGroup>
<Button variant="secondary" onClick={() => {}} size="rounded_small">
Expand Down
162 changes: 117 additions & 45 deletions packages/paste-website/src/component-examples/ChatComposerExamples.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Box } from "@twilio-paste/box";
import { Button } from "@twilio-paste/button";
import { ChatBubble, ChatMessage, ChatMessageMeta, ChatMessageMetaItem } from "@twilio-paste/chat-log";
import type { Chat } from "@twilio-paste/chat-log";
import { SendIcon } from "@twilio-paste/icons/esm/SendIcon";
import {
CLEAR_EDITOR_COMMAND,
COMMAND_PRIORITY_HIGH,
Expand Down Expand Up @@ -94,23 +91,6 @@ export const createNewMessage = (message: string): Omit<Chat, "id"> => {
};
};

export const SendButtonPlugin = ({ onClick }: { onClick: () => void }): JSX.Element => {
const [editor] = useLexicalComposerContext();

const handleSend = (): void => {
onClick();
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
};

return (
<Box position="absolute" top="space30" right="space30">
<Button variant="primary_icon" size="reset" onClick={handleSend}>
<SendIcon decorative={false} title="Send message" />
</Button>
</Box>
);
};

export const EnterKeySubmitPlugin = ({ onKeyDown }: { onKeyDown: () => void }): null => {
Comment on lines -97 to -113
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was used as an example of putting the button inside the text area which we want to avoid.

const [editor] = useLexicalComposerContext();

Expand All @@ -134,7 +114,7 @@ export const EnterKeySubmitPlugin = ({ onKeyDown }: { onKeyDown: () => void }):
};

export const ChatDialogExample = `const ChatDialog = () => {
const {chats, push} = useChatLogger(
const { chats, push } = useChatLogger(
{
content: (
<ChatBookend>
Expand All @@ -146,7 +126,7 @@ export const ChatDialogExample = `const ChatDialog = () => {
),
},
{
variant: 'inbound',
variant: "inbound",
content: (
<ChatMessage variant="inbound">
<ChatBubble>Quisque ullamcorper ipsum vitae lorem euismod sodales.</ChatBubble>
Expand All @@ -170,7 +150,7 @@ export const ChatDialogExample = `const ChatDialog = () => {
),
},
{
variant: 'inbound',
variant: "inbound",
content: (
<ChatMessage variant="inbound">
<ChatBubble>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</ChatBubble>
Expand All @@ -182,9 +162,9 @@ export const ChatDialogExample = `const ChatDialog = () => {
</ChatMessageMeta>
</ChatMessage>
),
}
},
);
const [message, setMessage] = React.useState('');
const [message, setMessage] = React.useState("");

const [mounted, setMounted] = React.useState(false);
const loggerRef = React.useRef(null);
Expand All @@ -196,7 +176,7 @@ export const ChatDialogExample = `const ChatDialog = () => {

React.useEffect(() => {
if (!mounted || !loggerRef.current) return;
scrollerRef.current?.scrollTo({top: loggerRef.current.scrollHeight, behavior: 'smooth'});
scrollerRef.current?.scrollTo({ top: loggerRef.current.scrollHeight, behavior: "smooth" });
}, [chats, mounted]);

const handleComposerChange = (editorState) => {
Expand All @@ -207,10 +187,12 @@ export const ChatDialogExample = `const ChatDialog = () => {
};

const submitMessage = () => {
if (message === '') return;
if (message === "") return;
push(createNewMessage(message));
};

const editorInstanceRef = React.useRef<LexicalEditor>(null);

return (
<Box>
<Box ref={scrollerRef} overflowX="hidden" overflowY="auto" maxHeight="size50" tabIndex={0}>
Expand All @@ -221,31 +203,121 @@ export const ChatDialogExample = `const ChatDialog = () => {
borderWidth="borderWidth0"
borderTopWidth="borderWidth10"
borderColor="colorBorderWeak"
display="flex"
flexDirection="row"
columnGap="space30"
paddingX="space70"
paddingTop="space50"
>
<ChatComposer
maxHeight="size10"
config={{
namespace: 'foo',
onError: (error) => {
throw error;
},
}}
ariaLabel="Message"
placeholder="Type here..."
onChange={handleComposerChange}
>
<ClearEditorPlugin />
<SendButtonPlugin onClick={submitMessage} />
<EnterKeySubmitPlugin onKeyDown={submitMessage} />
</ChatComposer>
<ChatComposerContainer>
<ChatComposer
maxHeight="size10"
config={{
namespace: "foo",
onError: (error) => {
throw error;
},
}}
ariaLabel="Message"
placeholder="Type here..."
onChange={handleComposerChange}
editorInstanceRef={editorInstanceRef}
>
<ClearEditorPlugin />
<EnterKeySubmitPlugin onKeyDown={submitMessage} />
</ChatComposer>
<ChatComposerActionGroup>
<Button variant="secondary_icon" size="reset">
<AttachIcon decorative={false} title="attach files to the message" />
</Button>
<Button
variant="primary_icon"
size="reset"
onClick={() => {
submitMessage();
editorInstanceRef.current?.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
}}
>
<SendIcon decorative={false} title="Send" />
</Button>
</ChatComposerActionGroup>
</ChatComposerContainer>
</Box>
</Box>
);
};

render(<ChatDialog />)`.trim();

export const ResponsiveContainedAttachmentsExample = `const ResponsiveContainedAttachmentsExample = () => {
const ExampleAttachment = () => (
<ChatComposerAttachmentCard onDismiss={() => {}} attachmentIcon={<DownloadIcon decorative />}>
<ChatComposerAttachmentLink href="www.google.com">Document-FINAL.doc</ChatComposerAttachmentLink>
<ChatComposerAttachmentDescription>123 MB</ChatComposerAttachmentDescription>
</ChatComposerAttachmentCard>
)

return (
<ChatComposerContainer>
<ChatComposer
ariaLabel="A chat with attachments"
initialValue="This is my initial value"
config={{
namespace: "customer-chat",
onError: (e) => {
throw e;
},
}}
/>
<ChatComposerActionGroup>
<Button variant="secondary_icon" size="reset">
<AttachIcon decorative={false} title="attach files to the message" />
</Button>
<Button variant="primary_icon" size="reset">
<SendIcon decorative={false} title="Send" />
</Button>
</ChatComposerActionGroup>
<ChatComposerAttachmentGroup columns={[1, 1, 2, 3]}>
{Array.from({ length: 6 }).map((_, index) => (
<ExampleAttachment key={index} />
))}
</ChatComposerAttachmentGroup>
</ChatComposerContainer>
)
}

render(<ResponsiveContainedAttachmentsExample />)`.trim();

export const ContainedDisabledExample = `const ContainedDisabledExample = () => {
const [isDisabled, setIsDisabled] = React.useState(true);
return (
<>
<Box marginBottom="space50">
<Checkbox checked={isDisabled} onClick={() => setIsDisabled((disabled) => !disabled)}>
Disable Input
</Checkbox>
</Box>
<ChatComposerContainer variant="contained">
<ChatComposer
ariaLabel="A chat that is disabled"
initialValue="This is my initial value"
config={{
namespace: "customer-chat",
onError: (e) => {
throw e;
},
}}
disabled={isDisabled}
/>
<ChatComposerActionGroup>
<Button variant="secondary_icon" size="reset" aria-disabled={isDisabled} disabled={isDisabled}>
<AttachIcon decorative={false} title="attach files to the message" />
</Button>
<Button variant="primary_icon" size="reset" aria-disabled={isDisabled} disabled={isDisabled}>
<SendIcon decorative={false} title="Send" />
</Button>
</ChatComposerActionGroup>
</ChatComposerContainer>
</>
);
}

render(<ContainedDisabledExample />)`.trim();
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ export const getStaticProps = async () => {
data: {
...packageJson,
...feature,
nameOverride: 'AI Chat Log',
},
componentApi,
mdxHeadings: [...mdxHeadings, ...componentApiTocData],
navigationData,
pageHeaderData: {
categoryRoute: SidebarCategoryRoutes.COMPONENTS,
githubUrl: "https://github.com/twilio-labs/paste/tree/main/packages/paste-core/components/ai-chat-log",
storybookUrl: "/?path=/story/components-chatlog--example-chat-log",
storybookUrl: "/?path=/story/components-ai-chat-log--example-ai-chat-log",
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ export const getStaticProps = async () => {
data: {
...packageJson,
...feature,
nameOverride: 'AI Chat Log',
},
navigationData,
mdxHeadings,
pageHeaderData: {
categoryRoute: SidebarCategoryRoutes.COMPONENTS,
githubUrl: "https://github.com/twilio-labs/paste/tree/main/packages/paste-core/components/ai-chat-log",
storybookUrl: "/?path=/story/components-chatlog--example-chat-log",
storybookUrl: "/?path=/story/components-ai-chat-log--example-ai-chat-log",
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ export const getStaticProps = async () => {
data: {
...packageJson,
...feature,
nameOverride: 'AI Chat Log',
},
navigationData,
mdxHeadings,
pageHeaderData: {
categoryRoute: SidebarCategoryRoutes.COMPONENTS,
githubUrl: "https://github.com/twilio-labs/paste/tree/main/packages/paste-core/components/ai-chat-log",
storybookUrl: "/?path=/story/components-chatlog--example-chat-log",
storybookUrl: "/?path=/story/components-ai-chat-log--example-ai-chat-log",
},
},
};
Expand Down
Loading
Loading