diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index ae46f80b..e1dc6d18 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -101,7 +101,8 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega override public var disabled: Bool { didSet { buttons.forEach { button in - button.disabled = disabled + var b = button + b.disabled = disabled } } } @@ -109,7 +110,8 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega override public var surface: Surface { didSet { buttons.forEach { button in - button.surface = surface + var b = button + b.surface = surface } } } diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index 384e342a..b994a9cf 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -21,13 +21,38 @@ open class CheckboxGroup: SelectorGroupHandlerBase { } public override var selectorViews: [Checkbox] { + willSet { + mainStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } + } + didSet { for selector in selectorViews { - if !mainStackView.arrangedSubviews.contains(selector) { - selector.onClick = { [weak self] handler in - self?.didSelect(handler) + selector.onClick = { [weak self] handler in + self?.didSelect(handler) + } + mainStackView.addArrangedSubview(selector) + } + } + } + + public var selectorModels: [CheckboxModel]? { + didSet { + if let selectorModels { + selectorViews = selectorModels.map { model in + return Checkbox().with { + $0.disabled = model.disabled + $0.surface = model.surface + $0.inputId = model.inputId + $0.value = model.value + $0.accessibilityLabel = model.accessibileText + $0.labelText = model.labelText + $0.labelTextAttributes = model.labelTextAttributes + $0.childText = model.childText + $0.childTextAttributes = model.childTextAttributes + $0.isSelected = model.selected + $0.errorText = model.errorText + $0.showError = model.showError } - mainStackView.addArrangedSubview(selector) } } } @@ -82,3 +107,40 @@ open class CheckboxGroup: SelectorGroupHandlerBase { } } +extension CheckboxGroup { + public struct CheckboxModel : Surfaceable, Disabling, Initable, FormFieldable, Errorable { + + public var disabled: Bool + public var surface: Surface + public var inputId: String? + public var value: AnyHashable? + public var accessibileText: String? + public var labelText: String? + public var labelTextAttributes: [any LabelAttributeModel]? + public var childText: String? + public var childTextAttributes: [any LabelAttributeModel]? + public var selected: Bool + public var showError: Bool + public var errorText: String? + + public init(disabled: Bool, surface: Surface = .light, inputId: String? = nil, value: AnyHashable? = nil, accessibileText: String? = nil, labelText: String? = nil, labelTextAttributes: [any LabelAttributeModel]? = nil, childText: String? = nil, childTextAttributes: [any LabelAttributeModel]? = nil, selected: Bool = false, showError: Bool = false, errorText: String? = nil) { + self.disabled = disabled + self.surface = surface + self.inputId = inputId + self.value = value + self.accessibileText = accessibileText + self.labelText = labelText + self.labelTextAttributes = labelTextAttributes + self.childText = childText + self.childTextAttributes = childTextAttributes + self.selected = selected + self.showError = showError + self.errorText = errorText + } + + public init() { + self.init(disabled: false) + } + } + +} diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index 14d61275..9c39bf19 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -15,18 +15,41 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase { // MARK: - Public Properties //-------------------------------------------------- public override var selectorViews: [RadioBox] { + willSet { + mainStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } + } + didSet { for selector in selectorViews { - if !mainStackView.arrangedSubviews.contains(selector) { - selector.onClick = { [weak self] handler in - self?.didSelect(handler) - } - mainStackView.addArrangedSubview(selector) + selector.onClick = { [weak self] handler in + self?.didSelect(handler) } + mainStackView.addArrangedSubview(selector) } } } + public var selectorModels: [RadioBoxModel]? { + didSet { + if let selectorModels { + selectorViews = selectorModels.map { model in + return RadioBox().with { + $0.accessibilityLabel = model.accessibileText + $0.text = model.text + $0.textAttributes = model.textAttributes + $0.subText = model.subText + $0.subTextAttributes = model.subTextAttributes + $0.subTextRight = model.subText + $0.subTextRightAttributes = model.subTextAttributes + $0.disabled = model.disabled + $0.inputId = model.inputId + $0.isSelected = model.selected + } + } + } + } + } + //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- @@ -80,3 +103,43 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase { valueChanged() } } + +extension RadioBoxGroup { + public struct RadioBoxModel: Surfaceable, Initable, Disabling, FormFieldable { + public var disabled: Bool + public var surface: Surface + public var inputId: String? + public var value: AnyHashable? + public var accessibileText: String? + public var text: String + public var textAttributes: [any LabelAttributeModel]? + public var subText: String? + public var subTextAttributes: [any LabelAttributeModel]? + public var subTextRight: String? + public var subTextRightAttributes: [any LabelAttributeModel]? + public var selected: Bool + + public init(disabled: Bool, surface: Surface = .light, inputId: String? = nil, value: AnyHashable? = nil, + text: String = "", textAttributes: [any LabelAttributeModel]? = nil, + subText: String? = nil, subTextAttributes: [any LabelAttributeModel]? = nil, + subTextRight: String? = nil, subTextRightAttributes: [any LabelAttributeModel]? = nil, + selected: Bool = false, errorText: String? = nil, accessibileText: String? = nil) { + self.disabled = disabled + self.surface = surface + self.inputId = inputId + self.value = value + self.text = text + self.textAttributes = textAttributes + self.subText = subText + self.subTextAttributes = subTextAttributes + self.subTextRight = subTextRight + self.subTextRightAttributes = subTextRightAttributes + self.selected = selected + self.accessibileText = accessibileText + } + + public init() { + self.init(disabled: false) + } + } +} diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 0477eb1b..ffdfdde3 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -15,13 +15,38 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase { // MARK: - Public Properties //-------------------------------------------------- public override var selectorViews: [RadioButton] { + willSet { + mainStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } + } + didSet { for selector in selectorViews { - if !mainStackView.arrangedSubviews.contains(selector) { - selector.onClick = { [weak self] handler in - self?.didSelect(handler) + selector.onClick = { [weak self] handler in + self?.didSelect(handler) + } + mainStackView.addArrangedSubview(selector) + } + } + } + + public var selectorModels: [RadioButtonModel]? { + didSet { + if let selectorModels { + selectorViews = selectorModels.map { model in + return RadioButton().with { + $0.disabled = model.disabled + $0.surface = model.surface + $0.inputId = model.inputId + $0.value = model.value + $0.accessibilityLabel = model.accessibileText + $0.labelText = model.labelText + $0.labelTextAttributes = model.labelTextAttributes + $0.childText = model.childText + $0.childTextAttributes = model.childTextAttributes + $0.isSelected = model.selected + $0.errorText = model.errorText + $0.showError = model.showError } - mainStackView.addArrangedSubview(selector) } } } @@ -86,3 +111,40 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase { radioButton.isSelected.toggle() } } + +extension RadioButtonGroup { + public struct RadioButtonModel: Surfaceable, Disabling, Initable, FormFieldable, Errorable { + + public var disabled: Bool + public var surface: Surface + public var inputId: String? + public var value: AnyHashable? + public var accessibileText: String? + public var labelText: String? + public var labelTextAttributes: [any LabelAttributeModel]? + public var childText: String? + public var childTextAttributes: [any LabelAttributeModel]? + public var selected: Bool + public var showError: Bool + public var errorText: String? + + public init(disabled: Bool, surface: Surface = .light, inputId: String? = nil, value: AnyHashable? = nil, accessibileText: String? = nil, labelText: String? = nil, labelTextAttributes: [any LabelAttributeModel]? = nil, childText: String? = nil, childTextAttributes: [any LabelAttributeModel]? = nil, selected: Bool = false, showError: Bool = false, errorText: String? = nil) { + self.disabled = disabled + self.surface = surface + self.inputId = inputId + self.value = value + self.accessibileText = accessibileText + self.labelText = labelText + self.labelTextAttributes = labelTextAttributes + self.childText = childText + self.childTextAttributes = childTextAttributes + self.selected = selected + self.showError = showError + self.errorText = errorText + } + + public init() { + self.init(disabled: false) + } + } +} diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 5d0485b7..0a5b15da 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -20,6 +20,28 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo collectionView.reloadData() } } + + public var selectorModels: [RadioSwatchModel]? { + didSet { + if let selectorModels { + selectorViews = selectorModels.map { model in + return RadioSwatch().with { + $0.accessibilityLabel = model.accessibileText + $0.text = model.text + $0.fillImage = model.fillImage + $0.primaryColor = model.primaryColor + $0.secondaryColor = model.secondaryColor + $0.strikethrough = model.strikethrough + $0.disabled = model.disabled + $0.surface = model.surface + $0.inputId = model.inputId + $0.value = model.value + $0.isSelected = model.selected + } + } + } + } + } //-------------------------------------------------- // MARK: - Private Properties @@ -165,3 +187,40 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo valueChanged() } } + +extension RadioSwatchGroup { + public struct RadioSwatchModel: Surfaceable, Disabling, Initable { + public var disabled: Bool = false + public var surface: Surface + public var inputId: String? + public var value: AnyHashable? + public var selected: Bool = false + public var text: String + public var fillImage: UIImage? + public var primaryColor: UIColor? + public var secondaryColor: UIColor? + public var strikethrough: Bool = false + public var accessibileText: String? + + public init(disabled: Bool, surface: Surface = .light, inputId: String? = nil, value: AnyHashable? = nil, selected: Bool = false, + text: String = "", fillImage: UIImage? = nil, primaryColor: UIColor? = nil, secondaryColor: UIColor? = nil, + strikethrough: Bool = false, accessibileText: String? = nil) { + self.disabled = disabled + self.surface = surface + self.inputId = inputId + self.value = value + self.selected = selected + self.text = text + self.fillImage = fillImage + self.primaryColor = primaryColor + self.secondaryColor = secondaryColor + self.strikethrough = strikethrough + self.accessibileText = accessibileText + } + + public init() { + self.init(disabled: false) + } + } +} + diff --git a/VDS/Protocols/Disabling.swift b/VDS/Protocols/Disabling.swift index e800e174..c0be6d22 100644 --- a/VDS/Protocols/Disabling.swift +++ b/VDS/Protocols/Disabling.swift @@ -7,6 +7,6 @@ import Foundation -public protocol Disabling: AnyObject { +public protocol Disabling { var disabled: Bool { get set } } diff --git a/VDS/Protocols/Surfaceable.swift b/VDS/Protocols/Surfaceable.swift index 916167f1..d7889f04 100644 --- a/VDS/Protocols/Surfaceable.swift +++ b/VDS/Protocols/Surfaceable.swift @@ -16,6 +16,6 @@ public enum Surface: String, Equatable { } } -public protocol Surfaceable: AnyObject { +public protocol Surfaceable { var surface: Surface { get set } }