Create new conversations or reply to existing ones


This component is in development; interface and features are subject to change prior to final release.

Visit the Replacements API step by step guide.

When to use #

The Composer component renders a message composer to create new threads and to reply to existing ones. The Composer is a complex component that can take a lot of props. To speed up development, we provide different components and hooks that allow you to customize the behavior to fit your needs, without having to worry about all of the Composer props.

There are two different components you can use:

  • SendComposer is used to send a new message to an existing thread. It can also be used to create a new thread.
  • EditComposer is used when you already have a message and would like to edit it.

Send messages and create threads #

You can use SendComposer whenever you want to create a new thread or when you have a thread to which you want to add replies.

How to use #

React:
import { betaV2 } from "@cord-sdk/react";
  
function ExampleComposer(channel) {
    const createThreadOptions = useMemo(() => {
        return {
            name: channel.name,
            location: { channel: channel.id },
            url: "https://www.myawesomeweb.com/" + channel.id,
            groupID: channel.org,
        };
    }, [channel.name, channel.id, channel.org]);

    return <betaV2.SendComposer
        createThread={createThreadOptions}
    />;
}
import { betaV2 } from "@cord-sdk/react";
  
function ExampleComposer(channel) {
    const createThreadOptions = useMemo(() => {
        return {
            name: channel.name,
            location: { channel: channel.id },
            url: "https://www.myawesomeweb.com/" + channel.id,
            groupID: channel.org,
        };
    }, [channel.name, channel.id, channel.org]);

    return <betaV2.SendComposer
        createThread={createThreadOptions}
    />;
}
Copy

View Source Code


Properties #


initialValue #

optional
Partial<ClientMessageData>
The initial value of the composer.

This is an object with the following fields:

Show property details



threadID #

optional
string
An arbitrary string that uniquely identifies a thread. Messages sent will go to the provided thread ID. If the thread does not exist, then the createThread prop should be passed.
Warning! An important restriction of working with thread identifiers is that they must be unique across your entire application. You can't use the same thread identifier in two separate groups. This is an intentional limitation imposed by Cord.


createThread #

optional
Partial<ClientCreateThread>
An object containing the data of the thread to be created. If the thread specified in threadID exists, the message will be added to that thread and this object will be ignored.

This is an object with the following fields:

Show property details



placeholder #

optional
string
Text to be displayed as a placeholder in the composer.


onBeforeSubmit #

optional
(arg: { message: Partial<ClientMessageData>; }) => Promise<{ message: Partial<ClientMessageData>; } | null>
Callback invoked before the message is sent. It receives the message data as an argument and should return the modified message data. If the callback returns null, the message will not be sent.


onAfterSubmit #

optional
(arg: { message: Partial<ClientMessageData>; }) => void
Callback invoked after the message is sent.


onCancel #

optional
() => void
Callback invoked when the user clicks on the cancel button in the composer.


autofocus #

optional
boolean


onFailSubmit #

optional
(error: unknown) => void


enableDragDropAttachments #

optional
boolean
Allows attachments to be added by dragging and dropping within the composer area. Defaults to true.


style #

optional
CSSProperties
Passes the style of the component. It will be applied to the root element.


className #

optional
string
Any classes to be added to the component. It will be applied to the root element.


expanded #

optional
"auto" | "never" | "always"
When set to auto, the composer will auto-expand when focused.


showCancelButton #

optional
boolean


replace #

optional
ReplaceConfig
Object that contains the components that will be replaced in the composer. Find more information about it here.

Editing messages #

You can use EditComposer whenever you want to edit an existing message.

How to use #

React:
import { betaV2, thread } from "@cord-sdk/react";
  
function ExampleComposer(messageID) {
    const message = thread.useMessage(messageID);

    return <betaV2.EditComposer
        threadId={message.threadId}
        messageId={messageID}
    />;
}
import { betaV2, thread } from "@cord-sdk/react";
  
function ExampleComposer(messageID) {
    const message = thread.useMessage(messageID);

    return <betaV2.EditComposer
        threadId={message.threadId}
        messageId={messageID}
    />;
}
Copy

View Source Code


Properties #


initialValue #

optional
Partial<ClientMessageData>
The initial value of the composer.

This is an object with the following fields:

Show property details



messageID #

required
string
The id of the message to be edited.


placeholder #

optional
string
Text to be displayed as a placeholder in the composer.


onBeforeSubmit #

optional
(arg: { message: Partial<ClientMessageData>; }) => Promise<{ message: Partial<ClientMessageData>; } | null>
Callback invoked before the message is sent. It receives the message data as an argument and should return the modified message data. If the callback returns null, the message will not be sent.


onAfterSubmit #

optional
(arg: { message: Partial<ClientMessageData>; }) => void
Callback invoked after the message is sent.


onCancel #

optional
() => void
Callback invoked when the user clicks on the cancel button in the composer.


autofocus #

optional
boolean


onFailSubmit #

optional
(error: unknown) => void


enableDragDropAttachments #

optional
boolean
Allows attachments to be added by dragging and dropping within the composer area. Defaults to true.


style #

optional
CSSProperties
Passes the style of the component. It will be applied to the root element.


className #

optional
string
Any classes to be added to the component. It will be applied to the root element.


expanded #

optional
"auto" | "never" | "always"
When set to auto, the composer will auto-expand when focused.


showCancelButton #

optional
boolean


replace #

optional
ReplaceConfig
Object that contains the components that will be replaced in the composer. Find more information about it here.

Customization with Replacements #

If you want to customize your component, you can customize the CSS (see below), but you can also switch parts of the component for your own ones with out Replacements API.

These are the components you can replace in the composer. Some are better understood in context. We suggest inspecting the component with your browser's developer tools to find elements with a data-cord-replace attribute.

ComponentDescription
ComposerLayout
Layout for the composer
TextEditor
Composer editor
SendButton
Button to send messages
ReactionPickButton
Button to add reactions
Button
Generic button component
ToolbarLayout
Composer toolbar layout. Contains "add attachment", "add emoji" and other buttons.
EmojiPicker
Popover that contains emojis to be picked

CSS customization #

If you want to customize this component, you can target the classes below in your app's CSS. These are guaranteed to be stable.

There are more classes that are best understood in context. We suggest inspecting the component with your browser's developer tools to view everything. You can target any classes starting with cord-.

Class nameDescription
.cord-composer
Applied to the container div. This class is always present.
.cord-empty
Applied to the container div when the text editor is empty
.cord-valid
Applied to the container div when the message is valid and can be sent. This means there either some non-whitespace text, or at least one attachment.
.cord-always-expand
Applied to the container div, reflects the composer expanded prop.
.cord-never-expand
Applied to the container div, reflects the composer expanded prop.
.cord-auto-expand
Applied to the container div, reflects the composer expanded prop.
.cord-editor-container
Applied to the div containing the editor.
.cord-attachments
Applied to the div containing the attachments (files and images).
.cord-composer-error-message
Applied to the div containing the error message that appears when a message fails to send

This component pairs well with:


Not finding the answer you need? Ask our Developer Community

Ask Cordy