-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4f4a9f
commit 8567a98
Showing
4 changed files
with
86 additions
and
5 deletions.
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
23 changes: 20 additions & 3 deletions
23
docusaurus/docs/React/components/core-components/thread-list-item.mdx
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 |
---|---|---|
@@ -1,4 +1,21 @@ | ||
TODO: | ||
--- | ||
id: thread-list-item | ||
title: ThreadListItem | ||
--- | ||
|
||
- basic definition | ||
- activation behavior | ||
An item component rendered within [`ThreadList` component](./thread-list.mdx). The item is divided into two components: | ||
|
||
`ThreadListItem` - a component and provider which renders `ThreadListItemUi` | ||
`ThreadListItemUi` - a component which renders the actual UI elements | ||
|
||
The goal is that as integrator you can provide a different look to your component while preserving the behavior or you can replace the behavior while keeping the default UI or you can change both if you require so. | ||
|
||
## Props | ||
|
||
### thread | ||
|
||
A thread instance provided by the [`ThreadList`](../core-components/thread-list.mdx). | ||
|
||
| Type | | ||
| ------ | | ||
| Thread | |
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
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,62 @@ | ||
--- | ||
id: custom-threads-view | ||
title: Custom Threads View | ||
keywords: [cookbook, threads, view] | ||
--- | ||
|
||
Our SDK comes with [`ChatView`](../components/utility-components/chat-view.mdx) which allows for an easy integration of different views. In this guide we'll show how to implement custom threads view while utilising core components and hooks. | ||
|
||
## Required Components & Hooks | ||
|
||
These components and hooks are required for your own implementation to work properly: | ||
|
||
- `ThreadList` | ||
- `ThreadListItem` - a provider for `ThreadListItemUi` with thread information, will be used to forward custom click event to the `ThreadListItemUi` button | ||
- `ThreadProvider` - "adapter" for Thread component to work properly with [`Thread` instance](https://github.com/GetStream/stream-chat-js/blob/master/src/thread.ts) | ||
- `Thread` - provides [`MessageList`](../components/core-components/message-list.mdx) with [`MessageInput`](../components/message-input-components/message-input.mdx) adjusted for threads | ||
- `useActiveThread` - takes your selected thread instance and handles its activity state (`Thread.activate()` & `Thread.deactivate()`) based on document focus and visibility | ||
|
||
## Building Custom Threads View | ||
|
||
```tsx | ||
import { | ||
ThreadList, | ||
ThreadListItem, | ||
ThreadProvider, | ||
Thread, | ||
WithComponents, | ||
useActiveThread, | ||
} from 'stream-chat-react'; | ||
|
||
export const CustomThreadsView = () => { | ||
const [activeThread, setActiveThread] = useState(undefined); | ||
|
||
useActiveThread({ activeThread }); | ||
|
||
return ( | ||
<div className='custom-threads-view'> | ||
<ThreadList | ||
virtuosoProps={{ | ||
itemContent: (_, thread) => ( | ||
<ThreadListItem | ||
thread={thread} | ||
threadListItemUiProps={{ | ||
'aria-selected': thread === activeThread, | ||
onClick: () => { | ||
setActiveThread(thread); | ||
}, | ||
}} | ||
/> | ||
), | ||
}} | ||
/> | ||
|
||
{activeThread && ( | ||
<ThreadProvider thread={activeThread}> | ||
<Thread /> | ||
</ThreadProvider> | ||
)} | ||
</div> | ||
); | ||
}; | ||
``` |