68 lines
2.0 KiB
Swift
68 lines
2.0 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 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
|
|
}
|
|
}
|