Skip to content

Commit

Permalink
refactor(review): rename wrapper to provider for tokens of sizes (#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 17, 2024
1 parent c2ece11 commit 1ba6494
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import OUDSTokensSemantic
// Create an issue for update https://github.com/Orange-OpenSource/ouds-ios/issues/new?template=token_update.yml

/// Defines wrapper objects for size semantic tokens (i.e. in the end `DimensionRawTokens`).
/// These values can be overriden inside ``OUDSSizeSemanticTokensWrapper`` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
extension OUDSSizeSemanticTokensWrapper: SizeMultipleSemanticTokens {
/// These values can be overriden inside ``OUDSSizeSemanticTokensProvider`` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
extension OUDSSizeSemanticTokensProvider: SizeMultipleSemanticTokens {

// MARK: - Semantic token - Sizing - Icon with typography

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 OUDSSizeSemanticTokensWrapper: SizeSemanticTokens {
extension OUDSSizeSemanticTokensProvider: SizeSemanticTokens {
@objc open var sizeIconDecorative2xl: SizeSemanticToken { DimensionRawTokens.dimension900 }
@objc open var sizeIconDecorative2xs: SizeSemanticToken { DimensionRawTokens.dimension200 }
@objc open var sizeIconDecorativeLg: SizeSemanticToken { DimensionRawTokens.dimension600 }
Expand Down
4 changes: 2 additions & 2 deletions OUDS/Core/OUDS/Sources/OUDSTheme/OUDSTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ open class OUDSTheme: @unchecked Sendable {
/// - fonts: An object providing all the font semantic tokens, by default `OUDSFontSemanticTokensProvider`
/// - grids: An object providing all the grid semantic tokens, by default `OUDSGridSemanticTokensProvider`
/// - opacities: An object providing all the opacity semantic tokens, by default `OUDSOpacitySemanticTokensProvider`
/// - sizes: An object providing all the size semantic tokens, by default `OUDSSizeSemanticTokensWrapper`
/// - sizes: An object providing all the size semantic tokens, by default `OUDSSizeSemanticTokensProvider`
/// - spaces: An object providing all the space semantic tokens, by default `OUDSSpaceSemanticTokensWrapper`
public init(colors: AllColorSemanticTokens = OUDSColorSemanticTokensProvider(),
borders: AllBorderSemanticTokens = OUDSBorderSemanticTokensProvider(),
elevations: AllElevationSemanticTokens = OUDSElevationSemanticTokensProvider(),
fonts: AllFontSemanticTokens = OUDSFontSemanticTokensProvider(),
grids: AllGridSemanticTokens = OUDSGridSemanticTokensProvider(),
opacities: AllOpacitySemanticTokens = OUDSOpacitySemanticTokensProvider(),
sizes: AllSizeSemanticTokens = OUDSSizeSemanticTokensWrapper(),
sizes: AllSizeSemanticTokens = OUDSSizeSemanticTokensProvider(),
spaces: AllSpaceSemanticTokens = OUDSSpaceSemanticTokensWrapper()) {
self.colors = colors
self.borders = borders
Expand Down
4 changes: 2 additions & 2 deletions OUDS/Core/OUDS/Sources/_OUDS.docc/Themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ You may want to define your own theme, thus you can override the `OrangeTheme` w

You will have to override the tokens wrapper you need. To do that, make a subclass of the wrapper you target:
- spaces tokens are `OUDSSpaceSemanticTokensWrapper`
- sizes tokens are in `OUDSSizeSemanticTokensWrapper`
- sizes tokens are in `OUDSSizeSemanticTokensProvider`
- colors tokens are all defined in `OrangeThemeColorSemanticTokensWrapper`
- borders tokens are in `OUDSBorderSemanticTokensProvider`
- elevations tokens are in `OUDSElevationSemanticTokensProvider`
Expand All @@ -82,7 +82,7 @@ class YourAppThemeSpaceTokensWrapper: OUDSSpaceSemanticTokensWrapper {

// Token wrapper for sizes

class YourAppThemeSizeTokensWrapper: OUDSSizeSemanticTokensWrapper {
class YourAppThemeSizeTokensWrapper: OUDSSizeSemanticTokensProvider {
override var sizeIconDecorative2xl: SizeSemanticToken {
DimensionRawTokens.dimension300
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import OUDSTokensSemantic

// swiftlint:disable required_deinit

/// Overrides **all** the size semantic tokens (from its super class, i.e. `OUDSSizeSemanticTokensWrapper` so as to test overriding of them (unit tests)
/// Overrides **all** the size semantic tokens (from its super class, i.e. `OUDSSizeSemanticTokensProvider` so as to test overriding of them (unit tests)
/// and to act like smoke tests with crashing tests if some tokens disappeared.
final class MockThemeSizeSemanticTokensWrapper: OUDSSizeSemanticTokensWrapper {
final class MockThemeSizeSemanticTokensWrapper: OUDSSizeSemanticTokensProvider {

static let mockThemeSizeRawToken: DimensionRawToken = 118_000
static let mockThemeSizeCompositeToken = MultipleSizeSemanticTokens(compact: 1, regular: 151)
Expand Down
4 changes: 2 additions & 2 deletions OUDS/Core/Themes/Orange/Sources/OrangeTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ open class OrangeTheme: OUDSTheme, @unchecked Sendable {
/// - fonts: An object providing all the font semantic tokens, by default `AllFontemanticTokens`, default set to `OUDSFontSemanticTokensProvider`
/// - grids: An object providing all the grid semantic tokens, by default `AllGridSemanticTokens`, default set to `OUDSGridSemanticTokensProvider`
/// - opacities: An object providing all the opacity semantic tokens, as `OpacitySemanticTokens` implementation, default set to `OUDSOpacitySemanticTokensProvider`
/// - sizes: An object providing all the size semantic tokens, as `AllSizeSemanticTokens` implementation, default set to `OUDSSizeSemanticTokensWrapper`
/// - sizes: An object providing all the size semantic tokens, as `AllSizeSemanticTokens` implementation, default set to `OUDSSizeSemanticTokensProvider`
/// - spaces: An object providing all the space semantic tokens, as `AllSpaceSemanticTokens` implementation, default set to `OUDSSpaceSemanticTokensWrapper`
override public init(colors: AllColorSemanticTokens = OrangeThemeColorSemanticTokensWrapper(),
borders: AllBorderSemanticTokens = OUDSBorderSemanticTokensProvider(),
elevations: AllElevationSemanticTokens = OUDSElevationSemanticTokensProvider(),
fonts: AllFontSemanticTokens = OUDSFontSemanticTokensProvider(),
grids: AllGridSemanticTokens = OUDSGridSemanticTokensProvider(),
opacities: AllOpacitySemanticTokens = OUDSOpacitySemanticTokensProvider(),
sizes: AllSizeSemanticTokens = OUDSSizeSemanticTokensWrapper(),
sizes: AllSizeSemanticTokens = OUDSSizeSemanticTokensProvider(),
spaces: AllSpaceSemanticTokens = OUDSSpaceSemanticTokensWrapper()) {
OUDSLogger.debug("Init of OrangeTheme")
super.init(colors: colors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ You may want to define your own theme, thus you can override the ``OrangeTheme``

You will have to override the tokens wrapper you need. To do that, make a subclass of the wrapper you target:
- spaces tokens are `OUDSSpaceSemanticTokensWrapper`
- sizes tokens are in `OUDSSizeSemanticTokensWrapper`
- sizes tokens are in `OUDSSizeSemanticTokensProvider`
- colors tokens are all defined in `OrangeThemeColorSemanticTokensWrapper`
- borders tokens are in `OUDSBorderSemanticTokensProvider`
- elevations tokens are in `OUDSElevationSemanticTokensProvider`
Expand All @@ -91,7 +91,7 @@ class YourAppThemeSpaceTokensWrapper: OUDSSpaceSemanticTokensWrapper {

// Token wrapper for sizes

class YourAppThemeSizeTokensWrapper: OUDSSizeSemanticTokensWrapper {
class YourAppThemeSizeTokensWrapper: OUDSSizeSemanticTokensProvider {
override var sizeIconDecorative2xl: SizeSemanticToken {
DimensionRawTokens.dimension300
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import OUDSFoundations
///
/// ```swift
/// // Define your own wrapper for size semantic tokens
/// class CustomSizeTokensWrapper: OUDSSizeSemanticTokensWrapper {
/// class CustomSizeTokensWrapper: OUDSSizeSemanticTokensProvider {
///
/// // Then override the size semantic tokens you want, using the dimension raw tokens available
///
Expand Down Expand Up @@ -49,11 +49,11 @@ import OUDSFoundations
/// ```swift
/// OrangeTheme(sizes: CustomSizeTokensWrapper())
/// ```
open class OUDSSizeSemanticTokensWrapper {
open class OUDSSizeSemanticTokensProvider {

/// Intializes the wrapper
public init() {
OUDSLogger.debug("Init of OUDSSizeSemanticTokensWrapper")
OUDSLogger.debug("Init of OUDSSizeSemanticTokensProvider")
}

deinit{ }
Expand All @@ -63,5 +63,5 @@ open class OUDSSizeSemanticTokensWrapper {
// the implemention of SizeSemanticTokens and SizeMultipleSemanticTokens are not here
// but in OUDS/OUDSTheme/OUDSTheme+SemanticTokens/OUDSTheme+SizeSemanticTokens.swift
// and in OUDS/OUDSTheme/OUDSTheme+SemanticTokens/OUDSTheme+SizeMultipleSemanticTokens.swift.
// This declaration of OUDSSizeSemanticTokensWrapper is here to allow to write documentation.
// This declaration of OUDSSizeSemanticTokensProvider is here to allow to write documentation.
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public typealias AllFontSemanticTokens = FontSemanticTokens & FontCompositeSeman

/// A type alias which merges ``SizeSemanticTokens`` and ``SizeMultipleSemanticTokens``.
/// It helps in the end to define a wrapper for all the semantic tokens of size, multiple or not, generated or not.
/// For example ``OUDSSizeSemanticTokensWrapper`` matches this type alias.
/// For example ``OUDSSizeSemanticTokensProvider`` matches this type alias.
public typealias AllSizeSemanticTokens = SizeSemanticTokens & SizeMultipleSemanticTokens

/// A type alias which merges ``SpaceSemanticTokens`` and ``SpaceMultipleSemanticTokens``.
Expand Down

0 comments on commit 1ba6494

Please sign in to comment.