Skip to content

Commit

Permalink
feat(FontWeight): Added brandeable FontWeights
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroruizponce committed Apr 18, 2023
1 parent 5afa182 commit d4280c2
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 195 deletions.
12 changes: 6 additions & 6 deletions MisticaCatalog/Source/FontsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import SwiftUI

struct FontView: View {
let fonts: [(name: String, font: Font)] = [
("text-preset10 bold", .textPreset10()),
("text-preset9 bold", .textPreset9()),
("text-preset8 bold", .textPreset8()),
("text-preset7 bold", .textPreset7()),
("text-preset6 bold", .textPreset6()),
("text-preset5 bold", .textPreset5()),
("text-preset10", .textPreset10()),
("text-preset9", .textPreset9()),
("text-preset8", .textPreset8()),
("text-preset7", .textPreset7()),
("text-preset6", .textPreset6()),
("text-preset5", .textPreset5()),
("text-preset4 medium", .textPreset4(weight: .medium)),
("text-preset4 regular", .textPreset4(weight: .regular)),
("text-preset4 light", .textPreset4(weight: .light)),
Expand Down
2 changes: 1 addition & 1 deletion Sources/Mistica/Components/Cards/DataCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private extension DataCard {

cardBaseView.contentView.headlineTopSpacing = 8

cardBaseView.contentView.titleLabel.font = .cardTitlePreset()
cardBaseView.contentView.titleLabel.font = .textPreset4(weight: .cardTitle)
cardBaseView.contentView.titleLabel.textColor = .textPrimary
cardBaseView.contentView.titleLabel.minHeight = 24
cardBaseView.contentView.titleLabel.numberOfLines = 2
Expand Down
99 changes: 99 additions & 0 deletions Sources/MisticaCommon/Fonts/FontStyle+Weights.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// FontStyle+Weights.swift
//
// Made with ❤️ by Novum
//
// Copyright © Telefonica. All rights reserved.
//

import SwiftUI
import UIKit

public extension FontStyle {
enum TextPreset1Weight: CaseIterable {
case regular, medium

var value: MisticaFontWeightType {
switch self {
case .regular: return .regular
case .medium: return .medium
}
}
}

enum TextPreset2Weight: CaseIterable {
case regular, medium

var value: MisticaFontWeightType {
switch self {
case .regular: return .regular
case .medium: return .medium
}
}
}

enum TextPreset3Weight: CaseIterable {
case light, regular, medium

var value: MisticaFontWeightType {
switch self {
case .light: return .light
case .regular: return .regular
case .medium: return .medium
}
}
}

enum TextPreset4Weight: CaseIterable {
case light, regular, medium, cardTitle

var value: MisticaFontWeightType {
switch self {
case .light: return .light
case .regular: return .regular
case .medium: return .medium
case .cardTitle: return MisticaConfig.currentFontWeights.cardTitlePreset
}
}
}
}

struct MovistarFontWeights: MisticaFontWeights {
public var cardTitlePreset: MisticaFontWeightType = .bold
public var textPreset5: MisticaFontWeightType = .bold
public var textPreset6: MisticaFontWeightType = .bold
public var textPreset7: MisticaFontWeightType = .bold
public var textPreset8: MisticaFontWeightType = .bold
public var textPreset9: MisticaFontWeightType = .bold
public var textPreset10: MisticaFontWeightType = .bold
}

struct O2FontWeights: MisticaFontWeights {
public var cardTitlePreset: MisticaFontWeightType = .regular
public var textPreset5: MisticaFontWeightType = .light
public var textPreset6: MisticaFontWeightType = .light
public var textPreset7: MisticaFontWeightType = .light
public var textPreset8: MisticaFontWeightType = .light
public var textPreset9: MisticaFontWeightType = .light
public var textPreset10: MisticaFontWeightType = .light
}

struct BlauFontWeights: MisticaFontWeights {
public var cardTitlePreset: MisticaFontWeightType = .regular
public var textPreset5: MisticaFontWeightType = .light
public var textPreset6: MisticaFontWeightType = .light
public var textPreset7: MisticaFontWeightType = .light
public var textPreset8: MisticaFontWeightType = .light
public var textPreset9: MisticaFontWeightType = .light
public var textPreset10: MisticaFontWeightType = .light
}

struct VivoFontWeights: MisticaFontWeights {
public var cardTitlePreset: MisticaFontWeightType = .regular
public var textPreset5: MisticaFontWeightType = .light
public var textPreset6: MisticaFontWeightType = .light
public var textPreset7: MisticaFontWeightType = .light
public var textPreset8: MisticaFontWeightType = .light
public var textPreset9: MisticaFontWeightType = .light
public var textPreset10: MisticaFontWeightType = .light
}
11 changes: 2 additions & 9 deletions Sources/MisticaCommon/Fonts/FontStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import UIKit
case textPreset8
case textPreset9
case textPreset10
case cardTitlePreset

func preferredFont(
weight: Font.Weight,
Expand Down Expand Up @@ -76,8 +75,6 @@ import UIKit
return "TextPreset9"
case .textPreset10:
return "TextPreset10"
case .cardTitlePreset:
return "CardTitlePreset"
}
}
}
Expand Down Expand Up @@ -128,8 +125,6 @@ private extension FontStyle {
return 32
case .textPreset10:
return 32
case .cardTitlePreset:
return 18
}
}

