Skip to content

Commit

Permalink
refactor: wrapping for semantic tokens of colors (#79) (WIP)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp committed Dec 13, 2024
1 parent e560187 commit a65c00c
Show file tree
Hide file tree
Showing 49 changed files with 1,541 additions and 1,456 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import OUDSTokensSemantic

// swiftlint:disable line_length

/// Defines wrapper objects for `ColorSemanticToken`.
/// These values can be overriden inside `OUDSTheme` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
/// Defines wrapper objects for `ColorSemanticToken` so as to pack light and dark mode colors.
/// These values can be overriden inside `OUDSColorSemanticTokensWrapper` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
/// Some tokens do not have values assigned in the design system, and must be overriden.
/// Some tokens must be overiden in `OrangeTheme` side because they rely on Orange brand colors.
/// Helps to expose color semantic tokens with two values to use depending to the color scheme (*Figma* cannot manage such tokens and generate them).
extension OUDSTheme: ColorMultipleSemanticTokens {
extension OUDSColorSemanticTokensWrapper: ColorMultipleSemanticTokens {

// MARK: - Color - Opacity - Invisible

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import OUDSTokensSemantic

// swiftlint:disable identifier_name

extension OUDSTheme: ColorSemanticTokens {
extension OUDSColorSemanticTokensWrapper: ColorSemanticTokens {
@objc open var colorOpacityInvisibleBlackLight: ColorSemanticToken { ColorRawTokens.colorOpacityBlack0 }
@objc open var colorOpacityInvisibleWhiteLight: ColorSemanticToken { ColorRawTokens.colorOpacityWhite0 }
@objc open var colorOpacityInvisibleBlackDark: ColorSemanticToken { ColorRawTokens.colorOpacityWhite0 }
Expand Down
13 changes: 12 additions & 1 deletion OUDS/Core/OUDS/Sources/OUDSTheme/OUDSTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,44 @@ open class OUDSTheme: @unchecked Sendable {
/// All opacity semantic tokens exposed in one object
public let opacities: OpacitySemanticTokens

/// All color semantic tokens exposed in one object
public let colors: AllColorSemanticTokens

/// A theme can have a custom font which is not the system font
public let customFontFamily: FontFamilySemanticToken?

// MARK: - Initializers

// swiftlint:disable force_cast
/// Defines a basic kind of abstract theme to subclass then.
/// No custom font family will be used.
/// - Parameters:
/// - borders: An object providing all the border semantic tokens, by default `OUDSBorderSemanticTokensWrapper`
/// - opacities: An object providing all the opacity semantic tokens, by default `OUDSOpacitySemanticTokensWrapper`
/// - colors: An object providing all the color semantic tokens, by default `OUDSColorSemanticTokensWrapper`
public init(borders: BorderSemanticTokens = OUDSBorderSemanticTokensWrapper(),
opacities: OpacitySemanticTokens = OUDSOpacitySemanticTokensWrapper()) {
opacities: OpacitySemanticTokens = OUDSOpacitySemanticTokensWrapper(),
colors: AllColorSemanticTokens = OUDSColorSemanticTokensWrapper() as! AllColorSemanticTokens) {
self.borders = borders
self.opacities = opacities
self.colors = colors
customFontFamily = nil
}
// swiftlint:enable force_cast

/// Defines a basic kind of abstract theme to subclass then.
/// - Parameters:
/// - borders: An object providing all the border semantic tokens, as `BorderSemanticTokens` implementation
/// - opacities: An object providing all the opacity semantic tokens, as `OpacitySemanticTokens` implementation
/// - colors: An object providing all the color semantic tokens, as `AllColorSemanticTokens` implementation
/// - customFontFamily: Set `nil` if system font to use, otherwise use the `FontFamilySemanticToken` you want to apply
public init(borders: BorderSemanticTokens,
opacities: OpacitySemanticTokens,
colors: AllColorSemanticTokens,
customFontFamily: FontFamilySemanticToken?) {
self.borders = borders
self.opacities = opacities
self.colors = colors
self.customFontFamily = customFontFamily
}

Expand Down

Large diffs are not rendered by default.

1,340 changes: 670 additions & 670 deletions OUDS/Core/OUDS/Tests/OUDSTheme/TestThemeOverrideOfColorSemanticTokens.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ import OUDSTokensSemantic
/// Overrides some colors using values defined in extension of ``ColorRawTokens`` in this current module.
/// Some tokens do not have values assigned in the design system, and must be overriden.
/// Ensures the colors are always the "dark mode" colors.
extension InverseTheme {
final class InverseThemeColorSemanticTokensWrapper: OUDSColorSemanticTokensWrapper {

// MARK: - Init

deinit { }

// MARK: - Overrides

// MARK: - Color - Opacity - Invisible

Expand Down
5 changes: 4 additions & 1 deletion OUDS/Core/Themes/Inverse/Sources/InverseTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
//

import OUDSThemesOrange
import OUDSTokensSemantic

/// This is an override of the default basic `OrangeTheme` with some inverted colors.
/// It can overrides any properties from its superclass, and can be derived too.
public final class InverseTheme: OrangeTheme, @unchecked Sendable {

// MARK: - Initializers

// swiftlint:disable force_cast
/// Initializes the `InverseTheme`
override public init() {
super.init()
super.init(colors: InverseThemeColorSemanticTokensWrapper() as! AllColorSemanticTokens)
}
// swiftlint:enable force_cast

deinit { }
}
Loading

0 comments on commit a65c00c

Please sign in to comment.