refactored toggle to match updated property names
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
087691bc62
commit
1f91459b9e
@ -107,26 +107,14 @@ open class ToggleBase<ModelType: ToggleModel>: Control<ModelType> {
|
||||
@Proxy(\.model.offText)
|
||||
public var offText: String
|
||||
|
||||
public var fontSize: TypographicalStyle.FontSize = .small{
|
||||
didSet {
|
||||
updateTypography()
|
||||
}
|
||||
}
|
||||
@Proxy(\.model.textSize)
|
||||
public var textSize: ToggleTextSize
|
||||
|
||||
public var isBold: Bool = false {
|
||||
didSet {
|
||||
updateTypography()
|
||||
}
|
||||
}
|
||||
@Proxy(\.model.textWeight)
|
||||
public var textWeight: ToggleTextWeight
|
||||
|
||||
@Proxy(\.model.textPosition)
|
||||
public var textPosition: TextPosition {
|
||||
didSet {
|
||||
if oldValue != textPosition {
|
||||
updateLabel(model)
|
||||
}
|
||||
}
|
||||
}
|
||||
public var textPosition: ToggleTextPosition
|
||||
|
||||
@Proxy(\.model.inputId)
|
||||
open var inputId: String?
|
||||
@ -161,25 +149,6 @@ open class ToggleBase<ModelType: ToggleModel>: Control<ModelType> {
|
||||
@Proxy(\.model.accessibilityLabelDisabled)
|
||||
open var accessibilityLabelDisabled: String?
|
||||
|
||||
//only allows
|
||||
//fontSize: small, large
|
||||
//fontWeight: regular, bold
|
||||
private func updateTypography() {
|
||||
if fontSize == .small {
|
||||
if isBold {
|
||||
model.typograpicalStyle = .BoldBodySmall
|
||||
} else {
|
||||
model.typograpicalStyle = .BodySmall
|
||||
}
|
||||
} else {
|
||||
if isBold {
|
||||
model.typograpicalStyle = .BoldBodyLarge
|
||||
} else {
|
||||
model.typograpicalStyle = .BodyLarge
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Constraints
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -8,19 +8,50 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public protocol ToggleModel: Modelable, FormFieldable, DataTrackable, Accessable, Labelable, BinaryColorable {
|
||||
public enum ToggleTextSize: String, CaseIterable {
|
||||
case small, large
|
||||
}
|
||||
|
||||
public enum ToggleTextWeight: String, CaseIterable {
|
||||
case regular, bold
|
||||
}
|
||||
|
||||
public enum ToggleTextPosition: String, CaseIterable {
|
||||
case left, right
|
||||
}
|
||||
|
||||
public protocol ToggleModel: Modelable, FormFieldable, DataTrackable, Accessable, BinaryColorable {
|
||||
var showText: Bool { get set }
|
||||
var on: Bool { get set }
|
||||
var offText: String { get set }
|
||||
var onText: String { get set }
|
||||
var textWeight: ToggleTextWeight { get set }
|
||||
var textSize: ToggleTextSize { get set }
|
||||
var textPosition: ToggleTextPosition { get set }
|
||||
}
|
||||
|
||||
extension ToggleModel {
|
||||
public var userTrueColor: Bool { return on }
|
||||
|
||||
public var labelModel: DefaultLabelModel {
|
||||
|
||||
var typograpicalStyle: TypographicalStyle
|
||||
if textSize == .small {
|
||||
if textWeight == .bold {
|
||||
typograpicalStyle = .BoldBodySmall
|
||||
} else {
|
||||
typograpicalStyle = .BodySmall
|
||||
}
|
||||
} else {
|
||||
if textWeight == .bold {
|
||||
typograpicalStyle = .BoldBodyLarge
|
||||
} else {
|
||||
typograpicalStyle = .BodyLarge
|
||||
}
|
||||
}
|
||||
|
||||
var model = DefaultLabelModel()
|
||||
model.textPosition = textPosition
|
||||
model.textPosition = textPosition == .left ? .left : .right
|
||||
model.typograpicalStyle = typograpicalStyle
|
||||
model.text = on ? onText : offText
|
||||
model.surface = surface
|
||||
@ -36,8 +67,9 @@ public struct DefaultToggleModel: ToggleModel {
|
||||
public var offText: String = "Off"
|
||||
public var onText: String = "On"
|
||||
|
||||
public var typograpicalStyle: TypographicalStyle = .BodySmall
|
||||
public var textPosition: TextPosition = .left
|
||||
public var textWeight: ToggleTextWeight = .regular
|
||||
public var textSize: ToggleTextSize = .small
|
||||
public var textPosition: ToggleTextPosition = .left
|
||||
|
||||
public var inputId: String?
|
||||
public var value: AnyHashable? = true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user