Skip to content

Commit e34e6bf

Browse files
committed
refactor: clean up (#521)
Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
1 parent 4733040 commit e34e6bf

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

OUDS/Core/Themes/Orange/Sources/Values/SemanticTokens/OrangeTheme+ColorModeMultipleSemanticTokens.swift

+32-30
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313

1414
import Foundation
15+
import OUDSFoundations
1516
import OUDSTokensRaw
1617
import OUDSTokensSemantic
1718
import SwiftUI
@@ -27,35 +28,35 @@ extension OrangeThemeColorModeSemanticTokensProvider: ColorModeMultipleSemanticT
2728

2829
// MARK: - Multiple tokens
2930

30-
@objc open var modeOnBrandPrimary: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnBrandPrimaryLight, dark: modeOnBrandPrimaryDark) }
31+
@objc open var modeOnBrandPrimary: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnBrandPrimary", light: modeOnBrandPrimaryLight, dark: modeOnBrandPrimaryDark) }
3132

32-
@objc open var modeOnBrandSecondary: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnBrandSecondaryLight, dark: modeOnBrandSecondaryDark) }
33+
@objc open var modeOnBrandSecondary: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnBrandSecondary", light: modeOnBrandSecondaryLight, dark: modeOnBrandSecondaryDark) }
3334

34-
@objc open var modeOnBrandTertiary: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnBrandTertiaryLight, dark: modeOnBrandTertiaryDark) }
35+
@objc open var modeOnBrandTertiary: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnBrandTertiary", light: modeOnBrandTertiaryLight, dark: modeOnBrandTertiaryDark) }
3536

36-
@objc open var modeOnStatusAccentEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusAccentEmphasizedLight, dark: modeOnStatusAccentEmphasizedDark) }
37+
@objc open var modeOnStatusAccentEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusAccentEmphasized", light: modeOnStatusAccentEmphasizedLight, dark: modeOnStatusAccentEmphasizedDark) }
3738

38-
@objc open var modeOnStatusAccentMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusAccentMutedLight, dark: modeOnStatusAccentMutedDark) }
39+
@objc open var modeOnStatusAccentMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusAccentMuted", light: modeOnStatusAccentMutedLight, dark: modeOnStatusAccentMutedDark) }
3940

40-
@objc open var modeOnStatusInfoEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusInfoEmphasizedLight, dark: modeOnStatusInfoEmphasizedDark) }
41+
@objc open var modeOnStatusInfoEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusInfoEmphasized", light: modeOnStatusInfoEmphasizedLight, dark: modeOnStatusInfoEmphasizedDark) }
4142

42-
@objc open var modeOnStatusInfoMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusInfoMutedLight, dark: modeOnStatusInfoMutedDark) }
43+
@objc open var modeOnStatusInfoMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusInfoMuted", light: modeOnStatusInfoMutedLight, dark: modeOnStatusInfoMutedDark) }
4344

44-
@objc open var modeOnStatusNegativeEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusNegativeEmphasizedLight, dark: modeOnStatusNegativeEmphasizedDark) }
45+
@objc open var modeOnStatusNegativeEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusNegativeEmphasized", light: modeOnStatusNegativeEmphasizedLight, dark: modeOnStatusNegativeEmphasizedDark) }
4546

46-
@objc open var modeOnStatusNegativeMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusNegativeMutedLight, dark: modeOnStatusNegativeMutedDark) }
47+
@objc open var modeOnStatusNegativeMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusNegativeMuted", light: modeOnStatusNegativeMutedLight, dark: modeOnStatusNegativeMutedDark) }
4748

48-
@objc open var modeOnStatusNeutralEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusNeutralEmphasizedLight, dark: modeOnStatusNeutralEmphasizedDark) }
49+
@objc open var modeOnStatusNeutralEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusNeutralEmphasized", light: modeOnStatusNeutralEmphasizedLight, dark: modeOnStatusNeutralEmphasizedDark) }
4950

50-
@objc open var modeOnStatusNeutralMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusNeutralMutedLight, dark: modeOnStatusNeutralMutedDark) }
51+
@objc open var modeOnStatusNeutralMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusNeutralMuted", light: modeOnStatusNeutralMutedLight, dark: modeOnStatusNeutralMutedDark) }
5152

