added standard style

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-06-29 12:05:42 -05:00
parent 97b6942127
commit 3f6e450739

View File

@ -52,6 +52,10 @@ public struct TextStyle: Equatable, RawRepresentable {
self.lineSpacing = lineSpacing
self.baselineOffset = baselineOffset
}
public var isBold: Bool {
rawValue.hasPrefix("bold")
}
}
extension VDSTypography {
@ -261,9 +265,43 @@ extension TextStyle {
boldMicro
]
}
}
extension TextStyle {
public enum StandardStyle: String, CaseIterable {
case featureXLarge,
featureLarge,
featureMedium,
featureSmall,
featureXSmall,
title2XLarge,
titleXLarge,
titleLarge,
titleMedium,
titleSmall,
bodyLarge,
bodyMedium,
bodySmall,
micro
public var bold: TextStyle {
return TextStyle(rawValue: "bold\(rawValue.prefix(1).uppercased())\(rawValue.dropFirst())")!
}
public var regular: TextStyle {
TextStyle(rawValue: rawValue)!
}
}
public func toStandardStyle() -> StandardStyle {
var rawName = rawValue
if rawName.hasPrefix("bold") {
let updatedRaw = rawName.replacingOccurrences(of: "bold", with: "")
rawName = updatedRaw.prefix(1).lowercased() + updatedRaw.dropFirst()
}
return StandardStyle(rawValue: rawName)!
}
}
//MARK: FontCategory
extension TextStyle {
@ -350,8 +388,8 @@ extension TextStyle {
}
}
extension TextStyle {
public func isWithin(_ collection: [TextStyle]) -> Bool {
extension RawRepresentable where Self.RawValue: Equatable {
public func isWithin(_ collection: [Self]) -> Bool {
(collection.first(where: {$0 == self}) != nil)
}
}