Skip to content

Commit

Permalink
feat: add skeleton component tokens (#388) (#389)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp authored Jan 10, 2025
1 parent b945e46 commit 77bfc8e
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [Library] Skeleton component tokens ([#388](https://github.com/Orange-OpenSource/ouds-ios/issues/388))
- [Library] Select component tokens ([#386](https://github.com/Orange-OpenSource/ouds-ios/issues/386))
- [Library] Link component tokens ([#384](https://github.com/Orange-OpenSource/ouds-ios/issues/384))

Expand Down
14 changes: 10 additions & 4 deletions OUDS/Core/OUDS/Sources/OUDSTheme/OUDSTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ open class OUDSTheme: @unchecked Sendable {
/// All components tokens related to select components like `OUDSSelect`
public let select: AllSelectComponentTokensProvider

/// All components tokens related to skeleotn components like `OUDSSkeleton`
public let skeleton: AllSkeletonComponentTokensProvider

// MARK: - Initializers

/// Defines a basic kind of abstract theme to subclass then.
Expand All @@ -86,9 +89,10 @@ open class OUDSTheme: @unchecked Sendable {
/// - opacities: An object providing all the opacity semantic tokens, as `AllOpacitySemanticTokensProvider` implementation
/// - sizes: An object providing all the size semantic tokens, as `AllSizeSemanticTokens` implementation
/// - spaces: An object providing all the space semantic tokens, as `AllSpaceSemanticTokensProvider` implementation
/// - button: An object providing all the component tokens for buttons
/// - link: An object providing all the component tokens for links
/// - select: An object providing all the component tokens for select
/// - button: An object providing all the component tokens for button component
/// - link: An object providing all the component tokens for links component
/// - select: An object providing all the component tokens for select component
/// - skeleton: An object providing all the component tokens for skeleton component
public init(colors: AllColorSemanticTokensProvider,
borders: AllBorderSemanticTokensProvider,
elevations: AllElevationSemanticTokensProvider,
Expand All @@ -100,7 +104,8 @@ open class OUDSTheme: @unchecked Sendable {
spaces: AllSpaceSemanticTokensProvider,
button: AllButtonComponentTokensProvider,
link: AllLinkComponentTokensProvider,
select: AllSelectComponentTokensProvider) {
select: AllSelectComponentTokensProvider,
skeleton: AllSkeletonComponentTokensProvider) {
self.colors = colors
self.borders = borders
self.elevations = elevations
Expand All @@ -113,6 +118,7 @@ open class OUDSTheme: @unchecked Sendable {
self.button = button
self.link = link
self.select = select
self.skeleton = skeleton
}

deinit { }
Expand Down
9 changes: 6 additions & 3 deletions OUDS/Core/Themes/Orange/Sources/OrangeTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ open class OrangeTheme: OUDSTheme, @unchecked Sendable {
spaces: AllSpaceSemanticTokensProvider = OrangeThemeSpaceSemanticTokensProvider(),
button: AllButtonComponentTokensProvider,
link: AllLinkComponentTokensProvider,
select: AllSelectComponentTokensProvider) {
select: AllSelectComponentTokensProvider,
skeleton: AllSkeletonComponentTokensProvider) {
OUDSLogger.debug("Init of OrangeTheme")
super.init(colors: colors,
borders: borders,
Expand All @@ -91,7 +92,8 @@ open class OrangeTheme: OUDSTheme, @unchecked Sendable {
spaces: spaces,
button: button,
link: link,
select: select)
select: select,
skeleton: skeleton)
}

/// Initializes the `OrangeTheme` and lets children classes to user their own tokens implementations.
Expand Down Expand Up @@ -127,7 +129,8 @@ open class OrangeTheme: OUDSTheme, @unchecked Sendable {
spaces: spaces,
button: OrangeThemeButtonComponentTokensProvider(sizes: sizes, borders: borders, colors: colors, spaces: spaces),
link: OrangeThemeLinkComponentTokensProvider(sizes: sizes, colors: colors, spaces: spaces),
select: OrangeThemeSelectComponentTokensProvider(sizes: sizes, colors: colors, spaces: spaces))
select: OrangeThemeSelectComponentTokensProvider(sizes: sizes, colors: colors, spaces: spaces),
skeleton: OrangeThemeSkeletonComponentTokensProvider(colors: colors))
}

deinit { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// Software Name: OUDS iOS
// SPDX-FileCopyrightText: Copyright (c) Orange SA
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
//

import OUDSFoundations
import OUDSTokensSemantic

// swiftlint:disable type_name

/// A class which wraps all **component tokens of skeleton** for skeleton objects like `OUDSSkeleton`.
/// Contains also references to semantic tokens providers so as to be able to use them to define the component tokens.
/// This provider should be integrated as a `AllSkeletonComponentTokensProvider` implementation inside `OUDSTheme` so as to provide
/// all tokens to the users. It helps users to override some of the tokens and assign them to an `OUDSTheme` implementation to use.
/// Custom themes can use subclass of ``OrangeThemeSkeletonComponentTokensProvider`` and apply the provider they need.
/// It implements also the protocol `SkeletonComponentTokens` so as to expose the component tokens for links through any `OUDSTheme`.
/// Skeleton components tokens are defined with semantic tokens of colors (from `AllColorSemanticTokensProvider`).
///
/// ```swift
/// // Define your own provider for skeleton component tokens
/// // by inheriting from existing provider
/// class CustomSkeletonComponentTokensProvider: OrangeThemeSkeletonComponentTokensProvider {
///
/// // Then override the skeleton component tokens you want.
///
/// override var skeletonColorGradientMiddle: MultipleColorSemanticTokens { colors.colorRepositoryOpacityBlackHigher }
///
/// // ...
/// }
///
/// // Or define your own provider from scratch
/// class CustomSkeletonComponentTokensProvider: SkeletonComponentTokens {
///
/// // And implement maybe hundreds of tokens.
/// // You are allowed to use semantic tokens providers if you want to define values.
/// }
/// ```
///
/// Then, you can give this `CustomSkeletonComponentTokensProvider` to your own theme implementation:
///
/// ```swift
/// class LocalTheme: OrangeTheme {
///
/// override init() {
/// super.init(skeleton: CustomSkeletonComponentTokensProvider())
/// }
/// }
/// ```
///
/// or to an already existing theme for example:
///
/// ```swift
/// OrangeTheme(skeleton: CustomSkeletonComponentTokensProvider())
/// ```
///
/// - Since: 0.9.0
open class OrangeThemeSkeletonComponentTokensProvider {

/// Provider of color semantic tokens to use for link colors
public let colors: AllColorSemanticTokensProvider

/// Defines a provider of component tokens dedicated to `OUDSSkeleton`
/// - Parameter colors: Provider for color semantic tokens
public init(colors: AllColorSemanticTokensProvider) {
OUDSLogger.debug("Init of OrangeThemeSkeletonComponentTokensProvider")
self.colors = colors
}

deinit { }

// ଘ( ・ω・)_/゚・:*:・。☆
// Note: So as to help the integration of generated code produced by the tokenator
// the implemention of SkeletonComponentTokens is not here but in Core/Themes/Orange/Values/ComponentTokens/OrangeTheme+SkeletonComponentTokens.swift
// This declaration of OrangeThemeSkeletonComponentTokensProvider is here also to allow to write documentation.
}

// swiftlint:enable type_name
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Software Name: OUDS iOS
// SPDX-FileCopyrightText: Copyright (c) Orange SA
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
//

import Foundation
import OUDSTokensComponent
import OUDSTokensSemantic

extension OrangeThemeSkeletonComponentTokensProvider: SkeletonComponentTokens {
@objc open var skeletonColorBg: MultipleColorSemanticTokens { colors.colorOpacityLowest }
@objc open var skeletonColorGradientMiddle: MultipleColorSemanticTokens { colors.colorOpacityLower }
@objc open var skeletonColorGradientStartEnd: MultipleColorSemanticTokens { colors.colorOpacityTransparent }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Software Name: OUDS iOS
// SPDX-FileCopyrightText: Copyright (c) Orange SA
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
//

import Foundation
import OUDSThemesOrange
import OUDSTokensComponent
import OUDSTokensRaw
import OUDSTokensSemantic

// swiftlint:disable required_deinit

final class MockThemeSkeletonComponentTokenProvider: OrangeThemeSkeletonComponentTokensProvider {

// MARK: - Mocks and setup

static let mockThemeSkeletonColor = MultipleColorSemanticTokens("#00FF00")

override public init(colors: AllColorSemanticTokensProvider) {
super.init(colors: colors)
}

// MARK: - Skeleton component tokens

override public var skeletonColorBg: MultipleColorSemanticTokens { Self.mockThemeSkeletonColor }
override public var skeletonColorGradientMiddle: MultipleColorSemanticTokens { Self.mockThemeSkeletonColor }
override public var skeletonColorGradientStartEnd: MultipleColorSemanticTokens { Self.mockThemeSkeletonColor }
}

// swiftlint:enable required_deinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Software Name: OUDS iOS
// SPDX-FileCopyrightText: Copyright (c) Orange SA
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
//

import OUDS
import OUDSThemesOrange
import XCTest

// swiftlint:disable required_deinit
// swiftlint:disable implicitly_unwrapped_optional
// swiftlint:disable type_name

final class TestThemeOverrideOfSkeletonComponentTokens: XCTestCase {

private var abstractTheme: OUDSTheme!
private var inheritedTheme: OUDSTheme!

override func setUp() async throws {
abstractTheme = OrangeTheme()
inheritedTheme = MockTheme()
}

func testInheritedThemeCanOverrideSkeletonComponentTokenColorBg() throws {
XCTAssertNotEqual(inheritedTheme.skeleton.skeletonColorBg, abstractTheme.skeleton.skeletonColorBg)
XCTAssertTrue(inheritedTheme.skeleton.skeletonColorBg == MockThemeSkeletonComponentTokenProvider.mockThemeSkeletonColor)
}

func testInheritedThemeCanOverrideSkeletonComponentTokenColorGradientMiddle() throws {
XCTAssertNotEqual(inheritedTheme.skeleton.skeletonColorGradientMiddle, abstractTheme.skeleton.skeletonColorGradientMiddle)
XCTAssertTrue(inheritedTheme.skeleton.skeletonColorGradientMiddle == MockThemeSkeletonComponentTokenProvider.mockThemeSkeletonColor)
}

func testInheritedThemeCanOverrideSkeletonComponentTokenColorGradientStartEnd() throws {
XCTAssertNotEqual(inheritedTheme.skeleton.skeletonColorGradientStartEnd, abstractTheme.skeleton.skeletonColorGradientStartEnd)
XCTAssertTrue(inheritedTheme.skeleton.skeletonColorGradientStartEnd == MockThemeSkeletonComponentTokenProvider.mockThemeSkeletonColor)
}
}

// swiftlint:enable required_deinit
// swiftlint:enable implicitly_unwrapped_optional
// swiftlint:enable type_name
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ final class MockTheme: OUDSTheme, @unchecked Sendable {
spaces: spaces,
button: MockThemeButtonComponentTokenProvider(sizes: sizes, borders: borders, colors: colors, spaces: spaces),
link: MockThemeLinkComponentTokenProvider(sizes: sizes, colors: colors, spaces: spaces),
select: MockThemeSelectComponentTokenProvider(sizes: sizes, colors: colors, spaces: spaces))
select: MockThemeSelectComponentTokenProvider(sizes: sizes, colors: colors, spaces: spaces),
skeleton: MockThemeSkeletonComponentTokenProvider(colors: colors))
}

deinit { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ public typealias AllLinkComponentTokensProvider = LinkComponentTokens
/// merging several protocols.
/// For example `OrangeThemeSelectComponentTokensProvider` matches this type alias.
public typealias AllSelectComponentTokensProvider = SelectComponentTokens

/// A type alias only for ``SkeletonComponentTokens`` so as to keep consistency with other type aliases
/// merging several protocols.
/// For example `OrangeThemeSkeletonComponentTokensProvider` matches this type alias.
public typealias AllSkeletonComponentTokensProvider = SkeletonComponentTokens
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Software Name: OUDS iOS
// SPDX-FileCopyrightText: Copyright (c) Orange SA
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
//

import OUDSTokensSemantic

// [File not generated by the tokenator]
// WARNING: Not synchronized anymore with the Figjam / Figma by developers team
// Create an issue for update https://github.com/Orange-OpenSource/ouds-ios/issues/new?template=token_update.yml

// swiftlint:disable missing_docs

/// Declares all component tokens for links components like `OUDSSkeleton`
/// Use for tokens providers like `OrangeThemeSkeletonComponentTokensProvider`.
///
/// - Since: 0.10.0
public protocol SkeletonComponentTokens {

// MARK: - Color

var skeletonColorBg: MultipleColorSemanticTokens { get }
var skeletonColorGradientMiddle: MultipleColorSemanticTokens { get }
var skeletonColorGradientStartEnd: MultipleColorSemanticTokens { get }
}

// swiftlint:enable missing_docs
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ struct Showcase: App {
- ``ButtonComponentTokens``
- ``LinkComponentTokens``
- ``SelectComponentTokens``
- ``SkeletonComponentTokens``

0 comments on commit 77bfc8e

Please sign in to comment.