chat-message
One message: avatar, author, time, text (with @mentions and links picked out), the message it replies to, and reactions. me is the signed-in user's name: their messages, mentions of them and their reactions are marked.
Try it: events appear here (reacttoggle, reply).
Source: chat-message.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/chat-message.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/chat-message.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/chat-message.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/chat-message.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/chat-message.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/chat-message.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/chat-message.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/chat-message.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/chat-message.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/chat-message.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/chat-message.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/chat-message.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/chat-message.js"></script>The compiled install writes src/components/zubra/chat-message.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<chat-message me="Sam Rivera"></chat-message>
<script type="module">
import './components/zubra/chat-message.js';
const element = document.querySelector('chat-message');
element.message = {
id: 'm1',
author: 'Maya Chen',
text: 'Shipped the date picker. @sam can you check it on mobile? Notes: https://example.com/notes',
time: 1794148200000,
reactions: { "🎉": ['Sam Rivera', 'Jo Park'], "👀": ['Jo Park'] },
replyTo: null,
};
element.addEventListener('reacttoggle', (event) => console.log('reacttoggle', event.detail));
element.addEventListener('reply', (event) => console.log('reply', event.detail));
</script>import './components/zubra/chat-message.js';
const message = {
id: 'm1',
author: 'Maya Chen',
text: 'Shipped the date picker. @sam can you check it on mobile? Notes: https://example.com/notes',
time: 1794148200000,
reactions: { "🎉": ['Sam Rivera', 'Jo Park'], "👀": ['Jo Park'] },
replyTo: null,
};
export function ChatMessageExample() {
return (
<chat-message
me="Sam Rivera"
message={message}
onreacttoggle={(event) => console.log('reacttoggle', event.detail)}
onreply={(event) => console.log('reply', event.detail)}
></chat-message>
);
}<script setup>
import './components/zubra/chat-message.js';
const message = {
id: 'm1',
author: 'Maya Chen',
text: 'Shipped the date picker. @sam can you check it on mobile? Notes: https://example.com/notes',
time: 1794148200000,
reactions: { "🎉": ['Sam Rivera', 'Jo Park'], "👀": ['Jo Park'] },
replyTo: null,
};
const onReacttoggle = (event) => console.log('reacttoggle', event.detail);
const onReply = (event) => console.log('reply', event.detail);
</script>
<template>
<chat-message
me="Sam Rivera"
:message.prop="message"
@reacttoggle="onReacttoggle"
@reply="onReply"
></chat-message>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/chat-message.js';
const message = {
id: 'm1',
author: 'Maya Chen',
text: 'Shipped the date picker. @sam can you check it on mobile? Notes: https://example.com/notes',
time: 1794148200000,
reactions: { "🎉": ['Sam Rivera', 'Jo Park'], "👀": ['Jo Park'] },
replyTo: null,
};
</script>
<chat-message
me="Sam Rivera"
{message}
onreacttoggle={(event) => console.log('reacttoggle', event.detail)}
onreply={(event) => console.log('reply', event.detail)}
></chat-message>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/chat-message.js';
@Component({
selector: 'app-chat-message-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<chat-message
me="Sam Rivera"
[message]="message"
(reacttoggle)="onReacttoggle($event)"
(reply)="onReply($event)"
></chat-message>
`,
})
export class ChatMessageExample {
message = {
id: 'm1',
author: 'Maya Chen',
text: 'Shipped the date picker. @sam can you check it on mobile? Notes: https://example.com/notes',
time: 1794148200000,
reactions: { "🎉": ['Sam Rivera', 'Jo Park'], "👀": ['Jo Park'] },
replyTo: null,
};
onReacttoggle(event: Event) {
console.log('reacttoggle', (event as CustomEvent).detail);
}
onReply(event: Event) {
console.log('reply', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
me | string | "" |
messageproperty only | { id, author, text, time, reactions, replyTo } | {"id":"","author":"","text":"","time":0,"reactions":{},"replyTo":null} |
| Event | When |
|---|---|
reacttoggle | A reaction was toggled; detail is the emoji. |
reply | Reply was chosen. |
Size
2.3 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.4 KB.