Message bubble is a must for migrating to Astro. I had a horribly coded version on my Jekyll blog, but I was always too lazy to optimize it. Now with the power of Astro.js, I have the chance to design one from ground up.
I’ve created a reusable component that mimics the familiar iOS iMessage style. Here’s how it looks in action:
Basic Conversation Example
Add a conversation by using a code block with the message
language:
明天被辞退也不是没可能 😮💨
他会记你小本本吗
我今天下午去上班
门卡卡住了几秒
Private Chat with Chat Title
Display a chat title for a private conversation:
How's your day going?
Pretty good! Just finished that project.
The client was very happy with the results.
That's great news!
Let's celebrate this weekend.
You can also set a custom chat title:
Are we still on for coffee?
Yes, see you at 3pm at the usual place
I might be 5 minutes late though
Group Chat Example
Group chats automatically show avatars for each person’s last message in a sequence:
Has everyone reviewed the document?
Yes, I added my comments yesterday
I also fixed some formatting issues
I'll finish my review today
Just a few more sections to go through
Showing Names in Group Chats
You can show names above message groups:
When is the next team meeting?
Thursday at 2pm
Should be about an hour long
I have a conflict then
Can we move it to Friday?
Showing Message Tails
By default, message tails are hidden. You can enable them:
I just got the project specs
Can you share them with me?
I'd like to review before the meeting
Custom Timestamp
Set a custom timestamp that will appear only on the final message:
Are you still awake?
Yes, just working on some late-night coding
Combined Options
You can combine multiple options:
What's up?
Meeting in 5 minutes!
I'll be there, just finishing up something
Should I bring my laptop?
Yes, we'll need it for the presentation
How It Works
The plugin automatically:
- Parses messages from the text format
- Identifies your messages based on the
myMessageName
in site configuration (Dylan Xu
) - Shows your messages as outgoing (blue bubbles) and others as incoming (gray bubbles)
- Automatically shows avatars for the last message in each group from each sender
- Adds increased spacing between different people’s message groups
- Shows custom time only on the final message of the conversation (when specified)
Configuration Options
- chatTitle: Show a chat title header (
true
,false
, or a custom title) - time: Show a custom time on the final message only (
time=14:30
) - tails: Show message tails (
true
orfalse
, default isfalse
) - showNames: Show sender names above message groups (
true
orfalse
)
Advanced Usage in MDX Files
For more control, you can use components in MDX files:
import MessageConversation from '../components/MessageConversation';
Settings > Export', sender: 'Dylan Xu', showTimestamp: true, timestamp: '10:32 AM' },
{ message: 'Found it, thanks!', sender: 'John Smith', showTimestamp: true, timestamp: '10:33 AM' }
]}
/>
Or parse raw text:
import MessageParser from '../components/MessageParser';