vds_ios/VDS/Components/Selector/SelectorModel.swift
Matt Bruce a671765e80 moved selectable into own protocol
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-08-23 12:54:57 -05:00

64 lines
1.9 KiB
Swift

//
// SelectorModel.swift
// VDS
//
// Created by Matt Bruce on 8/8/22.
//
import Foundation
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 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.textPosition = .left
model.typograpicalStyle = .BoldBodyLarge
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.textPosition = .left
model.typograpicalStyle = .BodyLarge
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.textPosition = .left
model.typograpicalStyle = .BodyMedium
model.text = errorText
model.surface = surface
model.disabled = disabled
return model
}
}