// // Typography+Enums.swift // VDS // // Created by Matt Bruce on 7/21/23. // import Foundation import UIKit //MARK: FontCategory extension TextStyle { /// Used in the Sample App but could be used elsewhere to allow selection of TextStyles public enum FontCategory: String, CaseIterable { case feature case title case body case micro public var sizes: [FontSize] { switch self { case .feature: return [.xlarge, .large, .medium, .small, .xsmall] case .title: return [.xxlarge, .xlarge, .large, .medium, .small] case .body: return [.large, .medium, .small] case .micro: return [] } } /// Find the TextStyle for the FontSize. /// - Parameters: /// - fontSize: FontSize you are looking for using this FontCategory. /// - isBold: Whether or not the Font is bold. /// - Returns: A TextStyle will be returned if all criteria is met, otherwise nil will be returned. public func style(for fontSize: FontSize?, isBold: Bool = false) -> TextStyle? { var styleName = "" if isBold { let newRaw = rawValue.prefix(1).description.uppercased() + rawValue.dropFirst() styleName = "\(isBold ? "bold" : "")\(newRaw)\(fontSize?.rawValue ?? "")" } else { styleName = "\(rawValue)\(fontSize?.rawValue ?? "")" } guard let style = TextStyle.textStyle(for: styleName) else { return nil } return style } } /// Find the TextStyle for the specific FontCategory and FontSize. /// - Parameters: /// - category: FontCategory you are looking for in the TextStyle /// - fontSize: FontSize you are looking for using the given FontCategory. /// - isBold: Whether or not the Font is bold. /// - Returns: A TextStyle will be returned if all criteria is met, otherwise nil will be returned. public func style(for category: FontCategory, with size: FontSize, isBold: Bool) -> TextStyle? { category.style(for: size, isBold: isBold) } } //MARK: FontSize extension TextStyle { /// Enum used to describe the size of font. public enum FontSize: String, CaseIterable { case xxlarge = "2XLarge" case xlarge = "XLarge" case large = "Large" case medium = "Medium" case small = "Small" case xsmall = "XSmall" } } /// Enum used to describe the alignment of text. public enum TextAlignment: String, CaseIterable { case left, right, center public var value: NSTextAlignment { switch self { case .left: return NSTextAlignment.left case .right: return NSTextAlignment.right case .center: return NSTextAlignment.center } } }