Skip to content

Commit 468f345

Browse files
Khader-1gnprice
authored andcommitted
channel_colors [nfc]: Rename StreamColorVariant to ChannelColorVariant
1 parent b5e496c commit 468f345

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

lib/widgets/channel_colors.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,67 +76,67 @@ class _ChannelColorSwatchesLerped extends ChannelColorSwatches {
7676
///
7777
/// Use this in UI code for colors related to [Subscription.color],
7878
/// such as the background of an unread count badge.
79-
class ChannelColorSwatch extends ColorSwatch<StreamColorVariant> {
79+
class ChannelColorSwatch extends ColorSwatch<ChannelColorVariant> {
8080
ChannelColorSwatch.light(int base) : this._(base, _computeLight(base));
8181
ChannelColorSwatch.dark(int base) : this._(base, _computeDark(base));
8282

8383
const ChannelColorSwatch._(int base, this._swatch) : super(base, _swatch);
8484

85-
final Map<StreamColorVariant, Color> _swatch;
85+
final Map<ChannelColorVariant, Color> _swatch;
8686

8787
/// The [Subscription.color] int that the swatch is based on.
88-
Color get base => this[StreamColorVariant.base]!;
88+
Color get base => this[ChannelColorVariant.base]!;
8989

90-
Color get unreadCountBadgeBackground => this[StreamColorVariant.unreadCountBadgeBackground]!;
90+
Color get unreadCountBadgeBackground => this[ChannelColorVariant.unreadCountBadgeBackground]!;
9191

9292
/// The stream icon on a plain-colored surface, such as white.
9393
///
9494
/// For the icon on a [barBackground]-colored surface,
9595
/// use [iconOnBarBackground] instead.
96-
Color get iconOnPlainBackground => this[StreamColorVariant.iconOnPlainBackground]!;
96+
Color get iconOnPlainBackground => this[ChannelColorVariant.iconOnPlainBackground]!;
9797

9898
/// The stream icon on a [barBackground]-colored surface.
9999
///
100100
/// For the icon on a plain surface, use [iconOnPlainBackground] instead.
101101
/// This color is chosen to enhance contrast with [barBackground]:
102102
/// <https://github.com/zulip/zulip/pull/27485>
103-
Color get iconOnBarBackground => this[StreamColorVariant.iconOnBarBackground]!;
103+
Color get iconOnBarBackground => this[ChannelColorVariant.iconOnBarBackground]!;
104104

105105
/// The background color of a bar representing a stream, like a recipient bar.
106106
///
107107
/// Use this in the message list, the "Inbox" view, and the "Streams" view.
108-
Color get barBackground => this[StreamColorVariant.barBackground]!;
108+
Color get barBackground => this[ChannelColorVariant.barBackground]!;
109109

110-
static Map<StreamColorVariant, Color> _computeLight(int base) {
110+
static Map<ChannelColorVariant, Color> _computeLight(int base) {
111111
final baseAsColor = Color(base);
112112

113113
final clamped20to75 = clampLchLightness(baseAsColor, 20, 75);
114114
final clamped20to75AsHsl = HSLColor.fromColor(clamped20to75);
115115

116116
return {
117-
StreamColorVariant.base: baseAsColor,
117+
ChannelColorVariant.base: baseAsColor,
118118

119119
// Follows `.unread-count` in Vlad's replit:
120120
// <https://replit.com/@VladKorobov/zulip-sidebar#script.js>
121121
// <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1624484>
122122
//
123123
// TODO fix bug where our results differ from the replit's (see unit tests)
124-
StreamColorVariant.unreadCountBadgeBackground:
124+
ChannelColorVariant.unreadCountBadgeBackground:
125125
clampLchLightness(baseAsColor, 30, 70)
126126
.withOpacity(0.3),
127127

128128
// Follows `.sidebar-row__icon` in Vlad's replit:
129129
// <https://replit.com/@VladKorobov/zulip-sidebar#script.js>
130130
//
131131
// TODO fix bug where our results differ from the replit's (see unit tests)
132-
StreamColorVariant.iconOnPlainBackground: clamped20to75,
132+
ChannelColorVariant.iconOnPlainBackground: clamped20to75,
133133

134134
// Follows `.recepeient__icon` in Vlad's replit:
135135
// <https://replit.com/@VladKorobov/zulip-topic-feed-colors#script.js>
136136
// <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1624484>
137137
//
138138
// TODO fix bug where our results differ from the replit's (see unit tests)
139-
StreamColorVariant.iconOnBarBackground:
139+
ChannelColorVariant.iconOnBarBackground:
140140
clamped20to75AsHsl
141141
.withLightness(clampDouble(clamped20to75AsHsl.lightness - 0.12, 0.0, 1.0))
142142
.toColor(),
@@ -149,14 +149,14 @@ class ChannelColorSwatch extends ColorSwatch<StreamColorVariant> {
149149
// <https://pub.dev/documentation/flutter_color_models/latest/flutter_color_models/ColorModel/interpolate.html>
150150
// which does ordinary RGB mixing. Investigate and send a PR?
151151
// TODO fix bug where our results differ from the replit's (see unit tests)
152-
StreamColorVariant.barBackground:
152+
ChannelColorVariant.barBackground:
153153
LabColor.fromColor(const Color(0xfff9f9f9))
154154
.interpolate(LabColor.fromColor(clamped20to75), 0.22)
155155
.toColor(),
156156
};
157157
}
158158

159-
static Map<StreamColorVariant, Color> _computeDark(int base) {
159+
static Map<ChannelColorVariant, Color> _computeDark(int base) {
160160
final baseAsColor = Color(base);
161161

162162
final clamped20to75 = clampLchLightness(baseAsColor, 20, 75);
@@ -166,11 +166,11 @@ class ChannelColorSwatch extends ColorSwatch<StreamColorVariant> {
166166
// on, and how the resulting values are a little off sometimes. The
167167
// comments mostly apply here too.
168168

169-
StreamColorVariant.base: baseAsColor,
170-
StreamColorVariant.unreadCountBadgeBackground:
169+
ChannelColorVariant.base: baseAsColor,
170+
ChannelColorVariant.unreadCountBadgeBackground:
171171
clampLchLightness(baseAsColor, 30, 70)
172172
.withOpacity(0.3),
173-
StreamColorVariant.iconOnPlainBackground: clamped20to75,
173+
ChannelColorVariant.iconOnPlainBackground: clamped20to75,
174174

175175
// Follows the web app (as of zulip/zulip@db03369ac); see
176176
// get_stream_privacy_icon_color in web/src/stream_color.ts.
@@ -185,9 +185,9 @@ class ChannelColorSwatch extends ColorSwatch<StreamColorVariant> {
185185
// https://chat.zulip.org/#narrow/stream/101-design/topic/UI.20redesign.3A.20recipient.20bar.20colors/near/1675786
186186
//
187187
// TODO fix bug where our results are unexpected (see unit tests)
188-
StreamColorVariant.iconOnBarBackground: clamped20to75,
188+
ChannelColorVariant.iconOnBarBackground: clamped20to75,
189189

190-
StreamColorVariant.barBackground:
190+
ChannelColorVariant.barBackground:
191191
LabColor.fromColor(const Color(0xff000000))
192192
.interpolate(LabColor.fromColor(clamped20to75), 0.38)
193193
.toColor(),
@@ -199,7 +199,7 @@ class ChannelColorSwatch extends ColorSwatch<StreamColorVariant> {
199199
if (identical(a, b)) {
200200
return a;
201201
}
202-
final Map<StreamColorVariant, Color> swatch;
202+
final Map<ChannelColorVariant, Color> swatch;
203203
if (b == null) {
204204
swatch = a!._swatch.map((key, color) => MapEntry(key, Color.lerp(color, null, t)!));
205205
} else {
@@ -214,7 +214,7 @@ class ChannelColorSwatch extends ColorSwatch<StreamColorVariant> {
214214
}
215215

216216
@visibleForTesting
217-
enum StreamColorVariant {
217+
enum ChannelColorVariant {
218218
base,
219219
unreadCountBadgeBackground,
220220
iconOnPlainBackground,

test/widgets/channel_colors_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,17 +460,17 @@ void main() {
460460
final swatchB = ChannelColorSwatch.dark(0xff76ce90);
461461
for (final t in [0.0, 0.5, 1.0, -0.1, 1.1]) {
462462
final result = ChannelColorSwatch.lerp(swatchA, swatchB, t)!;
463-
for (final variant in StreamColorVariant.values) {
463+
for (final variant in ChannelColorVariant.values) {
464464
final (subject, expected) = switch (variant) {
465-
StreamColorVariant.base => (check(result).base,
465+
ChannelColorVariant.base => (check(result).base,
466466
Color.lerp(swatchA.base, swatchB.base, t)!),
467-
StreamColorVariant.unreadCountBadgeBackground => (check(result).unreadCountBadgeBackground,
467+
ChannelColorVariant.unreadCountBadgeBackground => (check(result).unreadCountBadgeBackground,
468468
Color.lerp(swatchA.unreadCountBadgeBackground, swatchB.unreadCountBadgeBackground, t)!),
469-
StreamColorVariant.iconOnPlainBackground => (check(result).iconOnPlainBackground,
469+
ChannelColorVariant.iconOnPlainBackground => (check(result).iconOnPlainBackground,
470470
Color.lerp(swatchA.iconOnPlainBackground, swatchB.iconOnPlainBackground, t)!),
471-
StreamColorVariant.iconOnBarBackground => (check(result).iconOnBarBackground,
471+
ChannelColorVariant.iconOnBarBackground => (check(result).iconOnBarBackground,
472472
Color.lerp(swatchA.iconOnBarBackground, swatchB.iconOnBarBackground, t)!),
473-
StreamColorVariant.barBackground => (check(result).barBackground,
473+
ChannelColorVariant.barBackground => (check(result).barBackground,
474474
Color.lerp(swatchA.barBackground, swatchB.barBackground, t)!),
475475
};
476476
subject.equals(expected);

0 commit comments

Comments
 (0)