diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index d4fdd413..7f7742b8 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -442,8 +442,8 @@ EA4DB2FE28DCBC1900103EE3 /* Badge */ = { isa = PBXGroup; children = ( - EA4DB2FF28DCBC9900103EE3 /* BadgeModel.swift */, EA4DB30128DCBCA500103EE3 /* Badge.swift */, + EA4DB2FF28DCBC9900103EE3 /* BadgeModel.swift */, ); path = Badge; sourceTree = ""; diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index bb2f6108..936138ef 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -50,14 +50,14 @@ open class EntryField: Control { // Sizes are from InVision design specs. internal let containerSize = CGSize(width: 45, height: 45) - internal let primaryColorConfig = DisabledSurfaceColorConfiguration().with { + internal let primaryColorConfig = DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.interactiveDisabledOnlight $0.disabled.darkColor = VDSColor.interactiveDisabledOndark $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight $0.enabled.darkColor = VDSColor.elementsPrimaryOndark } - internal let secondaryColorConfig = DisabledSurfaceColorConfiguration().with { + internal let secondaryColorConfig = DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.interactiveDisabledOnlight $0.disabled.darkColor = VDSColor.interactiveDisabledOndark $0.enabled.lightColor = VDSColor.elementsSecondaryOnlight @@ -170,7 +170,7 @@ open class EntryField: Control { } open func getBackgroundConfig() -> AnyColorable { - return EntryFieldColorConfiguration().with { + return ErrorDisabledSurfaceColorConfiguration().with { $0.enabled.lightColor = VDSFormControlsColor.backgroundOnlight $0.enabled.darkColor = VDSFormControlsColor.backgroundOndark $0.disabled.lightColor = VDSFormControlsColor.backgroundOnlight @@ -183,7 +183,7 @@ open class EntryField: Control { } open func getBorderConfig() -> AnyColorable { - return EntryFieldColorConfiguration().with { + return ErrorDisabledSurfaceColorConfiguration().with { $0.enabled.lightColor = VDSFormControlsColor.borderOnlight $0.enabled.darkColor = VDSFormControlsColor.borderOnlight $0.disabled.lightColor = VDSColor.interactiveDisabledOnlight @@ -291,28 +291,33 @@ open class EntryField: Control { helperLabel.isHidden = true } } +} - //-------------------------------------------------- - // MARK: - Color Class Configurations - //-------------------------------------------------- - internal class EntryFieldColorConfiguration: DisabledSurfaceColorConfiguration { - public let error = SurfaceColorConfiguration() - - override func getColor(_ viewModel: ModelType) -> UIColor { - //only show error is enabled and showError == true - let showErrorColor = !viewModel.disabled && viewModel.showError +//-------------------------------------------------- +// MARK: - Color Class Configurations +//-------------------------------------------------- +internal class ErrorDisabledSurfaceColorConfiguration: DisabledSurfaceColorable { + typealias ModelType = Errorable & Surfaceable & Disabling + var error = SurfaceColorConfiguration() + var disabled = SurfaceColorConfiguration() + var enabled = SurfaceColorConfiguration() + + required public init(){} - if showErrorColor { - return error.getColor(viewModel) - } else { - return super.getColor(viewModel) - } + func getColor(_ viewModel: any ModelType) -> UIColor { + //only show error is enabled and showError == true + let showErrorColor = !viewModel.disabled && viewModel.showError + + if showErrorColor { + return error.getColor(viewModel) + } else { + return getDisabledColor(viewModel) } } } extension DefaultLabelModel { - public func addOptional(required: Bool, colorConfiguration: DisabledSurfaceColorConfiguration) -> DefaultLabelModel { + public func addOptional(required: Bool, colorConfiguration: DisabledSurfaceColorConfiguration) -> DefaultLabelModel { guard let text = text, !required else { return self} let optionColorAttr = ColorLabelAttribute(location: text.count + 2, length: 8, @@ -325,7 +330,7 @@ extension DefaultLabelModel { } } - public func addToolTip(action: PassthroughSubject, colorConfiguration: DisabledSurfaceColorConfiguration) -> DefaultLabelModel { + public func addToolTip(action: PassthroughSubject, colorConfiguration: DisabledSurfaceColorConfiguration) -> DefaultLabelModel { guard let text = text else { return self} var newAttributes = attributes ?? [] let newText = "\(text) " //create a little space between the final character and tooltip image diff --git a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift index 5e337a1d..d2f49038 100644 --- a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift +++ b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift @@ -153,10 +153,15 @@ open class TextEntryFieldBase: EntryField() - - override func getColor(_ viewModel: ModelType) -> UIColor { + internal class TextEntryFieldColorConfiguration: DisabledSurfaceColorable { + var success = SurfaceColorConfiguration() + var error = SurfaceColorConfiguration() + var disabled = SurfaceColorConfiguration() + var enabled = SurfaceColorConfiguration() + + required init(){} + + func getColor(_ viewModel: ModelType) -> UIColor { //only show error is enabled and showError == true let showErrorColor = !viewModel.disabled && viewModel.showError let showSuccessColor = !viewModel.disabled && viewModel.showSuccess @@ -168,10 +173,12 @@ open class TextEntryFieldBase: EntryField