Skip to content

Commit fc247d5

Browse files
committed
content: Add distinguishing pill colors for mentions
Fixes #646. Used the same pill colors as web to distinguish user mentions from user group and wildcard mentions. For colors used in web app: https://github.com/zulip/zulip/blob/81e0305f9/web/styles/app_variables.css#L2004 https://github.com/zulip/zulip/blob/81e0305f9/web/styles/app_variables.css#L2012 Previously, the pill colors for user mentions were used for all types of mentions.
1 parent 9059381 commit fc247d5

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

lib/widgets/content.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
4242
return ContentTheme._(
4343
colorCodeBlockBackground: const HSLColor.fromAHSL(0.04, 0, 0, 0).toColor(),
4444
colorDirectMentionBackground: const HSLColor.fromAHSL(0.2, 240, 0.7, 0.7).toColor(),
45+
colorGroupMentionBackground: const HSLColor.fromAHSL(0.18, 183, 0.6, 0.45).toColor(),
4546
colorGlobalTimeBackground: const HSLColor.fromAHSL(1, 0, 0, 0.93).toColor(),
4647
colorGlobalTimeBorder: const HSLColor.fromAHSL(1, 0, 0, 0.8).toColor(),
4748
colorLink: const HSLColor.fromAHSL(1, 200, 1, 0.4).toColor(),
@@ -76,6 +77,7 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
7677
return ContentTheme._(
7778
colorCodeBlockBackground: const HSLColor.fromAHSL(0.04, 0, 0, 1).toColor(),
7879
colorDirectMentionBackground: const HSLColor.fromAHSL(0.25, 240, 0.52, 0.6).toColor(),
80+
colorGroupMentionBackground: const HSLColor.fromAHSL(0.20, 183, 0.52, 0.4).toColor(),
7981
colorGlobalTimeBackground: const HSLColor.fromAHSL(0.2, 0, 0, 0).toColor(),
8082
colorGlobalTimeBorder: const HSLColor.fromAHSL(0.4, 0, 0, 0).toColor(),
8183
colorLink: const HSLColor.fromAHSL(1, 200, 1, 0.4).toColor(), // the same as light in Web
@@ -109,6 +111,7 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
109111
ContentTheme._({
110112
required this.colorCodeBlockBackground,
111113
required this.colorDirectMentionBackground,
114+
required this.colorGroupMentionBackground,
112115
required this.colorGlobalTimeBackground,
113116
required this.colorGlobalTimeBorder,
114117
required this.colorLink,
@@ -142,6 +145,7 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
142145

143146
final Color colorCodeBlockBackground;
144147
final Color colorDirectMentionBackground;
148+
final Color colorGroupMentionBackground;
145149
final Color colorGlobalTimeBackground;
146150
final Color colorGlobalTimeBorder;
147151
final Color colorLink;
@@ -203,6 +207,7 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
203207
ContentTheme copyWith({
204208
Color? colorCodeBlockBackground,
205209
Color? colorDirectMentionBackground,
210+
Color? colorGroupMentionBackground,
206211
Color? colorGlobalTimeBackground,
207212
Color? colorGlobalTimeBorder,
208213
Color? colorLink,
@@ -226,6 +231,7 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
226231
return ContentTheme._(
227232
colorCodeBlockBackground: colorCodeBlockBackground ?? this.colorCodeBlockBackground,
228233
colorDirectMentionBackground: colorDirectMentionBackground ?? this.colorDirectMentionBackground,
234+
colorGroupMentionBackground: colorGroupMentionBackground ?? this.colorGroupMentionBackground,
229235
colorGlobalTimeBackground: colorGlobalTimeBackground ?? this.colorGlobalTimeBackground,
230236
colorGlobalTimeBorder: colorGlobalTimeBorder ?? this.colorGlobalTimeBorder,
231237
colorLink: colorLink ?? this.colorLink,
@@ -256,6 +262,7 @@ class ContentTheme extends ThemeExtension<ContentTheme> {
256262
return ContentTheme._(
257263
colorCodeBlockBackground: Color.lerp(colorCodeBlockBackground, other.colorCodeBlockBackground, t)!,
258264
colorDirectMentionBackground: Color.lerp(colorDirectMentionBackground, other.colorDirectMentionBackground, t)!,
265+
colorGroupMentionBackground: Color.lerp(colorGroupMentionBackground, other.colorGroupMentionBackground, t)!,
259266
colorGlobalTimeBackground: Color.lerp(colorGlobalTimeBackground, other.colorGlobalTimeBackground, t)!,
260267
colorGlobalTimeBorder: Color.lerp(colorGlobalTimeBorder, other.colorGlobalTimeBorder, t)!,
261268
colorLink: Color.lerp(colorLink, other.colorLink, t)!,
@@ -1213,10 +1220,15 @@ class Mention extends StatelessWidget {
12131220
case WildcardMentionNode():
12141221
}
12151222

1223+
final backgroundPillColor = switch (node) {
1224+
UserMentionNode() => contentTheme.colorDirectMentionBackground,
1225+
UserGroupMentionNode() || WildcardMentionNode()
1226+
=> contentTheme.colorGroupMentionBackground,
1227+
};
1228+
12161229
return Container(
12171230
decoration: BoxDecoration(
1218-
// TODO(#646) different for wildcard mentions
1219-
color: contentTheme.colorDirectMentionBackground,
1231+
color: backgroundPillColor,
12201232
borderRadius: const BorderRadius.all(Radius.circular(3))),
12211233
padding: const EdgeInsets.symmetric(horizontal: 0.2 * kBaseFontSize),
12221234
child: InlineContent(

test/widgets/content_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,41 @@ void main() {
10471047
tester.widget(find.byType(Mention)), 'Greg Price');
10481048
});
10491049

1050+
group('pill colors', () {
1051+
testWidgets('pill color user mention', (tester) async {
1052+
await prepareContent(tester, plainContent(ContentExample.userMentionPlain.html),
1053+
wrapWithPerAccountStoreWidget: true);
1054+
final context = tester.element(find.byType(Mention));
1055+
final container = tester.widget<Container>(
1056+
find.descendant(of: find.byType(Mention), matching: find.byType(Container)));
1057+
check(container.decoration)
1058+
.isA<BoxDecoration>()
1059+
.color.equals(ContentTheme.of(context).colorDirectMentionBackground);
1060+
});
1061+
1062+
testWidgets('pill color user group mention', (tester) async {
1063+
await prepareContent(tester, plainContent(ContentExample.groupMentionPlain.html),
1064+
wrapWithPerAccountStoreWidget: true);
1065+
final context = tester.element(find.byType(Mention));
1066+
final container = tester.widget<Container>(
1067+
find.descendant(of: find.byType(Mention), matching: find.byType(Container)));
1068+
check(container.decoration)
1069+
.isA<BoxDecoration>()
1070+
.color.equals(ContentTheme.of(context).colorGroupMentionBackground);
1071+
});
1072+
1073+
testWidgets('pill color wildcard mention', (tester) async {
1074+
await prepareContent(tester, plainContent(ContentExample.channelWildcardMentionPlain.html),
1075+
wrapWithPerAccountStoreWidget: true);
1076+
final context = tester.element(find.byType(Mention));
1077+
final container = tester.widget<Container>(
1078+
find.descendant(of: find.byType(Mention), matching: find.byType(Container)));
1079+
check(container.decoration)
1080+
.isA<BoxDecoration>()
1081+
.color.equals(ContentTheme.of(context).colorGroupMentionBackground);
1082+
});
1083+
});
1084+
10501085
// TODO(#647):
10511086
// testFontWeight('non-silent self-user mention in plain paragraph',
10521087
// expectedWght: 600, // [etc.]

0 commit comments

Comments
 (0)