vds_ios/VDS/Components/Checkbox/CheckboxModel.swift
Matt Bruce ffe3641500 refactored out VDS from naming conventions
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-08-03 13:56:14 -05:00

102 lines
2.8 KiB
Swift

//
// ToggleModel.swift
// VDS
//
// Created by Matt Bruce on 7/22/22.
//
import Foundation
import UIKit
public protocol CheckboxModel: FormFieldable, Errorable, DataTrackable, Accessable, Surfaceable, Disabling, Initable {
var id: String? { get set }
var on: Bool { get set }
var labelText: String? { get set }
var childText: String? { get set }
}
extension CheckboxModel {
public var fontCategory: VDSFontCategory {
get { return .body }
set { return }
}
public var shouldShowError: Bool {
guard showError && !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: LabelModel? {
guard let labelText = labelText else { return nil }
let model = DefaultLabelModel()
model.fontSize = .large
model.textPosition = .left
model.fontWeight = .bold
model.fontCategory = .body
model.text = labelText
model.surface = surface
model.disabled = disabled
return model
}
public var childModel: LabelModel? {
guard let childText = childText else { return nil }
let model = DefaultLabelModel()
model.fontSize = .large
model.textPosition = .left
model.fontWeight = .regular
model.fontCategory = .body
model.text = childText
model.surface = surface
model.disabled = disabled
return model
}
public var errorModel: LabelModel? {
guard let errorText = errorText, showError else { return nil }
let 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
}
}
public struct DefaultCheckboxModel: CheckboxModel {
public var id: String?
public var on: Bool = false
public var labelText: String?
public var childText: String?
public var showError: Bool = false
public var errorText: String?
public var inputId: String?
public var value: AnyHashable?
public var surface: Surface = .light
public var disabled: Bool = false
public var dataAnalyticsTrack: String?
public var dataClickStream: String?
public var dataTrack: String?
public var accessibilityHintEnabled: String?
public var accessibilityHintDisabled: String?
public var accessibilityValueEnabled: String?
public var accessibilityValueDisabled: String?
public var accessibilityLabelEnabled: String?
public var accessibilityLabelDisabled: String?
public init() {}
}