Skip to content

Commit

Permalink
refactor: wrapping for semantic tokens of elevations (#79)
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 9d4df70 commit 6d946a8
Show file tree
Hide file tree
Showing 21 changed files with 306 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import OUDSTokensSemantic
// Create an issue for update https://github.com/Orange-OpenSource/ouds-ios/issues/new?template=token_update.yml

/// Defines basic values common to all themes for ``ElevationCompositeSemanticTokens``.
/// These values can be overriden inside ``OUDSTheme`` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
/// The aim of this extensions is to make relationships between all semantic tokens for elevations and associated raw tokens.
/// `OUDSTheme`` can be seen as a kind of "abstract class" in _object oriented paradigm_.
/// The *tokenator* is not able to provide code for such "composite" objects because the *Figma* tool itself cannot manage that and does not output anything in its JSON to process/
/// These values can be overriden inside ``OUDSElevationSemanticTokensWrapper`` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
/// The aim of this extension is to make relationships between all semantic tokens for elevations and associated raw tokens.
/// The *tokenator* is not able to provide code for such "composite" objects because the *Figma* tool itself cannot manage that and does not output anything in its JSON to process.
/// It defines in fact box shadows effects.
extension OUDSTheme: ElevationCompositeSemanticTokens {
extension OUDSElevationSemanticTokensWrapper: ElevationCompositeSemanticTokens {

// MARK: Semantic token - Elevation - Box shadow

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import OUDSTokensSemantic

// swiftlint:disable line_length

/// Defines wrapper objects for eelvation color semantic tokens.
/// These values can be overriden inside ``OUDSTheme`` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
extension OUDSTheme: ElevationMultipleSemanticTokens {
/// Defines wrapper objects for elevation color semantic tokens using ``MultipleColorSemanticTokens`` so as to exposed colors for light and dark color schemes.
/// These values can be overriden inside `OUDSElevationSemanticTokensWrapper` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
extension OUDSElevationSemanticTokensWrapper: ElevationMultipleSemanticTokens {

@objc open var elevationColorDefault: MultipleColorSemanticTokens { MultipleColorSemanticTokens(light: elevationColorDefaultLight, dark: elevationColorDefaultDark) }
@objc open var elevationColorDrag: MultipleColorSemanticTokens { MultipleColorSemanticTokens(light: elevationColorDragLight, dark: elevationColorDragDark) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import OUDSTokensSemantic

// swiftlint:disable identifier_name

extension OUDSTheme: ElevationSemanticTokens {
extension OUDSElevationSemanticTokensWrapper: ElevationSemanticTokens {
@objc open var elevationBlurDefault: ElevationBlurSemanticToken { ElevationRawTokens.elevationBlur300 }
@objc open var elevationBlurDrag: ElevationBlurSemanticToken { ElevationRawTokens.elevationBlur400 }
@objc open var elevationBlurEmphasized: ElevationBlurSemanticToken { ElevationRawTokens.elevationBlur600 }
Expand Down
23 changes: 16 additions & 7 deletions OUDS/Core/OUDS/Sources/OUDSTheme/OUDSTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ open class OUDSTheme: @unchecked Sendable {
// MARK: - Properties

/// All border semantic tokens exposed in one object
public let borders: BorderSemanticTokens
public let borders: AllBorderSemanticTokens

/// All opacity semantic tokens exposed in one object
public let opacities: OpacitySemanticTokens
public let opacities: AllOpacitySemanticTokens

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

/// All elevation semantic tokens exposed in one object
public let elevations: AllElevationSemanticTokens

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

Expand All @@ -49,12 +52,15 @@ open class OUDSTheme: @unchecked Sendable {
/// - 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(),
colors: AllColorSemanticTokens = OUDSColorSemanticTokensWrapper()) {
/// - elevations: An object providing all the elevation semantic tokens, by default `OUDSElevationSemanticTokensWrapper`
public init(borders: AllBorderSemanticTokens = OUDSBorderSemanticTokensWrapper(),
opacities: AllOpacitySemanticTokens = OUDSOpacitySemanticTokensWrapper(),
colors: AllColorSemanticTokens = OUDSColorSemanticTokensWrapper(),
elevations: AllElevationSemanticTokens = OUDSElevationSemanticTokensWrapper()) {
self.borders = borders
self.opacities = opacities
self.colors = colors
self.elevations = elevations
customFontFamily = nil
}

Expand All @@ -63,14 +69,17 @@ open class OUDSTheme: @unchecked Sendable {
/// - 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
/// - elevations: An object providing all the elevation semantic tokens, by default `AllElevationSemanticTokens`
/// - customFontFamily: Set `nil` if system font to use, otherwise use the `FontFamilySemanticToken` you want to apply
public init(borders: BorderSemanticTokens,
opacities: OpacitySemanticTokens,
public init(borders: AllBorderSemanticTokens,
opacities: AllOpacitySemanticTokens,
colors: AllColorSemanticTokens,
elevations: AllElevationSemanticTokens,
customFontFamily: FontFamilySemanticToken?) {
self.borders = borders
self.opacities = opacities
self.colors = colors
self.elevations = elevations
self.customFontFamily = customFontFamily
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://publicsource.org/license/MIT/
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://publicsource.org/license/MIT/
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,101 @@ import Foundation
import OUDSTokensRaw
import OUDSTokensSemantic

/// Overrides **all** the elevation composite semantic tokens (from its super class, i.e. `OUDSTheme` so as to test overriding of them (unit tests)
// swiftlint:disable required_deinit
// swiftlint:disable identifier_name
// swiftlint:disable line_length

/// Overrides **all** the elevation semantic tokens, both simple, multiple and composites (from its super class, i.e. `OUDSElevationSemanticTokensWrapper` so as to test overriding of them (unit tests)
/// and to act like smoke tests with crashing tests if some tokens disappeared.
extension MockTheme {
/// This ``MockThemeElevationSemanticTokensWrapper`` will be asigned in ``MockTheme`` as an ``AllElevationSemanticTokens`` implementation.
final class MockThemeElevationSemanticTokensWrapper: OUDSElevationSemanticTokensWrapper {

// MARK: Semantic token - Elevation - Box shadow (Composites)

static let mockThemeElevationCompositeSemanticToken = ElevationCompositeSemanticToken(ElevationRawTokens.elevationBottom_1_600)

// MARK: Semantic token - Elevation - Box shadow
override public var elevationNone: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }

override public var elevationRaised: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }

override public var elevationDrag: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }

override public var elevationOverlayDefault: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }

override public var elevationOverlayEmphasized: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }

override public var elevationStickyDefault: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }

override open var elevationNone: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }
override public var elevationStickyEmphasized: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }

override open var elevationRaised: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }
override public var elevationStickyNavigationScrolled: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }

override open var elevationDrag: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }
// MARK: - Semantic token - Elevation

override open var elevationOverlayDefault: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }
static let mockThemeElevationXRawToken: ElevationRawToken = 711
static let mockThemeElevationYRawToken: ElevationRawToken = 713
static let mockThemeElevationBlurRawToken: ElevationRawToken = 816
static let mockThemeElevationColorRawToken: ColorRawToken = ColorRawTokens.colorFunctionalMalachite500
static let mockThemeElevationMultipleColorSemanticToken = MultipleColorSemanticTokens(mockThemeElevationColorRawToken)

override open var elevationOverlayEmphasized: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }
// MARK: Semantic token - Elevation - X

override open var elevationStickyDefault: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }
override public var elevationXNone: ElevationYSemanticToken { Self.mockThemeElevationXRawToken }
override public var elevationXRaised: ElevationYSemanticToken { Self.mockThemeElevationXRawToken }
override public var elevationXDrag: ElevationYSemanticToken { Self.mockThemeElevationXRawToken }
override public var elevationXStickyDefault: ElevationYSemanticToken { Self.mockThemeElevationXRawToken }
override public var elevationXStickyEmphasized: ElevationYSemanticToken { Self.mockThemeElevationXRawToken }
override public var elevationXStickyNavigationScrolled: ElevationYSemanticToken { Self.mockThemeElevationXRawToken }

override open var elevationStickyEmphasized: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }
// MARK: Semantic token - Elevation - Y