52-
@objc open var modeOnStatusPositiveEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusPositiveEmphasizedLight, dark: modeOnStatusPositiveEmphasizedDark) }
53+
@objc open var modeOnStatusPositiveEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusPositiveEmphasized", light: modeOnStatusPositiveEmphasizedLight, dark: modeOnStatusPositiveEmphasizedDark) }
5354

54-
@objc open var modeOnStatusPositiveMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusPositiveMutedLight, dark: modeOnStatusPositiveMutedDark) }
55+
@objc open var modeOnStatusPositiveMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusPositiveMuted", light: modeOnStatusPositiveMutedLight, dark: modeOnStatusPositiveMutedDark) }
5556

56-
@objc open var modeOnStatusWarningEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusWarningEmphasizedLight, dark: modeOnStatusWarningEmphasizedDark) }
57+
@objc open var modeOnStatusWarningEmphasized: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusWarningEmphasized", light: modeOnStatusWarningEmphasizedLight, dark: modeOnStatusWarningEmphasizedDark) }
5758

58-
@objc open var modeOnStatusWarningMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens(light: modeOnStatusWarningMutedLight, dark: modeOnStatusWarningMutedDark) }
59+
@objc open var modeOnStatusWarningMuted: MultipleColorModeSemanticTokens { MultipleColorModeSemanticTokens("modeOnStatusWarningMuted", light: modeOnStatusWarningMutedLight, dark: modeOnStatusWarningMutedDark) }
5960

6061
// MARK: - Additional rules
6162

@@ -112,21 +113,22 @@ extension OrangeThemeColorModeSemanticTokensProvider: ColorModeMultipleSemanticT
112113
/// - Parameter mode: The color mpde token to use
113114
/// - Returns: The colors to apply
114115
public func toColor(from mode: MultipleColorModeSemanticTokens) -> MultipleColorSemanticTokens {
115-
if mode == modeOnBrandPrimary { return colors.colorSurfaceBrandPrimary }
116-
if mode == modeOnBrandSecondary { return colors.colorSurfaceBrandPrimary } // TODO: #521 - Not sure of this implementation
117-
if mode == modeOnBrandTertiary { return colors.colorSurfaceBrandPrimary } // TODO: #521 - Not sure of this implementation
118-
if mode == modeOnStatusAccentEmphasized { return colors.colorSurfaceStatusAccentEmphasized }
119-
if mode == modeOnStatusAccentMuted { return colors.colorSurfaceStatusAccentMuted }
120-
if mode == modeOnStatusInfoEmphasized { return colors.colorSurfaceStatusInfoEmphasized }
121-
if mode == modeOnStatusInfoMuted { return colors.colorSurfaceStatusInfoMuted }
122-
if mode == modeOnStatusNeutralEmphasized { return colors.colorSurfaceStatusNegativeEmphasized }
123-
if mode == modeOnStatusNegativeMuted { return colors.colorSurfaceStatusNegativeMuted }
124-
if mode == modeOnStatusNeutralEmphasized { return colors.colorSurfaceStatusNeutralEmphasized }
125-
if mode == modeOnStatusNeutralMuted { return colors.colorSurfaceStatusNeutralMuted }
126-
if mode == modeOnStatusPositiveEmphasized { return colors.colorSurfaceStatusPositiveEmphasized }
127-
if mode == modeOnStatusPositiveMuted { return colors.colorSurfaceStatusPositiveMuted }
128-
if mode == modeOnStatusWarningEmphasized { return colors.colorSurfaceStatusWarningEmphasized }
129-
if mode == modeOnStatusWarningMuted { return colors.colorSurfaceStatusWarningMuted }
116+
if mode.isEqual(modeOnBrandPrimary) { return colors.colorSurfaceBrandPrimary }
117+
if mode.isEqual(modeOnBrandSecondary) { return colors.colorSurfaceBrandPrimary } // TODO: #521 - Not sure of this implementation
118+
if mode.isEqual(modeOnBrandTertiary) { return colors.colorSurfaceBrandPrimary } // TODO: #521 - Not sure of this implementation
119+
if mode.isEqual(modeOnStatusAccentEmphasized) { return colors.colorSurfaceStatusAccentEmphasized }
120+
if mode.isEqual(modeOnStatusAccentMuted) { return colors.colorSurfaceStatusAccentMuted }
121+
if mode.isEqual(modeOnStatusInfoEmphasized) { return colors.colorSurfaceStatusInfoEmphasized }
122+
if mode.isEqual(modeOnStatusInfoMuted) { return colors.colorSurfaceStatusInfoMuted }
123+
if mode.isEqual(modeOnStatusNeutralEmphasized) { return colors.colorSurfaceStatusNegativeEmphasized }
124+
if mode.isEqual(modeOnStatusNeutralMuted) { return colors.colorSurfaceStatusNegativeMuted }
125+
if mode.isEqual(modeOnStatusNegativeEmphasized) { return colors.colorSurfaceStatusNeutralEmphasized }
126+
if mode.isEqual(modeOnStatusNegativeMuted) { return colors.colorSurfaceStatusNeutralMuted }
127+
if mode.isEqual(modeOnStatusPositiveEmphasized) { return colors.colorSurfaceStatusPositiveEmphasized }
128+
if mode.isEqual(modeOnStatusPositiveMuted) { return colors.colorSurfaceStatusPositiveMuted }
129+
if mode.isEqual(modeOnStatusWarningEmphasized) { return colors.colorSurfaceStatusWarningEmphasized }
130+
if mode.isEqual(modeOnStatusWarningMuted) { return colors.colorSurfaceStatusWarningMuted }
131+
OL.warning("Multiple color mode semantic token not managed: \(mode.name)")
130132
return colors.colorSurfaceBrandPrimary // TODO: #521 - Which default behavior?
131133
}
132134
// swiftlint:enable cyclomatic_complexity

