|
1 | 1 | ---
|
2 | 2 | id: channel_preview_ui
|
3 |
| -title: ChannelPreview UI |
| 3 | +title: Preview (ChannelPreview) |
4 | 4 | ---
|
5 | 5 |
|
6 | 6 | import GHComponentLink from '../../_docusaurus-components/GHComponentLink';
|
7 | 7 |
|
8 |
| -The ChannelPreview UI component receives props via the [`ChannelPreview`](./channel-preview.mdx) wrapper, and |
9 |
| -these props are a combination of the `ChannelPreview` props with additional UI specific items. The wrapper also handles the required logic |
10 |
| -while the UI component is responsible for the UI display and the click functionality for channel selection. |
| 8 | +The [`ChannelList`](../core-components/channel-list.mdx) property `Preview` is a UI placeholder (think of it as a UI of a `ChannelList` item) which receives props through the `ChannelList` and the [`ChannelPreview`](./channel-preview.mdx) wrapper which extends these props with additional UI-specific items and renders it. Apart from the UI the `Preview` component is also responsible for channel selection (click handler). |
11 | 9 |
|
12 |
| -This UI component is set via the `Preview` prop on `ChannelList`, and if nothing is provided then the default is used, [`ChannelPreviewMessenger`](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelPreview/ChannelPreviewMessenger.tsx). |
| 10 | +The `Preview` property defaults to [`ChannelPreviewMessenger`](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelPreview/ChannelPreviewMessenger.tsx) component if no custom component is provided. |
13 | 11 |
|
14 | 12 | ## Basic Usage
|
15 | 13 |
|
16 |
| -This UI component is very customizable; below is an example of how to use the `Preview` prop, and for a more involved step-by-step guide, using the many provided props, |
17 |
| -see [ChannelPreview Code Example](../../guides/customization/channel-list-preview.mdx#the-preview-prop-component). |
| 14 | +To customize the `ChannelList` item UI simply pass your custom `Preview` component to the `ChannelList`. See [The Preview Prop Component](../../guides/customization/channel-list-preview.mdx#the-preview-prop-component) for the extended guide. |
18 | 15 |
|
19 | 16 | ```tsx
|
20 |
| -const YourCustomChannelPreview = (previewProps) => { |
21 |
| - // render custom preview info here |
22 |
| - return <YourCustomChannelPreview {...previewProps} />; |
| 17 | +const CustomChannelPreviewUI = ({ latestMessage, lastMessage }) => { |
| 18 | + // "lastMessage" property is for the last |
| 19 | + // message that has been interacted with (pinned/edited/deleted) |
| 20 | + |
| 21 | + // to display last message of the channel use "latestMessage" property |
| 22 | + return <span>{latestMessage}</span>; |
23 | 23 | };
|
24 | 24 |
|
25 |
| -<ChannelList Preview={YourCustomChannelPreview} />; |
| 25 | +<ChannelList Preview={CustomChannelPreviewUI} />; |
26 | 26 | ```
|
27 | 27 |
|
28 | 28 | ## Props
|
29 | 29 |
|
30 | 30 | ### <div class="label required basic">Required</div> channel
|
31 | 31 |
|
32 |
| -This required prop is the channel to be previewed; comes from either the `channelRenderFilterFn` or `usePaginatedChannels` call from |
33 |
| -[ChannelList](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/ChannelList.tsx) and does not need to be set manually. |
| 32 | +This required prop is the channel to be previewed; comes from either the `channelRenderFilterFn` or `usePaginatedChannels` call from [ChannelList](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/ChannelList.tsx) and does not need to be set manually. |
34 | 33 |
|
35 |
| -| Type | |
36 |
| -| ------- | |
37 |
| -| Channel | |
| 34 | +| Type | |
| 35 | +| --------- | |
| 36 | +| `Channel` | |
38 | 37 |
|
39 | 38 | ### active
|
40 | 39 |
|
41 | 40 | If the component's channel is the active (selected) channel.
|
42 | 41 |
|
43 |
| -| Type | |
44 |
| -| ------- | |
45 |
| -| boolean | |
| 42 | +| Type | |
| 43 | +| --------- | |
| 44 | +| `boolean` | |
46 | 45 |
|
47 | 46 | ### activeChannel
|
48 | 47 |
|
49 | 48 | The currently selected channel object.
|
50 | 49 |
|
51 |
| -| Type | |
52 |
| -| ------- | |
53 |
| -| Channel | |
| 50 | +| Type | |
| 51 | +| --------- | |
| 52 | +| `Channel` | |
54 | 53 |
|
55 | 54 | ### Avatar
|
56 | 55 |
|
57 | 56 | The custom UI component to display the avatar for the channel.
|
58 | 57 |
|
59 |
| -| Type | Default | |
60 |
| -| --------- | ---------------------------------------------------------- | |
61 |
| -| component | <GHComponentLink text='Avatar' path='/Avatar/Avatar.tsx'/> | |
| 58 | +| Type | Default | |
| 59 | +| ----------- | ---------------------------------------------------------- | |
| 60 | +| `component` | <GHComponentLink text='Avatar' path='/Avatar/Avatar.tsx'/> | |
62 | 61 |
|
63 | 62 | ### channelUpdateCount
|
64 | 63 |
|
65 | 64 | A number that forces the update of the preview component on channel update.
|
66 | 65 |
|
67 |
| -| Type | |
68 |
| -| ------ | |
69 |
| -| number | |
| 66 | +| Type | |
| 67 | +| -------- | |
| 68 | +| `number` | |
70 | 69 |
|
71 | 70 | ### className
|
72 | 71 |
|
73 | 72 | Custom class for the channel preview root
|
74 | 73 |
|
75 |
| -| Type | |
76 |
| -| ------ | |
77 |
| -| string | |
| 74 | +| Type | |
| 75 | +| -------- | |
| 76 | +| `string` | |
78 | 77 |
|
79 | 78 | ### displayImage
|
80 | 79 |
|
81 | 80 | Image of channel to display.
|
82 | 81 |
|
83 |
| -| Type | |
84 |
| -| ------ | |
85 |
| -| string | |
| 82 | +| Type | |
| 83 | +| -------- | |
| 84 | +| `string` | |
86 | 85 |
|
87 | 86 | ### displayTitle
|
88 | 87 |
|
89 | 88 | Title of channel to display.
|
90 | 89 |
|
91 |
| -| Type | |
92 |
| -| ------ | |
93 |
| -| string | |
| 90 | +| Type | |
| 91 | +| -------- | |
| 92 | +| `string` | |
94 | 93 |
|
95 | 94 | ### lastMessage
|
96 | 95 |
|
97 | 96 | The last message received in a channel.
|
98 | 97 |
|
99 |
| -| Type | |
100 |
| -| ------------- | |
101 |
| -| StreamMessage | |
| 98 | +| Type | |
| 99 | +| --------------- | |
| 100 | +| `StreamMessage` | |
102 | 101 |
|
103 | 102 | ### latestMessage
|
104 | 103 |
|
105 | 104 | Latest message preview to display. Will be either a string or a JSX.Element rendering markdown.
|
106 | 105 |
|
107 |
| -| Type | |
108 |
| -| --------------------- | |
109 |
| -| string \| JSX.Element | |
| 106 | +| Type | |
| 107 | +| ----------------------- | |
| 108 | +| `string \| JSX.Element` | |
110 | 109 |
|
111 | 110 | ### messageDeliveryStatus
|
112 | 111 |
|
113 | 112 | Status describing whether own message has been delivered or read by another. If the last message is not an own message, then the status is undefined. The value is calculated from `channel.read` data on mount and updated on every `message.new` resp. `message.read` WS event.
|
114 | 113 |
|
115 | 114 | | Type |
|
116 |
| -|-------------------------| |
| 115 | +| ----------------------- | |
117 | 116 | | `MessageDeliveryStatus` |
|
118 | 117 |
|
119 | 118 | Use `MessageDeliveryStatus` enum to determine the current delivery status, for example:
|
120 | 119 |
|
121 |
| -```typescript jsx |
122 |
| -import { MessageDeliveryStatus } from 'stream-chat-react'; |
123 |
| -import { |
124 |
| - DoubleCheckMarkIcon, |
125 |
| - SingleCheckMarkIcon, |
126 |
| -} from '../icons'; |
| 120 | +```tsx |
| 121 | +import type { MessageDeliveryStatus } from 'stream-chat-react'; |
| 122 | +import { DoubleCheckMarkIcon, SingleCheckMarkIcon } from '../icons'; |
127 | 123 |
|
128 | 124 | type MessageDeliveryStatusIndicator = {
|
129 |
| - messageDeliveryStatus: MessageDeliveryStatus; |
130 |
| -} |
131 |
| - |
132 |
| -export const MessageDeliveryStatusIndicator = ({ messageDeliveryStatus }: MessageDeliveryStatusIndicator) => { |
133 |
| - // the last message is not an own message in the channel |
134 |
| - if (!messageDeliveryStatus) return null; |
135 |
| - |
136 |
| - return ( |
137 |
| - <div> |
138 |
| - {messageDeliveryStatus === MessageDeliveryStatus.DELIVERED && <SingleCheckMarkIcon /> } |
139 |
| - {messageDeliveryStatus === MessageDeliveryStatus.READ && <DoubleCheckMarkIcon /> } |
140 |
| - </div> |
141 |
| - ); |
| 125 | + messageDeliveryStatus: MessageDeliveryStatus; |
| 126 | +}; |
| 127 | + |
| 128 | +export const MessageDeliveryStatusIndicator = ({ |
| 129 | + messageDeliveryStatus, |
| 130 | +}: MessageDeliveryStatusIndicator) => { |
| 131 | + // the last message is not an own message in the channel |
| 132 | + if (!messageDeliveryStatus) return null; |
| 133 | + |
| 134 | + return ( |
| 135 | + <div> |
| 136 | + {messageDeliveryStatus === MessageDeliveryStatus.DELIVERED && <SingleCheckMarkIcon />} |
| 137 | + {messageDeliveryStatus === MessageDeliveryStatus.READ && <DoubleCheckMarkIcon />} |
| 138 | + </div> |
| 139 | + ); |
142 | 140 | };
|
143 | 141 | ```
|
144 | 142 |
|
145 | 143 | ### onSelect
|
146 | 144 |
|
147 | 145 | Custom handler invoked when the `ChannelPreview` is clicked. The SDK uses `ChannelPreview` to display items of channel search results. There, behind the scenes, the new active channel is set.
|
148 | 146 |
|
149 |
| -| Type | |
150 |
| -| --------------------------------- | |
151 |
| -| (event: React.MouseEvent) => void | |
| 147 | +| Type | |
| 148 | +| ----------------------------------- | |
| 149 | +| `(event: React.MouseEvent) => void` | |
152 | 150 |
|
153 | 151 | ### Preview
|
154 | 152 |
|
155 | 153 | The UI component to use for display.
|
156 | 154 |
|
157 |
| -| Type | Default | |
158 |
| -| --------- | ---------------------------------------------------------------------------------------------------- | |
159 |
| -| component | <GHComponentLink text='ChannelPreviewMessenger' path='/ChannelPreview/ChannelPreviewMessenger.tsx'/> | |
| 155 | +| Type | Default | |
| 156 | +| ----------- | ---------------------------------------------------------------------------------------------------- | |
| 157 | +| `component` | <GHComponentLink text='ChannelPreviewMessenger' path='/ChannelPreview/ChannelPreviewMessenger.tsx'/> | |
160 | 158 |
|
161 | 159 | ### setActiveChannel
|
162 | 160 |
|
163 | 161 | The setter function for a selected `channel`.
|
164 | 162 |
|
165 |
| -| Type | |
166 |
| -| ------------------------------------ | |
167 |
| -| ChatContextValue['setActiveChannel'] | |
| 163 | +| Type | |
| 164 | +| -------------------------------------- | |
| 165 | +| `ChatContextValue['setActiveChannel']` | |
168 | 166 |
|
169 | 167 | ### unread
|
170 | 168 |
|
171 | 169 | The number of unread Messages.
|
172 | 170 |
|
173 |
| -| Type | |
174 |
| -| ------ | |
175 |
| -| number | |
| 171 | +| Type | |
| 172 | +| -------- | |
| 173 | +| `number` | |
176 | 174 |
|
177 | 175 | ### watchers
|
178 | 176 |
|
179 | 177 | The object containing watcher parameters. See the [Pagination documentation](https://getstream.io/chat/docs/react/channel_pagination/?language=js) for a list of available fields for sort.
|
180 | 178 |
|
181 |
| -| Type | |
182 |
| -| ----------------------------------- | |
183 |
| -| { limit?: number; offset?: number } | |
| 179 | +| Type | |
| 180 | +| ------------------------------------- | |
| 181 | +| `{ limit?: number; offset?: number }` | |
0 commit comments