override open var elevationStickyNavigationScrolled: ElevationCompositeSemanticToken { Self.mockThemeElevationCompositeSemanticToken }
override public var elevationYNone: ElevationYSemanticToken { Self.mockThemeElevationYRawToken }
override public var elevationYRaised: ElevationYSemanticToken { Self.mockThemeElevationYRawToken }
override public var elevationYDrag: ElevationYSemanticToken { Self.mockThemeElevationYRawToken }
override public var elevationYStickyDefault: ElevationYSemanticToken { Self.mockThemeElevationYRawToken }
override public var elevationYStickyEmphasized: ElevationYSemanticToken { Self.mockThemeElevationYRawToken }
override public var elevationYStickyNavigationScrolled: ElevationYSemanticToken { Self.mockThemeElevationYRawToken }

// MARK: Semantic token - Elevation - Blur

override public var elevationBlurNone: ElevationBlurSemanticToken { Self.mockThemeElevationBlurRawToken }
override public var elevationBlurRaised: ElevationBlurSemanticToken { Self.mockThemeElevationBlurRawToken }
override public var elevationBlurDrag: ElevationBlurSemanticToken { Self.mockThemeElevationBlurRawToken }
override public var elevationBlurStickyDefault: ElevationBlurSemanticToken { Self.mockThemeElevationBlurRawToken }
override public var elevationBlurStickyEmphasized: ElevationBlurSemanticToken { Self.mockThemeElevationBlurRawToken }
override public var elevationBlurStickyNavigationScrolled: ElevationBlurSemanticToken { Self.mockThemeElevationBlurRawToken }

