CometChatTextFormatter
is an abstract utility class that provides the foundation for enabling rich text formatting in message composers and message bubbles. It can be extended to create custom formatter classes, allowing for specific text formatting such as mentions, hashtags, markdown, or any other custom styles within chat interfaces.
Field | Setter | Description |
---|---|---|
protected trackCharacter | setTrackingCharacter(trackCharacter: string) | The character that triggers formatting. For hashtags, this would be # . |
protected currentCaretPosition | setCaretPositionAndRange(currentCaretPosition, currentRange) | Current caret position or type of text selection in the input field. |
protected currentRange | setCaretPositionAndRange(currentCaretPosition, currentRange) | Represents the text range selected by the user or the cursor’s position. |
protected inputElementReference | setInputElementReference(inputElementReference) | Reference to the input field DOM element. Used to read textContent . |
protected regexPatterns | setRegexPatterns(regexPatterns) | Regex patterns to identify specific text patterns in user input. |
protected regexToReplaceFormatting | setRegexToReplaceFormatting(regexToReplaceFormatting) | Regex patterns to replace formatted text with the original text. |
protected keyUpCallBack | setKeyUpCallBack(keyUpCallBack) | Callback function for ‘keyup’ events. |
protected keyDownCallBack | setKeyDownCallBack(keyDownCallBack) | Callback function for ‘keydown’ events. |
protected reRender | setReRender(reRender) | Function to trigger a re-render of the component, useful for updating UI content. |
protected loggedInUser | setLoggedInUser(loggedInUser) | The logged-in user object set by the composer and text bubbles. |
protected id | setId(id) | A unique identifier for the formatter instance. |
textContent
or innerHtml
of the input element in formatters is not recommended. Use the reRender
method to update text content in the UI.getFormattedText
function of all formatters is invoked upon calling reRender
, maintaining the order in which they were received as props.CometChatTextFormatter
class and override the necessary methods. Ensure to handle text matching, formatting, and event listening as per your requirements.