Skip to content

Commit dd96117

Browse files
committed
Updated pill colours
1 parent ffa99e1 commit dd96117

File tree

3 files changed

+114
-14
lines changed

3 files changed

+114
-14
lines changed

DesignSystem/Sources/DesignSystem/Components/PostDisplayView.swift

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public struct PostDisplayView: View {
1919
let onBookmarkTap: (() async -> Bool)?
2020
let onCommentsTap: (() -> Void)?
2121

22+
@Environment(\.colorScheme) private var colorScheme
2223
@State private var isSubmittingUpvote = false
2324
@State private var isSubmittingBookmark = false
2425
@State private var displayedScore: Int
@@ -127,11 +128,10 @@ public struct PostDisplayView: View {
127128
let canInteract = canVote && !isUpvoted && !isLoading
128129
// Avoid keeping a disabled Button so the upvoted state retains the bright tint
129130
let (backgroundColor, textColor): (Color, Color) = {
130-
if isUpvoted {
131-
return (AppColors.upvotedColor.opacity(0.2), AppColors.upvotedColor)
132-
} else {
133-
return (Color.secondary.opacity(0.1), .secondary)
134-
}
131+
let style = AppColors.PillStyle.upvote(isActive: isUpvoted)
132+
let background = AppColors.pillBackground(for: style, colorScheme: colorScheme)
133+
let foreground = AppColors.pillForeground(for: style, colorScheme: colorScheme)
134+
return (background, foreground)
135135
}()
136136
let iconName = isUpvoted ? "arrow.up.circle.fill" : "arrow.up"
137137
let accessibilityLabel: String
@@ -159,8 +159,9 @@ public struct PostDisplayView: View {
159159
}
160160

161161
private var commentsPill: some View {
162-
let commentTextColor: Color = .secondary
163-
let commentBackgroundColor = Color.secondary.opacity(0.1)
162+
let style = AppColors.PillStyle.comments
163+
let commentTextColor = AppColors.pillForeground(for: style, colorScheme: colorScheme)
164+
let commentBackgroundColor = AppColors.pillBackground(for: style, colorScheme: colorScheme)
164165
// Brighter styling keeps the comments count from reading as a disabled control
165166
return pillView(
166167
iconName: "message",
@@ -177,13 +178,9 @@ public struct PostDisplayView: View {
177178

178179
private var bookmarkPill: some View {
179180
let isBookmarked = displayedBookmarked
180-
let backgroundColor: Color = {
181-
if isBookmarked {
182-
return AppColors.appTintColor.opacity(0.1)
183-
}
184-
return Color.secondary.opacity(0.1)
185-
}()
186-
let textColor: Color = isBookmarked ? AppColors.appTintColor : .secondary
181+
let style = AppColors.PillStyle.bookmark(isSaved: isBookmarked)
182+
let backgroundColor = AppColors.pillBackground(for: style, colorScheme: colorScheme)
183+
let textColor = AppColors.pillForeground(for: style, colorScheme: colorScheme)
187184
let iconName = isBookmarked ? "bookmark.fill" : "bookmark"
188185
let accessibilityLabel = isBookmarked ? "Remove bookmark" : "Save for later"
189186
let accessibilityHint = isBookmarked

DesignSystem/Sources/DesignSystem/Theme/AppColors.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,71 @@ public enum AppColors {
3636
public static func separator(for colorScheme: ColorScheme) -> Color {
3737
Color(.separator).opacity(colorScheme == .dark ? 0.6 : 0.3)
3838
}
39+
40+
public static func pillBackground(for style: PillStyle, colorScheme: ColorScheme) -> Color {
41+
switch style {
42+
case .upvote(isActive: true):
43+
return pillAccentBackground(for: upvotedColor, colorScheme: colorScheme)
44+
case .upvote(isActive: false):
45+
return pillNeutralBackground(for: colorScheme)
46+
case .bookmark(isSaved: true):
47+
return pillAccentBackground(for: appTintColor, colorScheme: colorScheme)
48+
case .bookmark(isSaved: false):
49+
return pillNeutralBackground(for: colorScheme)
50+
case .comments:
51+
return pillNeutralBackground(for: colorScheme)
52+
}
53+
}
54+
55+
public static func pillForeground(for style: PillStyle, colorScheme: ColorScheme) -> Color {
56+
switch style {
57+
case .upvote(isActive: true):
58+
return upvotedColor
59+
case .upvote(isActive: false):
60+
return pillNeutralForeground(for: colorScheme)
61+
case .bookmark(isSaved: true):
62+
return appTintColor
63+
case .bookmark(isSaved: false):
64+
return pillNeutralForeground(for: colorScheme)
65+
case .comments:
66+
return pillNeutralForeground(for: colorScheme)
67+
}
68+
}
69+
70+
public enum PillStyle: Sendable {
71+
case upvote(isActive: Bool)
72+
case bookmark(isSaved: Bool)
73+
case comments
74+
}
75+
76+
private static func pillNeutralBackground(for colorScheme: ColorScheme) -> Color {
77+
switch colorScheme {
78+
case .light:
79+
return Color.secondary.opacity(0.14)
80+
case .dark:
81+
return Color.secondary.opacity(0.1)
82+
@unknown default:
83+
return Color.secondary.opacity(0.1)
84+
}
85+
}
86+
87+
private static func pillAccentBackground(for baseColor: Color, colorScheme: ColorScheme) -> Color {
88+
switch colorScheme {
89+
case .light, .dark:
90+
return baseColor.opacity(0.2)
91+
@unknown default:
92+
return baseColor.opacity(0.2)
93+
}
94+
}
95+
96+
private static func pillNeutralForeground(for colorScheme: ColorScheme) -> Color {
97+
switch colorScheme {
98+
case .light, .dark:
99+
return Color.secondary
100+
@unknown default:
101+
return Color.secondary
102+
}
103+
}
39104
}
40105

41106
public enum AppGradients {

DesignSystem/Tests/DesignSystemTests/AppColorsTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,44 @@ struct AppColorsTests {
113113
#expect(unfocusedLight.approximatelyEquals(expectedLight))
114114
#expect(unfocusedDark.approximatelyEquals(expectedDark))
115115
}
116+
117+
@Test("Pill colour tokens reuse accent and neutral palettes")
118+
func pillColourSemantics() {
119+
let lightAccentBackground = resolvedColor(
120+
AppColors.pillBackground(for: .upvote(isActive: true), colorScheme: .light),
121+
style: .light
122+
)
123+
let expectedAccentBackground = resolvedColor(AppColors.upvotedColor.opacity(0.2), style: .light)
124+
#expect(lightAccentBackground.approximatelyEquals(expectedAccentBackground, tolerance: 0.01))
125+
126+
let lightNeutralBackground = resolvedColor(
127+
AppColors.pillBackground(for: .comments, colorScheme: .light),
128+
style: .light
129+
)
130+
let expectedNeutralBackground = resolvedColor(Color.secondary.opacity(0.1), style: .light)
131+
#expect(lightNeutralBackground.approximatelyEquals(expectedNeutralBackground, tolerance: 0.01))
132+
133+
let lightAccentForeground = resolvedColor(
134+
AppColors.pillForeground(for: .bookmark(isSaved: true), colorScheme: .light),
135+
style: .light
136+
)
137+
let expectedAccentForeground = resolvedColor(AppColors.appTintColor, style: .light)
138+
#expect(lightAccentForeground.approximatelyEquals(expectedAccentForeground))
139+
140+
let lightNeutralForeground = resolvedColor(
141+
AppColors.pillForeground(for: .upvote(isActive: false), colorScheme: .light),
142+
style: .light
143+
)
144+
let expectedNeutralForeground = resolvedColor(Color.secondary, style: .light)
145+
#expect(lightNeutralForeground.approximatelyEquals(expectedNeutralForeground))
146+
147+
let darkNeutralBackground = resolvedColor(
148+
AppColors.pillBackground(for: .comments, colorScheme: .dark),
149+
style: .dark
150+
)
151+
let expectedDarkNeutralBackground = resolvedColor(Color.secondary.opacity(0.1), style: .dark)
152+
#expect(darkNeutralBackground.approximatelyEquals(expectedDarkNeutralBackground, tolerance: 0.01))
153+
}
116154
}
117155

118156
// MARK: - Test Helpers

0 commit comments

Comments
 (0)