diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index dc66efc8..da63fc3a 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -8,15 +8,7 @@ import Foundation import UIKit -public protocol BinaryColorable{ - var userTrueColor: Bool { get } -} - -extension BinaryColorable where Self: Selectable { - public var userTrueColor: Bool { return selected } -} - -public typealias ClassColorable = Colorable & Initable & ObjectWithable +public typealias ObjectColorable = Colorable & Initable & ObjectWithable /// Meant to be used in a Object that implements the following interfaces for 2 possible color combinations /// - Surfaceable (var surface: Surface) @@ -30,16 +22,31 @@ public typealias ClassColorable = Colorable & Initable & ObjectWithable /// config.darkColor = .white /// /// let textColor = config.getColor(model) //returns .black -open class SurfaceColorConfiguration: ClassColorable { +final public class SurfaceColorConfiguration: ObjectColorable { + public typealias ModelType = Surfaceable public var lightColor: UIColor = .clear public var darkColor: UIColor = .clear required public init(){} - public func getColor(_ viewModel: ModelType) -> UIColor { + public func getColor(_ viewModel: any ModelType) -> UIColor { return viewModel.surface == .light ? lightColor : darkColor } } +///------------------------------------------------------------------- +///MARK -- DisabledSurfaceColorable +///------------------------------------------------------------------- +public protocol DisabledSurfaceColorable: ObjectColorable { + var disabled: SurfaceColorConfiguration { get set } + var enabled: SurfaceColorConfiguration { get set } +} + +extension DisabledSurfaceColorable { + public func getDisabledColor (_ viewModel: M) -> UIColor { + viewModel.disabled ? disabled.getColor(viewModel) : enabled.getColor(viewModel) + } +} + /// Meant to be used in a Object that implements the following interfaces for 4 possible color combinations /// - Disabling (var disabled: Bool) /// - Surfaceable (var surface: Surface) @@ -48,7 +55,7 @@ open class SurfaceColorConfiguration: ClassColorable { /// model.surface = .dark /// model.disabled = false /// -/// let config = DisabledSurfaceColorConfiguration() +/// let config = DisabledSurfaceColorConfiguration() /// /// //disabled == false /// config.enabled.lightColor = .black @@ -61,14 +68,40 @@ open class SurfaceColorConfiguration: ClassColorable { /// let textColor = config.getColor(model) //returns .white /// /// -open class DisabledSurfaceColorConfiguration: ClassColorable { - public var disabled = SurfaceColorConfiguration() - public var enabled = SurfaceColorConfiguration() +final public class DisabledSurfaceColorConfiguration: DisabledSurfaceColorable { + public typealias ModelType = Surfaceable & Disabling + public var disabled = SurfaceColorConfiguration() + public var enabled = SurfaceColorConfiguration() required public init(){} - public func getColor(_ viewModel: ModelType) -> UIColor { - return viewModel.disabled ? disabled.getColor(viewModel) : enabled.getColor(viewModel) + public func getColor(_ viewModel: any ModelType) -> UIColor { + getDisabledColor(viewModel) + } +} + +///------------------------------------------------------------------- +///MARK -- BinaryColorable +///------------------------------------------------------------------- +public protocol BinaryColorable{ + var userTrueColor: Bool { get } +} + +extension BinaryColorable where Self: Selectable { + public var userTrueColor: Bool { return selected } +} + +///------------------------------------------------------------------- +///MARK -- BinarySurfaceColorable +///------------------------------------------------------------------- +public protocol BinarySurfaceColorable: ObjectColorable { + var forTrue: SurfaceColorConfiguration { get set } + var forFalse: SurfaceColorConfiguration { get set } +} + +extension BinarySurfaceColorable { + public func getBinaryColor(_ viewModel: M) -> UIColor { + viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel) } } @@ -79,7 +112,7 @@ open class DisabledSurfaceColorConfiguration: /// let model = TestModel() /// model.surface = .dark /// model.on = true //this is read in the extension var userTrueColor -/// let config = BinarySurfaceColorConfiguration() +/// let config = BinarySurfaceColorConfiguration() /// /// //True from BinaryColorable.userTrueColor /// config.forTrue.lightColor = .black @@ -92,14 +125,30 @@ open class DisabledSurfaceColorConfiguration: /// let textColor = config.getColor(model) //returns .white /// /// -open class BinarySurfaceColorConfiguration: ClassColorable { - public var forTrue = SurfaceColorConfiguration() - public var forFalse = SurfaceColorConfiguration() +final public class BinarySurfaceColorConfiguration: BinarySurfaceColorable { + public typealias ModelType = Surfaceable & BinaryColorable + public var forTrue = SurfaceColorConfiguration() + public var forFalse = SurfaceColorConfiguration() required public init(){} - public func getColor(_ viewModel: ModelType) -> UIColor { - return viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel) + public func getColor(_ viewModel: any ModelType) -> UIColor { + getBinaryColor(viewModel) + } +} + +///------------------------------------------------------------------- +///MARK -- BinaryDisabledSurfaceColorable +///------------------------------------------------------------------- + +public protocol BinaryDisabledSurfaceColorable: ObjectColorable { + var forTrue: DisabledSurfaceColorConfiguration { get set } + var forFalse: DisabledSurfaceColorConfiguration { get set } +} + +extension BinaryDisabledSurfaceColorable { + public func getBinaryColor(_ viewModel: M) -> UIColor { + viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel) } } @@ -112,7 +161,7 @@ open class BinarySurfaceColorConfiguration() +/// let config = BinaryDisabledSurfaceColorConfiguration() /// /// //True /// config.forTrue.enabled.lightColor = .black @@ -129,13 +178,14 @@ open class BinarySurfaceColorConfiguration: ClassColorable { - public var forTrue = DisabledSurfaceColorConfiguration() - public var forFalse = DisabledSurfaceColorConfiguration() +final public class BinaryDisabledSurfaceColorConfiguration: BinaryDisabledSurfaceColorable { + public typealias ModelType = Disabling & Surfaceable & BinaryColorable + public var forTrue = DisabledSurfaceColorConfiguration() + public var forFalse = DisabledSurfaceColorConfiguration() required public init(){} - public func getColor(_ viewModel: ModelType) -> UIColor { - return viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel) + public func getColor(_ viewModel: any ModelType) -> UIColor { + getBinaryColor(viewModel) } } diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index caf908b0..746a445b 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -91,40 +91,40 @@ open class BadgeBase: View { // MARK: - Configuration //-------------------------------------------------- public func backgroundColor(for fillColor: BadgeFillColor) -> UIColor { - var config: SurfaceColorConfiguration + var config: SurfaceColorConfiguration switch model.fillColor { case .red: - config = SurfaceColorConfiguration().with { + config = SurfaceColorConfiguration().with { $0.lightColor = VDSColor.backgroundBrandhighlight $0.darkColor = VDSColor.backgroundBrandhighlight } case .yellow: - config = SurfaceColorConfiguration().with { + config = SurfaceColorConfiguration().with { $0.lightColor = VDSColor.paletteYellow62 $0.darkColor = VDSColor.paletteYellow62 } case .green: - config = SurfaceColorConfiguration().with { + config = SurfaceColorConfiguration().with { $0.lightColor = VDSColor.paletteGreen26 $0.darkColor = VDSColor.paletteGreen34 } case .orange: - config = SurfaceColorConfiguration().with { + config = SurfaceColorConfiguration().with { $0.lightColor = VDSColor.paletteOrange39 $0.darkColor = VDSColor.paletteOrange46 } case .blue: - config = SurfaceColorConfiguration().with { + config = SurfaceColorConfiguration().with { $0.lightColor = VDSColor.paletteBlue35 $0.darkColor = VDSColor.paletteBlue45 } case .black: - config = SurfaceColorConfiguration().with { + config = SurfaceColorConfiguration().with { $0.lightColor = VDSColor.paletteBlack $0.darkColor = VDSColor.paletteBlack } case .white: - config = SurfaceColorConfiguration().with { + config = SurfaceColorConfiguration().with { $0.lightColor = VDSColor.paletteWhite $0.darkColor = VDSColor.paletteWhite } @@ -138,21 +138,21 @@ open class BadgeBase: View { switch fillColor { case .red, .black: - return DisabledSurfaceColorConfiguration().with { + return DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.elementsPrimaryOndark $0.disabled.darkColor = VDSColor.elementsPrimaryOndark $0.enabled.lightColor = VDSColor.elementsPrimaryOndark $0.enabled.darkColor = VDSColor.elementsPrimaryOndark }.eraseToAnyColorable() case .yellow, .white: - return DisabledSurfaceColorConfiguration().with { + return DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.elementsPrimaryOnlight $0.disabled.darkColor = VDSColor.elementsPrimaryOnlight $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight $0.enabled.darkColor = VDSColor.elementsPrimaryOnlight }.eraseToAnyColorable() case .orange, .green, .blue: - return DisabledSurfaceColorConfiguration().with { + return DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.elementsPrimaryOndark $0.disabled.darkColor = VDSColor.elementsPrimaryOnlight $0.enabled.lightColor = VDSColor.elementsPrimaryOndark diff --git a/VDS/Components/Button/Button.swift b/VDS/Components/Button/Button.swift index 46f916ab..d31d4807 100644 --- a/VDS/Components/Button/Button.swift +++ b/VDS/Components/Button/Button.swift @@ -65,51 +65,45 @@ open class ButtonBase: UIButton, ModelHandlerable, ViewP isUserInteractionEnabled = isEnabled } } - + //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- - private var buttonBackgroundColorConfiguration: UseableColorConfiguration = { - return UseableColorConfiguration().with { - $0.primary.enabled.lightColor = VDSColor.backgroundPrimaryDark - $0.primary.enabled.darkColor = VDSColor.backgroundPrimaryLight - $0.primary.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.primary.disabled.darkColor = VDSColor.interactiveDisabledOndark - - $0.secondary.enabled.lightColor = UIColor.clear - $0.secondary.enabled.darkColor = UIColor.clear - $0.secondary.disabled.lightColor = UIColor.clear - $0.secondary.disabled.darkColor = UIColor.clear - } - }() + private var buttonBackgroundColorConfiguration = UseableColorConfiguration().with { + $0.primary.enabled.lightColor = VDSColor.backgroundPrimaryDark + $0.primary.enabled.darkColor = VDSColor.backgroundPrimaryLight + $0.primary.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.primary.disabled.darkColor = VDSColor.interactiveDisabledOndark + + $0.secondary.enabled.lightColor = UIColor.clear + $0.secondary.enabled.darkColor = UIColor.clear + $0.secondary.disabled.lightColor = UIColor.clear + $0.secondary.disabled.darkColor = UIColor.clear + } - private var buttonBorderColorConfiguration: UseableColorConfiguration = { - return UseableColorConfiguration().with { - $0.primary.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.primary.enabled.darkColor = VDSColor.elementsPrimaryOnlight - $0.primary.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.primary.disabled.darkColor = VDSColor.interactiveDisabledOndark - - $0.secondary.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.secondary.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.secondary.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.secondary.disabled.darkColor = VDSColor.interactiveDisabledOndark - } - }() + private var buttonBorderColorConfiguration = UseableColorConfiguration().with { + $0.primary.enabled.lightColor = VDSColor.elementsPrimaryOndark + $0.primary.enabled.darkColor = VDSColor.elementsPrimaryOnlight + $0.primary.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.primary.disabled.darkColor = VDSColor.interactiveDisabledOndark + + $0.secondary.enabled.lightColor = VDSColor.elementsPrimaryOnlight + $0.secondary.enabled.darkColor = VDSColor.elementsPrimaryOndark + $0.secondary.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.secondary.disabled.darkColor = VDSColor.interactiveDisabledOndark + } - private var buttonTitleColorConfiguration: UseableColorConfiguration = { - return UseableColorConfiguration().with { - $0.primary.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.primary.enabled.darkColor = VDSColor.elementsPrimaryOnlight - $0.primary.disabled.lightColor = VDSColor.elementsPrimaryOndark - $0.primary.disabled.darkColor = VDSColor.elementsPrimaryOnlight - - $0.secondary.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.secondary.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.secondary.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.secondary.disabled.darkColor = VDSColor.interactiveDisabledOndark - } - }() + private var buttonTitleColorConfiguration = UseableColorConfiguration().with { + $0.primary.enabled.lightColor = VDSColor.elementsPrimaryOndark + $0.primary.enabled.darkColor = VDSColor.elementsPrimaryOnlight + $0.primary.disabled.lightColor = VDSColor.elementsPrimaryOndark + $0.primary.disabled.darkColor = VDSColor.elementsPrimaryOnlight + + $0.secondary.enabled.lightColor = VDSColor.elementsPrimaryOnlight + $0.secondary.enabled.darkColor = VDSColor.elementsPrimaryOndark + $0.secondary.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.secondary.disabled.darkColor = VDSColor.interactiveDisabledOndark + } //-------------------------------------------------- // MARK: - Initializers @@ -213,9 +207,10 @@ open class ButtonBase: UIButton, ModelHandlerable, ViewP // MARK: - PRIVATE //-------------------------------------------------- - private class UseableColorConfiguration : ClassColorable { - public var primary = DisabledSurfaceColorConfiguration() - public var secondary = DisabledSurfaceColorConfiguration() + private class UseableColorConfiguration: ObjectColorable { + typealias ModelType = Disabling & Surfaceable & Useable + public var primary = DisabledSurfaceColorConfiguration() + public var secondary = DisabledSurfaceColorConfiguration() required public init(){} diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index caf2dd8a..e14e5b2b 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -230,8 +230,6 @@ open class CheckboxBase: Control { // MARK: - State //-------------------------------------------------- open override func updateView(viewModel: ModelType) { - let enabled = !viewModel.disabled - updateLabels(viewModel) updateSelector(viewModel) setAccessibilityHint() @@ -247,8 +245,8 @@ open class CheckboxBase: Control { //-------------------------------------------------- public let checkboxSize = CGSize(width: 20, height: 20) - private var checkboxBackgroundColorConfiguration: CheckboxErrorColorConfiguration = { - return CheckboxErrorColorConfiguration().with { + private var checkboxBackgroundColorConfiguration: ErrorBinaryDisabledSurfaceColorConfiguration = { + return ErrorBinaryDisabledSurfaceColorConfiguration().with { $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight @@ -261,8 +259,8 @@ open class CheckboxBase: Control { } }() - private var checkboxBorderColorConfiguration: CheckboxErrorColorConfiguration = { - return CheckboxErrorColorConfiguration().with { + private var checkboxBorderColorConfiguration: ErrorBinaryDisabledSurfaceColorConfiguration = { + return ErrorBinaryDisabledSurfaceColorConfiguration().with { $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight @@ -279,8 +277,8 @@ open class CheckboxBase: Control { } }() - private var checkboxCheckColorConfiguration: BinarySurfaceColorConfiguration = { - return BinarySurfaceColorConfiguration().with { + private var checkboxCheckColorConfiguration: BinarySurfaceColorConfiguration = { + return BinarySurfaceColorConfiguration().with { $0.forTrue.lightColor = VDSColor.elementsPrimaryOndark $0.forTrue.darkColor = VDSColor.elementsPrimaryOnlight } @@ -346,23 +344,28 @@ open class CheckboxBase: Control { } } } - - //-------------------------------------------------- - // MARK: - Color Class Configurations - //-------------------------------------------------- - private class CheckboxErrorColorConfiguration: BinaryDisabledSurfaceColorConfiguration { - public let error = BinarySurfaceColorConfiguration() - override func getColor(_ viewModel: ModelType) -> UIColor { - //only show error is enabled and showError == true - let showErrorColor = !viewModel.disabled && viewModel.showError - - if showErrorColor { - return error.getColor(viewModel) - } else { - return super.getColor(viewModel) - } - } - } - +} + +//-------------------------------------------------- +// MARK: - Color Class Configurations +//-------------------------------------------------- +internal class ErrorBinaryDisabledSurfaceColorConfiguration: BinaryDisabledSurfaceColorable { + typealias ModelType = Errorable & Disabling & Surfaceable & BinaryColorable + var error = BinarySurfaceColorConfiguration() + var forTrue = DisabledSurfaceColorConfiguration() + var forFalse = DisabledSurfaceColorConfiguration() + + required init() {} + + func getColor(_ viewModel: ModelType) -> UIColor { + //only show error is enabled and showError == true + let showErrorColor = !viewModel.disabled && viewModel.showError + + if showErrorColor { + return error.getColor(viewModel) + } else { + return getBinaryColor(viewModel) + } + } } diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 86364426..7601c8d1 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -67,7 +67,7 @@ open class LabelBase: UILabel, ModelHandlerable, ViewProt //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- - public var textColorConfiguration: AnyColorable = DisabledSurfaceColorConfiguration().with { + public var textColorConfiguration: AnyColorable = DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.elementsSecondaryOnlight $0.disabled.darkColor = VDSColor.elementsSecondaryOndark $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 4d71159d..a4e47b40 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -207,8 +207,6 @@ open class RadioBoxBase: Control { // MARK: - State //-------------------------------------------------- open override func updateView(viewModel: ModelType) { - let enabled = !viewModel.disabled - updateLabels(viewModel) updateSelector(viewModel) setAccessibilityHint() @@ -227,34 +225,30 @@ open class RadioBoxBase: Control { private var selectorBorderWidthSelected: CGFloat = 2.0 private var selectorBorderWidth: CGFloat = 1.0 - private var radioBoxBackgroundColorConfiguration: BinaryDisabledSurfaceColorConfiguration = { - return BinaryDisabledSurfaceColorConfiguration().with { - $0.forFalse.enabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.forFalse.disabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forFalse.disabled.darkColor = VDSFormControlsColor.backgroundOndark - - $0.forTrue.enabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forTrue.enabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.forTrue.disabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forTrue.disabled.darkColor = VDSFormControlsColor.backgroundOndark - } - }() + private var radioBoxBackgroundColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { + $0.forFalse.enabled.lightColor = VDSFormControlsColor.backgroundOnlight + $0.forFalse.enabled.darkColor = VDSFormControlsColor.backgroundOndark + $0.forFalse.disabled.lightColor = VDSFormControlsColor.backgroundOnlight + $0.forFalse.disabled.darkColor = VDSFormControlsColor.backgroundOndark + + $0.forTrue.enabled.lightColor = VDSFormControlsColor.backgroundOnlight + $0.forTrue.enabled.darkColor = VDSFormControlsColor.backgroundOndark + $0.forTrue.disabled.lightColor = VDSFormControlsColor.backgroundOnlight + $0.forTrue.disabled.darkColor = VDSFormControlsColor.backgroundOndark + } + + private var radioBoxBorderColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { + $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight + $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark + $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight + $0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark + + $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark + $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark + } - private var radioBoxBorderColorConfiguration: BinaryDisabledSurfaceColorConfiguration = { - return BinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark - - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark - } - }() - //-------------------------------------------------- // MARK: - RadioBox View Updates //-------------------------------------------------- diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index cb2081c9..4a77cb48 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -240,8 +240,6 @@ open class RadioButtonBase: Control { // MARK: - State //-------------------------------------------------- open override func updateView(viewModel: ModelType) { - let enabled = !viewModel.disabled - updateLabels(viewModel) updateSelector(viewModel) setAccessibilityHint() @@ -256,43 +254,37 @@ open class RadioButtonBase: Control { //-------------------------------------------------- public let radioButtonSize = CGSize(width: 20, height: 20) public let radioButtonSelectedSize = CGSize(width: 10, height: 10) - - private var radioButtonBackgroundColorConfiguration: RadioButtonErrorColorConfiguration = { - return RadioButtonErrorColorConfiguration().with { - //error doesn't care enabled/disable - $0.error.forTrue.lightColor = VDSColor.elementsPrimaryOnlight - $0.error.forTrue.darkColor = VDSColor.elementsPrimaryOndark - $0.error.forFalse.lightColor = VDSColor.feedbackErrorBackgroundOnlight - $0.error.forFalse.darkColor = VDSColor.feedbackErrorBackgroundOndark - } - }() - private var radioButtonBorderColorConfiguration: RadioButtonErrorColorConfiguration = { - return RadioButtonErrorColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark - //error doesn't care enabled/disable - $0.error.forTrue.lightColor = VDSColor.elementsPrimaryOnlight - $0.error.forTrue.darkColor = VDSColor.elementsPrimaryOndark - $0.error.forFalse.lightColor = VDSColor.feedbackErrorOnlight - $0.error.forFalse.darkColor = VDSColor.feedbackErrorOndark - } - }() - - private var radioButtonCheckColorConfiguration: BinaryDisabledSurfaceColorConfiguration = { - return BinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - } - }() + private var radioButtonBackgroundColorConfiguration = ErrorBinaryDisabledSurfaceColorConfiguration().with { + //error doesn't care enabled/disable + $0.error.forTrue.lightColor = VDSColor.elementsPrimaryOnlight + $0.error.forTrue.darkColor = VDSColor.elementsPrimaryOndark + $0.error.forFalse.lightColor = VDSColor.feedbackErrorBackgroundOnlight + $0.error.forFalse.darkColor = VDSColor.feedbackErrorBackgroundOndark + } + + private var radioButtonBorderColorConfiguration = ErrorBinaryDisabledSurfaceColorConfiguration().with { + $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight + $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark + $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight + $0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark + $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark + $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark + //error doesn't care enabled/disable + $0.error.forTrue.lightColor = VDSColor.elementsPrimaryOnlight + $0.error.forTrue.darkColor = VDSColor.elementsPrimaryOndark + $0.error.forFalse.lightColor = VDSColor.feedbackErrorOnlight + $0.error.forFalse.darkColor = VDSColor.feedbackErrorOndark + } + + private var radioButtonCheckColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { + $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight + $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark + $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark + } //-------------------------------------------------- // MARK: - RadioButton View @@ -338,23 +330,5 @@ open class RadioButtonBase: Control { shapeLayer.path = bezierPath.cgPath } } - - //-------------------------------------------------- - // MARK: - Color Class Configurations - //-------------------------------------------------- - private class RadioButtonErrorColorConfiguration: BinaryDisabledSurfaceColorConfiguration { - public let error = BinarySurfaceColorConfiguration() - override func getColor(_ viewModel: ModelType) -> UIColor { - //only show error is enabled and showError == true - let showErrorColor = !viewModel.disabled && viewModel.showError - - if showErrorColor { - return error.getColor(viewModel) - } else { - return super.getColor(viewModel) - } - } - } - } diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 1d0e4164..c53e7079 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -159,41 +159,36 @@ open class RadioSwatchBase: Control { public let swatchSize = CGSize(width: 48, height: 48) public let fillSize = CGSize(width: 36, height: 36) public let disabledAlpha = 0.5 - private var radioSwatchBackgroundColorConfiguration: BinaryDisabledSurfaceColorConfiguration = { - return BinaryDisabledSurfaceColorConfiguration().with { - $0.forFalse.enabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.forFalse.disabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forFalse.disabled.darkColor = VDSFormControlsColor.backgroundOndark - - $0.forTrue.enabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forTrue.enabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.forTrue.disabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forTrue.disabled.darkColor = VDSFormControlsColor.backgroundOndark - } - }() - private var radioSwatchBorderColorConfiguration: BinaryDisabledSurfaceColorConfiguration = { - return BinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark - } - }() + private var radioSwatchBackgroundColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { + $0.forFalse.enabled.lightColor = VDSFormControlsColor.backgroundOnlight + $0.forFalse.enabled.darkColor = VDSFormControlsColor.backgroundOndark + $0.forFalse.disabled.lightColor = VDSFormControlsColor.backgroundOnlight + $0.forFalse.disabled.darkColor = VDSFormControlsColor.backgroundOndark + $0.forTrue.enabled.lightColor = VDSFormControlsColor.backgroundOnlight + $0.forTrue.enabled.darkColor = VDSFormControlsColor.backgroundOndark + $0.forTrue.disabled.lightColor = VDSFormControlsColor.backgroundOnlight + $0.forTrue.disabled.darkColor = VDSFormControlsColor.backgroundOndark + } + + private var radioSwatchBorderColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { + $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight + $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark + $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight + $0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark + $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark + $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark + } + + private var radioSwatchFillBorderColorConfiguration = DisabledSurfaceColorConfiguration().with { + $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight + $0.enabled.darkColor = VDSColor.elementsPrimaryOndark + $0.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.disabled.darkColor = VDSColor.interactiveDisabledOndark + } - private var radioSwatchFillBorderColorConfiguration: DisabledSurfaceColorConfiguration = { - return DisabledSurfaceColorConfiguration().with { - $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.disabled.darkColor = VDSColor.interactiveDisabledOndark - } - }() //-------------------------------------------------- // MARK: - RadioBox View Updates //-------------------------------------------------- diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 27d19634..8babbace 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -64,31 +64,27 @@ open class ToggleBase: Control { public let toggleContainerSize = CGSize(width: 52, height: 44) public let knobSize = CGSize(width: 20, height: 20) - private var toggleColorConfiguration: BinaryDisabledSurfaceColorConfiguration = { - return BinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.paletteGreen26 - $0.forTrue.enabled.darkColor = VDSColor.paletteGreen34 - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.forFalse.enabled.lightColor = VDSColor.elementsSecondaryOnlight - $0.forFalse.enabled.darkColor = VDSColor.paletteGray44 - $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark - } - } () + private var toggleColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { + $0.forTrue.enabled.lightColor = VDSColor.paletteGreen26 + $0.forTrue.enabled.darkColor = VDSColor.paletteGreen34 + $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark + $0.forFalse.enabled.lightColor = VDSColor.elementsSecondaryOnlight + $0.forFalse.enabled.darkColor = VDSColor.paletteGray44 + $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight + $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark + } - private var knobColorConfiguration: BinaryDisabledSurfaceColorConfiguration = { - return BinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forTrue.disabled.lightColor = VDSColor.paletteGray95 - $0.forTrue.disabled.darkColor = VDSColor.paletteGray44 - $0.forFalse.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.forFalse.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forFalse.disabled.lightColor = VDSColor.paletteGray95 - $0.forFalse.disabled.darkColor = VDSColor.paletteGray44 - } - } () + private var knobColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { + $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOndark + $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark + $0.forTrue.disabled.lightColor = VDSColor.paletteGray95 + $0.forTrue.disabled.darkColor = VDSColor.paletteGray44 + $0.forFalse.enabled.lightColor = VDSColor.elementsPrimaryOndark + $0.forFalse.enabled.darkColor = VDSColor.elementsPrimaryOndark + $0.forFalse.disabled.lightColor = VDSColor.paletteGray95 + $0.forFalse.disabled.darkColor = VDSColor.paletteGray44 + } //-------------------------------------------------- // MARK: - Public Properties diff --git a/VDS/Protocols/Withable.swift b/VDS/Protocols/Withable.swift index 62af68ab..0ab9eebd 100644 --- a/VDS/Protocols/Withable.swift +++ b/VDS/Protocols/Withable.swift @@ -48,3 +48,4 @@ public extension Withable { return copy } } +