Skip to content

Commit 7d9b287

Browse files
committed
feat: improve styles for part grouping nested stacked layouts
1 parent 63284ee commit 7d9b287

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

packages/component/src/Activity/StackedLayout.module.css

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158

159159
&.stacked-layout--hide-avatar,
160160
&.stacked-layout--show-avatar {
161-
.stacked-layout__avatar-gutter {
161+
&.stacked-layout--activity .stacked-layout__avatar-gutter {
162162
width: var(--webchat__size--avatar);
163163
}
164164
}
@@ -167,17 +167,17 @@
167167
&.stacked-layout--show-avatar,
168168
&.stacked-layout--hide-nub,
169169
&.stacked-layout--show-nub {
170-
.stacked-layout__attachment {
170+
&.stacked--activity .stacked-layout__attachment {
171171
max-width: calc(var(--webchat__max-width--attachment-bubble) + var(--webchat__padding--regular));
172172
min-width: calc(var(--webchat__min-width--attachment-bubble) + var(--webchat__padding--regular));
173173
}
174174

175-
.stacked-layout__message {
175+
&.stacked-layout--activity .stacked-layout__message {
176176
max-width: calc(var(--webchat__max-width--message-bubble) + var(--webchat__padding--regular));
177177
min-width: calc(var(--webchat__min-width--message-bubble) + var(--webchat__padding--regular));
178178
}
179179

180-
.stacked-layout__nub-pad {
180+
&.stacked-layout--activity .stacked-layout__nub-pad {
181181
width: var(--webchat__padding--regular);
182182
}
183183
}
@@ -190,6 +190,14 @@
190190
}
191191

192192
&.stacked-layout--group {
193+
&.stacked-layout--hide-avatar,
194+
&.stacked-layout--show-avatar {
195+
> .stacked-layout__main > .stacked-layout__avatar-gutter {
196+
width: var(--webchat__size--avatar);
197+
padding-inline-end: var(--webchat__padding--regular);
198+
}
199+
}
200+
193201
.stacked-layout__bubble {
194202
grid-template: 'content' 1fr / 1fr;
195203
}

packages/component/src/Activity/StackedLayout.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ type StackedLayoutInnerProps = Readonly<{
3232
activity: WebChatActivity;
3333
children?: ReactNode | undefined;
3434
fromUser: boolean;
35+
hasAvatar: boolean;
3536
hasDisplayText: boolean;
37+
hasNub: boolean;
3638
id: string;
3739
renderAvatar?: false | (() => Exclude<ReactNode, boolean | null | undefined>) | undefined;
3840
renderBubbleContent: (title?: string | undefined, showStatus?: boolean) => ReactNode;
@@ -45,31 +47,24 @@ const StackedLayoutInner = memo(
4547
activity,
4648
children,
4749
fromUser,
50+
hasAvatar,
4851
hasDisplayText,
52+
hasNub,
4953
id,
5054
renderAvatar,
5155
renderBubbleContent,
5256
showAvatar,
5357
showNub
5458
}: StackedLayoutInnerProps) => {
55-
const [styleOptions] = useStyleOptions();
5659
const [{ initials: botInitials }] = useAvatarForBot();
57-
const [{ initials: userInitials }] = useAvatarForUser();
5860
const localize = useLocalizer();
5961
const classNames = useStyles(styles);
6062

6163
const messageThing = useMemo(() => getOrgSchemaMessage(activity.entities), [activity]);
62-
const { bubbleNubSize, bubbleFromUserNubSize } = styleOptions;
6364
const greetingAlt = (
6465
fromUser ? localize('ACTIVITY_YOU_SAID_ALT') : localize('ACTIVITY_BOT_SAID_ALT', botInitials || '')
6566
).replace(/\s{2,}/gu, ' ');
6667

67-
const initials = fromUser ? userInitials : botInitials;
68-
const nubSize = fromUser ? bubbleFromUserNubSize : bubbleNubSize;
69-
70-
const hasAvatar = initials || typeof initials === 'string';
71-
const hasNub = typeof nubSize === 'number';
72-
7368
return (
7469
<StackedLayoutMain avatar={showAvatar && renderAvatar && renderAvatar()}>
7570
{!!(hasDisplayText || messageThing?.abstract) && (
@@ -147,18 +142,18 @@ const StackedLayout = ({
147142
const nubSize = fromUser ? bubbleFromUserNubSize : bubbleNubSize;
148143
const otherInitials = fromUser ? botInitials : userInitials;
149144
const otherNubSize = fromUser ? bubbleNubSize : bubbleFromUserNubSize;
145+
const activityKey = useGetKeyByActivity()(activity);
146+
const isInGroup = !!useGetLogicalGroupKey()(activityKey);
150147

151-
const hasAvatar = initials || typeof initials === 'string';
148+
const hasAvatar = (initials || typeof initials === 'string') && !isInGroup;
152149
const hasOtherAvatar = otherInitials || typeof otherInitials === 'string';
153150
const hasNub = typeof nubSize === 'number';
154151
const hasOtherNub = typeof otherNubSize === 'number';
155152
const topAlignedCallout = isZeroOrPositive(nubOffset);
156-
const activityKey = useGetKeyByActivity()(activity);
157-
const isInGroup = !!useGetLogicalGroupKey()(activityKey);
158153

159154
const extraTrailing = !hasOtherAvatar && hasOtherNub; // This is for bot message with user nub and no user avatar. And vice versa.
160155

161-
const showAvatar = !isInGroup && showCallout && hasAvatar && !!renderAvatar;
156+
const showAvatar = showCallout && hasAvatar && !!renderAvatar;
162157
const showNub = !isInGroup && showCallout && hasNub && (topAlignedCallout || !attachments?.length);
163158

164159
const showStatus = !!messageThing?.creativeWorkStatus || isInGroup;
@@ -304,6 +299,7 @@ const StackedLayout = ({
304299
fromUser={fromUser}
305300
hideAvatar={hasAvatar && !showAvatar}
306301
hideNub={hasNub && !showNub}
302+
isActivity={true}
307303
noMessage={!activityDisplayText && !isCollapsible}
308304
showAvatar={showAvatar}
309305
showNub={showNub}
@@ -312,7 +308,9 @@ const StackedLayout = ({
312308
<StackedLayoutInner
313309
activity={activity}
314310
fromUser={fromUser}
311+
hasAvatar={hasAvatar}
315312
hasDisplayText={!!activityDisplayText?.length || isCollapsible}
313+
hasNub={hasNub}
316314
id={ariaLabelId}
317315
renderAvatar={renderAvatar}
318316
renderBubbleContent={renderBubbleContent}

packages/component/src/Activity/StackedLayoutRoot.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const stackedLayoutRootPropsSchema = pipe(
1414
fromUser: optional(boolean()),
1515
hideAvatar: optional(boolean()),
1616
hideNub: optional(boolean()),
17+
isActivity: optional(boolean()),
1718
isGroup: optional(boolean()),
1819
noMessage: optional(boolean()),
1920
showAvatar: optional(boolean()),
@@ -33,6 +34,7 @@ const StackedLayoutRoot = memo((props: StackedLayoutRootProps) => {
3334
fromUser,
3435
hideAvatar,
3536
hideNub,
37+
isActivity,
3638
isGroup,
3739
noMessage,
3840
showAvatar,
@@ -50,6 +52,7 @@ const StackedLayoutRoot = memo((props: StackedLayoutRootProps) => {
5052
[classNames['stacked-layout--extra-trailing']]: extraTrailing,
5153
[classNames['stacked-layout--hide-avatar']]: hideAvatar,
5254
[classNames['stacked-layout--hide-nub']]: hideNub,
55+
[classNames['stacked-layout--activity']]: isActivity,
5356
[classNames['stacked-layout--group']]: isGroup,
5457
[classNames['stacked-layout--no-message']]: noMessage,
5558
[classNames['stacked-layout--show-avatar']]: showAvatar,

0 commit comments

Comments
 (0)