Skip to content

Commit

Permalink
refactor: wrapping for semantic tokens of fonts (#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 6d946a8 commit 567893d
Show file tree
Hide file tree
Showing 19 changed files with 592 additions and 552 deletions.
46 changes: 23 additions & 23 deletions OUDS/Core/Components/Sources/Extensions/View+Typography.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import OUDSTokensSemantic
// swiftlint:disable line_length

/// Defines basic values common to all themes for ``FontCompositeSemanticTokens``.
/// These values can be overriden inside ``OUDSTheme`` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
/// These values can be overriden inside ``OUDSFontSemanticTokensWrapper`` 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 composite semantic tokens for typography / fonts and associated composite raw tokens.
/// `OUDSTheme` can be seen as a kind of "abstract class" in _object oriented paradigm_.
extension OUDSTheme: FontCompositeSemanticTokens {
/// 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.
extension OUDSFontSemanticTokensWrapper: FontCompositeSemanticTokens {

// MARK: - Semantic tokens - Typography - Composites - Display

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 typography semantic tokens but "multiple", i.e. tokens with values depending to size classes or color schemes.
/// 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: FontMultipleSemanticTokens {
/// Defines wrapper objects for font semantic tokens but "multiple", i.e. tokens with values depending to size classes or color schemes.
/// These values can be overriden inside `OUDSFontSemanticTokensWrapper` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
extension OUDSFontSemanticTokensWrapper: FontMultipleSemanticTokens {

// MARK: - Semantic token - Typography - Font - Size

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

extension OUDSTheme: FontSemanticTokens {
extension OUDSFontSemanticTokensWrapper: FontSemanticTokens {
@objc open var fontFamily: FontFamilySemanticToken { FontRawTokens.fontFamilySystemSfPro }
@objc open var fontLetterSpacingBodyLargeMobile: FontLetterSpacingSemanticToken { FontRawTokens.fontLetterSpacing250 }
@objc open var fontLetterSpacingBodyLargeTablet: FontLetterSpacingSemanticToken { FontRawTokens.fontLetterSpacing250 }
Expand Down
11 changes: 10 additions & 1 deletion OUDS/Core/OUDS/Sources/OUDSTheme/OUDSTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ open class OUDSTheme: @unchecked Sendable {
/// All elevation semantic tokens exposed in one object
public let elevations: AllElevationSemanticTokens

/// All font semantic tokens exposed in one object
public let fonts: AllFontSemanticTokens

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

Expand All @@ -53,14 +56,17 @@ open class OUDSTheme: @unchecked Sendable {
/// - opacities: An object providing all the opacity semantic tokens, by default `OUDSOpacitySemanticTokensWrapper`
/// - colors: An object providing all the color semantic tokens, by default `OUDSColorSemanticTokensWrapper`
/// - elevations: An object providing all the elevation semantic tokens, by default `OUDSElevationSemanticTokensWrapper`
/// - fonts: An object providing all the font semantic tokens, by default `OUDSFontSemanticTokensWrapper`
public init(borders: AllBorderSemanticTokens = OUDSBorderSemanticTokensWrapper(),
opacities: AllOpacitySemanticTokens = OUDSOpacitySemanticTokensWrapper(),
colors: AllColorSemanticTokens = OUDSColorSemanticTokensWrapper(),
elevations: AllElevationSemanticTokens = OUDSElevationSemanticTokensWrapper()) {
elevations: AllElevationSemanticTokens = OUDSElevationSemanticTokensWrapper(),
fonts: AllFontSemanticTokens = OUDSFontSemanticTokensWrapper()) {
self.borders = borders
self.opacities = opacities
self.colors = colors
self.elevations = elevations
self.fonts = fonts
customFontFamily = nil
}

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

Expand Down
Loading

0 comments on commit 567893d

Please sign in to comment.