-
Notifications
You must be signed in to change notification settings - Fork 119
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
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 8b934dd
feat(composer): addition of all attatchment components
krisantrobus 0829a26
feat(composer): lint fix
krisantrobus ea4c801
feat(composer): fix disabled styling
krisantrobus 441ba42
feat(composer): responsive columns and JS doc
krisantrobus 876088c
feat(composer-docs): wip examples
krisantrobus e76ef9b
feat(composer): add new plugin to access state
krisantrobus a05ed0c
feat(composer): fix lint issues
krisantrobus 4713bed
feat(docs-composer): added in stories for log types
krisantrobus 405f374
chore(docs): update AI Chat Log page name
krisantrobus c581489
chore(chat-composer): clenaup unused imports
krisantrobus e69f614
chore(chat-composer): remove duplicate story
krisantrobus 2534672
chore(docs/chat-composer): content changes for latest component updates
krisantrobus 8af3b51
chore(chat-composer): remove attachment
krisantrobus 1c3ea40
chore(chat-composer): remove unused component
krisantrobus 343632d
chore(chat-composer): pr cleanup
krisantrobus 85bbfeb
chore(docs/ai-chat-log): correct storybook link
krisantrobus a234e96
chore(docs/chat-composer): type fix
krisantrobus 3453284
chore(docs/chat-composer): formatting fix
krisantrobus 0679fe2
chore(docs/chat-composer): lint fix
krisantrobus 4527247
chore(docs/chat-composer): story update
krisantrobus 76126ca
Update packages/paste-website/src/pages/components/chat-composer/inde…
krisantrobus 7adcb91
Apply suggestions from code review
krisantrobus f9d5401
chore(docs/chat-composer): remove redundant changeset
krisantrobus bab674e
chore(docs/chat-composer): update docs AI story example
krisantrobus 8ee5cb9
Merge branch 'docs/chat-composer' of github.com:twilio-labs/paste int…
krisantrobus 9f1b2cc
chore(chat-composer): updated typedoc
krisantrobus 8b6008a
Update packages/paste-website/src/pages/components/chat-composer/inde…
krisantrobus 5720307
chore(docs/chat-composer): show default contained variant
krisantrobus d75f5f0
Merge branch 'docs/chat-composer' of github.com:twilio-labs/paste int…
krisantrobus 8b24cdc
chore(docs/chat-composer): formatting fix
krisantrobus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
||
|
@@ -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> | ||
|
@@ -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> | ||
|
@@ -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> | ||
|
@@ -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); | ||
|
@@ -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) => { | ||
|
@@ -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}> | ||
|
@@ -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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.