Styles
Properties related to message styling.
messageStyles
- Type: {
default?: MessageRoleStyles,
image?: MessageRoleStyles,
audio?: MessageRoleStyles,
file?: MessageRoleStyles,
html?: MessageRoleStyles,
intro?: MessageElementsStyles,
error?: MessageElementsStyles,
loading?: LoadingMessageStyles
}
Object defining the styling for various message types.
default is applied to all message types.
image is applied to messages that contain an image.
audio is applied to messages that contain an audio player.
file is applied to messages that contain a file attachment.
html is applied to messages that contain custom elements - more info.
intro is applied to the introMessage.
error is applied to error messages.
loading is applied to messages with loading elements.
remarkable
-
Type: {
xhtmlOut?: boolean,
html?: boolean,
breaks?: boolean,
langPrefix?: "language-${string}",
linkTarget?: string,
typographer?: boolean,
quotes?: string,
highlight?: (str: string, lang: string) => void,
math?: true|{delimiter?: string; options?: KatexOptions},
applyHTML?: boolean
} -
Default: { breaks: true, linkTarget: "_blank" }
Deep Chat uses the remarkable library to render markdown for its text messages.
Use this object to change its configuration.
xhtmlOut uses '/' to close single tags via <br />.
html enables HTML tags in source.
breaks converts '\n' in paragraphs into <br>.
langPrefix is a CSS language prefix for fenced blocks.
linkTarget sets the target to open links in. "\_blank" is used to open links in a new tab.
typographer enables some language-neutral replacement + quotes beautification.
quotes is double + single quotes replacement pairs.
highlight is a function that should return escaped HTML or '' if the source string is not changed. This is mostly used with highlight.js. See here on how you can set up this configuration.
math uses the KaTex library to render math expressions.
applyHTML applies html capabilities to remarkable responses such as Deep Chat classes.
Use this demo to experiment and find the configuration that suits you.
See external modules for remarkable plugins such as linkify and KaTex, more info1, info2.
- Sample code
- Full code
<deep-chat remarkable='{"html": true, "typographer": true}'></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
remarkable='{"html": true, "typographer": true}'
history='[
{"text": "Text containing <button>html</button>", "role": "user"},
{"text": "Typographic text: (c)", "role": "user"}
]'
style="border-radius: 8px"
demo="true"
></deep-chat>
Types
Shared property types for the messageStyles object:
MessageRoleStyles
- Type: {
shared?: MessageElementsStyles,
user?: MessageElementsStyles,
ai?: MessageElementsStyles,
[custom]?: MessageElementsStyles
}
Object defining the styling for various message roles.
shared is applied to all message roles.
user is applied to messages from the user.
ai is applied to messages returned from the target service.
custom roles (e.g. "bob") use ai styling, but they can have additional styling.
- Sample code
- Full code
<deep-chat
messageStyles='{
"default": {
"shared": {"bubble": {"color": "white"}},
"ai": {"bubble": {"backgroundColor": "#3cbe3c"}},
"user": {"bubble": {"backgroundColor": "#6767ff"}},
"bob": {"bubble": {"backgroundColor": "#ffa500"}}
}
}'
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
messageStyles='{
"default": {
"shared": {"bubble": {"color": "white"}},
"ai": {"bubble": {"backgroundColor": "#3cbe3c"}},
"user": {"bubble": {"backgroundColor": "#6767ff"}},
"bob": {"bubble": {"backgroundColor": "#ffa500"}}
}
}'
history='[
{"text": "What is the meaning of life?", "role": "user"},
{
"text": "This ultimately depends on the person, but it could be the pursuit of happiness or fulfillment.",
"role": "ai"
},
{
"text": "We dont laugh because we feel good, we feel good because we laugh.",
"role": "bob"
}
]'
style="border-radius: 8px"
demo="true"
></deep-chat>
MessageElementsStyles
- Type: {
outerContainer?: CustomStyle,
innerContainer?: CustomStyle,
bubble?: CustomStyle,
media?: CustomStyle
}
Object defining the styling for various elements that encompass a message.
outerContainer contains all elements related to the message.
innerContainer is an element inside the outerContainer that is mostly used to set message side padding.
bubble is the element that displays the actual message contents.
media is applied to image, audio and file type messages which contain an extra child element inside the bubble
to display the file contents.
- Sample code
- Full code
<deep-chat
messageStyles='{
"default": {
"shared": {
"outerContainer": {"backgroundColor": "orange"},
"innerContainer": {"backgroundColor": "yellow"},
"bubble": {"color": "black"}
},
"ai": {"bubble": {"backgroundColor": "lightgreen"}},
"user": {"bubble": {"backgroundColor": "lightblue"}}
}
}'
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
messageStyles='{
"default": {
"shared": {
"outerContainer": {"backgroundColor": "orange"},
"innerContainer": {"backgroundColor": "yellow"},
"bubble": {"color": "black"}
},
"ai": {"bubble": {"backgroundColor": "lightgreen"}},
"user": {"bubble": {"backgroundColor": "lightblue"}}
}
}'
history='[
{"text": "What is the meaning of life?", "role": "user"},
{
"text": "This ultimately depends on the person, but it could be the pursuit of happiness or fulfillment.",
"role": "ai"
}
]'
style="border-radius: 8px"
demo="true"
></deep-chat>
LoadingMessageStyles
- Type: {
message?: LoadingStyles,
history?:{full?: LoadingStyles,small?: LoadingStyles}
}
Object defining the styling for various message loading elements.
message is the default loading element that is displayed when waiting for a response to a message request.
history is composed of two types of loading elements that are displayed when loading history via loadHistory:
full is displayed when the initial chat history is being loaded on component render and small is displayed when user scrolls to the top of the chat to load more history.
- Sample code
- Full code
<deep-chat
messageStyles='{
"loading": {
"message": {
"styles": {
"bubble": {"backgroundColor": "#6decff", "color": "white"}
}},
"history": {
"small": {
"styles": {
"outerContainer": {"marginBottom": "60px"},
"bubble": {"color": "#6decff", "border": "11px solid", "height": "80px", "width": "80px"}
}}}}}'
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
messageStyles='{
"loading": {
"message": {
"styles": {
"bubble": {"backgroundColor": "#6decff", "color": "white"}
}},
"history": {
"small": {
"styles": {
"outerContainer": {"marginBottom": "60px"},
"bubble": {"color": "#6decff", "border": "11px solid", "height": "80px", "width": "80px"}
}}}}}'
style="border-radius: 8px"
demo='{"displayLoading": {"message": true, "history": {"small": true}}}'
></deep-chat>
LoadingStyles
- Type: {
styles?: MessageElementsStyles,html?: string}
Object defining the styling for elements that contain a loading animation.
styles is applied to the various elements of a loading message.
html can be used to define your own loading animation via custom markdown.
- Sample code
- Full code
<deep-chat
messageStyles='{
"loading": {
"history": {
"full": {
"styles": {"outerContainer": {"marginTop": "28px"}},
"html": "<div class=\"lds-ripple\"><div></div><div></div></div>"
},
"small": {
"styles": {"outerContainer": {"marginTop": "-10px", "marginBottom": "50px"}}
}}}}'
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
messageStyles='{
"loading": {
"history": {
"full": {
"styles": {"outerContainer": {"marginTop": "28px"}},
"html": "<div class=\"lds-ripple\"><div></div><div></div></div>"
},
"small": {
"styles": {"outerContainer": {"marginTop": "-10px", "marginBottom": "50px"}}
}}}}'
auxiliaryStyle="
.lds-ripple {
color: #1c4c5b
}
.lds-ripple,
.lds-ripple div {
box-sizing: border-box;
}
.lds-ripple {
display: inline-block;
position: relative;
width: 80px;
height: 80px;
}
.lds-ripple div {
position: absolute;
border: 4px solid currentColor;
opacity: 1;
border-radius: 50%;
animation: lds-ripple 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}
.lds-ripple div:nth-child(2) {
animation-delay: -0.5s;
}
@keyframes lds-ripple {
0% {
top: 36px;
left: 36px;
width: 8px;
height: 8px;
opacity: 0;
}
4.9% {
top: 36px;
left: 36px;
width: 8px;
height: 8px;
opacity: 0;
}
5% {
top: 36px;
left: 36px;
width: 8px;
height: 8px;
opacity: 1;
}
100% {
top: 0;
left: 0;
width: 80px;
height: 80px;
opacity: 0;
}
}"
style="border-radius: 8px"
demo='{"displayLoading": {"history": {"full": true}}}'
></deep-chat>
KatexOptions
- Type: {
leqno?: boolean,
fleqn?: boolean,
throwOnError?: boolean,
errorColor?: string,
macros?: Record<string, string>,
minRuleThickness?: number,
colorIsTextColor?: boolean,
maxSize?: number,
maxExpand?: number,
globalGroup?: boolean
}
Object defining the options for the KaTex math renderer.
leqno is used to display math has \tags rendered on the left instead of the right.
fleqn displays math renders flush left with a 2em left margin.
throwOnError throws a ParseError when it encounters an unsupported command .
errorColor is a color string for errors defined in the format "#xxx" or "#xxxxxx".
macros is a collection of custom macros. E.g. macros: {"\\R": "\\mathbb{R}"}
minRuleThickness is the minimum thickness of horizontal rules.
colorIsTextColor is used to enable color functions prior to Katex version 0.8.0.
maxSize caps all user specified sizes.
maxExpand limits the number of macro expansions.
globalGroup is used to run KaTex code in the global group.
More Examples
Files
- Sample code
- Full code
<deep-chat
messageStyles='{
"image": {
"shared": {
"media": {"borderRadius": "0px"}
}
},
"audio": {
"shared": {
"media": {"borderRadius": "30px", "border": "1px solid #8c8c8c", "backgroundColor": "red"}
}
},
"file": {
"shared": {
"bubble": {"backgroundColor": "grey"}
}
}
}'
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
messageStyles='{
"image": {
"shared": {
"media": {"borderRadius": "0px"}
}
},
"audio": {
"shared": {
"media": {"borderRadius": "30px", "border": "1px solid #8c8c8c", "backgroundColor": "red"}
}
},
"file": {
"shared": {
"bubble": {"backgroundColor": "grey"}
}
}
}'
history='[
{"files": [{"src": "path-to-file.jpeg", "type": "image"}], "role": "user"},
{"files": [{"src": "path-to-file.wav", "type": "audio"}], "role": "ai"},
{"files": [{"src": "path-to-file.txt", "name": "text-file.txt", "type": "file"}], "role": "user"}
]'
style="border-radius: 8px"
demo="true"
></deep-chat>
The "audio" media player is controlled by the browser and and its styling may not be overwritable by the media property.
In the Safari browser, the "audio" media player can be expanded by setting the width property in media to 200px or higher.
Grouped messages
Message elements have the following classes depending on their position in respect to their role: deep-chat-top-message, deep-chat-middle-message and deep-chat-bottom-message.
You can use these classes to add custom grouping styling via the auxiliaryStyle property.
- Sample code
- Full code
<deep-chat
auxiliaryStyle="
.deep-chat-top-message .message-bubble {
border-top-left-radius: 5px !important;
border-top-right-radius: 5px !important;
}
.deep-chat-middle-message .message-bubble {
margin-top: 0px;
}
.deep-chat-bottom-message .message-bubble {
margin-top: 0px;
border-bottom-left-radius: 5px !important;
border-bottom-right-radius: 5px !important;
}
.deep-chat-top-message.deep-chat-bottom-message .message-bubble {
margin-top: 10px;
}"
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Frameworks) -->
<deep-chat
auxiliaryStyle="
.deep-chat-top-message .message-bubble {
border-top-left-radius: 5px !important;
border-top-right-radius: 5px !important;
}
.deep-chat-middle-message .message-bubble {
margin-top: 0px;
}
.deep-chat-bottom-message .message-bubble {
margin-top: 0px;
border-bottom-left-radius: 5px !important;
border-bottom-right-radius: 5px !important;
}
.deep-chat-top-message.deep-chat-bottom-message .message-bubble {
margin-top: 10px;
}"
messageStyles='{
"default": {
"shared": {
"bubble": {
"borderRadius": "0px"
}}}}'
history='[
{"text": "Group 1", "role": "group1"},
{"text": "Group 2", "role": "group2"},
{"text": "Group 2", "role": "group2"},
{"text": "Group 2", "role": "group2"},
{"text": "Group 3", "role": "group3"},
{"text": "Group 3", "role": "group3"}
]'
demo="true"
></deep-chat>
If you are using avatars, add the following css to the auxiliaryStyle:
.deep-chat-top-message.deep-chat-bottom-message .avatar-container {
margin-top: 10px;
}
.avatar-container {
margin-top: 0px;
}
Intro message
- Sample code
- Full code
<deep-chat
messageStyles='{
"intro": {"bubble": {"backgroundColor": "#475cc7", "color": "white", "fontSize": "16px"}}
}'
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
messageStyles='{
"intro": {
"bubble": {"backgroundColor": "#475cc7", "color": "white", "fontSize": "16px"}
}
}'
introMessage='{"text": "Hi I am an AiAssistant, ask me anything!"}'
style="border-radius: 8px"
demo="true"
></deep-chat>
Loading bubble
- Sample code
- Full code
<deep-chat
messageStyles='{
"loading": {
"bubble": {"backgroundColor": "#3793ff", "fontSize": "20px", "color": "white"}
}
}'
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
messageStyles='{
"loading": {
"bubble": {"backgroundColor": "#3793ff", "fontSize": "20px", "color": "white"}
}
}'
style="border-radius: 8px"
demo='{"displayLoading": {"message": true}}'
></deep-chat>
Error messages
- Sample code
- Full code
<deep-chat
messageStyles='{
"error": {
"bubble": {"backgroundColor": "#f98e00", "color": "white", "fontSize": "15px"}
}
}'
></deep-chat>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<deep-chat
messageStyles='{
"error": {
"bubble": {"backgroundColor": "#f98e00", "color": "white", "fontSize": "15px"}
}
}'
style="border-radius: 8px"
demo='{"displayErrors": {"service": true}}'
></deep-chat>