Merge branch 'update/SelectorView' into 'develop'

updated groups to allow models

See merge request BPHV_MIPS/vds_ios!58
This commit is contained in:
Bruce, Matt R 2023-04-27 12:30:22 +00:00
commit 7596541e34
7 changed files with 265 additions and 17 deletions

View File

@ -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
}
}
}

View File

@ -21,13 +21,38 @@ open class CheckboxGroup: SelectorGroupHandlerBase<Checkbox> {
}
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<Checkbox> {
}
}
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)
}
}
}

View File

@ -15,18 +15,41 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase<RadioBox> {
// 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<RadioBox> {
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)
}
}
}

View File

@ -15,13 +15,38 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase<RadioButton> {
// 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> {
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)
}
}
}

View File

@ -20,6 +20,28 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase<RadioSwatch>, 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<RadioSwatch>, 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)
}
}
}

View File

@ -7,6 +7,6 @@
import Foundation
public protocol Disabling: AnyObject {
public protocol Disabling {
var disabled: Bool { get set }
}

View File

@ -16,6 +16,6 @@ public enum Surface: String, Equatable {
}
}
public protocol Surfaceable: AnyObject {
public protocol Surfaceable {
var surface: Surface { get set }
}