Skip to content

Commit 325409c

Browse files
committed
feat: implement chat bubble style API
1 parent ad6c1ec commit 325409c

File tree

4 files changed

+75
-7
lines changed

4 files changed

+75
-7
lines changed

src/chat-bubble/interfaces.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,31 @@ export interface ChatBubbleProps {
3131
* Useful for when there are multiple consecutive messages coming from the same author.
3232
*/
3333
hideAvatar?: boolean;
34+
35+
/**
36+
* @awsuiSystem core
37+
*/
38+
style?: ChatBubbleProps.Style;
3439
}
3540

3641
export namespace ChatBubbleProps {
3742
export type Type = "incoming" | "outgoing";
43+
export interface Style {
44+
root?: {
45+
columnGap?: string;
46+
};
47+
bubble?: {
48+
background?: string;
49+
borderColor?: string;
50+
borderRadius?: string;
51+
borderWidth?: string;
52+
boxShadow?: string;
53+
color?: string;
54+
fontSize?: string;
55+
fontWeight?: string;
56+
rowGap?: string;
57+
paddingBlock?: string;
58+
paddingInline?: string;
59+
};
60+
}
3861
}

src/chat-bubble/internal.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getDataAttributes } from "../internal/base-component/get-data-attribute
77
import { InternalBaseComponentProps } from "../internal/base-component/use-base-component";
88
import { InternalLoadingBar } from "../loading-bar/internal";
99
import { ChatBubbleProps } from "./interfaces.js";
10+
import { getBubbleStyle, getChatBubbleRootStyle } from "./style";
1011

1112
import styles from "./styles.css.js";
1213

@@ -20,6 +21,7 @@ export default function InternalChatBubble({
2021
showLoadingBar,
2122
hideAvatar = false,
2223
ariaLabel,
24+
style,
2325
__internalRootRef = null,
2426
...rest
2527
}: InternalChatBubbleProps) {
@@ -43,6 +45,7 @@ export default function InternalChatBubble({
4345
ref={__internalRootRef}
4446
role="group"
4547
aria-label={ariaLabel}
48+
style={getChatBubbleRootStyle(style)}
4649
>
4750
{avatar && (
4851
<div ref={avatarRef} className={clsx(styles.avatar, hideAvatar && styles.hide)}>
@@ -54,12 +57,15 @@ export default function InternalChatBubble({
5457
className={clsx(styles["message-area"], styles[`chat-bubble-type-${type}`], {
5558
[styles["with-loading-bar"]]: showLoadingBar,
5659
})}
60+
style={getBubbleStyle(style)}
5761
>
5862
<div className={styles.content}>{children}</div>
59-
6063
{actions && <div className={styles.actions}>{actions}</div>}
61-
62-
{showLoadingBar && <InternalLoadingBar variant="gen-ai-masked" />}
64+
{showLoadingBar && (
65+
<div className={styles["loading-bar-wrapper"]}>
66+
<InternalLoadingBar variant="gen-ai-masked" />
67+
</div>
68+
)}
6369
</div>
6470
</div>
6571
);

src/chat-bubble/style.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import { SYSTEM } from "../internal/environment";
4+
import { ChatBubbleProps } from "./interfaces";
5+
6+
export function getChatBubbleRootStyle(style: ChatBubbleProps.Style | undefined) {
7+
if (SYSTEM !== "core") {
8+
return {};
9+
}
10+
11+
return {
12+
columnGap: style?.root?.columnGap,
13+
};
14+
}
15+
16+
export function getBubbleStyle(style: ChatBubbleProps.Style | undefined) {
17+
if (SYSTEM !== "core") {
18+
return {};
19+
}
20+
21+
return {
22+
background: style?.bubble?.background,
23+
borderRadius: style?.bubble?.borderRadius,
24+
borderStyle: style?.bubble?.borderWidth ? "solid" : undefined,
25+
borderColor: style?.bubble?.borderColor,
26+
borderWidth: style?.bubble?.borderWidth,
27+
boxShadow: style?.bubble?.boxShadow,
28+
paddingBlock: style?.bubble?.paddingBlock,
29+
paddingInline: style?.bubble?.paddingInline,
30+
color: style?.bubble?.color,
31+
fontSize: style?.bubble?.fontSize,
32+
fontWeight: style?.bubble?.fontWeight,
33+
rowGap: style?.bubble?.rowGap,
34+
};
35+
}

src/chat-bubble/styles.scss

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
}
1919

2020
.message-area {
21+
position: relative;
2122
display: flex;
2223
flex-direction: column;
2324
gap: cs.$space-scaled-s;
@@ -30,10 +31,6 @@
3031
border-end-start-radius: cs.$border-radius-chat-bubble;
3132
border-end-end-radius: cs.$border-radius-chat-bubble;
3233

33-
&.with-loading-bar {
34-
padding-block-end: 0;
35-
}
36-
3734
&.chat-bubble-type-outgoing {
3835
color: cs.$color-text-chat-bubble-outgoing;
3936
background-color: cs.$color-background-chat-bubble-outgoing;
@@ -45,6 +42,13 @@
4542
}
4643
}
4744

45+
.loading-bar-wrapper {
46+
position: absolute;
47+
bottom: 0;
48+
left: 0;
49+
width: 100%;
50+
}
51+
4852
.avatar {
4953
padding-block: cs.$space-scaled-xs;
5054

0 commit comments

Comments
 (0)