diff --git a/VDS/Typography/Typography.swift b/VDS/Typography/Typography.swift index 84c190c1..902eb09e 100644 --- a/VDS/Typography/Typography.swift +++ b/VDS/Typography/Typography.swift @@ -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) } }