Skip to content

Commit ff23ec8

Browse files
committed
Move AppColor to DesignSystem
1 parent 815edf2 commit ff23ec8

File tree

192 files changed

+414
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+414
-226
lines changed

Modules/Package.swift

+10-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ let package = Package(
6060
.product(name: "Gifu", package: "Gifu"),
6161
]),
6262
.target(name: "BuildSettingsKit"),
63-
.target(name: "DesignSystem", swiftSettings: [.swiftLanguageMode(.v5)]),
63+
.target(
64+
name: "DesignSystem",
65+
dependencies: [
66+
"BuildSettingsKit",
67+
.product(name: "ColorStudio", package: "color-studio"),
68+
],
69+
resources: [.process("Resources")],
70+
swiftSettings: [.swiftLanguageMode(.v5)]
71+
),
6472
.target(name: "JetpackStatsWidgetsCore", swiftSettings: [.swiftLanguageMode(.v5)]),
6573
// SFHFKeychainUtils is an old Objective-C keychain wrapper.
6674
// The implementatoin predates ARC, hence the dedicated target with ARC disabled, for the time being.
@@ -96,7 +104,7 @@ let package = Package(
96104
.target(name: "WordPressTesting", resources: [.process("Resources")]),
97105
.target(
98106
name: "WordPressUI",
99-
dependencies: ["AsyncImageKit", "WordPressShared"],
107+
dependencies: ["AsyncImageKit", "DesignSystem", "WordPressShared"],
100108
resources: [.process("Resources")],
101109
swiftSettings: [.swiftLanguageMode(.v5)]
102110
),
@@ -175,7 +183,6 @@ enum XcodeSupport {
175183
.product(name: "Reachability", package: "Reachability"),
176184
.product(name: "SVProgressHUD", package: "SVProgressHUD"),
177185
.product(name: "ZIPFoundation", package: "ZIPFoundation"),
178-
.product(name: "ColorStudio", package: "color-studio"),
179186
.product(name: "Aztec", package: "AztecEditor-iOS"),
180187
.product(name: "WordPressEditor", package: "AztecEditor-iOS"),
181188
]
@@ -252,7 +259,6 @@ enum XcodeSupport {
252259
"WordPressUI",
253260
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
254261
.product(name: "WordPressAPI", package: "wordpress-rs"),
255-
.product(name: "ColorStudio", package: "color-studio"),
256262
]),
257263
.xcodeTarget("XcodeTarget_Intents", dependencies: [
258264
"BuildSettingsKit",

Modules/Sources/BuildSettingsKit/BuildSettings+Live.swift

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extension BuildSettings {
44
static let live = BuildSettings(bundle: .app)
55

66
init(bundle: Bundle) {
7+
brand = AppBrand(rawValue: bundle.infoValue(forKey: "WPAppBrand"))!
78
pushNotificationAppID = bundle.infoValue(forKey: "WPPushNotificationAppID")
89
appGroupName = bundle.infoValue(forKey: "WPAppGroupName")
910
appKeychainAccessGroup = bundle.infoValue(forKey: "WPAppKeychainAccessGroup")

Modules/Sources/BuildSettingsKit/BuildSettings+Preview.swift

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Foundation
33
/// The container for Xcode previews.
44
extension BuildSettings {
55
nonisolated(unsafe) static var preview = BuildSettings(
6+
brand: .jetpack,
67
pushNotificationAppID: "xcpreview_push_notification_id",
78
appGroupName: "xcpreview_app_group_name",
89
appKeychainAccessGroup: "xcpreview_app_keychain_access_group"

Modules/Sources/BuildSettingsKit/BuildSettings.swift

+12-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ import Foundation
1212
/// - **Test** – `BuildSettings` are not available when running unit tests as
1313
/// they are incompatible with parallelized tests and are generally not recommended.
1414
public struct BuildSettings: Sendable {
15+
public var brand: AppBrand
1516
public var pushNotificationAppID: String
1617
public var appGroupName: String
1718
public var appKeychainAccessGroup: String
1819

1920
public static var current: BuildSettings {
2021
switch BuildSettingsEnvironment.current {
21-
case .live: .live
22-
case .preview: .preview
22+
case .live:
23+
return .live
24+
case .preview:
25+
return .preview
26+
case .test:
27+
fatalError("BuildSettings are unavailable when running unit tests. Make sure to inject the values manually in system under test.")
2328
}
2429
}
2530
}
31+
32+
public enum AppBrand: String, Sendable {
33+
case wordpress
34+
case jetpack
35+
}

Modules/Sources/BuildSettingsKit/BuildSettingsEnvironment.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Foundation
33
enum BuildSettingsEnvironment {
44
case live
55
case preview
6+
case test
67

78
static let current: BuildSettingsEnvironment = {
89
#if DEBUG
@@ -11,7 +12,7 @@ enum BuildSettingsEnvironment {
1112
return .preview
1213
}
1314
if processInfo.isTesting {
14-
fatalError("BuildSettings are unavailable when running unit tests. Make sure to inject the values manually in system under test.")
15+
return .test
1516
}
1617
#endif
1718
return .live

Modules/Sources/DesignSystem/Components/DSButtonStyle.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import SwiftUI
2+
import BuildSettingsKit
23

34
public struct DSButtonStyle {
45
public enum Emphasis: CaseIterable {
@@ -17,7 +18,11 @@ public struct DSButtonStyle {
1718
public let size: Size
1819
public let isJetpack: Bool
1920

20-
public init(emphasis: Emphasis, size: Size, isJetpack: Bool) {
21+
public init(
22+
emphasis: Emphasis,
23+
size: Size,
24+
isJetpack: Bool = BuildSettings.current.brand == .jetpack
25+
) {
2126
self.emphasis = emphasis
2227
self.size = size
2328
self.isJetpack = isJetpack
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import UIKit
2+
import SwiftUI
3+
import ColorStudio
4+
import BuildSettingsKit
5+
6+
public enum UIAppColor {
7+
/// A tint color used in places like navigation bars.
8+
///
9+
/// - note: The Jetpack app uses
10+
public static var tint: UIColor {
11+
switch BuildSettings.current.brand {
12+
case .wordpress: primary
13+
case .jetpack: UIColor.label
14+
}
15+
}
16+
17+
public static var primary: UIColor {
18+
switch BuildSettings.current.brand {
19+
case .wordpress: UIColor(light: CSColor.Blue.base, dark: primary(.shade40))
20+
case .jetpack: UIColor(light: CSColor.JetpackGreen.shade(.shade40), dark: CSColor.JetpackGreen.shade(.shade30))
21+
}
22+
}
23+
24+
public static func primary(_ shade: ColorStudioShade) -> UIColor {
25+
switch BuildSettings.current.brand {
26+
case .wordpress: CSColor.Blue.shade(shade)
27+
case .jetpack: CSColor.JetpackGreen.shade(shade)
28+
}
29+
}
30+
}
31+
32+
extension UIAppColor {
33+
public static func accent(_ shade: ColorStudioShade) -> UIColor {
34+
CSColor.Pink.shade(shade)
35+
}
36+
37+
public static func error(_ shade: ColorStudioShade) -> UIColor {
38+
CSColor.Red.shade(shade)
39+
}
40+
41+
public static func warning(_ shade: ColorStudioShade) -> UIColor {
42+
CSColor.Yellow.shade(shade)
43+
}
44+
45+
public static func success(_ shade: ColorStudioShade) -> UIColor {
46+
CSColor.Green.shade(shade)
47+
}
48+
49+
public static func gray(_ shade: ColorStudioShade) -> UIColor {
50+
CSColor.Gray.shade(shade)
51+
}
52+
53+
public static func blue(_ shade: ColorStudioShade) -> UIColor {
54+
CSColor.Blue.shade(shade)
55+
}
56+
57+
public static func green(_ shade: ColorStudioShade) -> UIColor {
58+
CSColor.Green.shade(shade)
59+
}
60+
61+
public static func red(_ shade: ColorStudioShade) -> UIColor {
62+
CSColor.Red.shade(shade)
63+
}
64+
65+
public static func pink(_ shade: ColorStudioShade) -> UIColor {
66+
CSColor.Pink.shade(shade)
67+
}
68+
69+
public static func yellow(_ shade: ColorStudioShade) -> UIColor {
70+
CSColor.Yellow.shade(shade)
71+
}
72+
73+
public static func purple(_ shade: ColorStudioShade) -> UIColor {
74+
CSColor.Purple.shade(shade)
75+
}
76+
77+
public static func orange(_ shade: ColorStudioShade) -> UIColor {
78+
CSColor.Orange.shade(shade)
79+
}
80+
81+
public static func celadon(_ shade: ColorStudioShade) -> UIColor {
82+
CSColor.Celadon.shade(shade)
83+
}
84+
85+
public static func wordPressBlue(_ shade: ColorStudioShade) -> UIColor {
86+
CSColor.WordPressBlue.shade(shade)
87+
}
88+
89+
public static func jetpackGreen(_ shade: ColorStudioShade) -> UIColor {
90+
CSColor.JetpackGreen.shade(shade)
91+
}
92+
93+
public static let primaryLight: UIColor = primary(.shade30)
94+
public static let primaryDark: UIColor = primary(.shade70)
95+
96+
public static func neutral(_ shade: ColorStudioShade) -> UIColor {
97+
return switch shade {
98+
case .shade0: UIColor(light: gray(.shade0), dark: gray(.shade100))
99+
case .shade5: UIColor(light: gray(.shade5), dark: gray(.shade90))
100+
case .shade10: UIColor(light: gray(.shade10), dark: gray(.shade80))
101+
case .shade20: UIColor(light: gray(.shade20), dark: gray(.shade70))
102+
case .shade30: UIColor(light: gray(.shade30), dark: gray(.shade60))
103+
case .shade40: UIColor(light: gray(.shade40), dark: gray(.shade50))
104+
case .shade50: UIColor(light: gray(.shade50), dark: gray(.shade40))
105+
case .shade60: UIColor(light: gray(.shade60), dark: gray(.shade30))
106+
case .shade70: UIColor(light: gray(.shade70), dark: gray(.shade20))
107+
case .shade80: UIColor(light: gray(.shade80), dark: gray(.shade10))
108+
case .shade90: UIColor(light: gray(.shade90), dark: gray(.shade5))
109+
case .shade100: UIColor(light: gray(.shade100), dark: gray(.shade0))
110+
}
111+
}
112+
113+
public static let accent = CSColor.Pink.base
114+
public static let divider = CSColor.Gray.shade(.shade10)
115+
public static let error = CSColor.Red.base
116+
public static let gray = CSColor.Gray.base
117+
public static let blue = CSColor.Blue.base
118+
119+
public static let success = CSColor.Green.base
120+
public static let text = CSColor.Gray.shade(.shade80)
121+
public static let textSubtle = CSColor.Gray.shade(.shade50)
122+
public static let warning = CSColor.Yellow.base
123+
public static let jetpackGreen = CSColor.JetpackGreen.base
124+
public static let editorPrimary = CSColor.Blue.base
125+
public static let neutral = CSColor.Gray.base
126+
127+
public static let statsPrimaryHighlight = UIColor(light: accent(.shade30), dark: accent(.shade60))
128+
public static let statsSecondaryHighlight = UIColor(light: accent(.shade60), dark: accent(.shade30))
129+
130+
// TODO : These should be customized for WP and JP
131+
public static let appBarTint = UIColor.systemOrange
132+
public static let appBarText = UIColor.systemOrange
133+
134+
public static let placeholderElement = UIColor(light: .systemGray5, dark: .systemGray4)
135+
public static let placeholderElementFaded: UIColor = UIColor(light: .systemGray6, dark: .systemGray5)
136+
137+
public static let prologueBackground = UIColor(light: blue(.shade0), dark: .systemBackground)
138+
139+
public static let switchStyle: SwitchToggleStyle = SwitchToggleStyle(tint: Color(UIAppColor.primary))
140+
}
141+
142+
public enum AppColor {
143+
public static var tint: Color { Color(UIAppColor.tint) }
144+
public static var primary: Color { Color(UIAppColor.primary) }
145+
}
146+
147+
private extension UIColor {
148+
convenience init(light: UIColor, dark: UIColor) {
149+
self.init { traitCollection in
150+
if traitCollection.userInterfaceStyle == .dark {
151+
return dark
152+
} else {
153+
return light
154+
}
155+
}
156+
}
157+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@_exported import DesignSystem
2+
@_exported import AsyncImageKit
3+
@_exported import WordPressShared

WordPress/Classes/Extensions/Colors and Styles/UIColor+MurielColorsObjC.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import UIKit
2+
import WordPressUI
3+
14
/// Objective-C *only* API for the Muriel colors
25
@objc extension UIColor {
36

WordPress/Classes/Extensions/Colors and Styles/UIColor+Notice.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import UIKit
2+
import WordPressUI
3+
14
extension UIColor {
25

36
static var invertedSystem5: UIColor {

WordPress/Classes/Extensions/Colors and Styles/WPStyleGuide+Aztec.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import UIKit
2-
import Gridicons
32
import WordPressShared
3+
import WordPressUI
44

55
extension WPStyleGuide {
66
static let aztecFormatBarInactiveColor: UIColor = .secondaryLabel

WordPress/Classes/Extensions/Colors and Styles/WPStyleGuide+FilterTabBar.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import UIKit
2+
import WordPressUI
23

34
extension WPStyleGuide {
45
@objc class func configureFilterTabBar(_ filterTabBar: FilterTabBar) {

WordPress/Classes/Extensions/UITableViewCell+enableDisable.swift

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import UIKit
12
import WordPressShared
3+
import WordPressUI
24

35
extension UITableViewCell {
46
/// Enable cell interaction

WordPress/Classes/Models/Notifications/Actions/ApproveComment.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import UIKit
2+
import WordPressUI
3+
14
/// Encapsulates logic to approve a comment
25
class ApproveComment: DefaultNotificationActionCommand {
36
enum TitleStrings {

WordPress/Classes/Models/Notifications/Actions/Follow.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import UIKit
2+
import WordPressUI
3+
14
/// Encapsulates logic to follow a blog
25
final class Follow: DefaultNotificationActionCommand {
36
static let title = NSLocalizedString("notifications.action.subscribe.title", value: "Subscribe", comment: "Prompt to subscribe to a blog.")

WordPress/Classes/Models/Notifications/Actions/NotificationAction.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import UIKit
2+
import WordPressUI
3+
14
/// Base Notification Action Command.
25
class DefaultNotificationActionCommand: FormattableContentActionCommand {
36
var on: Bool

WordPress/Classes/Models/Notifications/Actions/TrashComment.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import UIKit
2+
import WordPressUI
3+
14
/// Encapsulates logic to trash a comment
25
class TrashComment: DefaultNotificationActionCommand {
36
static let title = NSLocalizedString("Trash", comment: "Trashes the comment")

WordPress/Classes/Models/Revisions/DiffAbstractValue+Attributes.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import UIKit
2+
import WordPressUI
3+
14
extension DiffAbstractValue {
25
var attributes: [NSAttributedString.Key: Any]? {
36
switch operation {

0 commit comments

Comments
 (0)