diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index c14e6f1c..a1288aa2 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -112,209 +112,3 @@ open class SurfaceColorConfiguration: ObjectColorable { return getColor(object.surface) } } - -///------------------------------------------------------------------- -///MARK -- DisabledSurfaceColorable -///------------------------------------------------------------------- -public protocol DisabledSurfaceColorable: ObjectColorable { - var disabled: SurfaceColorConfiguration { get set } - var enabled: SurfaceColorConfiguration { get set } -} - -extension DisabledSurfaceColorable { - public func getDisabledColor (_ object: M) -> UIColor { - object.disabled ? disabled.getColor(object) : enabled.getColor(object) - } -} - -/// 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) -/// -/// let model = TestModel() -/// model.surface = .dark -/// model.disabled = false -/// -/// let config = DisabledSurfaceColorConfiguration() -/// -/// //disabled == false -/// config.enabled.lightColor = .black -/// config.enabled.darkColor = .white -/// -/// //disabled == true -/// config.disabled.lightColor = .gray -/// config.disabled.darkColor = .lightGray -/// -/// let textColor = config.getColor(model) //returns .white -/// -/// -open class DisabledSurfaceColorConfiguration: DisabledSurfaceColorable { - public typealias ObjectType = Surfaceable & Disabling - public var disabled = SurfaceColorConfiguration() - public var enabled = SurfaceColorConfiguration() - - required public init(){} - - public func getColor(_ object: any ObjectType) -> UIColor { - getDisabledColor(object) - } -} - -///------------------------------------------------------------------- -///MARK -- BinaryColorable -///------------------------------------------------------------------- -public protocol BinaryColorable{ - var useTrueColor: Bool { get } -} - -extension BinaryColorable where Self: Control { - public var useTrueColor: Bool { return isSelected } -} - -///------------------------------------------------------------------- -///MARK -- BinarySurfaceColorable -///------------------------------------------------------------------- -public protocol BinarySurfaceColorable: ObjectColorable { - var forTrue: SurfaceColorConfiguration { get set } - var forFalse: SurfaceColorConfiguration { get set } -} - -extension BinarySurfaceColorable { - public func getBinaryColor(_ object: M) -> UIColor { - object.useTrueColor ? forTrue.getColor(object) : forFalse.getColor(object) - } -} - -/// Meant to be used in a Object that implements the following interfaces for 4 possible color combinations -/// - BinaryColorable (var userTrueColor: Bool) -/// - Surfaceable (var surface: Surface) -/// -/// let model = TestModel() -/// model.surface = .dark -/// model.on = true //this is read in the extension var userTrueColor -/// let config = BinarySurfaceColorConfiguration() -/// -/// //True from BinaryColorable.userTrueColor -/// config.forTrue.lightColor = .black -/// config.forTrue.darkColor = .white -/// -/// //False from BinaryColorable.userTrueColor -/// config.forFalse.lightColor = .red -/// config.forFalse.darkColor = .red -/// -/// let textColor = config.getColor(model) //returns .white -/// -/// -final public class BinarySurfaceColorConfiguration: BinarySurfaceColorable { - public typealias ObjectType = Surfaceable & BinaryColorable - public var forTrue = SurfaceColorConfiguration() - public var forFalse = SurfaceColorConfiguration() - - required public init(){} - - public func getColor(_ object: any ObjectType) -> UIColor { - getBinaryColor(object) - } -} - -///------------------------------------------------------------------- -///MARK -- BinaryDisabledSurfaceColorable -///------------------------------------------------------------------- - -public protocol BinaryDisabledSurfaceColorable: ObjectColorable { - var forTrue: DisabledSurfaceColorConfiguration { get set } - var forFalse: DisabledSurfaceColorConfiguration { get set } -} - -extension BinaryDisabledSurfaceColorable { - public func getBinaryColor(_ object: M) -> UIColor { - object.useTrueColor ? forTrue.getColor(object) : forFalse.getColor(object) - } -} - -/// Meant to be used in a Object that implements the following interfaces for 8 possible color combinations -/// - BinaryColorable (var userTrueColor: Bool) -/// - Disabling (var disabled: Bool) -/// - Surfaceable (var surface: Surface) -/// -/// let model = TestModel() -/// model.on = false -/// model.disabled = false -/// model.surface = .light -/// let config = BinaryDisabledSurfaceColorConfiguration() -/// -/// //True -/// config.forTrue.enabled.lightColor = .black -/// config.forTrue.enabled.darkColor = .white -/// config.forTrue.disabled.lightColor = .darkGray -/// config.forTrue.disabled.darkColor = .lightGray -/// -/// //False -/// config.forFalse.enabled.lightColor = .red -/// config.forFalse.enabled.darkColor = .red -/// config.forFalse.disabled.lightColor =.darkGray -/// config.forFalse.disabled.darkColor = .lightGray -/// -/// let textColor = config.getColor(model) -/// -/// -final public class BinaryDisabledSurfaceColorConfiguration: BinaryDisabledSurfaceColorable { - public typealias ObjectType = Disabling & Surfaceable & BinaryColorable - public var forTrue = DisabledSurfaceColorConfiguration() - public var forFalse = DisabledSurfaceColorConfiguration() - - required public init(){} - - public func getColor(_ object: any ObjectType) -> UIColor { - getBinaryColor(object) - } -} - -public class ControlStateColorConfiguration: ObjectColorable { - public typealias ObjectType = UIControl & Surfaceable - public var disabled = SurfaceColorConfiguration() - public var normal = SurfaceColorConfiguration() - public var highlighted: SurfaceColorConfiguration? - public var selected: SurfaceColorConfiguration? - public var error: SurfaceColorConfiguration? - - required public init(){} - - public func setColorable(_ config: SurfaceColorConfiguration, for state: UIControl.State) { - switch state { - case .disabled: - disabled = config - - case .highlighted: - highlighted = config - - case .selected: - selected = config - - case .error: - error = config - - default: - normal = config - } - } - - public func getColor(_ object: any ObjectType) -> UIColor { - - if object.state == .disabled { - return disabled.getColor(object) - - } else if let highlighted, object.state == .highlighted { - return highlighted.getColor(object) - - } else if let selected, object.state == .selected { - return selected.getColor(object) - - } else if let error, object.state == .error { - return error.getColor(object) - - } else { - return normal.getColor(object) - } - } -} diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index ed615958..e68c818d 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -170,22 +170,6 @@ open class Button: ButtonBase, Useable { minWidthConstraint?.isActive = true } } - - //-------------------------------------------------- - // MARK: - PRIVATE - //-------------------------------------------------- - - private class UseableColorConfiguration: ObjectColorable { - typealias ObjectType = Buttonable & Useable - public var primary = ControlStateColorConfiguration() - public var secondary = ControlStateColorConfiguration() - - required public init(){} - - public func getColor(_ object: ObjectType) -> UIColor { - return object.use == .primary ? primary.getColor(object) : secondary.getColor(object) - } - } } fileprivate extension ButtonSize { diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index 0013c77a..a6ac59c7 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -159,11 +159,9 @@ internal class CaretView: View { public var size: CaretSize? { didSet{ didChange() } } - public var colorConfiguration: AnyColorable = DisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.elementsSecondaryOnlight - $0.disabled.darkColor = VDSColor.elementsSecondaryOndark - $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.enabled.darkColor = VDSColor.elementsPrimaryOndark + public var colorConfiguration: AnyColorable = ViewColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forDisabled: true) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false) }.eraseToAnyColorable() diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 97bd6361..91c08aab 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -27,7 +27,7 @@ public class SoloCheckbox: CheckboxBase{ } @objc(VDSCheckboxBase) -open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Errorable { +open class CheckboxBase: Control, Accessable, DataTrackable, Errorable { //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index ad3846db..7951c4cd 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -27,7 +27,7 @@ public class SoloRadioBox: RadioBoxBase{ } @objc(VDSRadioBoxBase) -open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ +open class RadioBoxBase: Control, Accessable, DataTrackable{ //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index fd36bded..674a0a6f 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -34,7 +34,7 @@ public class SoloRadioButton: RadioButtonBase { } @objc(VDSRadioButtonBase) -open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, Errorable { +open class RadioButtonBase: Control, Accessable, DataTrackable, Errorable { //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 0ee397a7..5c36c575 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -31,7 +31,7 @@ public class SolorRadioSwatch: RadioSwatchBase{ } @objc(VDSRadioSwatchBase) -open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable { +open class RadioSwatchBase: Control, Accessable, DataTrackable { //-------------------------------------------------- // MARK: - Initializers diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index 59dda2b1..d38d4453 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -358,26 +358,3 @@ open class EntryField: Control, Accessable { } } } - -//-------------------------------------------------- -// 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(){} - - 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) - } - } -} diff --git a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift index 92cf1cc6..280a66e0 100644 --- a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift +++ b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift @@ -185,32 +185,6 @@ open class TextEntryFieldBase: EntryField { } } } - - internal class TextEntryFieldColorConfiguration: DisabledSurfaceColorable { - var success = SurfaceColorConfiguration() - var error = SurfaceColorConfiguration() - var disabled = SurfaceColorConfiguration() - var enabled = SurfaceColorConfiguration() - - required init(){} - - func getColor(_ object: TextEntryField) -> UIColor { - //only show error is enabled and showError == true - let showErrorColor = !object.disabled && object.showError - let showSuccessColor = !object.disabled && object.showSuccess - - if showErrorColor { - return error.getColor(object) - - } else if showSuccessColor { - return success.getColor(object) - - } else { - return getDisabledColor(object) - } - } - } - } extension TextEntryFieldType { diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 775768d3..d5b86437 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -42,7 +42,7 @@ public class Toggle: ToggleBase{ } @objc(VDSToggleBase) -open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { +open class ToggleBase: Control, Accessable, DataTrackable { //-------------------------------------------------- // MARK: - Initializers @@ -97,7 +97,7 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { private var knobColorConfiguration = ControlColorConfiguration().with { $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forState: .normal) - $0.setSurfaceColors(VDSColor.paletteGray95, VDSColor.paletteGray44, forState: .disabled) + $0.setSurfaceColors(VDSColor.paletteGray95, VDSColor.paletteGray44, forState: .disabled) $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forState: .selected) }