// MARK: Semantic token - Elevation - Color (Multiples)

override public var elevationColorDefault: MultipleColorSemanticTokens { Self.mockThemeElevationMultipleColorSemanticToken }
override public var elevationColorNone: MultipleColorSemanticTokens { Self.mockThemeElevationMultipleColorSemanticToken }
override public var elevationColorRaised: MultipleColorSemanticTokens { Self.mockThemeElevationMultipleColorSemanticToken }
override public var elevationColorDrag: MultipleColorSemanticTokens { Self.mockThemeElevationMultipleColorSemanticToken }
override public var elevationColorEmphasized: MultipleColorSemanticTokens { Self.mockThemeElevationMultipleColorSemanticToken }
override public var elevationColorStickyDefault: MultipleColorSemanticTokens { Self.mockThemeElevationMultipleColorSemanticToken }
override public var elevationColorStickyEmphasized: MultipleColorSemanticTokens { Self.mockThemeElevationMultipleColorSemanticToken }
override public var elevationColorStickyNavigationScrolled: MultipleColorSemanticTokens { Self.mockThemeElevationMultipleColorSemanticToken }

// MARK: Semantic token - Elevation - Color (semantic tokens)

override public var elevationColorDefaultLight: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorDefaultDark: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorNoneLight: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorNoneDark: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorRaisedLight: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorRaisedDark: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorDragLight: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorDragDark: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorEmphasizedLight: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorEmphasizedDark: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorStickyDefaultLight: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorStickyDefaultDark: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorStickyEmphasizedLight: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorStickyEmphasizedDark: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorStickyNavigationScrolledLight: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
override public var elevationColorStickyNavigationScrolledDark: ElevationColorSemanticToken { Self.mockThemeElevationColorRawToken }
}

// swiftlint:enable required_deinit
// swiftlint:enable identifier_name
// swiftlint:enable line_length
Loading

0 comments on commit 6d946a8

Please sign in to comment.