diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 8e44489f..0b92f610 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -31,7 +31,6 @@ EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33622B2891E73B0071C351 /* FontProtocol.swift */; }; EA33622E2891EA3C0071C351 /* DispatchQueue+Once.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33622D2891EA3C0071C351 /* DispatchQueue+Once.swift */; }; EA3362302891EB4A0071C351 /* Fonts.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33622F2891EB4A0071C351 /* Fonts.swift */; }; - EA3362322891F2ED0071C351 /* FontStyles.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3362312891F2ED0071C351 /* FontStyles.swift */; }; EA33623E2892EE950071C351 /* UIDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33623D2892EE950071C351 /* UIDevice.swift */; }; EA3362402892EF6C0071C351 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33623F2892EF6B0071C351 /* Label.swift */; }; EA3362432892EFF20071C351 /* LabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3362422892EFF20071C351 /* LabelModel.swift */; }; @@ -55,7 +54,6 @@ EAF7F0A2289AFB3900B287F5 /* Errorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A1289AFB3900B287F5 /* Errorable.swift */; }; EAF7F0A4289B017C00B287F5 /* LabelAttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */; }; EAF7F0A6289B0CE000B287F5 /* Resetable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A5289B0CE000B287F5 /* Resetable.swift */; }; - EAF7F0A8289B119400B287F5 /* Fontable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A7289B119400B287F5 /* Fontable.swift */; }; EAF7F0AB289B13FD00B287F5 /* LabelAttributeFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AA289B13FD00B287F5 /* LabelAttributeFont.swift */; }; EAF7F0AD289B142900B287F5 /* LabelAttributeStrikeThrough.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AC289B142900B287F5 /* LabelAttributeStrikeThrough.swift */; }; EAF7F0AF289B144C00B287F5 /* LabelAttributeUnderline.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AE289B144C00B287F5 /* LabelAttributeUnderline.swift */; }; @@ -65,7 +63,6 @@ EAF7F0B7289C12A600B287F5 /* UITapGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0B6289C12A600B287F5 /* UITapGestureRecognizer.swift */; }; EAF7F0B9289C139800B287F5 /* ColorConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0B8289C139800B287F5 /* ColorConfiguration.swift */; }; EAF7F0BB289D80ED00B287F5 /* Modelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0BA289D80ED00B287F5 /* Modelable.swift */; }; - EAF7F0BD289D81B100B287F5 /* FontStyleable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0BC289D81B100B287F5 /* FontStyleable.swift */; }; EAF7F0F8289DB1AC00B287F5 /* VDSFormControlsTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAF7F0E8289DB0DA00B287F5 /* VDSFormControlsTokens.xcframework */; }; EAF7F0F9289DB1AC00B287F5 /* VDSTypographyTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA3361F32891D5290071C351 /* VDSTypographyTokens.xcframework */; }; EAF7F0FB289DB1AC00B287F5 /* VDSColorTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAF7F0E9289DB0DA00B287F5 /* VDSColorTokens.xcframework */; }; @@ -115,7 +112,6 @@ EA33622B2891E73B0071C351 /* FontProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontProtocol.swift; sourceTree = ""; }; EA33622D2891EA3C0071C351 /* DispatchQueue+Once.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+Once.swift"; sourceTree = ""; }; EA33622F2891EB4A0071C351 /* Fonts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fonts.swift; sourceTree = ""; }; - EA3362312891F2ED0071C351 /* FontStyles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontStyles.swift; sourceTree = ""; }; EA33623D2892EE950071C351 /* UIDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIDevice.swift; sourceTree = ""; }; EA33623F2892EF6B0071C351 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; EA3362422892EFF20071C351 /* LabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelModel.swift; sourceTree = ""; }; @@ -138,7 +134,6 @@ EAF7F0A1289AFB3900B287F5 /* Errorable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errorable.swift; sourceTree = ""; }; EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeModel.swift; sourceTree = ""; }; EAF7F0A5289B0CE000B287F5 /* Resetable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resetable.swift; sourceTree = ""; }; - EAF7F0A7289B119400B287F5 /* Fontable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fontable.swift; sourceTree = ""; }; EAF7F0AA289B13FD00B287F5 /* LabelAttributeFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeFont.swift; sourceTree = ""; }; EAF7F0AC289B142900B287F5 /* LabelAttributeStrikeThrough.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeStrikeThrough.swift; sourceTree = ""; }; EAF7F0AE289B144C00B287F5 /* LabelAttributeUnderline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeUnderline.swift; sourceTree = ""; }; @@ -148,7 +143,6 @@ EAF7F0B6289C12A600B287F5 /* UITapGestureRecognizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITapGestureRecognizer.swift; sourceTree = ""; }; EAF7F0B8289C139800B287F5 /* ColorConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorConfiguration.swift; sourceTree = ""; }; EAF7F0BA289D80ED00B287F5 /* Modelable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modelable.swift; sourceTree = ""; }; - EAF7F0BC289D81B100B287F5 /* FontStyleable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontStyleable.swift; sourceTree = ""; }; EAF7F0E8289DB0DA00B287F5 /* VDSFormControlsTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSFormControlsTokens.xcframework; path = ../SharedFrameworks/VDSFormControlsTokens.xcframework; sourceTree = ""; }; EAF7F0E9289DB0DA00B287F5 /* VDSColorTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSColorTokens.xcframework; path = ../SharedFrameworks/VDSColorTokens.xcframework; sourceTree = ""; }; EAF7F0EA289DB0DA00B287F5 /* VDSAccessibilityTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSAccessibilityTokens.xcframework; path = ../SharedFrameworks/VDSAccessibilityTokens.xcframework; sourceTree = ""; }; @@ -284,8 +278,6 @@ EA3361AC288B26190071C351 /* DataTrackable.swift */, EA3361A9288B25E40071C351 /* Disabling.swift */, EAF7F0A1289AFB3900B287F5 /* Errorable.swift */, - EAF7F0A7289B119400B287F5 /* Fontable.swift */, - EAF7F0BC289D81B100B287F5 /* FontStyleable.swift */, EA3361AE288B26310071C351 /* FormFieldable.swift */, EA33624628931B050071C351 /* Initable.swift */, EA3362442892F9130071C351 /* Labelable.swift */, @@ -323,7 +315,6 @@ isa = PBXGroup; children = ( EA33622F2891EB4A0071C351 /* Fonts.swift */, - EA3362312891F2ED0071C351 /* FontStyles.swift */, EA33622B2891E73B0071C351 /* FontProtocol.swift */, ); path = Fonts; @@ -534,7 +525,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - EA3362322891F2ED0071C351 /* FontStyles.swift in Sources */, EAF7F0B5289C126F00B287F5 /* UILabel.swift in Sources */, EAF7F0A6289B0CE000B287F5 /* Resetable.swift in Sources */, EAB1D29428A3ECF700DAE764 /* SelectorGroupBase.swift in Sources */, @@ -569,7 +559,6 @@ EA3C3B4C2894823E000CA526 /* AnyProxy.swift in Sources */, EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */, EAB1D29A28A5611D00DAE764 /* SelectorGroupModel.swift in Sources */, - EAF7F0A8289B119400B287F5 /* Fontable.swift in Sources */, EAF7F0BB289D80ED00B287F5 /* Modelable.swift in Sources */, EAF7F09E289AAEC000B287F5 /* Constants.swift in Sources */, EA3361B3288B265D0071C351 /* Changable.swift in Sources */, @@ -586,7 +575,6 @@ EA3361AD288B26190071C351 /* DataTrackable.swift in Sources */, EA33623E2892EE950071C351 /* UIDevice.swift in Sources */, EA3362302891EB4A0071C351 /* Fonts.swift in Sources */, - EAF7F0BD289D81B100B287F5 /* FontStyleable.swift in Sources */, EAF7F0AD289B142900B287F5 /* LabelAttributeStrikeThrough.swift in Sources */, EA3361B8288B2AAA0071C351 /* ViewProtocol.swift in Sources */, EA3361BF288B2EA60071C351 /* ModelHandlerable.swift in Sources */, diff --git a/VDS/Components/Label/Attributes/LabelAttributeFont.swift b/VDS/Components/Label/Attributes/LabelAttributeFont.swift index f0575c63..80e773ad 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeFont.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeFont.swift @@ -14,12 +14,12 @@ public struct LabelAttributeFont: LabelAttributeModel { //-------------------------------------------------- public var location: Int public var length: Int - public var style: FontStyle + public var style: TypographicalStyle public var color: String //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(location: Int, length: Int, style: FontStyle, color: String = "#000000") { + public init(location: Int, length: Int, style: TypographicalStyle, color: String = "#000000") { self.location = location self.length = length self.style = style diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index bce1f89f..d8231647 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -27,14 +27,8 @@ open class LabelBase: UILabel, ModelHandlerable, ViewProt @Proxy(\.model.attributes) open var attributes: [LabelAttributeModel]? - @Proxy(\.model.fontCategory) - open var fontCategory: FontCategory - - @Proxy(\.model.fontSize) - open var fontSize: FontSize - - @Proxy(\.model.fontWeight) - open var fontWeight: FontWeight + @Proxy(\.model.typograpicalStyle) + open var typograpicalStyle: TypographicalStyle @Proxy(\.model.textPosition) open var textPosition: TextPosition @@ -104,7 +98,7 @@ open class LabelBase: UILabel, ModelHandlerable, ViewProt text = nil attributedText = nil textColor = .black - font = FontStyle.RegularBodyLarge.font + font = TypographicalStyle.BodyLarge.font textAlignment = .left accessibilityCustomActions = [] accessibilityTraits = .staticText @@ -131,7 +125,7 @@ open class LabelBase: UILabel, ModelHandlerable, ViewProt if let vdsFont = viewModel.font { font = vdsFont } else { - font = FontStyle.defaultStyle.font + font = TypographicalStyle.defaultStyle.font } if let attributes = viewModel.attributes, let text = viewModel.text, let font = font, let textColor = textColor { diff --git a/VDS/Components/Label/LabelModel.swift b/VDS/Components/Label/LabelModel.swift index e8a7e750..c03d1047 100644 --- a/VDS/Components/Label/LabelModel.swift +++ b/VDS/Components/Label/LabelModel.swift @@ -16,9 +16,7 @@ public protocol LabelModel: Modelable, Labelable { public struct DefaultLabelModel: LabelModel { public var text: String? public var attributes: [LabelAttributeModel]? - public var fontCategory: FontCategory = .body - public var fontSize: FontSize = .small - public var fontWeight: FontWeight = .regular + public var typograpicalStyle: TypographicalStyle = .BodySmall public var textPosition: TextPosition = .left public var surface: Surface = .light public var disabled: Bool = false diff --git a/VDS/Components/Selector/SelectorModel.swift b/VDS/Components/Selector/SelectorModel.swift index df730437..83c7cd5f 100644 --- a/VDS/Components/Selector/SelectorModel.swift +++ b/VDS/Components/Selector/SelectorModel.swift @@ -19,12 +19,7 @@ public protocol SelectorModel: Modelable, FormFieldable, Errorable, DataTrackabl } extension SelectorModel { - - public var fontCategory: FontCategory { - get { return .body } - set { return } - } - + public var shouldShowError: Bool { guard hasError && !disabled && errorText?.isEmpty == false else { return false } return true @@ -38,10 +33,8 @@ extension SelectorModel { public var labelModel: DefaultLabelModel? { guard let labelText = labelText else { return nil } var model = DefaultLabelModel() - model.fontSize = .large model.textPosition = .left - model.fontWeight = .bold - model.fontCategory = .body + model.typograpicalStyle = .BoldBodyLarge model.text = labelText model.surface = surface model.disabled = disabled @@ -52,10 +45,8 @@ extension SelectorModel { public var childModel: DefaultLabelModel? { guard let childText = childText else { return nil } var model = DefaultLabelModel() - model.fontSize = .large model.textPosition = .left - model.fontWeight = .regular - model.fontCategory = .body + model.typograpicalStyle = .BodyLarge model.text = childText model.surface = surface model.disabled = disabled @@ -66,10 +57,8 @@ extension SelectorModel { public var errorModel: DefaultLabelModel? { guard let errorText = errorText, hasError else { return nil } var model = DefaultLabelModel() - model.fontSize = .medium model.textPosition = .left - model.fontWeight = .regular - model.fontCategory = .body + model.typograpicalStyle = .BodyMedium model.text = errorText model.surface = surface model.disabled = disabled diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 94d13851..b765972a 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -109,11 +109,17 @@ open class ToggleBase: Control, Changable { @Proxy(\.model.offText) public var offText: String - @Proxy(\.model.fontSize) - public var fontSize: FontSize + public var fontSize: TypographicalStyle.FontSize = .small{ + didSet { + updateTypography() + } + } - @Proxy(\.model.fontWeight) - public var fontWeight: FontWeight + public var fontWeight: TypographicalStyle.FontWeight = .regular { + didSet { + updateTypography() + } + } @Proxy(\.model.textPosition) public var textPosition: TextPosition { @@ -170,6 +176,25 @@ open class ToggleBase: Control, Changable { } } } + + //only allows + //fontSize: small, large + //fontWeight: regular, bold + private func updateTypography() { + if fontSize == .small { + if fontWeight == .regular { + model.typograpicalStyle = .BodySmall + } else { + model.typograpicalStyle = .BoldBodySmall + } + } else { + if fontWeight == .regular { + model.typograpicalStyle = .BodyLarge + } else { + model.typograpicalStyle = .BoldBodyLarge + } + } + } //-------------------------------------------------- // MARK: - Constraints diff --git a/VDS/Components/Toggle/ToggleModel.swift b/VDS/Components/Toggle/ToggleModel.swift index 32fafe37..500c0e84 100644 --- a/VDS/Components/Toggle/ToggleModel.swift +++ b/VDS/Components/Toggle/ToggleModel.swift @@ -16,19 +16,12 @@ public protocol ToggleModel: Modelable, FormFieldable, DataTrackable, Accessable } extension ToggleModel { - public var fontCategory: FontCategory { - get { return .body } - set { return } - } - public var userTrueColor: Bool { return on } public var label: DefaultLabelModel { var model = DefaultLabelModel() - model.fontSize = fontSize model.textPosition = textPosition - model.fontWeight = fontWeight - model.fontCategory = .body + model.typograpicalStyle = typograpicalStyle model.text = on ? onText : offText model.surface = surface model.disabled = disabled @@ -43,9 +36,7 @@ public struct DefaultToggleModel: ToggleModel { public var offText: String = "Off" public var onText: String = "On" - public var fontCategory: FontCategory = .body - public var fontSize: FontSize = .small - public var fontWeight: FontWeight = .regular + public var typograpicalStyle: TypographicalStyle = .BodySmall public var textPosition: TextPosition = .left public var inputId: String? diff --git a/VDS/Fonts/FontStyles.swift b/VDS/Fonts/FontStyles.swift deleted file mode 100644 index 03839274..00000000 --- a/VDS/Fonts/FontStyles.swift +++ /dev/null @@ -1,221 +0,0 @@ -// -// VDSFontStyles.swift -// VDS -// -// Created by Matt Bruce on 7/27/22. -// - -import Foundation -import UIKit -import VDSTypographyTokens - -public enum FontWeight: String, Codable { - case regular - case bold - - var titleCase: String { - switch self { - case .regular: return "Regular" - case .bold: return "Bold" - } - } -} - -public enum TextPosition: String, Codable, 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 - } - } -} - -public enum FontCategory: String, Codable, CaseIterable { - case feature - case title - case body - case micro - - var fontSizes: [FontSize] { - switch self { - case .feature: - return [.xlarge, .medium, .small, .xsmall] - case .title: - return [.xxlarge, .xlarge, .large, .medium, .small] - case .body: - return [.large, .medium, .small, .xsmall] - case .micro: - return [] - } - } - - var titleCase: String { - switch self { - case .feature: return "Feature" - case .title: return "Title" - case .body: return "Body" - case .micro: return "Micro" - } - } -} - -public enum FontSize: String, Codable, CaseIterable { - case xxlarge - case xlarge - case large - case medium - case small - case xsmall - - var titleCase: String { - switch self { - case .xxlarge: return "2XLarge" - case .xlarge: return "XLarge" - case .large: return "Large" - case .medium: return "Medium" - case .small: return "Small" - case .xsmall: return "XSmall" - } - } -} - -public enum FontStyle: String, Codable, CaseIterable { - public enum Error: Swift.Error { - case styleNotFound(fontCatergory: FontCategory, fontSize: FontSize, availableFontSizes: [FontSize]) - } - - case RegularFeatureXLarge - case BoldFeatureXLarge - case RegularFeatureLarge - case BoldFeatureLarge - case RegularFeatureMedium - case BoldFeatureMedium - case RegularFeatureSmall - case BoldFeatureSmall - case RegularFeatureXSmall - case BoldFeatureXSmall - - case RegularTitle2XLarge - case BoldTitle2XLarge - case RegularTitleXLarge - case BoldTitleXLarge - case RegularTitleLarge - case BoldTitleLarge - case RegularTitleMedium - case BoldTitleMedium - case RegularTitleSmall - case BoldTitleSmall - - case RegularBodyLarge - case BoldBodyLarge - case RegularBodyMedium - case BoldBodyMedium - case RegularBodySmall - case BoldBodySmall - - case RegularMicro - case BoldMicro - - public var pointSize: CGFloat { - switch self { - case .RegularFeatureXLarge, .BoldFeatureXLarge: - return UIDevice.isIPad ? VDSTypography.fontSizeFeature144 : VDSTypography.fontSizeFeature96 - case .RegularFeatureLarge, .BoldFeatureLarge: - return UIDevice.isIPad ? VDSTypography.fontSizeFeature128 : VDSTypography.fontSizeFeature80 - case .RegularFeatureMedium, .BoldFeatureMedium: - return UIDevice.isIPad ? VDSTypography.fontSizeFeature96 : VDSTypography.fontSizeFeature64 - case .RegularFeatureSmall, .BoldFeatureSmall: - return UIDevice.isIPad ? VDSTypography.fontSizeFeature80 : VDSTypography.fontSizeFeature48 - case .RegularFeatureXSmall, .BoldFeatureXSmall: - return UIDevice.isIPad ? VDSTypography.fontSizeFeature64 : VDSTypography.fontSizeFeature40 - case .RegularTitle2XLarge, .BoldTitle2XLarge: - return UIDevice.isIPad ? VDSTypography.fontSizeTitle64 : VDSTypography.fontSizeTitle40 - case .RegularTitleXLarge, .BoldTitleXLarge: - return UIDevice.isIPad ? VDSTypography.fontSizeTitle48 : VDSTypography.fontSizeTitle32 - case .RegularTitleLarge, .BoldTitleLarge: - return UIDevice.isIPad ? VDSTypography.fontSizeTitle32 : VDSTypography.fontSizeTitle24 - case .RegularTitleMedium, .BoldTitleMedium: - return UIDevice.isIPad ? VDSTypography.fontSizeTitle24 : VDSTypography.fontSizeTitle20 - case .RegularTitleSmall, .BoldTitleSmall: - return UIDevice.isIPad ? VDSTypography.fontSizeTitle20 : VDSTypography.fontSizeTitle16 - case .RegularBodyLarge, .BoldBodyLarge: - return VDSTypography.fontSizeBody16 - case .RegularBodyMedium, .BoldBodyMedium: - return VDSTypography.fontSizeBody14 - case .RegularBodySmall, .BoldBodySmall: - return VDSTypography.fontSizeBody12 - case .RegularMicro, .BoldMicro: - return VDSTypography.fontSizeMicro11 - } - } - - public var fontFace: Fonts { - switch self { - case .BoldFeatureXLarge, - .BoldFeatureLarge, - .BoldFeatureMedium, - .BoldFeatureSmall, - .BoldFeatureXSmall, - .BoldTitle2XLarge, - .BoldTitleXLarge, - .BoldTitleLarge, - .BoldTitleMedium, - .BoldTitleSmall, - .BoldBodyLarge, - .BoldBodyMedium, - .BoldBodySmall: - return .dsBold - - case .RegularFeatureXLarge, - .RegularFeatureLarge, - .RegularFeatureMedium, - .RegularFeatureSmall, - .RegularFeatureXSmall, - .RegularTitle2XLarge, - .RegularTitleXLarge, - .RegularTitleLarge, - .RegularTitleMedium, - .RegularTitleSmall, - .RegularBodyLarge, - .RegularBodyMedium, - .RegularBodySmall: - return .dsRegular - - case .BoldMicro: - return .txBold - - case .RegularMicro: - return .txRegular - } - } - - public static var defaultStyle: FontStyle { - return FontStyle.RegularBodyLarge - } - - public var font: UIFont { - return fontFace.font(ofSize: pointSize) - } - - public var superScriptFont: UIFont { - return fontFace.font(ofSize: pointSize / 2) - } - - public static func style(for category: FontCategory, fontWeight: FontWeight, fontSize: FontSize) throws -> FontStyle { - let fontName = "\(fontWeight.titleCase)\(category.titleCase)\(fontSize.titleCase)" - guard let fontStyle = FontStyle(rawValue: fontName) else { - throw FontStyle.Error.styleNotFound(fontCatergory: category, fontSize: fontSize, availableFontSizes: category.fontSizes) - } - return fontStyle - } - - public static func font(for category: FontCategory, fontWeight: FontWeight, fontSize: FontSize) throws -> UIFont { - return try style(for: category, fontWeight: fontWeight, fontSize: fontSize).font - } -} diff --git a/VDS/Protocols/FontStyleable.swift b/VDS/Protocols/FontStyleable.swift deleted file mode 100644 index 9ae23ee1..00000000 --- a/VDS/Protocols/FontStyleable.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// FontStyleable.swift -// VDS -// -// Created by Matt Bruce on 8/5/22. -// - -import Foundation - -public protocol FontStyleable { - var fontStyle: FontStyle { get set } -} diff --git a/VDS/Protocols/Fontable.swift b/VDS/Protocols/Fontable.swift deleted file mode 100644 index 19d90dc6..00000000 --- a/VDS/Protocols/Fontable.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// Fontable.swift -// VDS -// -// Created by Matt Bruce on 8/3/22. -// - -import Foundation -import UIKit - -public protocol Fontable { - var fontSize: FontSize { get set } - var fontWeight: FontWeight { get set } - var fontCategory: FontCategory { get set } -} - -extension Fontable { - - var fontStyle: FontStyle? { - return try? FontStyle.style(for: fontCategory, fontWeight: fontWeight, fontSize: fontSize) - } - - var font: UIFont? { - return fontStyle?.font - } -} diff --git a/VDS/Protocols/Labelable.swift b/VDS/Protocols/Labelable.swift index 26c2eef2..f5ff76cc 100644 --- a/VDS/Protocols/Labelable.swift +++ b/VDS/Protocols/Labelable.swift @@ -6,7 +6,15 @@ // import Foundation +import UIKit -public protocol Labelable: Fontable { +public protocol Labelable { + var typograpicalStyle: TypographicalStyle { get set } var textPosition: TextPosition { get set } } + +extension Labelable { + public var font: UIFont? { + return typograpicalStyle.font + } +} diff --git a/VDS/Typography/Typography.swift b/VDS/Typography/Typography.swift index ad2ac3b7..8cd48a13 100644 --- a/VDS/Typography/Typography.swift +++ b/VDS/Typography/Typography.swift @@ -8,6 +8,21 @@ import Foundation import VDSTypographyTokens +public enum TextPosition: String, Codable, 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 + } + } +} + public enum TypographicalStyle: String, Codable, CaseIterable { case FeatureXLarge @@ -47,9 +62,21 @@ public enum TypographicalStyle: String, Codable, CaseIterable { } } +//MARK: FontSize +extension TypographicalStyle { + public enum FontSize: String, Codable, CaseIterable { + case xxlarge + case xlarge + case large + case medium + case small + case xsmall + } +} + //MARK: FontWeight extension TypographicalStyle { - public enum FontWeight { + public enum FontWeight: String, Codable, CaseIterable { case light case regular case bold