-
Notifications
You must be signed in to change notification settings - Fork 114
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
fix: chat small fixes #2859
Merged
Merged
fix: chat small fixes #2859
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 | ||
--- | ||
|
||
[Chat Composer] refactor stories, create a new one called Conversations UI Kit Example. |
This file contains 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/lexical-library': minor | ||
'@twilio-paste/core': minor | ||
--- | ||
|
||
[Lexical Library] add export for: CLEAR_EDITOR_COMMAND, CLEAR_EDITOR_COMMAND, KEY_ENTER_COMMAND, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_NORMAL, COMMAND_PRIORITY_LOW, and COMMAND_PRIORITY_EDITOR | ||
This file contains 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-log': patch | ||
'@twilio-paste/core': patch | ||
--- | ||
|
||
[Chat Log] refactor styles to use row gap instead of margin bottom |
71 changes: 71 additions & 0 deletions
71
packages/paste-core/components/chat-composer/stories/ConversationsUIKit/helpers.tsx
This file contains 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,71 @@ | ||
import * as React from 'react'; | ||
import {ChatMessage, ChatBubble, ChatMessageMeta, ChatMessageMetaItem} from '@twilio-paste/chat-log'; | ||
import type {Chat} from '@twilio-paste/chat-log'; | ||
import {Box} from '@twilio-paste/box'; | ||
import {Button} from '@twilio-paste/button'; | ||
import {SendIcon} from '@twilio-paste/icons/esm/SendIcon'; | ||
import { | ||
useLexicalComposerContext, | ||
CLEAR_EDITOR_COMMAND, | ||
COMMAND_PRIORITY_HIGH, | ||
KEY_ENTER_COMMAND, | ||
} from '@twilio-paste/lexical-library'; | ||
|
||
export const createNewMessage = (message: string): Omit<Chat, 'id'> => { | ||
const time = new Date().toLocaleString('en-US', { | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
hour12: true, | ||
}); | ||
|
||
return { | ||
variant: 'outbound', | ||
content: ( | ||
<ChatMessage variant="outbound"> | ||
<ChatBubble>{message}</ChatBubble> | ||
<ChatMessageMeta aria-label={`said by you at ${time}`}> | ||
<ChatMessageMetaItem>{time}</ChatMessageMetaItem> | ||
</ChatMessageMeta> | ||
</ChatMessage> | ||
), | ||
}; | ||
}; | ||
|
||
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 => { | ||
const [editor] = useLexicalComposerContext(); | ||
|
||
const handleEnterKey = React.useCallback( | ||
(event: KeyboardEvent) => { | ||
const {shiftKey, ctrlKey} = event; | ||
if (shiftKey || ctrlKey) return false; | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
onKeyDown(); | ||
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined); | ||
return true; | ||
}, | ||
[editor, onKeyDown] | ||
); | ||
|
||
React.useEffect(() => { | ||
return editor.registerCommand(KEY_ENTER_COMMAND, handleEnterKey, COMMAND_PRIORITY_HIGH); | ||
}, [editor, handleEnterKey]); | ||
return null; | ||
}; |
183 changes: 183 additions & 0 deletions
183
packages/paste-core/components/chat-composer/stories/ConversationsUIKit/index.stories.tsx
This file contains 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,183 @@ | ||
import * as React from 'react'; | ||
import { | ||
MinimizableDialog, | ||
MinimizableDialogButton, | ||
MinimizableDialogContainer, | ||
MinimizableDialogHeader, | ||
MinimizableDialogContent, | ||
} from '@twilio-paste/minimizable-dialog'; | ||
import {AutoScrollPlugin, $getRoot, ClearEditorPlugin} from '@twilio-paste/lexical-library'; | ||
import {ChatIcon} from '@twilio-paste/icons/esm/ChatIcon'; | ||
import {Box} from '@twilio-paste/box'; | ||
import type {Story} from '@storybook/react'; | ||
import { | ||
ChatLogger, | ||
useChatLogger, | ||
ChatMessage, | ||
ChatMessageMeta, | ||
ChatMessageMetaItem, | ||
ChatBubble, | ||
ChatAttachment, | ||
ChatEvent, | ||
ChatAttachmentDescription, | ||
ChatAttachmentLink, | ||
ChatBookend, | ||
ChatBookendItem, | ||
ComposerAttachmentCard, | ||
} from '@twilio-paste/chat-log'; | ||
import {Avatar} from '@twilio-paste/avatar'; | ||
import {DownloadIcon} from '@twilio-paste/icons/esm/DownloadIcon'; | ||
import type {EditorState} from '@twilio-paste/lexical-library'; | ||
|
||
import {ChatComposer} from '../../src'; | ||
import {SendButtonPlugin, EnterKeySubmitPlugin, createNewMessage} from './helpers'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default { | ||
title: 'Components/Conversations UI Kit', | ||
component: ChatComposer, | ||
}; | ||
|
||
const ComposerAttachmentExample: React.FC = () => ( | ||
<Box display="flex" flexDirection="row" columnGap="space40" overflowX="scroll" paddingX="space70" paddingY="space50"> | ||
<Box maxWidth="size20"> | ||
<ComposerAttachmentCard onDismiss={() => {}}> | ||
<ChatAttachment attachmentIcon={<DownloadIcon color="colorTextIcon" decorative />}> | ||
<ChatAttachmentLink href="www.google.com">Document-FINAL.doc</ChatAttachmentLink> | ||
<ChatAttachmentDescription>123 MB</ChatAttachmentDescription> | ||
</ChatAttachment> | ||
</ComposerAttachmentCard> | ||
</Box> | ||
<Box maxWidth="size20"> | ||
<ComposerAttachmentCard onDismiss={() => {}}> | ||
<ChatAttachment attachmentIcon={<DownloadIcon color="colorTextIcon" decorative />}> | ||
<ChatAttachmentLink href="www.google.com">Document-FINAL.doc</ChatAttachmentLink> | ||
<ChatAttachmentDescription>123 MB</ChatAttachmentDescription> | ||
</ChatAttachment> | ||
</ComposerAttachmentCard> | ||
</Box> | ||
</Box> | ||
); | ||
|
||
export const ConversationsUIKitExample: Story = () => { | ||
const scrollRef = React.createRef<HTMLDivElement>(); | ||
const {chats, push} = useChatLogger( | ||
{ | ||
content: ( | ||
<ChatBookend> | ||
<ChatBookendItem>Today</ChatBookendItem> | ||
<ChatBookendItem> | ||
<strong>Chat Started</strong>・3:34 PM | ||
</ChatBookendItem> | ||
</ChatBookend> | ||
), | ||
}, | ||
{ | ||
variant: 'inbound', | ||
content: ( | ||
<ChatMessage variant="inbound"> | ||
<ChatBubble>Quisque ullamcorper ipsum vitae lorem euismod sodales.</ChatBubble> | ||
<ChatBubble> | ||
<ChatAttachment attachmentIcon={<DownloadIcon color="colorTextIcon" decorative />}> | ||
<ChatAttachmentLink href="www.google.com">Document-FINAL.doc</ChatAttachmentLink> | ||
<ChatAttachmentDescription>123 MB</ChatAttachmentDescription> | ||
</ChatAttachment> | ||
</ChatBubble> | ||
<ChatMessageMeta aria-label="said by Gibby Radki at 5:04pm"> | ||
<ChatMessageMetaItem>Gibby Radki ・ 5:04 PM</ChatMessageMetaItem> | ||
</ChatMessageMeta> | ||
</ChatMessage> | ||
), | ||
}, | ||
{ | ||
content: ( | ||
<ChatEvent> | ||
<strong>Lauren Gardner</strong> has joined the chat ・ 4:26 PM | ||
</ChatEvent> | ||
), | ||
}, | ||
{ | ||
variant: 'inbound', | ||
content: ( | ||
<ChatMessage variant="inbound"> | ||
<ChatBubble>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</ChatBubble> | ||
<ChatMessageMeta aria-label="said by Lauren Gardner at 4:30pm"> | ||
<ChatMessageMetaItem> | ||
<Avatar name="Lauren Gardner" size="sizeIcon20" /> | ||
Lauren Gardner ・ 4:30 PM | ||
</ChatMessageMetaItem> | ||
</ChatMessageMeta> | ||
</ChatMessage> | ||
), | ||
} | ||
); | ||
const [message, setMessage] = React.useState(''); | ||
|
||
const handleComposerChange = (editorState: EditorState): void => { | ||
editorState.read(() => { | ||
const text = $getRoot().getTextContent(); | ||
setMessage(text); | ||
}); | ||
}; | ||
|
||
const submitMessage = (): void => { | ||
push(createNewMessage(message)); | ||
}; | ||
|
||
return ( | ||
<MinimizableDialogContainer visible> | ||
<MinimizableDialogButton variant="primary" size="circle"> | ||
<ChatIcon decorative={false} title="Chat" /> | ||
</MinimizableDialogButton> | ||
<MinimizableDialog aria-label="Live chat"> | ||
<MinimizableDialogHeader>Live chat</MinimizableDialogHeader> | ||
<MinimizableDialogContent> | ||
<Box overflowY="scroll" maxHeight="size50" tabIndex={0}> | ||
<ChatLogger chats={chats} /> | ||
</Box> | ||
<Box | ||
ref={scrollRef} | ||
borderStyle="solid" | ||
borderWidth="borderWidth0" | ||
borderTopWidth="borderWidth10" | ||
borderColor="colorBorderWeak" | ||
display="flex" | ||
flexDirection="row" | ||
columnGap="space30" | ||
paddingX="space70" | ||
paddingTop="space50" | ||
> | ||
<ChatComposer | ||
maxHeight="size10" | ||
config={{ | ||
namespace: 'foo', | ||
onError: (error: Error) => { | ||
throw error; | ||
}, | ||
}} | ||
ariaLabel="Message" | ||
placeholder="Type here..." | ||
onChange={handleComposerChange} | ||
> | ||
<AutoScrollPlugin scrollRef={scrollRef} /> | ||
<ClearEditorPlugin /> | ||
<SendButtonPlugin onClick={submitMessage} /> | ||
<EnterKeySubmitPlugin onKeyDown={submitMessage} /> | ||
</ChatComposer> | ||
</Box> | ||
<ComposerAttachmentExample /> | ||
</MinimizableDialogContent> | ||
</MinimizableDialog> | ||
</MinimizableDialogContainer> | ||
); | ||
}; | ||
|
||
ConversationsUIKitExample.parameters = { | ||
a11y: { | ||
/* | ||
* axe says that the chat attachment links and some of the bubbles are failing contrast even though they're not. | ||
* Disabled the tests because all of these components are tested in other stories. | ||
*/ | ||
disable: true, | ||
}, | ||
}; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: it's usually more readable to put content like this into a bulleted list (not a big thing tho, so for next time!)