Skip to content

Commit da459a1

Browse files
committed
add property to limit bubble height easily
1 parent a907b71 commit da459a1

3 files changed

Lines changed: 46 additions & 18 deletions

File tree

src/components/Chat/ChatContent.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export interface ChatContentProps extends React.HTMLAttributes<HTMLDivElement>,
3131
* If `left` is set then the avatar is on the left side, and the indentation on the right side.
3232
*/
3333
alignment?: "left" | "right" | "block";
34+
/**
35+
* If set then the chat bubble only grows to a height of 50% of the viewport.
36+
* In case you need to set other maximum heights then use the `style` property directly.
37+
*/
38+
limitHeight?: boolean;
3439
/**
3540
* If given then the content is automatically parsed and displayed by our `<Markdown />` component.
3641
* `children` need to a `string` then, otherwise it cannot be parsed.
@@ -49,6 +54,7 @@ export const ChatContent = ({
4954
displayType = "bubble",
5055
indentation = true,
5156
alignment = "left",
57+
limitHeight,
5258
markdownProps,
5359
...otherDivProps
5460
}: ChatContentProps) => {
@@ -58,6 +64,7 @@ export const ChatContent = ({
5864
`${eccgui}-chat__content` +
5965
` ${eccgui}-chat__content--display-${displayType}` +
6066
` ${eccgui}-chat__content--align-${alignment}` +
67+
(limitHeight ? ` ${eccgui}-chat__content--limitheight` : "") +
6168
(className ? ` ${className}` : "")
6269
}
6370
{...otherDivProps}
@@ -90,7 +97,7 @@ export const ChatContent = ({
9097
>
9198
{React.cloneElement(avatar, { size: "small", ratio: "1:1", rounded: true, resizing: "cover" })}
9299
</FlexibleLayoutItem>
93-
<FlexibleLayoutItem>{content}</FlexibleLayoutItem>
100+
<FlexibleLayoutItem className={`${eccgui}-chat__content-wrapper`}>{content}</FlexibleLayoutItem>
94101
</FlexibleLayoutContainer>
95102
) : (
96103
content

src/components/Chat/_chat.scss

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,55 @@
11
.#{$eccgui}-chat__content {
2-
--#{$eccgui}-chat__content-background: #{$light-gray5};
3-
42
position: relative;
53
min-height: $button-height;
64
padding: $eccgui-size-inline-whitespace;
5+
overflow: auto;
76
background-color: var(--#{$eccgui}-chat__content-background);
87
border-radius: $pt-border-radius;
98
}
109

1110
.#{$eccgui}-chat__content--display-free {
12-
padding: 0;
11+
padding: 1px 0;
1312

1413
--#{$eccgui}-chat__content-background: transparent;
1514
}
1615

1716
.#{$eccgui}-chat__content--display-bubble {
1817
margin-left: 0.5 * $eccgui-size-block-whitespace;
1918

20-
&::before {
21-
position: absolute;
22-
top: calc(#{mini-units(3)} - #{0.5 * $eccgui-size-block-whitespace});
23-
left: calc(-0.5 * #{$eccgui-size-block-whitespace} + 1px);
24-
width: $eccgui-size-block-whitespace;
25-
height: $eccgui-size-block-whitespace;
26-
content: " ";
27-
background-color: var(--#{$eccgui}-chat__content-background);
28-
clip-path: polygon(0% 50%, 50% 0%, 50% 100%);
29-
}
30-
3119
&.#{$eccgui}-chat__content--align-right {
3220
margin-right: 0.5 * $eccgui-size-block-whitespace;
3321
margin-left: none;
22+
}
23+
}
3424

25+
.#{$eccgui}-chat__content-wrapper {
26+
--#{$eccgui}-chat__content-background: #{$light-gray5};
27+
&:has(.#{$eccgui}-chat__content--display-bubble) {
28+
position: relative;
29+
30+
&::before {
31+
position: absolute;
32+
top: calc(#{mini-units(3)} - #{0.5 * $eccgui-size-block-whitespace});
33+
left: 0;
34+
width: $eccgui-size-block-whitespace;
35+
height: $eccgui-size-block-whitespace;
36+
content: " ";
37+
background-color: var(--#{$eccgui}-chat__content-background);
38+
transform: rotate(45deg);
39+
}
40+
}
41+
&:has(.#{$eccgui}-chat__content--display-bubble.#{$eccgui}-chat__content--align-right) {
3542
&::before {
36-
right: calc(-0.5 * #{$eccgui-size-block-whitespace} + 1px);
43+
right: 0;
3744
left: auto;
38-
clip-path: polygon(100% 50%, 50% 0%, 50% 100%);
3945
}
4046
}
4147
}
4248

49+
.#{$eccgui}-chat__content--limitheight {
50+
max-height: 50vh;
51+
}
52+
4353
.eccgui-chat__inputfield {
4454
min-height: mini-units(9);
4555
max-height: 39vh;

src/components/Chat/stories/ChatContent.stories.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { LoremIpsum } from "react-lorem-ipsum";
33
import { Meta, StoryFn } from "@storybook/react";
44

5-
import { ChatContent, Depiction, Icon, OverflowText } from "../../../index";
5+
import { ChatContent, Depiction, HtmlContentBlock, Icon, OverflowText } from "../../../index";
66

77
import canonicalIcons from "./../../Icon/canonicalIconNames";
88

@@ -41,3 +41,14 @@ Default.args = {
4141
</OverflowText>
4242
),
4343
};
44+
45+
export const LongChatBubble = TemplateFull.bind({});
46+
LongChatBubble.args = {
47+
...Default.args,
48+
children: (
49+
<HtmlContentBlock>
50+
<LoremIpsum p={10} avgSentencesPerParagraph={10} random={false} />
51+
</HtmlContentBlock>
52+
),
53+
limitHeight: true,
54+
};

0 commit comments

Comments
 (0)