@@ -4,31 +4,29 @@ import 'store.dart';
44import 'text.dart' ;
55import 'theme.dart' ;
66
7- /// A widget to display a given number of unreads in a conversation .
7+ /// A widget to display a given number (e.g. of unread messages or of users) .
88///
99/// See Figma's "counter-menu" component, which this is based on:
1010/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=2037-186671&m=dev
1111/// It looks like that component was created for the main menu,
1212/// then adapted for various other contexts, like the Inbox page.
13- /// See [UnreadCountBadgeStyle] .
14- ///
15- /// Currently this widget supports only the component's "kind=unread" variant,
16- /// not "kind=quantity".
17- // TODO support the "kind=quantity" variant, update dartdoc
18- class UnreadCountBadge extends StatelessWidget {
19- const UnreadCountBadge ({
13+ /// See [CounterStyle] and [CounterKind] for the possible variants.
14+ class Counter extends StatelessWidget {
15+ const Counter ({
2016 super .key,
21- this .style = UnreadCountBadgeStyle .other,
17+ this .style = CounterStyle .other,
18+ required this .kind,
2219 required this .count,
2320 required this .channelIdForBackground,
24- });
21+ }) : assert ( ! (kind == CounterKind .quantity && channelIdForBackground != null )) ;
2522
26- final UnreadCountBadgeStyle style;
23+ final CounterStyle style;
24+ final CounterKind kind;
2725 final int count;
2826
2927 /// An optional [Subscription.streamId] , for a channel-colorized background.
3028 ///
31- /// Useful when this badge represents messages in one specific channel.
29+ /// Useful when this counter represents unreads in one specific channel.
3230 ///
3331 /// If null, the default neutral background will be used.
3432 // TODO remove; the Figma doesn't use this anymore.
@@ -48,40 +46,54 @@ class UnreadCountBadge extends StatelessWidget {
4846 final swatch = colorSwatchFor (context, subscription);
4947 backgroundColor = swatch.unreadCountBadgeBackground;
5048 } else {
51- textColor = designVariables.labelCounterUnread;
49+ textColor = switch (kind) {
50+ CounterKind .unread => designVariables.labelCounterUnread,
51+ CounterKind .quantity => designVariables.labelCounterQuantity,
52+ };
5253 backgroundColor = designVariables.bgCounterUnread;
5354 }
5455
5556 final padding = switch (style) {
56- UnreadCountBadgeStyle .mainMenu =>
57+ CounterStyle .mainMenu =>
5758 const EdgeInsets .symmetric (horizontal: 5 , vertical: 4 ),
58- UnreadCountBadgeStyle .other =>
59+ CounterStyle .other =>
5960 const EdgeInsets .symmetric (horizontal: 5 , vertical: 3 ),
6061 };
6162
62- final double wght = switch (style) {
63- UnreadCountBadgeStyle .mainMenu => 600 ,
64- UnreadCountBadgeStyle .other => 500 ,
63+ final double wght = switch ((style, kind)) {
64+ (CounterStyle .mainMenu, CounterKind .unread ) => 600 ,
65+ (CounterStyle .mainMenu, CounterKind .quantity) => 500 ,
66+ (CounterStyle .other, CounterKind .unread ) => 500 ,
67+ (CounterStyle .other, CounterKind .quantity) => 500 ,
6568 };
6669
67- return DecoratedBox (
68- decoration: BoxDecoration (
69- borderRadius: BorderRadius .circular (5 ),
70- color: backgroundColor,
71- ),
72- child: Padding (
73- padding: padding,
74- child: Text (
75- style: TextStyle (
76- fontSize: 16 ,
77- height: (16 / 16 ),
78- color: textColor,
79- ).merge (weightVariableTextStyle (context, wght: wght)),
80- count.toString ())));
70+ Widget result = Padding (
71+ padding: padding,
72+ child: Text (
73+ style: TextStyle (
74+ fontSize: 16 ,
75+ height: (16 / 16 ),
76+ color: textColor,
77+ ).merge (weightVariableTextStyle (context, wght: wght)),
78+ count.toString ()));
79+
80+ switch (kind) {
81+ case CounterKind .unread:
82+ result = DecoratedBox (
83+ decoration: BoxDecoration (
84+ borderRadius: BorderRadius .circular (5 ),
85+ color: backgroundColor,
86+ ),
87+ child: result);
88+ case CounterKind .quantity:
89+ // no decoration
90+ }
91+
92+ return result;
8193 }
8294}
8395
84- enum UnreadCountBadgeStyle {
96+ enum CounterStyle {
8597 /// The style to use in the main menu.
8698 ///
8799 /// Figma:
@@ -98,6 +110,22 @@ enum UnreadCountBadgeStyle {
98110 other,
99111}
100112
113+ enum CounterKind {
114+ /// The counter counts unread messages.
115+ ///
116+ /// Figma:
117+ /// Main-menu style: https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=2037-185125&m=dev
118+ /// Other style: https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=6205-26001&m=dev
119+ unread,
120+
121+ /// The counter counts something else, like users or starred messages.
122+ ///
123+ /// Figma:
124+ /// Main-menu style: https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=2037-186672&m=dev
125+ /// Other style: https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=6025-293468&m=dev
126+ quantity,
127+ }
128+
101129class MutedUnreadBadge extends StatelessWidget {
102130 const MutedUnreadBadge ({super .key});
103131
0 commit comments