From 8cbef2e910de6307c0375de310410ffda57990e5 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 26 Apr 2023 16:11:15 -0500 Subject: [PATCH] added model extensions on selectorviews Signed-off-by: Matt Bruce --- VDS/Components/Checkbox/CheckboxGroup.swift | 56 ++++++++++++++++++ VDS/Components/RadioBox/RadioBoxGroup.swift | 57 +++++++++++++++++++ .../RadioButton/RadioButtonGroup.swift | 56 ++++++++++++++++++ .../RadioSwatch/RadioSwatchGroup.swift | 55 ++++++++++++++++++ 4 files changed, 224 insertions(+) diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index 384e342a..d6a28a98 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -82,3 +82,59 @@ 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) + } + } + + public func setSelectorViewModels(models: [CheckboxModel]) { + selectorViews = models.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 + } + } + } + +} diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index 14d61275..6299eb7a 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -80,3 +80,60 @@ 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) + } + } + + public func setSelectorViewModels(models: [RadioBoxModel]) { + selectorViews = models.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 + } + } + } +} diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 0477eb1b..88e17440 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -86,3 +86,59 @@ 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) + } + } + + public func setSelectorViewModels(models: [RadioButtonModel]) { + selectorViews = models.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 + } + } + } +} diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 5d0485b7..c6362f33 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -165,3 +165,58 @@ 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) + } + } + + public func setSelectorViewModels(models: [RadioSwatchModel]) { + selectorViews = models.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 + } + } + } +} +