Zubra UI
Code for
GitHub

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

Compiled (any project)
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
One file, no dependencies (4.3 KB gzipped)
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
.zb source (to edit it with Zubra)
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
No build: a script tag, straight from this site
HTML
<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

index.html
<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>
Example.jsx
import './components/zubra/message-composer.js';

export function MessageComposerExample() {
  return (
    <message-composer
      placeholder="Message #design"
      onsend={(event) => console.log('send', event.detail)}
    ></message-composer>
  );
}
Example.vue
<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('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/message-composer.js';
</script>

<message-composer
  placeholder="Message #design"
  onsend={(event) => console.log('send', event.detail)}
></message-composer>
example.component.ts
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

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
placeholderstring"Message"
disabledbooleanfalse
replytounknownnull
Events
EventWhen
typingThe user typed (at most every two seconds).
sendSend was chosen; detail is the trimmed text.
replycancelThe 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.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour