added isEnabled for setters where disabled is set

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-25 13:03:34 -05:00
parent 8489ba9085
commit 5811fa7a01
18 changed files with 57 additions and 7 deletions

View File

@ -143,7 +143,7 @@ public class ControlColorConfiguration: KeyColorConfigurable {
///Meant to be used with any object that implements Surfaceable and Disabling. More than likely this is any View.
public class ViewColorConfiguration: KeyColorConfigurable {
public typealias KeyType = Bool
public typealias ObjectType = Surfaceable & Disabling
public typealias ObjectType = Surfaceable & Disabling & Enabling
public var keyColors: [KeyColorConfiguration<KeyType>] = []
public required init() { }
@ -161,7 +161,7 @@ public class ViewColorConfiguration: KeyColorConfigurable {
/// - Parameter object: Object that implements Surfaceable and Disabling
/// - Returns: UIColor correspoding to either true/false for the disabled state and surface
public func getColor(_ object: ObjectType) -> UIColor {
if let keyColor = keyColors.first(where: {$0.key == object.disabled }) {
if let keyColor = keyColors.first(where: {$0.key == !object.isEnabled }) {
return keyColor.surfaceConfig.getColor(object)
} else {
return .clear //default

View File

@ -37,6 +37,14 @@ open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
}
}
override open var isEnabled: Bool {
didSet {
selectorViews.forEach { handler in
handler.isEnabled = isEnabled
}
}
}
/// Current Surface and this is used to pass down to child objects that implement Surfacable.
override open var surface: Surface {
didSet {

View File

@ -192,6 +192,7 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
selectorView.isSelected = isSelected
selectorView.isHighlighted = isHighlighted
selectorView.disabled = disabled
selectorView.isEnabled = isEnabled
selectorView.surface = surface
}
@ -238,6 +239,7 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
if let labelText {
label.surface = surface
label.disabled = disabled
label.isEnabled = isEnabled
label.attributes = labelTextAttributes
label.text = labelText
label.isHidden = false
@ -253,6 +255,7 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
childLabel.text = childText
childLabel.surface = surface
childLabel.disabled = disabled
childLabel.isEnabled = isEnabled
childLabel.attributes = childTextAttributes
childLabel.isHidden = false
@ -277,6 +280,7 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
errorLabel.text = errorText
errorLabel.surface = surface
errorLabel.disabled = disabled
errorLabel.isEnabled = isEnabled
mainStackView.spacing = 8
errorLabel.isHidden = false
} else {

View File

@ -158,5 +158,6 @@ open class Badge: View {
label.text = text
label.surface = surface
label.disabled = disabled
label.isEnabled = isEnabled
}
}

View File

@ -342,6 +342,7 @@ open class BadgeIndicator: View {
label.text = getText()
label.surface = surface
label.disabled = disabled
label.isEnabled = isEnabled
label.sizeToFit()
setNeedsLayout()
layoutIfNeeded()

View File

@ -11,7 +11,7 @@ import VDSColorTokens
import VDSFormControlsTokens
import Combine
public protocol Buttonable: UIControl, Surfaceable, Disabling {
public protocol Buttonable: UIControl, Surfaceable, Disabling, Enabling {
var availableSizes: [ButtonSize] { get }
var text: String? { get set }
var intrinsicContentSize: CGSize { get }

View File

@ -103,6 +103,16 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
}
}
/// Whether this object is enabled or not
override open var isEnabled: Bool {
didSet {
buttons.forEach { button in
var b = button
b.isEnabled = isEnabled
}
}
}
/// Current Surface and this is used to pass down to child objects that implement Surfacable
override open var surface: Surface {
didSet {

View File

@ -41,6 +41,7 @@ open class CheckboxGroup: SelectorGroupHandlerBase<CheckboxItem> {
selectorViews = selectorModels.enumerated().map { index, model in
return CheckboxItem().with {
$0.disabled = model.disabled
$0.isEnabled = !model.disabled
$0.surface = model.surface
$0.inputId = model.inputId
$0.value = model.value

View File

@ -44,6 +44,7 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase<RadioBoxItem> {
$0.subTextRight = model.subText
$0.subTextRightAttributes = model.subTextAttributes
$0.disabled = model.disabled
$0.isEnabled = !model.disabled
$0.inputId = model.inputId
$0.isSelected = model.selected
}

View File

@ -188,6 +188,7 @@ open class RadioBoxItem: Control, Changeable {
textLabel.text = text
textLabel.surface = surface
textLabel.disabled = disabled
textLabel.isEnabled = isEnabled
textLabel.attributes = textAttributes
//subText label
@ -195,6 +196,7 @@ open class RadioBoxItem: Control, Changeable {
subTextLabel.text = subText
subTextLabel.surface = surface
subTextLabel.disabled = disabled
subTextLabel.isEnabled = isEnabled
subTextLabel.attributes = subTextAttributes
subTextLabel.isHidden = false
@ -210,6 +212,7 @@ open class RadioBoxItem: Control, Changeable {
subTextRightLabel.text = subTextRight
subTextRightLabel.surface = surface
subTextRightLabel.disabled = disabled
subTextRightLabel.isEnabled = isEnabled
subTextRightLabel.attributes = subTextRightAttributes
subTextRightLabel.isHidden = false

View File

@ -36,6 +36,7 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase<RadioButtonItem> {
selectorViews = selectorModels.enumerated().map { index, model in
return RadioButtonItem().with {
$0.disabled = model.disabled
$0.isEnabled = !model.disabled
$0.surface = model.surface
$0.inputId = model.inputId
$0.value = model.value

View File

@ -33,6 +33,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase<RadioSwatch>, UICo
$0.secondaryColor = model.secondaryColor
$0.strikethrough = model.strikethrough
$0.disabled = model.disabled
$0.isEnabled = !model.disabled
$0.surface = model.surface
$0.inputId = model.inputId
$0.value = model.value
@ -80,6 +81,17 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase<RadioSwatch>, UICo
collectionView.reloadData()
}
}
/// Whether this object is disabled or not
override public var isEnabled: Bool {
didSet {
for selector in selectorViews {
selector.isEnabled = isEnabled
}
collectionView.reloadData()
}
}
/// Current Surface and this is used to pass down to child objects that implement Surfacable
override public var surface: Surface {
didSet {
@ -133,6 +145,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase<RadioSwatch>, UICo
label.text = selectedHandler?.text ?? " "
label.surface = surface
label.disabled = disabled
label.isEnabled = isEnabled
collectionView.reloadData()
}
@ -151,7 +164,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase<RadioSwatch>, UICo
// MARK: - UICollectionViewDelegate
//--------------------------------------------------
open func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
return !selectorViews[indexPath.row].disabled
return selectorViews[indexPath.row].isEnabled
}
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

View File

@ -164,6 +164,7 @@ open class TabsContainer: View {
tabMenu.surface = surface
tabMenu.disabled = disabled
tabMenu.isEnabled = isEnabled
tabMenu.orientation = orientation
tabMenu.borderLine = borderLine
tabMenu.fillContainer = fillContainer

View File

@ -302,7 +302,7 @@ open class EntryField: Control, Changeable {
titleLabel.attributes = attributes
titleLabel.surface = surface
titleLabel.disabled = disabled
titleLabel.isEnabled = isEnabled
}
open func updateErrorLabel(){
@ -310,6 +310,7 @@ open class EntryField: Control, Changeable {
errorLabel.text = errorText
errorLabel.surface = surface
errorLabel.disabled = disabled
errorLabel.isEnabled = isEnabled
errorLabel.isHidden = false
icon.name = .error
icon.color = VDSColor.paletteBlack
@ -327,6 +328,7 @@ open class EntryField: Control, Changeable {
helperLabel.text = helperText
helperLabel.surface = surface
helperLabel.disabled = disabled
helperLabel.isEnabled = isEnabled
helperLabel.isHidden = false
} else {
helperLabel.isHidden = true

View File

@ -176,6 +176,7 @@ open class InputField: EntryField, UITextFieldDelegate {
successLabel.text = successText
successLabel.surface = surface
successLabel.disabled = disabled
successLabel.isEnabled = isEnabled
successLabel.isHidden = false
errorLabel.isHidden = true
icon.name = .checkmarkAlt

View File

@ -200,6 +200,7 @@ open class Toggle: Control, Changeable {
updateLabel()
toggleView.surface = surface
toggleView.disabled = disabled
toggleView.isEnabled = isEnabled
toggleView.isOn = isOn
}
@ -235,6 +236,7 @@ open class Toggle: Control, Changeable {
label.text = statusText
label.surface = surface
label.disabled = disabled
label.isEnabled = isEnabled
switch textPosition {
case .left:
NSLayoutConstraint.deactivate(rightConstraints)

View File

@ -72,7 +72,8 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
label.attributes = labelAttributes
label.surface = surface
label.disabled = disabled
label.isEnabled = isEnabled
//add tooltip
if let labelText, !labelText.isEmpty {
label.addTooltip(model: .init(surface: surface, closeButtonText: tooltipCloseButtonText, title: tooltipTitle, content: tooltipContent, contentView: tooltipContentView))

View File

@ -9,7 +9,7 @@ import Foundation
import UIKit
import Combine
public protocol ViewProtocol: AnyObject, Initable, Resettable, Disabling, Surfaceable {
public protocol ViewProtocol: AnyObject, Initable, Resettable, Disabling, Enabling, Surfaceable {
/// Set of Subscribers for any Publishers for this Control.
var subscribers: Set<AnyCancellable> { get set }