Skip to content

Commit 49b1079

Browse files
committed
Add some docs
1 parent 67d3936 commit 49b1079

File tree

10 files changed

+68
-1
lines changed

10 files changed

+68
-1
lines changed

src/components/AttachmentButton/AttachmentButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface AttachmentButtonAdditionalProps {
1414
}
1515

1616
export interface AttachmentButtonProps extends AttachmentButtonAdditionalProps {
17+
/** Callback for attachment button tap event */
1718
onPress?: () => void
1819
}
1920

src/components/Chat/Chat.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,56 @@ dayjs.extend(calendar)
4848
export type ChatTopLevelProps = InputTopLevelProps & MessageTopLevelProps
4949

5050
export interface ChatProps extends ChatTopLevelProps {
51+
/** If {@link ChatProps.dateFormat} and/or {@link ChatProps.timeFormat} is not enough to
52+
* customize date headers in your case, use this to return an arbitrary
53+
* string based on a `dateTime` of a particular message. Can be helpful to
54+
* return "Today" if `dateTime` is today. IMPORTANT: this will replace
55+
* all default date headers, so you must handle all cases yourself, like
56+
* for example today, yesterday and before. Or you can just return the same
57+
* date header for any message. */
5158
customDateHeaderText?: (dateTime: number) => string
59+
/** Allows you to customize the date format. IMPORTANT: only for the date,
60+
* do not return time here. @see {@link ChatProps.timeFormat} to customize the time format.
61+
* @see {@link ChatProps.customDateHeaderText} for more customization. */
5262
dateFormat?: string
63+
/** Disable automatic image preview on tap. */
5364
disableImageGallery?: boolean
65+
/** Allows you to change what the user sees when there are no messages.
66+
* `emptyChatPlaceholder` and `emptyChatPlaceholderTextStyle` are ignored
67+
* in this case. */
5468
emptyState?: () => React.ReactNode
69+
/** Use this to enable `LayoutAnimation`. Experimental on Android (same as React Native). */
5570
enableAnimation?: boolean
5671
flatListProps?: Partial<FlatListProps<MessageType.DerivedAny[]>>
5772
inputProps?: InputAdditionalProps
73+
/** Used for pagination (infinite scroll) together with {@link ChatProps.onEndReached}.
74+
* When true, indicates that there are no more pages to load and
75+
* pagination will not be triggered. */
5876
isLastPage?: boolean
77+
/** Override the default localized copy. */
5978
l10nOverride?: Partial<Record<keyof typeof l10n[keyof typeof l10n], string>>
6079
locale?: keyof typeof l10n
6180
messages: MessageType.Any[]
81+
/** Used for pagination (infinite scroll). Called when user scrolls
82+
* to the very end of the list (minus `onEndReachedThreshold`).
83+
* See {@link ChatProps.flatListProps} to set it up. */
6284
onEndReached?: () => Promise<void>
85+
/** Show user names for received messages. Useful for a group chat. Will be
86+
* shown only on text messages. */
6387
showUserNames?: boolean
88+
/** Chat theme. Implement {@link Theme} to create your own theme or use
89+
* existing one, like the {@link defaultTheme}. */
6490
theme?: Theme
91+
/**
92+
* Allows you to customize the time format. IMPORTANT: only for the time,
93+
* do not return date here. @see {@link ChatProps.dateFormat} to customize the date format.
94+
* @see {@link ChatProps.customDateHeaderText} for more customization.
95+
*/
6596
timeFormat?: string
6697
user: User
6798
}
6899

