title | package | description | slug |
---|---|---|---|
Chat Log |
@twilio-paste/chat-log |
A Chat Log is a collection of Chat components for displaying conversations between people. |
/components/chat-log/ |
import {graphql} from 'gatsby'; import {Anchor} from '@twilio-paste/anchor'; import {Avatar} from '@twilio-paste/avatar'; import {Box} from '@twilio-paste/box'; import { ChatAttachment, ChatAttachmentDescription, ChatAttachmentLink, ChatBookend, ChatBookendItem, ChatBubble, ChatEvent, ChatLog, ChatMessage, ChatMessageMeta, ChatMessageMetaItem, } from '@twilio-paste/chat-log'; import Changelog from '@twilio-paste/chat-log/CHANGELOG.md'; import {DownloadIcon} from '@twilio-paste/icons/esm/DownloadIcon'; import {HelpText} from '@twilio-paste/help-text'; import {Callout, CalloutHeading, CalloutText} from '@twilio-paste/callout';
import {SidebarCategoryRoutes} from '../../../constants'; import { basicInboundMessage, basicOutboundMessage, inboundMessageMeta, outboundMessageMeta, inboundMessageAttachment, outboundMessageAttachment, inboundComplexMessage, outboundComplexMessage, basicChatEvent, basicChatBookend, kitchenSink, } from '../../../component-examples/ChatLogExamples.ts';
export const pageQuery = graphql{ allPasteComponent(filter: {name: {eq: "@twilio-paste/chat-log"}}) { edges { node { name description status version } } } mdx(frontmatter: {slug: {eq: "/components/chat-log/"}}) { fileAbsolutePath frontmatter { slug title description } headings { depth value } } allAirtable(filter: {data: {Feature: {eq: "Chat Log"}}}) { edges { node { data { Documentation Figma Design_committee_review Engineer_committee_review Code status } } } } }
;
<LivePreview scope={{ChatLog, ChatMessage, ChatBubble, ChatMessageMeta, ChatMessageMetaItem, Avatar}} language="jsx">
{<ChatLog> <ChatMessage variant='inbound'> <ChatBubble> Hello, what can I help you with? </ChatBubble> <ChatMessageMeta aria-label="said by Gibby Radki at 3:35 PM"> <ChatMessageMetaItem> <Avatar name="Gibby Radki" size="sizeIcon20" /> Gibby Radki ・ 3:35 PM </ChatMessageMetaItem> </ChatMessageMeta> </ChatMessage> <ChatMessage variant='outbound'> <ChatBubble> Hi! What is your return policy? </ChatBubble> <ChatMessageMeta aria-label="said by you at 3:35 PM"> <ChatMessageMetaItem>3:35 PM</ChatMessageMetaItem> </ChatMessageMeta> </ChatMessage> </ChatLog>
}
A Chat Log is a way to display conversations between people and can include complex content like attachments. The chat can be between two or more people.
The Chat Log package includes these main components:
- ChatLog
- ChatMessage
- ChatBubble
- ChatBookend
- ChatEvent
- ChatAttachment
- ChatMessageMeta
To ensure the chat is accessible, only use the Chat components within a ChatLog component and use ChatMessage to wrap ChatBubbles and ChatMessageMeta components together.
The only other accessibility requirement is providing the ChatMessageMeta a descriptive label via the aria-label
React prop.
The ChatLog component has role=”log”
which means that any new messages added to it are announced by assistive technology.
A basic message is simply text sent from a chat participant and is built with the ChatMessage and ChatBubble components. It can either be inbound or outbound.
<LivePreview scope={{ChatLog, ChatMessage, ChatBubble}} language="jsx" noInline> {basicInboundMessage}
<LivePreview scope={{ChatLog, ChatMessage, ChatBubble}} language="jsx" noInline> {basicOutboundMessage}
Use Message Meta to append additional information to a message such as the name of the sender, the time, or a read receipt.
ChatMessageMeta should be a child of ChatMessage so that the text and meta information are correctly grouped together for assistive technologies. It also needs a readable aria-label
that summarizes what the meta information says.
<LivePreview scope={{ChatLog, ChatMessage, ChatBubble, ChatMessageMeta, ChatMessageMetaItem, Avatar}} language="jsx" noInline
{inboundMessageMeta}
<LivePreview scope={{ChatLog, ChatMessage, ChatBubble, ChatMessageMeta, ChatMessageMetaItem}} language="jsx" noInline> {outboundMessageMeta}
A message can include an attachment. If sent with additional text, the attachment should be in its own ChatBubble.
<LivePreview scope={{ ChatLog, ChatMessage, ChatBubble, ChatAttachment, ChatAttachmentDescription, ChatAttachmentLink, DownloadIcon, }} language="jsx" noInline
{inboundMessageAttachment}
<LivePreview scope={{ ChatLog, ChatMessage, ChatBubble, ChatAttachment, ChatAttachmentDescription, ChatAttachmentLink, DownloadIcon, }} language="jsx" noInline
{outboundMessageAttachment}
ChatMessages can contain multiple ChatBubbles and ChatMessageMetas.
<LivePreview scope={{ ChatLog, ChatAttachment, ChatAttachmentDescription, ChatAttachmentLink, ChatBubble, ChatMessage, ChatMessageMeta, ChatMessageMetaItem, DownloadIcon, Avatar, }} language="jsx" noInline
{inboundComplexMessage}
<LivePreview scope={{ ChatLog, ChatAttachment, ChatAttachmentDescription, ChatAttachmentLink, ChatBubble, ChatMessage, ChatMessageMeta, ChatMessageMetaItem, DownloadIcon, }} language="jsx" noInline
{outboundComplexMessage}
Chat Events are for things that can happen during the chat, like someone joining or the chat transferring to a different agent.
<LivePreview scope={{ChatLog, ChatEvent}} language="jsx" noInline> {basicChatEvent}
Chat Bookends are for when the chat starts, ends, and the day when the chat spans multiple days.
<LivePreview scope={{ChatLog, ChatBookend, ChatBookendItem}} language="jsx" noInline> {basicChatBookend}
This example combines all the separate features displayed previously into one example. It shows how all the features work together harmoniously through composition.
<LivePreview scope={{ ChatAttachment, ChatAttachmentDescription, ChatAttachmentLink, ChatBookend, ChatBookendItem, ChatBubble, ChatEvent, ChatLog, ChatMessage, ChatMessageMeta, ChatMessageMetaItem, Avatar, DownloadIcon, Box, }} language="jsx" noInline
{kitchenSink}
yarn add @twilio-paste/chat-log - or - yarn add @twilio-paste/core
import {
ChatLog,
ChatMessage,
ChatMessageMeta,
ChatMessageMetaItem,
ChatBubble,
ChatBookend,
ChatBookendItem,
} from '@twilio-paste/core/chat-log';
export const Basic = () => {
return (
<ChatLog>
<ChatMessage variant="inbound">
<ChatBubble>Ahoy!</ChatBubble>
<ChatMessageMeta aria-label="said by Gibby Radki 4 minutes ago">
<ChatMessageMetaItem>Gibby Radki ・ 4 minutes ago</ChatMessageMetaItem>
</ChatMessageMeta>
</ChatMessage>
<ChatMessage variant="outbound">
<ChatBubble>Howdy!</ChatBubble>
<ChatMessageMeta aria-label="said by you 2 minutes ago">
<ChatMessageMetaItem>2 minutes ago</ChatMessageMetaItem>
</ChatMessageMeta>
<ChatMessageMeta aria-label="(read)">
<ChatMessageMetaItem>Read</ChatMessageMetaItem>
</ChatMessageMeta>
</ChatMessage>
</ChatLog>
);
};
Prop | Type | Description | Default |
---|---|---|---|
attachmentIcon |
NonNullable<React.ReactNode> |
Specify a Paste Icon or Spinner to be displayed in the Attachment | |
children |
NonNullable<React.ReactNode> |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_ATTACHMENT' |
Prop | Type | Description | Default |
---|---|---|---|
children |
string |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_ATTACHMENT_DESCRIPTION' |
ChatAttachmentLink inherits the same props as Anchor as well as the following:
Prop | Type | Description | Default |
---|---|---|---|
href |
string |
A URL to route to | |
children |
string |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_ATTACHMENT_LINK' |
Prop | Type | Description | Default |
---|---|---|---|
children? |
React.ReactNode |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_BOOKEND' |
Prop | Type | Description | Default |
---|---|---|---|
children? |
React.ReactNode |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_BOOKEND_ITEM' |
Prop | Type | Description | Default |
---|---|---|---|
children? |
React.ReactNode |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_BUBBLE' |
Prop | Type | Description | Default |
---|---|---|---|
children? |
React.ReactNode |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_EVENT' |
Prop | Type | Description | Default |
---|---|---|---|
children? |
React.ReactNode |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_LOG' |
Prop | Type | Description | Default |
---|---|---|---|
variant |
'inbound', 'outbound' |
The variant of the message | |
children? |
React.ReactNode |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_MESSAGE' |
Prop | Type | Description | Default |
---|---|---|---|
aria-label |
string |
A label that summarizes the content of the ChatMessageMeta | |
children |
NonNullable<React.ReactNode> |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_MESSAGE_META' |
Prop | Type | Description | Default |
---|---|---|---|
children |
NonNullable<React.ReactNode> |
||
element? |
string |
Overrides the default element name to apply unique styles with the Customization Provider | 'CHAT_MESSAGE_META_ITEM' |