Skip to content

Commit bda97ba

Browse files
committed
docs: add docs for Poll and PollContent components
1 parent 02bd3fb commit bda97ba

File tree

12 files changed

+124
-50
lines changed

12 files changed

+124
-50
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
An instance of the [`Poll` class](https://github.com/GetStream/stream-chat-js/blob/master/src/poll.ts) containing reactive state.
2+
3+
It is used by the underlying `usePollContext`, `usePollStateStore` and `usePollState` hooks to provide us with the reactive `Poll` state.
4+
5+
:::note
6+
7+
If you need the `Poll` instance you may get it from `client.polls.fromState(pollId)`.
8+
9+
:::
10+
11+
| Type |
12+
| ------ |
13+
| object |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
A `Component` prop used to render the content of the `Poll` component in `MessageList`.
2+
3+
| Type | Default |
4+
| ------------- | ---------------------------------------------- |
5+
| ComponentType | [`PollContent`](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Poll/Poll.tsx) |
6+
7+
#### Props
8+
9+
##### `PollHeader`
10+
11+
A `Component` prop used to render the header of the `PollContent` component.
12+
13+
| Type | Default |
14+
| ------------- | ---------------------------------------------- |
15+
| ComponentType | [`PollHeader`](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Poll/Poll.tsx) |
16+
17+
##### `PollButtons`
18+
19+
A `Component` prop used to render the buttons of the `PollContent` component.
20+
21+
| Type | Default |
22+
| ------------- | ---------------------------------------------- |
23+
| ComponentType | [`PollButtons`](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Poll/Poll.tsx) |
24+

docusaurus/docs/reactnative/contexts/create-poll-context.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { CreatePollContext } from 'stream-chat-react-native';
2424
const value = useContext(CreatePollContext);
2525
```
2626

27-
Alternatively, you can also use `useCreatePollContext` hook provided by library to consume `CreatePollContext`.
27+
Alternatively, you can also use the `useCreatePollContext` hook provided by library to consume `CreatePollContext`.
2828

2929
```tsx
3030
import { useCreatePollContext } from 'stream-chat-react-native';

docusaurus/docs/reactnative/contexts/poll-context.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,41 @@
22
id: poll-context
33
title: PollContext
44
---
5+
6+
import MessageProp from '../common-content/contexts/message-context/message.mdx';
7+
import Poll from '../common-content/contexts/poll-context/poll.mdx';
8+
9+
The `PollContext` is provided by the [`Poll`](../../ui-components/poll) component. If you are not familiar with React Context API, please read about it on [React docs](https://reactjs.org/docs/context.html).
10+
11+
The `PollContext` needs to be used within the [`Channel` component](../../core-components/channel) as it depends on various values provided by it in order to work.
12+
13+
## Basic Usage
14+
15+
The `PollContext` can be consumed by any of the child components of `Channel` as following:
16+
17+
```tsx
18+
import { useContext } from 'react';
19+
import { CreatePollContext } from 'stream-chat-react-native';
20+
21+
const value = useContext(PollContext);
22+
```
23+
24+
Alternatively, you can also use the `usePollContext` hook provided by library to consume `PollContext`.
25+
26+
```tsx
27+
import { usePollContext } from 'stream-chat-react-native';
28+
29+
const value = usePollContext();
30+
```
31+
32+
## Value
33+
34+
### <div class="label description">_forwarded from [MessageContext](../../contexts/message-context#message)_ props</div> message {#message}
35+
36+
<MessageProp />
37+
38+
### `poll` *
39+
40+
<Poll />
41+
42+

docusaurus/docs/reactnative/ui-components/poll.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,27 @@
22
id: poll
33
title: Poll
44
---
5+
6+
import MessageProp from '../common-content/contexts/message-context/message.mdx';
7+
import Poll from '../common-content/contexts/poll-context/poll.mdx';
8+
import PollContent from '../common-content/ui-components/poll/poll-content.mdx'
9+
10+
A component used to render a poll within a `MessageList`. Needs to be structured inside a [`Channel` component](../core-components/channel).
11+
12+
It will render its default `PollContent`, which can be overridden for custom UI. Its children have access to the entire `poll` state through the `usePollState` hook.
13+
14+
## Props
15+
16+
### <div class="label description">_forwarded from [MessageContext](../../contexts/message-context#message)_ props</div> message {#message}
17+
18+
<MessageProp />
19+
20+
### `poll` *
21+
22+
<Poll />
23+
24+
### `PollContent`
25+
26+
<PollContent />
27+
28+

package/src/components/Channel/Channel.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ export type ChannelPropsWithContext<
331331
| 'TypingIndicatorContainer'
332332
| 'UrlPreview'
333333
| 'VideoThumbnail'
334-
| 'Poll'
335-
| 'PollButtons'
336-
| 'PollHeader'
334+
| 'PollContent'
337335
| 'hasCreatePoll'
338336
>
339337
> &
@@ -575,9 +573,7 @@ const ChannelWithContext = <
575573
openPollCreationDialog,
576574
OverlayReactionList = OverlayReactionListDefault,
577575
overrideOwnCapabilities,
578-
Poll,
579-
PollButtons,
580-
PollHeader,
576+
PollContent,
581577
ReactionList = ReactionListDefault,
582578
read,
583579
Reply = ReplyDefault,
@@ -2429,9 +2425,7 @@ const ChannelWithContext = <
24292425
onPressInMessage,
24302426
onPressMessage,
24312427
OverlayReactionList,
2432-
Poll,
2433-
PollButtons,
2434-
PollHeader,
2428+
PollContent,
24352429
ReactionList,
24362430
removeMessage,
24372431
Reply,

package/src/components/Channel/hooks/useCreateMessagesContext.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ export const useCreateMessagesContext = <
7777
onPressInMessage,
7878
onPressMessage,
7979
OverlayReactionList,
80-
Poll,
81-
PollButtons,
82-
PollHeader,
80+
PollContent,
8381
ReactionList,
8482
removeMessage,
8583
Reply,
@@ -180,9 +178,7 @@ export const useCreateMessagesContext = <
180178
onPressInMessage,
181179
onPressMessage,
182180
OverlayReactionList,
183-
Poll,
184-
PollButtons,
185-
PollHeader,
181+
PollContent,
186182
ReactionList,
187183
removeMessage,
188184
Reply,

package/src/components/Message/Message.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ export type MessagePropsWithContext<
176176
| 'setQuotedMessageState'
177177
| 'supportedReactions'
178178
| 'updateMessage'
179-
| 'Poll'
180-
| 'PollButtons'
181-
| 'PollHeader'
179+
| 'PollContent'
182180
> &
183181
Pick<MessageOverlayContextValue<StreamChatGenerics>, 'setData'> &
184182
Pick<OverlayContextValue, 'setOverlay'> &
@@ -288,9 +286,7 @@ const MessageWithContext = <
288286
onThreadSelect,
289287
openThread,
290288
OverlayReactionList,
291-
Poll,
292-
PollButtons,
293-
PollHeader,
289+
PollContent,
294290
preventPress,
295291
removeMessage,
296292
retrySendMessage,
@@ -574,15 +570,9 @@ const MessageWithContext = <
574570
const PollWrapper = useCallback(() => {
575571
const poll = message?.poll_id ? client.polls.fromState(message.poll_id) : undefined;
576572
return message?.poll_id && poll ? (
577-
<PollComponent<StreamChatGenerics>
578-
message={message}
579-
poll={poll}
580-
Poll={Poll}
581-
PollButtons={PollButtons}
582-
PollHeader={PollHeader}
583-
/>
573+
<PollComponent<StreamChatGenerics> message={message} poll={poll} PollContent={PollContent} />
584574
) : null;
585-
}, [PollButtons, PollHeader, Poll, client, message]);
575+
}, [PollContent, client, message]);
586576