Expand All @@ -141,8 +136,7 @@ private extension FontStyle {
return .subheadline
case .textPreset3:
return .body
case .textPreset4,
.cardTitlePreset:
case .textPreset4:
return .headline
case .textPreset5:
return .title3
Expand All @@ -165,8 +159,7 @@ private extension FontStyle {
return .subheadline
case .textPreset3:
return .body
case .textPreset4,
.cardTitlePreset:
case .textPreset4:
return .headline
case .textPreset5:
if #available(iOS 14.0, *) {
Expand Down
24 changes: 10 additions & 14 deletions Sources/MisticaCommon/Fonts/FontToolkit+Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,43 @@ import SwiftUI

public extension Font {
static func textPreset1(weight: FontStyle.TextPreset1Weight, constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.textPreset1.preferredFont(weight: weight.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset1.preferredFont(weight: weight.value.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset2(weight: FontStyle.TextPreset2Weight, constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.textPreset2.preferredFont(weight: weight.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset2.preferredFont(weight: weight.value.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset3(weight: FontStyle.TextPreset3Weight, constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.textPreset3.preferredFont(weight: weight.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset3.preferredFont(weight: weight.value.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset4(weight: FontStyle.TextPreset4Weight, constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.textPreset4.preferredFont(weight: weight.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset4.preferredFont(weight: weight.value.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset5(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.textPreset5.preferredFont(weight: FontStyle.TextPreset5Weight.default.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset5.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset5.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset6(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.textPreset6.preferredFont(weight: FontStyle.TextPreset6Weight.default.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset6.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset6.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset7(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.textPreset7.preferredFont(weight: FontStyle.TextPreset7Weight.default.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset7.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset7.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset8(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.textPreset8.preferredFont(weight: FontStyle.TextPreset8Weight.default.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset8.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset8.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset9(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.textPreset9.preferredFont(weight: FontStyle.TextPreset9Weight.default.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset9.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset9.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset10(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.textPreset10.preferredFont(weight: FontStyle.TextPreset10Weight.default.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func cardTitlePreset(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> Font {
FontStyle.cardTitlePreset.preferredFont(weight: FontStyle.CardTitlePresetWeight.default.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset10.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset10.systemWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func preferredFont(for fontStyle: FontStyle, weight: Font.Weight, constrainedToPreferredSize constrainedPreferredSize: UIContentSizeCategory) -> Font {
Expand Down
24 changes: 10 additions & 14 deletions Sources/MisticaCommon/Fonts/FontToolkit+UIFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,43 @@ var _isDynamicTypeEnabled = true

public extension UIFont {
static func textPreset1(weight: FontStyle.TextPreset1Weight, constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.textPreset1.preferredFont(weight: weight.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset1.preferredFont(weight: weight.value.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset2(weight: FontStyle.TextPreset2Weight, constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.textPreset2.preferredFont(weight: weight.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset2.preferredFont(weight: weight.value.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset3(weight: FontStyle.TextPreset3Weight, constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.textPreset3.preferredFont(weight: weight.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset3.preferredFont(weight: weight.value.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset4(weight: FontStyle.TextPreset4Weight, constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.textPreset4.preferredFont(weight: weight.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset4.preferredFont(weight: weight.value.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset5(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.textPreset5.preferredFont(weight: FontStyle.TextPreset5Weight.default.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset5.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset5.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset6(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.textPreset6.preferredFont(weight: FontStyle.TextPreset6Weight.default.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset6.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset6.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset7(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.textPreset7.preferredFont(weight: FontStyle.TextPreset7Weight.default.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset7.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset7.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset8(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.textPreset8.preferredFont(weight: FontStyle.TextPreset8Weight.default.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset8.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset8.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset9(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.textPreset9.preferredFont(weight: FontStyle.TextPreset9Weight.default.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset9.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset9.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func textPreset10(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.textPreset10.preferredFont(weight: FontStyle.TextPreset10Weight.default.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func cardTitlePreset(constrainedToPreferredSize: UIContentSizeCategory? = nil) -> UIFont {
FontStyle.cardTitlePreset.preferredFont(weight: FontStyle.CardTitlePresetWeight.default.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
FontStyle.textPreset10.preferredFont(weight: MisticaConfig.currentFontWeights.textPreset10.systemUIFontWeight, constrainedToPreferredSize: constrainedToPreferredSize)
}

static func preferredFont(for fontStyle: FontStyle, weight: UIFont.Weight, constrainedToPreferredSize constrainedPreferredSize: UIContentSizeCategory) -> UIFont {
Expand Down
Loading

0 comments on commit d4280c2

Please sign in to comment.