From cade12b0cd121e54dc9b72a7802236226e2e5d93 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 16 Aug 2022 18:16:16 -0500 Subject: [PATCH] refactored label Signed-off-by: Matt Bruce --- VDS/Components/Label/Label.swift | 6 +++ VDS/Components/Toggle/Toggle.swift | 14 ++--- VDS/Typography/Typography.swift | 87 ++++++++++++------------------ 3 files changed, 48 insertions(+), 59 deletions(-) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 531176a0..53eaef6a 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -24,6 +24,12 @@ open class LabelBase: UILabel, ModelHandlerable, ViewProt //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- + @Proxy(\.model.surface) + open var surface: Surface + + @Proxy(\.model.disabled) + open var disabled: Bool + @Proxy(\.model.attributes) open var attributes: [LabelAttributeModel]? diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index b765972a..577ed811 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -115,7 +115,7 @@ open class ToggleBase: Control, Changable { } } - public var fontWeight: TypographicalStyle.FontWeight = .regular { + public var isBold: Bool = false { didSet { updateTypography() } @@ -182,16 +182,16 @@ open class ToggleBase: Control, Changable { //fontWeight: regular, bold private func updateTypography() { if fontSize == .small { - if fontWeight == .regular { - model.typograpicalStyle = .BodySmall - } else { + if isBold { model.typograpicalStyle = .BoldBodySmall + } else { + model.typograpicalStyle = .BodySmall } } else { - if fontWeight == .regular { - model.typograpicalStyle = .BodyLarge - } else { + if isBold { model.typograpicalStyle = .BoldBodyLarge + } else { + model.typograpicalStyle = .BodyLarge } } } diff --git a/VDS/Typography/Typography.swift b/VDS/Typography/Typography.swift index 8cd48a13..d623d34f 100644 --- a/VDS/Typography/Typography.swift +++ b/VDS/Typography/Typography.swift @@ -62,64 +62,47 @@ public enum TypographicalStyle: String, Codable, CaseIterable { } } -//MARK: FontSize +//MARK: FontCategory extension TypographicalStyle { - public enum FontSize: String, Codable, CaseIterable { - case xxlarge - case xlarge - case large - case medium - case small - case xsmall + public enum FontCategory: String, Codable, CaseIterable { + case feature = "Feature" + case title = "Title" + case body = "Body" + case micro = "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 [] + } + } + + public func style(for fontSize: FontSize, isBold: Bool = false) -> TypographicalStyle? { + let styleName = "\(isBold ? "Bold" : "")\(self.rawValue)\(fontSize.rawValue)" + guard let style = TypographicalStyle(rawValue: styleName) else { + return nil + } + return style + } } } -//MARK: FontWeight +//MARK: FontSize extension TypographicalStyle { - public enum FontWeight: String, Codable, CaseIterable { - case light - case regular - case bold + public enum FontSize: String, Codable, CaseIterable { + case xxlarge = "2XLarge" + case xlarge = "XLarge" + case large = "Large" + case medium = "Medium" + case small = "Small" + case xsmall = "XSmall" } - - public var fontWeight: FontWeight { - switch self { - case .BoldFeatureXLarge, - .BoldFeatureLarge, - .BoldFeatureMedium, - .BoldFeatureSmall, - .BoldFeatureXSmall, - .BoldTitle2XLarge, - .BoldTitleXLarge, - .BoldTitleLarge, - .BoldTitleMedium, - .BoldTitleSmall, - .BoldBodyLarge, - .BoldBodyMedium, - .BoldBodySmall, - .BoldMicro: - return .bold - - case .FeatureXLarge, - .FeatureLarge, - .FeatureMedium, - .FeatureSmall, - .FeatureXSmall, - .Title2XLarge, - .TitleXLarge, - .TitleLarge: - return .light - - case .TitleMedium, - .TitleSmall, - .BodyLarge, - .BodyMedium, - .BodySmall, - .Micro: - return .regular - } - } - } //MARK: PointSize