message-composer
Writing a message: Enter sends, Shift+Enter adds a line, the box grows with the text, an emoji menu inserts at the caret, and a message being replied to shows above.
Try it: events appear here (send).
Source: message-composer.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/message-composer.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/message-composer.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/message-composer.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/message-composer.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/message-composer.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/message-composer.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/message-composer.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/message-composer.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/message-composer.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/message-composer.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/message-composer.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/message-composer.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/message-composer.js"></script>The compiled install writes src/components/zubra/message-composer.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
<message-composer placeholder="Message #design"></message-composer>
<script type="module">
import './components/zubra/message-composer.js';
const element = document.querySelector('message-composer');
element.addEventListener('send', (event) => console.log('send', event.detail));
</script>import './components/zubra/message-composer.js';
export function MessageComposerExample() {
return (
<message-composer
placeholder="Message #design"
onsend={(event) => console.log('send', event.detail)}
></message-composer>
);
}<script setup>
import './components/zubra/message-composer.js';
const onSend = (event) => console.log('send', event.detail);
</script>
<template>
<message-composer placeholder="Message #design" @send="onSend"></message-composer>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/message-composer.js';
</script>
<message-composer
placeholder="Message #design"
onsend={(event) => console.log('send', event.detail)}
></message-composer>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/message-composer.js';
@Component({
selector: 'app-message-composer-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<message-composer placeholder="Message #design" (send)="onSend($event)"></message-composer>
`,
})
export class MessageComposerExample {
onSend(event: Event) {
console.log('send', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
placeholder | string | "Message" |
disabled | boolean | false |
replyto | unknown | null |
| Event | When |
|---|---|
typing | The user typed (at most every two seconds). |
send | Send was chosen; detail is the trimmed text. |
replycancel | The reply was cancelled. |
Size
2.0 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.6 KB.