-
Notifications
You must be signed in to change notification settings - Fork 29
186 style scroll chat composer #189
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
base: main
Are you sure you want to change the base?
Changes from all commits
cac2757
8754e1b
592988b
78b17ef
572d132
1912981
ff99ef4
000b192
3895a09
1490940
47c985d
78ae115
ab90920
673e858
f038db4
1697505
4010387
0ef9026
c05e275
0c6bf1f
42406a4
05ecf19
623b60e
5eb5800
3baf128
671c7ac
1a289a3
9fa63c7
462fe09
d1d49ff
1d4f762
2544749
0b2bf8c
ad8be78
0452402
95c73b5
8646e83
516695c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@twilio-labs/dev-phone-ui": patch | ||
--- | ||
|
||
Preserve newlines in inbound and outbound sms. | ||
Add react text area auto resize component. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {useLexicalComposerContext, CLEAR_EDITOR_COMMAND } from "@twilio-paste/core/lexical-library"; | ||
import { Button } from "@twilio-paste/core"; | ||
import {CustomizationProvider} from '@twilio-paste/core/customization'; | ||
import { SendIcon } from '@twilio-paste/icons/esm/SendIcon'; | ||
|
||
// Renders a send button for the Paste Chat Composer | ||
function SendButtonPlugin({ onClick, canSendMessages }) { | ||
|
||
const [editor] = useLexicalComposerContext(); | ||
|
||
const sendIt = (e) => { | ||
onClick(e); | ||
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined); | ||
} | ||
|
||
return ( | ||
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. I found the CustomizationProvider (below) which should allow us to do a better job of styling. As-is, I don't think we can ship it, it looks way too odd to me. But maybe we can target the individual elements better to style them in a way that makes more sense. |
||
<CustomizationProvider | ||
elements={{ | ||
SMS_SEND_BUTTON: { | ||
float: 'right', | ||
}, | ||
}} | ||
> | ||
<Button element="SMS_SEND_BUTTON" onClick={sendIt} type={"submit"} disabled={!canSendMessages}> | ||
<SendIcon decorative /> | ||
Send | ||
</Button> | ||
</CustomizationProvider> | ||
) | ||
} | ||
|
||
export default SendButtonPlugin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
import { useContext, useState, useMemo } from "react"; | ||
import { Button, Input, Label, Box, Grid, Column } from "@twilio-paste/core"; | ||
import { SendIcon } from '@twilio-paste/icons/esm/SendIcon'; | ||
import React, { useContext, useState, useMemo } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { Label, Box, Grid, HelpText, Column, AutoScrollPlugin } from "@twilio-paste/core"; | ||
import { ChatComposer } from "@twilio-paste/core/chat-composer"; | ||
import { TwilioConversationsContext } from '../WebsocketManagers/ConversationsManager'; | ||
import MessageList from "./MessageList" | ||
import { $getRoot, ClearEditorPlugin } from "@twilio-paste/core/lexical-library"; | ||
import SendButtonPlugin from "./SendButtonPlugin"; | ||
|
||
// Top-level container for Dev Phone SMS | ||
function SendSmsForm({ numberInUse }) { | ||
const [messageBody, setMessageBody] = useState(''); | ||
|
||
const channelData = useSelector(state => state.channelData) | ||
const destinationNumber = useSelector(state => state.destinationNumber) | ||
|
||
const conversationsClient = useContext(TwilioConversationsContext) | ||
const {sendMessage, sendSms} = conversationsClient | ||
const { sendMessage, sendSms } = conversationsClient | ||
|
||
const canSendMessages = useMemo(() => { | ||
return destinationNumber && destinationNumber.length > 6; | ||
}, [destinationNumber]); | ||
|
||
// Handles the UI state for sending messages | ||
const sendIt = async (e) => { | ||
e.preventDefault() | ||
if (canSendMessages) { | ||
|
@@ -30,32 +32,44 @@ function SendSmsForm({ numberInUse }) { | |
} | ||
}; | ||
|
||
const myOnChange = (editorState) => { | ||
editorState.read(() => { | ||
const root = $getRoot(); | ||
setMessageBody(root.getTextContent()); | ||
}); | ||
}; | ||
|
||
|
||
return ( | ||
<Box width="100%" backgroundColor={"colorBackgroundBody"}> | ||
<Box width="100%" backgroundColor={"default"} overflowX="hidden" overflowY="auto"> | ||
<MessageList | ||
devPhoneName={channelData.devPhoneName} | ||
/> | ||
<form onSubmit={(e) => sendIt(e)} method={"GET"}> | ||
<Label htmlFor="sendSmsBody" required>Message</Label> | ||
<Grid gutter={"space20"} marginBottom="space40"> | ||
<Column span={10}> | ||
<Input id="sendSmsBody" type="text" value={messageBody} onChange={(e) => setMessageBody(e.target.value)} /> | ||
</Column> | ||
<Column span={2}> | ||
<Button type={"submit"} disabled={!canSendMessages}> | ||
<SendIcon decorative /> | ||
Send | ||
</Button> | ||
</Column> | ||
</Grid> | ||
</form> | ||
<Label htmlFor="sendSmsBody" required>Message</Label> | ||
|
||
<Grid gutter={"space20"} marginBottom="space40"> | ||
<Column span={12}> | ||
<ChatComposer | ||
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. I simplified the use of Paste here, I don't think we can componentize our way out of this. I have no idea how lexical manages this - I tried using Flexbox and the button just floats left. But there must be some way to manage it sensibly. |
||
config={{ | ||
namespace: "send_sms", | ||
onError: (e) => { | ||
throw e; | ||
} | ||
}} | ||
placeholder="Chat text" | ||
ariaLabel="A basic chat composer" | ||
onChange={myOnChange} | ||
element="SEND_SMS_COMPOSER" | ||
> | ||
<ClearEditorPlugin /> | ||
<SendButtonPlugin canSendMessages={canSendMessages} onClick={sendIt} /> | ||
</ChatComposer> | ||
<HelpText id="send_sms_help_text">Enter at most 1600 characters</HelpText> | ||
</Column> | ||
</Grid> | ||
</Box> | ||
|
||
); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
export default SendSmsForm; |
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.
These dependencies should be in the UI package, not up at the top - these aren't necessary for the
dev-phone-plugin