vds_ios/VDS/Components/Selector/SelectorModel.swift
Matt Bruce 9d440aaeac refactored to hasError
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-08-11 17:30:54 -05:00

79 lines
2.2 KiB
Swift

//
// SelectorModel.swift
// VDS
//
// Created by Matt Bruce on 8/8/22.
//
import Foundation
public protocol Selectable {
var selected: Bool { get set }
}
public protocol SelectorModel: Modelable, FormFieldable, Errorable, DataTrackable, Accessable, Selectable {
var labelText: String? { get set }
var labelTextAttributes: [LabelAttributeModel]? { get set }
var childText: String? { get set }
var childTextAttributes: [LabelAttributeModel]? { get set }
}
extension SelectorModel {
public var fontCategory: FontCategory {
get { return .body }
set { return }
}
public var shouldShowError: Bool {
guard hasError && !disabled && errorText?.isEmpty == false else { return false }
return true
}
public var shouldShowLabels: Bool {
guard labelText?.isEmpty == false || childText?.isEmpty == false else { return false }
return true
}
public var labelModel: DefaultLabelModel? {
guard let labelText = labelText else { return nil }
var model = DefaultLabelModel()
model.fontSize = .large
model.textPosition = .left
model.fontWeight = .bold
model.fontCategory = .body
model.text = labelText
model.surface = surface
model.disabled = disabled
model.attributes = labelTextAttributes
return model
}
public var childModel: DefaultLabelModel? {
guard let childText = childText else { return nil }
var model = DefaultLabelModel()
model.fontSize = .large
model.textPosition = .left
model.fontWeight = .regular
model.fontCategory = .body
model.text = childText
model.surface = surface
model.disabled = disabled
model.attributes = childTextAttributes
return model
}
public var errorModel: DefaultLabelModel? {
guard let errorText = errorText, hasError else { return nil }
var model = DefaultLabelModel()
model.fontSize = .medium
model.textPosition = .left
model.fontWeight = .regular
model.fontCategory = .body
model.text = errorText
model.surface = surface
model.disabled = disabled
return model
}
}