vds_ios/VDS/Typography/Typography+Enums.swift
Matt Bruce dffede1350 refactored Typography into new files
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-07-21 10:44:24 -05:00

93 lines
2.9 KiB
Swift

//
// 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 {
public enum FontSize: String, CaseIterable {
case xxlarge = "2XLarge"
case xlarge = "XLarge"
case large = "Large"
case medium = "Medium"
case small = "Small"
case xsmall = "XSmall"
}
}
public enum TextPosition: String, CaseIterable {
case left, right, center
var textAlignment: NSTextAlignment {
switch self {
case .left:
return NSTextAlignment.left
case .right:
return NSTextAlignment.right
case .center:
return NSTextAlignment.center
}
}
}