Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update readme to include formatDate example #553

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/react-inbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,31 @@ New Theme Properties:
- `theme.menu`: clicking on the inbox title opens a dropdown menu with options to edit `preferences`
- `theme.message.clickableContainer`: when a message has an action href, we now make the entire message clickable instead of rendering an explicit button. this theme property allows access to this component. `theme.message.container` will still apply to this component but if you want to target the clickableContainer separatly you can target `theme.message.clickableContainer` which will be an `anchor` element instead of a `div`;

### [Using Custom Date Format](#using-custom-date-format)

The inbox component accepts a function in property `formatDate` of type `(isoDate: string) => string;`. You can overwrite Courier's date formats on each message using `formatDate` for use cases like internationalization and override the browser's default.

Example using [date-fns](https://date-fns.org):

```
import formatDistanceStrict from "date-fns/formatDistanceStrict";
import { Locale } from "date-fns";

const getTimeAgo = (created: string, locale: Locale) => {
return formatDistanceStrict(new Date(created).getTime(), Date.now(), {
addSuffix: true,
roundingMethod: "floor",
locale
})(created);
}

---

<Inbox
formatDate={isoDate=>getTimeAgo(isoDate, users_locale)}
>
```

## [Listening to Events](#events)

You can listen to inbox events by passing onEvent prop to <Inbox/>
Expand Down
Loading