100+
/** Entry component, represents the complete chat */
69101
export const Chat = ({
70102
customDateHeaderText,
71103
dateFormat,

src/components/ImageMessage/ImageMessage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import styles from './styles'
77

88
export interface ImageMessageProps {
99
message: MessageType.DerivedImage
10+
/** Maximum message width */
1011
messageWidth: number
1112
}
1213

14+
/** Image message component. Supports different
15+
* aspect ratios, renders blurred image as a background which is visible
16+
* if the image is narrow, renders image in form of a file if aspect
17+
* ratio is very small or very big. */
1318
export const ImageMessage = ({ message, messageWidth }: ImageMessageProps) => {
1419
const theme = React.useContext(ThemeContext)
1520
const user = React.useContext(UserContext)

src/components/Input/Input.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@ import { SendButton } from '../SendButton'
1515
import styles from './styles'
1616

1717
export interface InputTopLevelProps {
18+
/** Whether attachment is uploading. Will replace attachment button with a
19+
* {@link CircularActivityIndicator}. Since we don't have libraries for
20+
* managing media in dependencies we have no way of knowing if
21+
* something is uploading so you need to set this manually. */
1822
isAttachmentUploading?: boolean
23+
/** @see {@link AttachmentButtonProps.onPress} */
1924
onAttachmentPress?: () => void
25+
/** Will be called on {@link SendButton} tap. Has {@link MessageType.PartialText} which can
26+
* be transformed to {@link MessageType.Text} and added to the messages list. */
2027
onSendPress: (message: MessageType.PartialText) => void
28+
/** Controls the visibility behavior of the {@link SendButton} based on the
29+
* `TextInput` state. Defaults to `editing`. */
2130
sendButtonVisibilityMode?: 'always' | 'editing'
2231
textInputProps?: TextInputProps
2332
}
@@ -29,6 +38,8 @@ export interface InputAdditionalProps {
2938

3039
export type InputProps = InputTopLevelProps & InputAdditionalProps
3140

41+
/** Bottom bar input component with a text input, attachment and
42+
* send buttons inside. By default hides send button when text input is empty. */
3243
export const Input = ({
3344
attachmentButtonProps,
3445
attachmentCircularActivityIndicatorProps,

src/components/Message/Message.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,31 @@ import { TextMessage, TextMessageTopLevelProps } from '../TextMessage'
1616
import styles from './styles'
1717

1818
export interface MessageTopLevelProps extends TextMessageTopLevelProps {
19+
/** Called when user makes a long press on any message */
1920
onMessageLongPress?: (message: MessageType.Any) => void
21+
/** Called when user taps on any message */
2022
onMessagePress?: (message: MessageType.Any) => void
23+
/** Render a custom message inside predefined bubble */
2124
renderCustomMessage?: (
2225
message: MessageType.Custom,
2326
messageWidth: number
2427
) => React.ReactNode
28+
/** Render a file message inside predefined bubble */
2529
renderFileMessage?: (
2630
message: MessageType.File,
2731
messageWidth: number
2832
) => React.ReactNode
33+
/** Render an image message inside predefined bubble */
2934
renderImageMessage?: (
3035
message: MessageType.Image,
3136
messageWidth: number
3237
) => React.ReactNode
38+
/** Render a text message inside predefined bubble */
3339
renderTextMessage?: (
3440
message: MessageType.Text,
3541
messageWidth: number
3642
) => React.ReactNode
43+
/** Show user avatars for received messages. Useful for a group chat. */
3744
showUserAvatars?: boolean
3845
}
3946

@@ -47,6 +54,9 @@ export interface MessageProps extends MessageTopLevelProps {
4754
showStatus: boolean
4855
}
4956

57+
/** Base component for all message types in the chat. Renders bubbles around
58+
* messages and status. Sets maximum width for a message for
59+
* a nice look on larger screens. */
5060
export const Message = React.memo(
5161
({
5262
enableAnimation,

src/components/SendButton/SendButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface SendButtonPropsAdditionalProps {
1414
}
1515

1616
export interface SendButtonProps extends SendButtonPropsAdditionalProps {
17+
/** Callback for send button tap event */
1718
onPress: () => void
1819
}
1920

src/components/TextMessage/TextMessage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import { getUserName, ThemeContext, UserContext } from '../../utils'
1212
import styles from './styles'
1313

1414
export interface TextMessageTopLevelProps {
15+
/** @see {@link LinkPreviewProps.onPreviewDataFetched} */
1516
onPreviewDataFetched?: ({
1617
message,
1718
previewData,
1819
}: {
1920
message: MessageType.DerivedText
2021
previewData: PreviewData
2122
}) => void
23+
/** Enables link (URL) preview */
2224
usePreviewData?: boolean
2325
}
2426

src/l10n.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Base chat l10n containing all required properties to provide localized copy. */
12
export const l10n = {
23
en: {
34
attachmentButtonAccessibilityLabel: 'Send media',

src/theme.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Theme } from './types'
44

55
// For internal usage only. Use values from theme itself.
66

7-
/** See {@link ThemeColors.userAvatarNameColors} */
7+
/** @see {@link ThemeColors.userAvatarNameColors} */
88
export const COLORS: ColorValue[] = [
99
'#ff6767',
1010
'#66e0da',
@@ -45,6 +45,7 @@ const SECONDARY = '#f5f5f7'
4545
/** Secondary dark */
4646
const SECONDARY_DARK = '#2b2250'
4747

48+
/** Default chat theme which implements {@link Theme} */
4849
export const defaultTheme: Theme = {
4950
borders: {
5051
inputBorderRadius: 20,
@@ -155,6 +156,7 @@ export const defaultTheme: Theme = {
155156
},
156157
}
157158

159+
/** Dark chat theme which implements {@link Theme} */
158160
export const darkTheme: Theme = {
159161
...defaultTheme,
160162
colors: {

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export interface Size {
111111
width: number
112112
}
113113

114+
/** Base chat theme containing all required properties to make a theme.
115+
* Implement this interface if you want to create a custom theme. */
114116
export interface Theme {
115117
borders: ThemeBorders
116118
colors: ThemeColors

0 commit comments

Comments
 (0)