more documentation also made text optional in radiobox

fixed bug in model setting

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-28 18:15:10 -05:00
parent c8ee289640
commit 08fd42fcb9
2 changed files with 41 additions and 17 deletions

View File

@ -66,8 +66,8 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase<RadioBoxItem> {
$0.textAttributes = model.textAttributes $0.textAttributes = model.textAttributes
$0.subText = model.subText $0.subText = model.subText
$0.subTextAttributes = model.subTextAttributes $0.subTextAttributes = model.subTextAttributes
$0.subTextRight = model.subText $0.subTextRight = model.subTextRight
$0.subTextRightAttributes = model.subTextAttributes $0.subTextRightAttributes = model.subTextRightAttributes
$0.isEnabled = !model.disabled $0.isEnabled = !model.disabled
$0.inputId = model.inputId $0.inputId = model.inputId
$0.isSelected = model.selected $0.isSelected = model.selected

View File

@ -12,7 +12,7 @@ import VDSColorTokens
import VDSFormControlsTokens import VDSFormControlsTokens
@objc(VDSRadioBoxItem) @objc(VDSRadioBoxItem)
open class RadioBoxItem: Control, Changeable { open class RadioBoxItem: Control, Changeable, FormFieldable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
@ -49,7 +49,8 @@ open class RadioBoxItem: Control, Changeable {
private var selectorLeftLabelStackView = UIStackView().with { private var selectorLeftLabelStackView = UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
$0.axis = .vertical $0.axis = .vertical
$0.spacing = 4 $0.alignment = .top
$0.spacing = 0
$0.isHidden = false $0.isHidden = false
} }
@ -64,33 +65,39 @@ open class RadioBoxItem: Control, Changeable {
} }
} }
/// Label used to render the text.
open var textLabel = Label().with { open var textLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
$0.textPosition = .left $0.textPosition = .left
$0.textStyle = .boldBodyLarge $0.textStyle = .boldBodyLarge
} }
/// Label used to render the subText.
open var subTextLabel = Label().with { open var subTextLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
$0.textPosition = .left $0.textPosition = .left
$0.textStyle = .bodyLarge $0.textStyle = .bodyLarge
} }
/// Label used to render the subTextRight.
open var subTextRightLabel = Label().with { open var subTextRightLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
$0.textPosition = .right $0.textPosition = .right
$0.textStyle = .bodyLarge $0.textStyle = .bodyLarge
} }
/// Selector for this RadioBox.
open var selectorView = UIView().with { open var selectorView = UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
} }
open var text: String = "Default Text" { didSet { setNeedsUpdate() }} /// If provided, the RadioBox text will be rendered.
open var text: String? { didSet { setNeedsUpdate() }}
/// Array of LabelAttributeModel objects used in rendering the text. /// Array of LabelAttributeModel objects used in rendering the text.
open var textAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }} open var textAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
/// If provided, the RadioBox textAttributedText will be rendered.
open var textAttributedText: NSAttributedString? { open var textAttributedText: NSAttributedString? {
didSet { didSet {
textLabel.useAttributedText = !(textAttributedText?.string.isEmpty ?? true) textLabel.useAttributedText = !(textAttributedText?.string.isEmpty ?? true)
@ -99,11 +106,13 @@ open class RadioBoxItem: Control, Changeable {
} }
} }
/// If provided, the RadioBox subtext will be rendered.
open var subText: String? { didSet { setNeedsUpdate() }} open var subText: String? { didSet { setNeedsUpdate() }}
/// Array of LabelAttributeModel objects used in rendering the subText. /// Array of LabelAttributeModel objects used in rendering the subText.
open var subTextAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }} open var subTextAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
/// If provided, the RadioBox subTextAttributedText will be rendered.
open var subTextAttributedText: NSAttributedString? { open var subTextAttributedText: NSAttributedString? {
didSet { didSet {
subTextLabel.useAttributedText = !(subTextAttributedText?.string.isEmpty ?? true) subTextLabel.useAttributedText = !(subTextAttributedText?.string.isEmpty ?? true)
@ -112,11 +121,13 @@ open class RadioBoxItem: Control, Changeable {
} }
} }
/// If provided, the RadioBox subtextRight will be rendered.
open var subTextRight: String? { didSet { setNeedsUpdate() }} open var subTextRight: String? { didSet { setNeedsUpdate() }}
/// Array of LabelAttributeModel objects used in rendering the subTextRight. /// Array of LabelAttributeModel objects used in rendering the subTextRight.
open var subTextRightAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }} open var subTextRightAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
/// If provided, the RadioBox subTextRightAttributedText will be rendered.
open var subTextRightAttributedText: NSAttributedString? { open var subTextRightAttributedText: NSAttributedString? {
didSet { didSet {
subTextRightLabel.useAttributedText = !(subTextRightAttributedText?.string.isEmpty ?? true) subTextRightLabel.useAttributedText = !(subTextRightAttributedText?.string.isEmpty ?? true)
@ -125,6 +136,7 @@ open class RadioBoxItem: Control, Changeable {
} }
} }
/// If provided, the radio box will be rendered to show the option with a strikethrough.
open var strikethrough: Bool = false { didSet { setNeedsUpdate() }} open var strikethrough: Bool = false { didSet { setNeedsUpdate() }}
open var inputId: String? { didSet { setNeedsUpdate() }} open var inputId: String? { didSet { setNeedsUpdate() }}
@ -198,7 +210,7 @@ open class RadioBoxItem: Control, Changeable {
subTextLabel.textStyle = .bodyLarge subTextLabel.textStyle = .bodyLarge
subTextRightLabel.textStyle = .bodyLarge subTextRightLabel.textStyle = .bodyLarge
text = "Default Text" text = nil
textAttributes = nil textAttributes = nil
textAttributedText = nil textAttributedText = nil
subText = nil subText = nil
@ -246,21 +258,31 @@ open class RadioBoxItem: Control, Changeable {
//-------------------------------------------------- //--------------------------------------------------
func updateLabels() { func updateLabels() {
var leftCount = 0
//add the stackview to hold the 2 labels //add the stackview to hold the 2 labels
//text label //text label
textLabel.text = text if let text, !text.isEmpty {
textLabel.surface = surface textLabel.text = text
textLabel.isEnabled = isEnabled textLabel.surface = surface
textLabel.attributes = textAttributes textLabel.isEnabled = isEnabled
textLabel.attributes = textAttributes
textLabel.isHidden = false
leftCount += 1
} else if textAttributedText != nil {
textLabel.isHidden = false
} else {
textLabel.isHidden = true
}
//subText label //subText label
if let subText { if let subText, !subText.isEmpty {
subTextLabel.text = subText subTextLabel.text = subText
subTextLabel.surface = surface subTextLabel.surface = surface
subTextLabel.isEnabled = isEnabled subTextLabel.isEnabled = isEnabled
subTextLabel.attributes = subTextAttributes subTextLabel.attributes = subTextAttributes
subTextLabel.isHidden = false subTextLabel.isHidden = false
leftCount += 1
} else if subTextAttributedText != nil { } else if subTextAttributedText != nil {
subTextLabel.isHidden = false subTextLabel.isHidden = false
@ -269,7 +291,7 @@ open class RadioBoxItem: Control, Changeable {
} }
//subTextRight label //subTextRight label
if let subTextRight { if let subTextRight, !subTextRight.isEmpty {
subTextRightLabel.text = subTextRight subTextRightLabel.text = subTextRight
subTextRightLabel.surface = surface subTextRightLabel.surface = surface
subTextRightLabel.isEnabled = isEnabled subTextRightLabel.isEnabled = isEnabled
@ -282,6 +304,8 @@ open class RadioBoxItem: Control, Changeable {
} else { } else {
subTextRightLabel.isHidden = true subTextRightLabel.isHidden = true
} }
selectorLeftLabelStackView.spacing = leftCount > 1 ? 4 : 0
} }
//-------------------------------------------------- //--------------------------------------------------