suiss/ui · Component
Message
Lays out a single chat message with an optional avatar, header and footer.
Message is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Message arranges one message row: an optional MessageAvatar and a MessageContent column. Inside the content, place an optional MessageHeader (such as a sender name), one or more bubbles, and an optional MessageFooter (such as a timestamp or read receipt). Wrap consecutive messages in MessageGroup to stack them.
Message handles layout only. Pair it with Bubble for the message surface and with Message Scroller for a scrolling transcript.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
-
Add the
cnhelper. -
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a Message:
Examples
Align end
Set align="end" on Message for messages sent by the current user. The row reverses, so the avatar moves to the end.
With header and footer
Put a MessageHeader above the bubble for the sender name and a MessageFooter below it for a timestamp. When a footer is present, the avatar shifts up to line up with the last bubble.
Conversation
A MessageGroup with an incoming message of two bubbles and an outgoing reply.
API Reference
MessageGroup
Stacks several messages vertically.
Also accepts the props of React.ComponentProps<"div">.
Message
The row for one message that sets its alignment.
| Prop | Type | Default |
|---|---|---|
align | "start" | "end" | "start" |
Also accepts the props of React.ComponentProps<"div">.
align="end" reverses the row for outgoing messages, so the avatar moves to the end and the content's children and the footer align to the end edge.
MessageAvatar
A round container for the sender's avatar, aligned to the bottom of the row.
Also accepts the props of React.ComponentProps<"div">.
MessageContent
The column that holds the header, bubbles and footer.
Also accepts the props of React.ComponentProps<"div">.
MessageHeader
Small secondary text above the bubbles, such as the sender name.
Also accepts the props of React.ComponentProps<"div">.
MessageFooter
Small secondary text below the bubbles, such as a timestamp.
Also accepts the props of React.ComponentProps<"div">.
The header and footer drop their horizontal padding when the message contains an element with data-variant="ghost".
Each part sets a data-slot, such as message or message-footer, for styling. Message also sets data-align.
Web preview
Message is a horizontal View that places an avatar next to a column of bubbles. Its align prop puts the row on the leading (start) or trailing (end) side and passes the alignment to any Bubble inside through context.
MessageGroup stacks several messages into a conversation. MessageHeader and MessageFooter hold small secondary text, such as a sender name or a timestamp. Put a MessageAvatar and a MessageContent inside each Message, and place Bubble components, a MessageHeader and a MessageFooter in MessageContent.
Installation
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Align end
A message aligned to the trailing side, as for the current user.
Web preview
With header and footer
A message with a sender name in MessageHeader and a timestamp in MessageFooter. When MessageContent contains a footer, the avatar shifts up to line up with the last bubble.
Web preview
Conversation
A MessageGroup with an incoming and an outgoing message, including a read receipt footer.
Web preview
Accessibility
- Messages are plain
ViewandTextelements, so screen readers read the header, bubble text and footer in order. - Give avatars without visible text, such as images, an
accessibilityLabel.
API Reference
MessageGroup
Vertical stack of messages.
Also accepts the props of ViewProps.
Message
Row that holds the avatar and content and sets the alignment.
| Prop | Type | Default |
|---|---|---|
align | MessageAlign | "start" |
Also accepts the props of ViewProps.
align also passes the side to nested bubbles and the footer through context.
MessageAvatar
Round slot for an avatar, pinned to the bottom of the row.
Also accepts the props of ViewProps.
MessageContent
Column of bubbles built on BubbleGroup.
Also accepts the props of React.ComponentProps<typeof BubbleGroup>.
MessageHeader
Small secondary text above the bubbles.
Also accepts the props of ViewProps.
Plain strings in MessageHeader and MessageFooter are wrapped in Text for you, so you can pass text directly or mix it with an Icon.
MessageFooter
Small secondary text below the bubbles, aligned with the message side.
Also accepts the props of ViewProps.
MessageGroup
Vertical stack of messages.
| Parameter | Type | Default |
|---|---|---|
spacing | CGFloat | 8 |
content | () -> Content | - |
Message
Row that holds the avatar and content and sets the alignment.
| Parameter | Type | Default |
|---|---|---|
align | Align | .start |
content | () -> Content | - |
MessageAvatar
Round slot for an avatar, pinned to the bottom of the row.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
MessageContent
Column of bubbles built on BubbleGroup.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
MessageHeader
Small secondary text above the bubbles.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
_Â text | LocalizedStringKey | - |
verbatim | String | - |
Overloads: init(content:), init(_:), init(verbatim:).
MessageFooter
Small secondary text below the bubbles, aligned with the message side.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
_Â text | LocalizedStringKey | - |
verbatim | String | - |
Overloads: init(content:), init(_:), init(verbatim:).
MessageAlign
Values: Start, End.
MessageGroup
Vertical stack of messages.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable ColumnScope.() -> Unit | - |
Message
Row that holds the avatar and content and sets the alignment.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
align | MessageAlign: Start | End | MessageAlign.Start |
content | @Composable () -> Unit | - |
MessageAvatar
Round slot for an avatar, pinned to the bottom of the row.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable BoxScope.() -> Unit | - |
MessageContent
Column of bubbles built on BubbleGroup.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable () -> Unit | - |
MessageHeader
Small secondary text above the bubbles.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable RowScope.() -> Unit | - |
text | String | - |
Overloads: MessageHeader(content), MessageHeader(text).
MessageFooter
Small secondary text below the bubbles, aligned with the message side.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable RowScope.() -> Unit | - |
text | String | - |
Overloads: MessageFooter(content), MessageFooter(text).