Skip to content

Commit

Permalink
refactor: move composite tokens in dedicated files to help parser (#129
Browse files Browse the repository at this point in the history
…) (#131)

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp authored Sep 25, 2024
1 parent b0237e4 commit 7624a2c
Show file tree
Hide file tree
Showing 56 changed files with 1,004 additions and 969 deletions.
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [Library] Unit tests for composite tokens
- [Library] Unit tests for multiple tokens
- [Library] Add color semantic composite tokens embeding light and dark modes values
- [Library] Add spacing semantic tokens huge and jumbo
- [Library] Add spacing semantic tokens "huge" and "jumbo"
- [Library] Add closed "sys" dimension semantic tokens
- [Tool] GitHub issue template for tokens update request
- [Library] Add more sizing semantic tokens ([#122](https://github.com/Orange-OpenSource/ouds-ios/issues/122))
Expand All @@ -19,10 +19,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- [Library] Rename dimension semantic tokens to apply T-Shirt size rules ([#130](https://github.com/Orange-OpenSource/ouds-ios/issues/130))
- [Library] Rename `SizingCompositeSemanticToken` to `MultipleSizingSemanticToken` to keep "composite" word for *Figma* design system
- [Library] Rename `ColorCompositeSemanticToken` to `MultipleColorRawToken` to keep "composite" word for *Figma* design system
- [Library] Rename `TypographyCompositeSemanticToken` to `MultipleTypographyTokens` to keep "composite" word for *Figma* design system
- [Library] Rename `SpacingCompositeSemanticToken` to `MultipleSpacingTokens` to keep "composite" word for *Figma* design system
- [Library] Rename `SizingCompositeSemanticToken` to `MultipleSizingTokens` to keep "composite" word for *Figma* design system
- [Library] Rename `ColorCompositeSemanticToken` to `MultipleColorTokens` to keep "composite" word for *Figma* design system
- [Library] Elevation colors have been merged into "multiple" objects colors to have less variables and manage color schemes
- [Library] Update color semantic tokens to better manage light and dark modes values
- [Library] Update elevation colors focus light and dark
- [Library] Rename space padding inline component tokens by removing "component" word
- [Library] Improve documentation about raw and semantic tokens definitions ([#127](https://github.com/Orange-OpenSource/ouds-ios/issues/127))
- [Library] Improve documentation about raw tokens definitions
- [Library] Move composite tokens elsewhere to help parser ([#129](https://github.com/Orange-OpenSource/ouds-ios/issues/129))
- [Library] Improve documentation about raw and semantic tokens definitions ([#127](https://github.com/Orange-OpenSource/ouds-ios/issues/127))
- [Library] Rename some sizing semantic tokens ([#122](https://github.com/Orange-OpenSource/ouds-ios/issues/122))
- [Library] Replace "adaptable" word by "scaled" in space semantic tokens, "fix" by "fixed" and remove "layout" ([#117](https://github.com/Orange-OpenSource/ouds-ios/issues/117))

Expand All @@ -31,6 +41,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Library] Remove some base multiplier factor from raw tokens
- [Library] Remove raw tokens `elevationZIndex` ([#119](https://github.com/Orange-OpenSource/ouds-ios/issues/119))

### Fixed

- [Library] Blur values for elevation composite raw tokens

## [0.2.0](https://github.com/Orange-OpenSource/ouds-ios/compare/0.1.0...0.2.0) - 2024-09-19

### Added
Expand Down
4 changes: 2 additions & 2 deletions OUDS/Core/Components/Sources/Extensions/View+Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ extension View {
/// - familyName: The font family name to load later (e.g. "Luciole")
/// - token: The typography token to use to get useful values for `compact` or `regular` mode
/// - Returns: The `View` with the custom font applied
func customFont(familyName: String, typography token: TypographyCompositeSemanticToken) -> some View {
func customFont(familyName: String, typography token: MultipleTypographyTokens) -> some View {
self.modifier(CustomFontModifier(token: token, fontFamilyName: familyName))
}

/// Applies a `FontModifier` to use the system font on the current `View` with a specific token
/// - Parameter token: The typography token to use to get useful values for `compact` or `regular` mode
/// - Returns: The `View` with the custom font applied
func systemFont(typography token: TypographyCompositeSemanticToken) -> some View {
func systemFont(typography token: MultipleTypographyTokens) -> some View {
self.modifier(FontModifier(token: token))
}
}
9 changes: 5 additions & 4 deletions OUDS/Core/Components/Sources/Extensions/View+Shadows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ extension View {
/// - Parameter elevation: The token to give for the shadow / elevation effect
/// - Returns `View`: The current `View` with the shadow / elevation effect
public func shadow(elevation: ElevationCompositeSemanticToken) -> some View {
// TODO: Manage light and dark color scheme
return self
.shadow(color: elevation.color.color,
radius: elevation.radius,
x: CGFloat(elevation.x),
y: CGFloat(elevation.y))
.shadow(color: elevation.light.color.color,
radius: elevation.light.radius,
x: CGFloat(elevation.light.x),
y: CGFloat(elevation.light.y))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct CustomFontModifier: ViewModifier {
// MARK: - Properties

/// The typography style to apply
let token: TypographyCompositeSemanticToken
let token: MultipleTypographyTokens

/// The name of the custom font family, should be registered previously in the app, like "Luciole".
let fontFamilyName: String
Expand Down
4 changes: 2 additions & 2 deletions OUDS/Core/Components/Sources/ViewModifiers/FontModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import Foundation
import OUDSTokensSemantic
import SwiftUI

/// A `ViewModifier` which will apply the system `Font` in a component `View` using a `TypographyCompositeSemanticToken`
/// A `ViewModifier` which will apply the system `Font` in a component `View` using a `MultipleTypographyTokens`
/// Note that `FontModifier` use default system font but nothing for others fonts embeded in device
struct FontModifier: ViewModifier {

// MARK: - Properties

// TODO: How to manage other fonts on device?

let token: TypographyCompositeSemanticToken
let token: MultipleTypographyTokens

/// The size of the font to apply
private var fontSize: CGFloat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import SwiftUI

// swiftlint:disable line_length
/// A `ViewModifier` which will make possible to get the horizontal and vertical classes as `@Environment` values
/// so as to define the viewport and use finaly the suitable `TypographyCompositeSemanticToken`.
/// so as to define the viewport and use finaly the suitable `MultipleTypographyTokens`.
/// In fact _Swift extension_ does not allow to have such stored properties, and we don't want to use *UIKit* `UIScreen.main.traitCollection` to get values
/// which may be out of date.
/// For more details about layouts, see [the Apple documentation about devices dimensions](https://developer.apple.com/design/human-interface-guidelines/layout#iOS-iPadOS-device-size-classes)
Expand All @@ -29,7 +29,7 @@ struct TypographyModifier: ViewModifier {
/// The name of a possible custom font family, or `nil` if the font is use is _system font_
let customFontFamily: TypographyFontFamilyRawToken?
/// The typography to apply for *compact* or *regular* modes
let typography: TypographyCompositeSemanticToken
let typography: MultipleTypographyTokens

/// To get programatically and on the fly the horizontal layout size
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
Expand Down Expand Up @@ -63,7 +63,7 @@ struct TypographyModifier: ViewModifier {
}

/// Applies to the `Content` the *adaptive font* (i.e. *font family*, *font weight*, *font size* and the *line height*
/// depending to the current `TypographyCompositeSemanticToken`
/// depending to the current `MultipleTypographyTokens`
func body(content: Content) -> some View {
content
.font(adaptiveFont())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public static let elevationBottom_3_500 = ElevationCompositeRawToken(x: 0, y: 4,

Your application identity can be strongly based on the *typography* you use, i.e. the font family you choose and other configuration details like the font size or the font weight.

With OUDS, typography depends to the class size, i.e. wether or not the application is in _compact mode_ or in _regular mode_, and is defined with a [`TypographyCompositeSemanticToken`](https://ios.unified-design-system.orange.com/documentation/oudstokenssemantic/typographycompositesemantictoken). defined in the [`OUDSTkensSemantic` `TypographySemanticTokens`](https://ios.unified-design-system.orange.com/documentation/oudstokenssemantic/typographysemantictokens/).
With OUDS, typography depends to the class size, i.e. wether or not the application is in _compact mode_ or in _regular mode_, and is defined with a [`MultipleTypographyTokens`](https://ios.unified-design-system.orange.com/documentation/oudstokenssemantic/multipletypographytokens). defined in the [`OUDSTkensSemantic` `TypographySemanticTokens`](https://ios.unified-design-system.orange.com/documentation/oudstokenssemantic/typographysemantictokens/).

The _theme_ contains lots of `TypographyCompositeSemanticToken` listing all the combinations of typography you can apply, and these *composite semantic tokens* use *composite raw tokens*. For example:
The _theme_ contains lots of `MultipleTypographyTokens` listing all the combinations of typography you can apply, and these *composite semantic tokens* use *composite raw tokens*. For example:

```swift
// Here is a definition of a semantic token inside the theme for typography "typeDisplayMedium":
@objc open var typeDisplayMedium: TypographyCompositeSemanticToken {
TypographyCompositeSemanticToken(compact: TypographyRawTokens.typeBold750, regular: TypographyRawTokens.typeBold1050)
@objc open var typeDisplayMedium: MultipleTypographyTokens {
MultipleTypographyTokens(compact: TypographyRawTokens.typeBold750, regular: TypographyRawTokens.typeBold1050)
}

// And here are the raw tokebs definitions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ extension OUDSTheme: ButtonsComponentTokens {
@objc open var buttonWidth: SizingSemanticToken { DimensionRawTokens.dimension3000 }
@objc open var buttonHeight: SizingSemanticToken { DimensionRawTokens.dimension1000 }

@objc open var buttonTypography: TypographyCompositeSemanticToken { typeDisplayMedium }
@objc open var buttonTypography: MultipleTypographyTokens { typeDisplayMedium }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import OUDSTokensRaw
import OUDSTokensSemantic
import OUDSTokensComponent

// swiftlint:disable line_length

/// Defines for `FormsTextInputComponentTokens` the basic configuration which can be overriden in subthemes / subclasses of this theme.
/// **Warning: These are random and dumb values**
extension OUDSTheme: FormsTextInputComponentTokens {
Expand All @@ -26,7 +24,7 @@ extension OUDSTheme: FormsTextInputComponentTokens {

@objc open var ftiTitleFontWeight: TypographyFontWeightSemanticToken { fontWeightHeading }
@objc open var ftiTitleFontSize: TypographyFontSizeSemanticToken { fontSizeLabelLarge }
@objc open var ftiTitleColor: ColorSemanticToken { ColorCompositeSemanticToken(light: ColorRawTokens.colorFunctionalLightGray80, dark: ColorRawTokens.colorFunctionalDarkGray640) }
@objc open var ftiTitleColor: ColorSemanticToken { MultipleColorTokens(light: ColorRawTokens.colorFunctionalLightGray80, dark: ColorRawTokens.colorFunctionalDarkGray640) }

@objc open var ftiSubtitleFontWeight: TypographyFontWeightSemanticToken { fontWeightDisplay }
@objc open var ftiSubtitleFontSize: TypographyFontSizeSemanticToken { fontSizeLabelMedium }
Expand All @@ -40,5 +38,3 @@ extension OUDSTheme: FormsTextInputComponentTokens {

@objc open var ftiBorderWidth: BorderWidthSemanticToken { borderWidthThin }
}

// swiftlint:enable line_length
Loading

0 comments on commit 7624a2c

Please sign in to comment.