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:
parent
c8ee289640
commit
08fd42fcb9
@ -66,8 +66,8 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase<RadioBoxItem> {
|
||||
$0.textAttributes = model.textAttributes
|
||||
$0.subText = model.subText
|
||||
$0.subTextAttributes = model.subTextAttributes
|
||||
$0.subTextRight = model.subText
|
||||
$0.subTextRightAttributes = model.subTextAttributes
|
||||
$0.subTextRight = model.subTextRight
|
||||
$0.subTextRightAttributes = model.subTextRightAttributes
|
||||
$0.isEnabled = !model.disabled
|
||||
$0.inputId = model.inputId
|
||||
$0.isSelected = model.selected
|
||||
|
||||
@ -12,7 +12,7 @@ import VDSColorTokens
|
||||
import VDSFormControlsTokens
|
||||
|
||||
@objc(VDSRadioBoxItem)
|
||||
open class RadioBoxItem: Control, Changeable {
|
||||
open class RadioBoxItem: Control, Changeable, FormFieldable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -49,7 +49,8 @@ open class RadioBoxItem: Control, Changeable {
|
||||
private var selectorLeftLabelStackView = UIStackView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.axis = .vertical
|
||||
$0.spacing = 4
|
||||
$0.alignment = .top
|
||||
$0.spacing = 0
|
||||
$0.isHidden = false
|
||||
}
|
||||
|
||||
@ -64,33 +65,39 @@ open class RadioBoxItem: Control, Changeable {
|
||||
}
|
||||
}
|
||||
|
||||
/// Label used to render the text.
|
||||
open var textLabel = Label().with {
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.textPosition = .left
|
||||
$0.textStyle = .boldBodyLarge
|
||||
}
|
||||
|
||||
|
||||
/// Label used to render the subText.
|
||||
open var subTextLabel = Label().with {
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.textPosition = .left
|
||||
$0.textStyle = .bodyLarge
|
||||
}
|
||||
|
||||
/// Label used to render the subTextRight.
|
||||
open var subTextRightLabel = Label().with {
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.textPosition = .right
|
||||
$0.textStyle = .bodyLarge
|
||||
}
|
||||
|
||||
|
||||
/// Selector for this RadioBox.
|
||||
open var selectorView = UIView().with {
|
||||
$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.
|
||||
open var textAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
|
||||
|
||||
/// If provided, the RadioBox textAttributedText will be rendered.
|
||||
open var textAttributedText: NSAttributedString? {
|
||||
didSet {
|
||||
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() }}
|
||||
|
||||
/// Array of LabelAttributeModel objects used in rendering the subText.
|
||||
open var subTextAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
|
||||
|
||||
|
||||
/// If provided, the RadioBox subTextAttributedText will be rendered.
|
||||
open var subTextAttributedText: NSAttributedString? {
|
||||
didSet {
|
||||
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() }}
|
||||
|
||||
/// Array of LabelAttributeModel objects used in rendering the subTextRight.
|
||||
open var subTextRightAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
|
||||
|
||||
/// If provided, the RadioBox subTextRightAttributedText will be rendered.
|
||||
open var subTextRightAttributedText: NSAttributedString? {
|
||||
didSet {
|
||||
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 inputId: String? { didSet { setNeedsUpdate() }}
|
||||
@ -198,7 +210,7 @@ open class RadioBoxItem: Control, Changeable {
|
||||
subTextLabel.textStyle = .bodyLarge
|
||||
subTextRightLabel.textStyle = .bodyLarge
|
||||
|
||||
text = "Default Text"
|
||||
text = nil
|
||||
textAttributes = nil
|
||||
textAttributedText = nil
|
||||
subText = nil
|
||||
@ -246,30 +258,40 @@ open class RadioBoxItem: Control, Changeable {
|
||||
//--------------------------------------------------
|
||||
func updateLabels() {
|
||||
|
||||
var leftCount = 0
|
||||
//add the stackview to hold the 2 labels
|
||||
//text label
|
||||
textLabel.text = text
|
||||
textLabel.surface = surface
|
||||
textLabel.isEnabled = isEnabled
|
||||
textLabel.attributes = textAttributes
|
||||
if let text, !text.isEmpty {
|
||||
textLabel.text = text
|
||||
textLabel.surface = surface
|
||||
textLabel.isEnabled = isEnabled
|
||||
textLabel.attributes = textAttributes
|
||||
textLabel.isHidden = false
|
||||
leftCount += 1
|
||||
} else if textAttributedText != nil {
|
||||
textLabel.isHidden = false
|
||||
|
||||
} else {
|
||||
textLabel.isHidden = true
|
||||
}
|
||||
|
||||
//subText label
|
||||
if let subText {
|
||||
if let subText, !subText.isEmpty {
|
||||
subTextLabel.text = subText
|
||||
subTextLabel.surface = surface
|
||||
subTextLabel.isEnabled = isEnabled
|
||||
subTextLabel.attributes = subTextAttributes
|
||||
subTextLabel.isHidden = false
|
||||
|
||||
leftCount += 1
|
||||
} else if subTextAttributedText != nil {
|
||||
subTextLabel.isHidden = false
|
||||
|
||||
|
||||
} else {
|
||||
subTextLabel.isHidden = true
|
||||
}
|
||||
|
||||
//subTextRight label
|
||||
if let subTextRight {
|
||||
if let subTextRight, !subTextRight.isEmpty {
|
||||
subTextRightLabel.text = subTextRight
|
||||
subTextRightLabel.surface = surface
|
||||
subTextRightLabel.isEnabled = isEnabled
|
||||
@ -282,6 +304,8 @@ open class RadioBoxItem: Control, Changeable {
|
||||
} else {
|
||||
subTextRightLabel.isHidden = true
|
||||
}
|
||||
|
||||
selectorLeftLabelStackView.spacing = leftCount > 1 ? 4 : 0
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user