You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BREAKING CHANGE: Removed default values for timestamp formatting props
like calendar or format for DateSeparator, EventComponent,
MessageTimestamp. The formatting configuration now entirely relies on
i18n translations.
Copy file name to clipboardExpand all lines: docusaurus/docs/React/guides/date-time-formatting.mdx
+24-36Lines changed: 24 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ The following components provided by the SDK display datetime:
18
18
19
19
The datetime format customization can be done on multiple levels:
20
20
21
-
1.Override the default component prop values
21
+
1.Component prop values
22
22
2. Supply custom formatting function
23
23
3. Format date via i18n
24
24
@@ -29,11 +29,11 @@ All the mentioned components accept timestamp formatter props:
29
29
```ts
30
30
exporttypeTimestampFormatterOptions= {
31
31
/* If true, call the `Day.js` calendar function to get the date string to display (e.g. "Yesterday at 3:58 PM"). */
32
-
calendar?:boolean|null;
32
+
calendar?:boolean;
33
33
/* Object specifying date display formats for dates formatted with calendar extension. Active only if calendar prop enabled. */
34
-
calendarFormats?:Record<string, string>|null;
34
+
calendarFormats?:Record<string, string>;
35
35
/* Overrides the default timestamp format if calendar is disabled. */
36
-
format?:string|null;
36
+
format?:string;
37
37
};
38
38
```
39
39
@@ -54,7 +54,7 @@ If calendar formatting is enabled, the dates are formatted with time-relative wo
54
54
If any of the `calendarFormats` keys are missing, then the underlying library will fall back to hard-coded english equivalents
55
55
:::
56
56
57
-
If `calendar` formatting is enabled, the `format` prop would be ignored. So to apply the `format` string, the `calendar` has to be disabled (applies to `DateSeparator` and `MessageTimestamp`.
57
+
If `calendar` formatting is enabled, the `format` prop would be ignored. So to apply the `format` string, the `calendar` has to be disabled (applies to `DateSeparator` and `MessageTimestamp`).
58
58
59
59
All the components can be overridden through `Channel` component context:
60
60
@@ -117,44 +117,32 @@ Until now, the datetime values could be customized within the `Channel` componen
117
117
118
118
The default datetime formatting configuration is stored in the JSON translation files. The default translation keys are namespaced with prefix `timestamp/` followed by the component name. For example, the message date formatting can be targeted via `timestamp/MessageTimestamp`, because the underlying component is called `MessageTimestamp`.
119
119
120
-
##### Overriding the prop defaults
121
-
122
-
The default date and time rendering components in the SDK were created with default prop values that override the configuration parameters provided over JSON translations. Therefore, if we wanted to configure the formatting from JSON translation files, we need to nullify the prop defaults first. An example follows:
120
+
You can change the default configuration by passing an object to `translationsForLanguage``Streami18n` option with all or some of the relevant translation keys:
Once the default prop values are nullified, we override the default formatting rules in the JSON translation value. We can take a look at an example of German translation for SystemMessage:
145
+
Once the default prop values are nullified, we override the default formatting rules. We can take a look at an example of German translation for SystemMessage (below a JSON example - note the escaped quotes):
- variable `timestamp` is the name of variable which value will be inserted into the string
167
155
- value separator `|` signals the separation between the interpolated value and the formatting function name
168
156
-`timestampFormatter` is the name of the formatting function that is used to convert the `timestamp` value into desired format
169
-
- the `timestampFormatter` can be passed the same parameters as the React components (`calendar`, `calendarFormats`, `format`) as if the function was called with these values. The values can be simple scalar values as well as objects (note `calendarFormats` should be an object)
157
+
- the `timestampFormatter` can be passed the same parameters as the React components (`calendar`, `calendarFormats`, `format`) as if the function was called with these values. The values can be simple scalar values as well as objects (note `calendarFormats` should be an object). The params should be separated by semicolon `;`.
170
158
171
159
:::note
172
160
The described rules follow the formatting rules required by the i18n library used under the hood - `i18next`. You can learn more about the rules in [the formatting section of the `i18next` documentation](https://www.i18next.com/translation-function/formatting#basic-usage).
-`DateSeparator` - separates message groups in message lists
12
+
-`EventComponent` - displays system messages
13
+
-`MessageTimestamp` - displays the creation timestamp for a message in a message list
14
+
15
+
These components had previously default values for props like `format` or `calendar`. This setup required for a custom formatting to be set up via i18n service, the default values had to be nullified. For a better developer experience we decided to remove the default prop values and rely on default configuration provided via i18n translations. The value `null` is not a valid value for `format`, `calendar` or `calendarFormats` props.
16
+
17
+
:::important
18
+
**Action required**<br/>
19
+
If you are not using the default translations provided with the SDK, make sure to follow the [date & time formatting guide](../guides/date-time-formatting) to verify that your dates are formatted according to your needs.
20
+
:::
21
+
7
22
## Avatar changes
8
23
9
24
The `Avatar` styles are applied through CSS from the version 12 upwards. Therefore, the following changes were applied:
0 commit comments