108 lines
3.2 KiB
Swift
108 lines
3.2 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 labelTextAttributes: [LabelAttributeModel]? { get set }
|
|
var childText: String? { get set }
|
|
var childTextAttributes: [LabelAttributeModel]? { get set }
|
|
}
|
|
|
|
extension CheckboxModel {
|
|
public var fontCategory: FontCategory {
|
|
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
|
|
model.attributes = labelTextAttributes
|
|
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
|
|
model.attributes = childTextAttributes
|
|
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 labelTextAttributes: [LabelAttributeModel]?
|
|
public var childText: String?
|
|
public var childTextAttributes: [LabelAttributeModel]?
|
|
|
|
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() {}
|
|
}
|