OUDS/Core/Tokens/SemanticTokens/Sources/Multiples/MultipleColorModeSemanticToken.swift

+12-4
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,32 @@ import SwiftUI
4949
/// - Since: 0.13.0
5050
public final class MultipleColorModeSemanticTokens: NSObject, Sendable {
5151

52+
/// Because such tokens can have the same light and dark values, a name can be used to identity them
53+
public let name: String
54+
5255
/// For **light** mode scheme
5356
public let light: ColorModeSemanticToken
5457

5558
/// For **dark** mode scheme
5659
public let dark: ColorModeSemanticToken
5760

5861
/// Initializes a new color mode color multiple semantic token with the same value for light and dark modes
59-
/// - Parameter value: The `ColorModeSemanticToken` to apply wether the device is in *light* and *dark* mode
60-
public init(_ value: ColorModeSemanticToken) {
62+
/// - Parameters:
63+
/// - name: A unique name for the token
64+
/// - value: The `ColorModeSemanticToken` to apply wether the device is in *light* and *dark* mode
65+
public init(_ name: String, _ value: ColorModeSemanticToken) {
66+
self.name = name
6167
self.light = value
6268
self.dark = value
6369
}
6470

6571
/// Initializes a new color mode multiple semantic token with two values
6672
/// - Parameters:
73+
/// - name: A unique name for the token
6774
/// - light: The `ColorModeSemanticToken` to apply if device in *light* mode
6875
/// - dark: The `ColorModeSemanticToken` to apply if device in *dark* mode
69-
public init(light: ColorModeSemanticToken, dark: ColorModeSemanticToken) {
76+
public init(_ name: String, light: ColorModeSemanticToken, dark: ColorModeSemanticToken) {
77+
self.name = name
7078
self.light = light
7179
self.dark = dark
7280
}
@@ -78,6 +86,6 @@ public final class MultipleColorModeSemanticTokens: NSObject, Sendable {
7886
/// `isEqual` override is preferred for `NSObject`.
7987
override public func isEqual(_ object: Any?) -> Bool {
8088
guard let other = object as? MultipleColorModeSemanticTokens else { return false }
81-
return self.light == other.light && self.dark == other.dark
89+
return self.name == other.name
8290
}
8391
}

0 commit comments

Comments
 (0)