ChatDrawer
Props, styling and a live ChatDrawer example.
Customize
Custom footer; takes precedence over the built-in composer.
Alias of `controller`.
Renders the built-in composer and wires message Reply to it.
Move focus into the drawer when it first mounts open. Defaults to `false`; focus always moves when `open` changes to `true`.
composerProps17 props
Offer file attachments: the attach button, drop and paste. Defaults to `true`. Turn it off when the composer's actions have no upload adapter.
File types the attach button offers, as for `<input accept>`.
Offer named file types. Omit to keep the single file picker.
Allow picking several files at once. Defaults to `true`.
Resolves the reply banner's quoted message without a controller.
Replaces the locale's `composer.placeholder`.
Rendered in the toolbar before the built-in buttons.
Rendered after the message field, before the send or mic button.
Show the emoji picker button. Defaults to `true`.
Show the voice note button. Defaults to `true` where the browser has `MediaRecorder` and `getUserMedia`.
Send a voice note as soon as it finishes uploading. Defaults to `true`.
Options for the "/" quick reply menu.
Called after a quick reply's text is inserted.
Rows the message field grows to before it scrolls. Defaults to 8.
Presentation-only: never reloads history or cancels a send.
Show a Reply action on each message.
npm install @polymorfa/react@dev @polymorfa/browser@devimport { useState } from "react";
import { PolymorfaProvider, ChatDrawer } from "@polymorfa/react";
const appearance = { theme: "light", variables: { colorPrimary: "#635bff" } };
export function ChatDrawerExample({ conversation, composer }) {
const [open, setOpen] = useState(true);
return (
<PolymorfaProvider tokenEndpoint="/api/polymorfa/token" appearance={appearance}>
<style>{"/* Composer row alignment until the UI Kit stylesheet includes it. */\n.pmfa-composer .pmfa-input { min-height: 40px; padding-block: max(4px, calc((40px - 1.45em - 2px) / 2)); }\n.pmfa-chat-window .pmfa-composer .pmfa-input { min-height: 44px; padding-block: max(4px, calc((44px - 1.4em - 2px) / 2)); }\n.pmfa-chat-window .pmfa-composer-row .pmfa-btn-icon { min-height: 44px; margin-block: 0; }\n@media (max-width: 600px) { .pmfa-composer .pmfa-input { min-height: 44px; padding-block: max(4px, calc((44px - 1.45em - 2px) / 2)); } }"}</style>
<ChatDrawer
controller={conversation}
composerController={composer}
open={open}
title="Avery Morgan"
autoFocus={false}
composerProps={{
attachments: true,
accept: "image/*,application/pdf",
attachmentKinds: ["image", "document"],
multiple: true,
emoji: true,
voiceNotes: false,
voiceNoteAutoSend: false,
placeholder: "Write a message…",
maxRows: 8,
quickReplies: [
{ id: "hello", shortcut: "hello", text: "Hi! How can I help?" }
]
}}
onClose={() => setOpen(false)}
/>
</PolymorfaProvider>
);
}ChatDrawer from @polymorfa/react. Choose props and styles above; the preview stays visible in every code view.
Props#
openbooleanShows the drawer. Nothing renders while it is
false.Default
trueonClose() => voidCalled by the close button and by Escape inside the drawer.
composerReactNodeCustom footer; takes precedence over the built-in composer.
titlestringDrawer title and accessible name.
conversationConversationControllerAlias of
controller.composerControllerMessageComposerControllerRenders the built-in composer and wires message Reply to it.
createComposerController() => MessageComposerControllerFactory for a composer the drawer owns.
autoFocusbooleanMove focus into the drawer when it first mounts open. Defaults to
false; focus always moves whenopenchanges totrue.Default
falsecomposerPropsOmit<ComposeBoxProps, "controller" | "createController" | "conversation">Props for the built-in composer.
classNamestringSame as
MessageList.classNamesSlotClassNamesSame as
MessageList.controllerConversationControllerConversation to render.
createController() => ConversationControllerConversation to render.
messageFilter(message: ConversationMessage) => booleanPresentation-only: never reloads history or cancels a send.
renderMessage(message: ConversationMessage) => ReactNodeSame as
MessageList.renderAttachmentRenderAttachmentSame as
MessageList.onReply(message: ConversationMessage) => voidShow a Reply action on each message.
composerProps#
onSent() => voidCalled after a send.
classNamestringClass for the root.
classNamesSlotClassNamesClasses keyed by slot.
attachmentsbooleanOffer file attachments: the attach button, drop and paste. Defaults to
true. Turn it off when the composer's actions have no upload adapter.Default
trueacceptstringFile types the attach button offers, as for
<input accept>.attachmentKindsreadonly AttachmentKind[]Offer named file types. Omit to keep the single file picker.
multiplebooleanAllow picking several files at once. Defaults to
true.Default
truemessagesreadonly ConversationMessage[]Resolves the reply banner's quoted message without a controller.
placeholderstringReplaces the locale's
composer.placeholder.Default Locale text
startActionsReactNodeRendered in the toolbar before the built-in buttons.
endActionsReactNodeRendered after the message field, before the send or mic button.
emojibooleanShow the emoji picker button. Defaults to
true.Default
truevoiceNotesbooleanShow the voice note button. Defaults to
truewhere the browser hasMediaRecorderandgetUserMedia.Default
truewhere supportedvoiceNoteAutoSendbooleanSend a voice note as soon as it finishes uploading. Defaults to
true.Default
truequickRepliesreadonly QuickReplyOption[]Options for the "/" quick reply menu.
onQuickReply(option: QuickReplyOption) => voidCalled after a quick reply's text is inserted.
maxRowsnumberRows the message field grows to before it scrolls. Defaults to 8.
Default
8
Types#
Named types used in the props above.
type AttachmentKind =
| "image"
| "video"
| "audio"
| "document";type RenderAttachment = (attachment: MessageAttachment, message: ConversationMessage) => ReactNode;Styling#
Use className, classNames (a class for any slot, typed SlotClassNames), appearance variables and element styles. The Style panel applies changes to the live component. See Appearance.
Setup#
Use the provider and server route for your application. The preview above uses local sample data and controllers. Chat controllers and inbox data sources keep your data separate from the UI.