updated documentation

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-30 10:18:19 -05:00
parent c0236a433c
commit d78a87273e
2 changed files with 22 additions and 6 deletions

View File

@ -13,7 +13,7 @@ import Combine
/// A toggle is a control that lets customers instantly turn on
/// or turn off a single option, setting or function.
@objc(VDSToggle)
open class Toggle: Control, Changeable {
open class Toggle: Control, Changeable, FormFieldable {
//--------------------------------------------------
// MARK: - Initializers
@ -33,14 +33,17 @@ open class Toggle: Control, Changeable {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
/// Enum for the size of text for the label.
public enum TextSize: String, CaseIterable {
case small, large
}
/// Enum to determine of the weight for the text style used for the label.
public enum TextWeight: String, CaseIterable {
case regular, bold
}
/// Enum for the text alignment in relation to the toggle view.
public enum TextPosition: String, CaseIterable {
case left, right
}
@ -94,12 +97,14 @@ open class Toggle: Control, Changeable {
}
}
/// Actual toggle used in this component.
open var toggleView = ToggleView().with {
$0.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
$0.isUserInteractionEnabled = false
$0.isAccessibilityElement = false
}
/// Used in showing the on/off text.
open var label = Label().with {
$0.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
$0.setContentHuggingPriority(.defaultHigh, for: .horizontal)
@ -110,6 +115,7 @@ open class Toggle: Control, Changeable {
}.eraseToAnyColorable()
}
/// State of the toggle view.
open var isOn: Bool {
get { isSelected }
set {
@ -120,20 +126,28 @@ open class Toggle: Control, Changeable {
}
}
/// If set to true, the toggle view will include animation between state changes.
open var isAnimated: Bool = true { didSet { setNeedsUpdate() }}
/// If set to true, displays text either to the right or left of the toggle.
open var showText: Bool = false { didSet { setNeedsUpdate() }}
/// Text that will be shown in the status text when isOn is true
open var onText: String = "On" { didSet { setNeedsUpdate() }}
/// Text that will be shown in the status text when isOn is false
open var offText: String = "Off" { didSet { setNeedsUpdate() }}
/// Returns the correct text status based on the isOn state and correlates with onText or offText.
open var statusText: String { isOn ? onText : offText }
/// Changes the font size of the status text.
open var textSize: TextSize = .small { didSet { setNeedsUpdate() }}
/// Changes the font weight of the status text.
open var textWeight: TextWeight = .regular { didSet { setNeedsUpdate() }}
/// Positions status text to either the right or left of toggle.
open var textPosition: TextPosition = .left { didSet { setNeedsUpdate() }}
open var inputId: String? { didSet { setNeedsUpdate() }}

View File

@ -13,7 +13,7 @@ import Combine
/// A toggle is a control that lets customers instantly turn on
/// or turn off a single option, setting or function.
@objc(VDSToggleView)
open class ToggleView: Control, Changeable {
open class ToggleView: Control, Changeable, FormFieldable {
//--------------------------------------------------
// MARK: - Initializers
@ -52,7 +52,8 @@ open class ToggleView: Control, Changeable {
// MARK: - Public Properties
//--------------------------------------------------
open var onChangeSubscriber: AnyCancellable?
/// State of the toggle view.
open var isOn: Bool {
get { isSelected }
set {
@ -62,7 +63,7 @@ open class ToggleView: Control, Changeable {
setNeedsUpdate()
}
}
/// If set to true, the toggle view will include animation between state changes.
open var isAnimated: Bool = true { didSet { setNeedsUpdate() }}
open var inputId: String? { didSet { setNeedsUpdate() }}
@ -76,8 +77,9 @@ open class ToggleView: Control, Changeable {
// MARK: - Configuration Properties
//--------------------------------------------------
// Sizes are from InVision design specs.
public let toggleSize = CGSize(width: 52, height: 28)
public let knobSize = CGSize(width: 24, height: 24)
private let toggleSize = CGSize(width: 52, height: 28)
private let knobSize = CGSize(width: 24, height: 24)
private var toggleColorConfiguration = ControlColorConfiguration().with {
$0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.paletteGray44, forState: .normal)