587577
const showMessageOverlay = async (isMessageActionsVisible = true, error = errorOrFailed) => {
588578
await dismissKeyboard();

package/src/components/Message/MessageSimple/MessageContent.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const MessageContentWithContext = <
145145
threadList,
146146
} = props;
147147
const { client } = useChatContext();
148-
const { Poll: PollOverride, PollButtons, PollHeader } = useMessagesContext();
148+
const { PollContent: PollContentOverride } = useMessagesContext();
149149

150150
const {
151151
theme: {
@@ -389,9 +389,7 @@ const MessageContentWithContext = <
389389
key={`poll_${message.poll_id}`}
390390
message={message}
391391
poll={poll}
392-
Poll={PollOverride}
393-
PollButtons={PollButtons}
394-
PollHeader={PollHeader}
392+
PollContent={PollContentOverride}
395393
/>
396394
) : null;
397395
}

package/src/components/Poll/Poll.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ import {
1919
MessagesContextValue,
2020
PollContextProvider,
2121
PollContextValue,
22-
usePollContext,
2322
useTheme,
2423
useTranslationContext,
2524
} from '../../contexts';
2625
import type { DefaultStreamChatGenerics } from '../../types/types';
2726

2827
export type PollProps<
2928
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
30-
> = Pick<PollContextValue<StreamChatGenerics>, 'poll' | 'message' | 'PollHeader' | 'PollButtons'> &
31-
Pick<MessagesContextValue<StreamChatGenerics>, 'Poll'>;
29+
> = Pick<PollContextValue<StreamChatGenerics>, 'poll' | 'message'> &
30+
Pick<MessagesContextValue<StreamChatGenerics>, 'PollContent'>;
3231

3332
export const PollButtons = () => (
3433
<>
@@ -70,8 +69,13 @@ export const PollHeader = () => {
7069
);
7170
};
7271

73-
const PollWithContext = () => {
74-
const { PollButtons: PollButtonsOverride, PollHeader: PollHeaderOverride } = usePollContext();
72+
export const PollContent = ({
73+
PollButtons: PollButtonsOverride,
74+
PollHeader: PollHeaderOverride,
75+
}: {
76+
PollButtons?: React.ComponentType;
77+
PollHeader?: React.ComponentType;
78+
}) => {
7579
const { options } = usePollState();
7680

7781
const {
@@ -100,19 +104,15 @@ export const Poll = <
100104
>({
101105
message,
102106
poll,
103-
Poll: PollOverride,
104-
PollButtons,
105-
PollHeader,
107+
PollContent: PollContentOverride,
106108
}: PollProps<StreamChatGenerics>) => (
107109
<PollContextProvider
108110
value={{
109111
message,
110112
poll,
111-
PollButtons,
112-
PollHeader,
113113
}}
114114
>
115-
{PollOverride ? <PollOverride /> : <PollWithContext />}
115+
{PollContentOverride ? <PollContentOverride /> : <PollContent />}
116116
</PollContextProvider>
117117
);
118118

0 commit comments

Comments
 (0)