Display all the Threads in a given location, add new Threads, and reply inline with a flexible, embeddable UI component. Threaded Comments is ideal for showing conversations on a page, or creating a comment section.
The <ThreadedComments />
component renders a composer and a list of comments. Every new comment created from that composer will appear in the same list. You can react and reply to each comment inline.
This component is great for an all-in-one threaded commenting experience. If you don't want multiple threads, take a look at the single Thread component instead.
import { ThreadedComments } from "@cord-sdk/react";
export function Example() {
return (
<ThreadedComments
location={'my-awesome-location'}
messageOrder={'newest_on_top'}
composerPosition={'top'}
topLevelComposerExpanded={'false'}
onThreadClick={(threadId, threadSummary) =>
console.log("user clicked on thread:", threadId, threadSummary)
}
/>
);
}
Threaded Comments is built on top of our lower-level components and APIs, such as the Message component and our Thread API. The complete source code is available here under a permissive license. You can use it to learn from as an example, or even copy-paste into your own app to remix and build a custom experience.
This diagram shows how Threaded Comments is built using other, smaller, Cord components. Use this to help style your integration, or to break apart and create something new.
Threads with this location will be shown by the component. Any new threads will also be created with this location.
false
, only threads that exactly match the provided location are shown. If true
, threads in any partially matching location are also shown.false
.Takes one of two possible values: newest_on_top
or newest_on_bottom
.
If set to newest_on_top
, the comment that was created the most recently will render first, with the rest of the comments following below in reverse chronological order.
If set to newest_on_bottom
, the comment that was created the most recently will render last, which means that all comments will be sorted in chronological order.
The default value is newest_on_bottom
.
Takes one of two possible values: top
or bottom
.
If set to top
, the composer will be rendered above the list of threads.
If set to bottom
, the composer will be rendered below the list of threads.
If set to none
, the composer will not appear at all.
The default value is bottom
.
If true
, the top level composer will always appear expanded. This means that it will always show the button list (such as the mention button and emoji button) right below the editor.
If false
, the top level composer will start from a single-line state, but will expand when a user clicks in the editor or starts typing. It will return to a single-line state when it loses focus and there is no input in the editor.
The default value is false
.
composerExpanded
property above,
but to the composers for replying to a thread.Takes one of the following values: initiallyCollapsed
, initiallyExpanded
oralwaysCollapsed
.
If set to initiallyCollapsed
, thread replies will initially show a facepile and the number of replies, if any. On click, the replies will become visible, together with a composer.
If set to initiallyExpanded
, all replies will initially be visible. Both hiding them and replying will be available.
If set to alwaysCollapsed
, a facepile and the number of replies for a thread will be shown, if there are any, but viewing the replies and replying will be disabled.
The default value is initiallyCollapsed
.
.cord-threaded-comments.cord-highlighted
.This prop tells ThreadedComments how to display resolved threads. It takes one of the following values: interleaved
, tabbed
, resolvedOnly
or unresolvedOnly
.
If set to interleaved
, both resolved and unresolved threads will appear together, sorted by the order specified in the messageOrder
property.
If set to tabbed
, two tabs will appear on the top part of the component, with "Open" and "Resolved" labels respectively. Clicking on each of them will filter for the relevant threads. Note that when resolved threads are visible, the composer will not be shown since it doesn't make sense to create a new, but already resolved thread.
If set to resolvedOnly
, only resolved threads will be shown.
If set to unresolvedOnly
, only unresolved threads will be shown.
The default value is unresolvedOnly
.
true
, the top-level composer input
field will render with the autofocus
HTML attribute set.false
.true
, a tooltip with the user's displayName will
appear on the Facepile with the profile pictures of the users who have replied to each thread. The default value is false
threadUrl
defaults to window.location.href
. Setting this
property would override that default.threadId
and messageId
of the
message which was clicked as an argument.onRender
to determine when loading is complete.onLoading
to determine when a component begins loading.threadId
linked to the composer.threadId
linked to the composer.threadId
linked to the composer.threadId
and messageId
linked to the message sent.onMessageMouseEnter
.onMessageEditEnd
to determine when editing is complete.onMessageEditStart
to determine when editing begins.If you want to customize this component, you can target the classes below in your app's CSS. These are guaranteed to be stable.
This component itself makes use of the following components. Take a look at their documentation for what classes are available to target within those components.
The following classes are also available specific to this component:
.cord-threaded-comments-tab-container
.cord-threaded-comments-tab
tabContainer
..cord-threaded-comments-thread-list
ThreadList
component, hence the long name..cord-threaded-comments-thread
Thread
component, hence the long name..cord-threaded-comments-resolved-thread-header
.cord-threaded-comments-reopen-button
.cord-expand-replies
.cord-replies-container
Message
components which are the replies to a thread. This may appear below the initial message of a thread..cord-hide-replies
.cord-show-more
.cord-viewer-avatar-with-composer