From 0ace568f7d26e19069e299b16a870eb798b947be Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 1 Aug 2022 15:42:50 -0500 Subject: [PATCH] refactored label text Signed-off-by: Matt Bruce --- VDS/Components/Label/VDSLabel.swift | 18 +++++++++++++++++- VDS/Components/Label/VDSLabelModel.swift | 3 ++- VDS/Components/Toggle/VDSToggleModel.swift | 3 +-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Label/VDSLabel.swift b/VDS/Components/Label/VDSLabel.swift index acb6fc58..558ccb32 100644 --- a/VDS/Components/Label/VDSLabel.swift +++ b/VDS/Components/Label/VDSLabel.swift @@ -50,10 +50,26 @@ open class VDSLabel: UILabel, Modelable { } } + private func getTextColor(for disabled: Bool, surface: Surface) -> UIColor { + if disabled { + if surface == .light { + return VDSColor.elementsSecondaryOnlight + } else { + return VDSColor.elementsSecondaryOndark + } + } else { + if surface == .light { + return VDSColor.elementsPrimaryOnlight + } else { + return VDSColor.elementsPrimaryOndark + } + } + } + //functions private func onStateChange(viewModel: VDSLabelModel) { textAlignment = viewModel.textPosition.textAlignment - textColor = viewModel.surface == .dark ? VDSColor.elementsPrimaryOndark : VDSColor.elementsPrimaryOnlight + textColor = getTextColor(for: viewModel.disabled, surface: viewModel.surface) guard let vdsFont = try? VDSFontStyle.font(for: viewModel.fontCategory, fontWeight: viewModel.fontWeight, fontSize: viewModel.fontSize) else { font = VDSFontStyle.RegularBodyLarge.font diff --git a/VDS/Components/Label/VDSLabelModel.swift b/VDS/Components/Label/VDSLabelModel.swift index 77520860..721f87ea 100644 --- a/VDS/Components/Label/VDSLabelModel.swift +++ b/VDS/Components/Label/VDSLabelModel.swift @@ -8,7 +8,7 @@ import Foundation import UIKit -public protocol VDSLabelModel: Labelable, Surfaceable { +public protocol VDSLabelModel: Labelable, Surfaceable, Disabling { } open class DefaultLabelModel: VDSLabelModel { @@ -17,5 +17,6 @@ open class DefaultLabelModel: VDSLabelModel { public var fontWeight: VDSFontWeight = .regular public var textPosition: VDSTextPosition = .left public var surface: Surface = .light + public var disabled: Bool = false required public init(){} } diff --git a/VDS/Components/Toggle/VDSToggleModel.swift b/VDS/Components/Toggle/VDSToggleModel.swift index 41c14372..475d40c6 100644 --- a/VDS/Components/Toggle/VDSToggleModel.swift +++ b/VDS/Components/Toggle/VDSToggleModel.swift @@ -14,7 +14,7 @@ extension VDSToggle { } } -public protocol VDSToggleModel: VDSLabelModel, FormFieldable, DataTrackable, Disabling, Accessable { +public protocol VDSToggleModel: VDSLabelModel, FormFieldable, DataTrackable, Accessable { var id: String? { get set } var showText: Bool { get set } var on: Bool { get set } @@ -32,7 +32,6 @@ extension VDSToggleModel { public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel { public var id: String? public var inputId: String? - public var disabled: Bool = false public var showText: Bool = false public var on: Bool = false public var offText: String = "Off"