Digital ACT-191 ONEAPP-7135 story: using tooltip model
This commit is contained in:
parent
530a6786d8
commit
a6f03e3e1e
@ -34,7 +34,7 @@ open class DropdownSelect: Control {
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
///Boolean value that determines if component should show the error state/error message.
|
||||
/// Boolean value that determines if component should show the error state/error message.
|
||||
open var error: Bool = false { didSet { setNeedsUpdate() }}
|
||||
|
||||
/// Message displayed when there is an error.
|
||||
@ -43,7 +43,7 @@ open class DropdownSelect: Control {
|
||||
/// If provided, will be used as text for the helper label.
|
||||
open var helperText: String? { didSet { setNeedsUpdate() }}
|
||||
|
||||
/// used if the component is enabled or not.
|
||||
/// Used if the component is enabled or not.
|
||||
open override var isEnabled: Bool { didSet { setNeedsUpdate() }}
|
||||
|
||||
/// If true, the label will be displayed inside the dropdown container. Otherwise, the label will be above the dropdown container like a normal text input.
|
||||
@ -61,40 +61,19 @@ open class DropdownSelect: Control {
|
||||
/// Allows unique ID to be passed to the element.
|
||||
open var selectId: String? { didSet { setNeedsUpdate() }}
|
||||
|
||||
// TO DO: either have model or individual title and content.
|
||||
/// Config object for tooltip option, is optional.
|
||||
open var tooltipModel: Tooltip.TooltipModel? { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// Used to set tooltip title.
|
||||
open var tooltipTitle: String {
|
||||
get { return _tooltipTitle }
|
||||
set {
|
||||
_tooltipTitle = newValue
|
||||
updateTooltip()
|
||||
setNeedsUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
/// Used to set tooltip content.
|
||||
open var tooltipContent: String {
|
||||
get { return _tooltipContent }
|
||||
set {
|
||||
_tooltipContent = newValue
|
||||
updateTooltip()
|
||||
setNeedsUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
/// If provided, will render with trnasparent background.
|
||||
open var transparentBackground: Bool = false { didSet { setNeedsUpdate() }}
|
||||
|
||||
/// Used to set width for the Dropdown Select.
|
||||
open var width: Int? { didSet { setNeedsUpdate() }}
|
||||
|
||||
// TO DO: create model for options
|
||||
/// TO DO: create model for options
|
||||
open var options: [String]? { didSet { setNeedsUpdate() }}
|
||||
|
||||
///Boolean or a Function that returns a boolean value that determines if component should show the error state/error message.Functon receives the 'event' object on input change.
|
||||
/// Boolean value that determines if component should show the error state/error message. Functon receives the 'event' object on input change.
|
||||
open var showError: Bool = false { didSet { setNeedsUpdate() }}
|
||||
|
||||
open override var state: UIControl.State {
|
||||
@ -110,10 +89,6 @@ open class DropdownSelect: Control {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
internal var _tooltipTitle: String = ""
|
||||
|
||||
internal var _tooltipContent: String = ""
|
||||
|
||||
internal var minWidthDefault = 66.0
|
||||
internal var minWidthInlineLabel = 102.0
|
||||
|
||||
@ -210,9 +185,8 @@ open class DropdownSelect: Control {
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Lifecycle
|
||||
// MARK: - Overrides
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
@ -227,6 +201,7 @@ open class DropdownSelect: Control {
|
||||
|
||||
dropdownField.width(0)
|
||||
|
||||
// container stack
|
||||
let spacing = VDSFormControls.spaceInset
|
||||
containerStack.pinToSuperView(.init(top: spacing, left: spacing, bottom: spacing, right: spacing))
|
||||
containerStack.addArrangedSubview(dropdownField)
|
||||
@ -238,6 +213,7 @@ open class DropdownSelect: Control {
|
||||
containerStack.setCustomSpacing(VDSLayout.Spacing.space1X.value, after: inlineDisplayLabel)
|
||||
containerStack.setCustomSpacing(VDSLayout.Spacing.space3X.value, after: selectedOptionLabel)
|
||||
|
||||
// component stack
|
||||
stackView.addArrangedSubview(eyebrowLabel)
|
||||
stackView.addArrangedSubview(container)
|
||||
stackView.addArrangedSubview(errorLabel)
|
||||
@ -272,40 +248,7 @@ open class DropdownSelect: Control {
|
||||
}.store(in: &subscribers)
|
||||
}
|
||||
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
|
||||
eyebrowLabel.reset()
|
||||
inlineDisplayLabel.reset()
|
||||
selectedOptionLabel.reset()
|
||||
errorLabel.reset()
|
||||
helperLabel.reset()
|
||||
|
||||
eyebrowLabel.labelTextAlignment = .left
|
||||
eyebrowLabel.labelTextStyle = .bodySmall
|
||||
inlineDisplayLabel.textStyle = .boldBodyLarge
|
||||
inlineDisplayLabel.textAlignment = .left
|
||||
selectedOptionLabel.textStyle = .bodyLarge
|
||||
selectedOptionLabel.textAlignment = .left
|
||||
errorLabel.textAlignment = .left
|
||||
errorLabel.textStyle = .bodySmall
|
||||
helperLabel.textAlignment = .left
|
||||
helperLabel.textStyle = .bodySmall
|
||||
tooltipModel = nil
|
||||
tooltipTitle = ""
|
||||
tooltipContent = ""
|
||||
label = nil
|
||||
errorText = nil
|
||||
error = false
|
||||
isEnabled = false
|
||||
readOnly = false
|
||||
inlineLabel = false
|
||||
helperText = nil
|
||||
transparentBackground = false
|
||||
required = false
|
||||
options = []
|
||||
}
|
||||
|
||||
/// Used to make changes to the View based off a change events or from local properties.
|
||||
open override func updateView() {
|
||||
container.backgroundColor = backgroundColorConfiguration.getColor(self)
|
||||
container.layer.borderColor = containerBorderColorConfiguration.getColor(self).cgColor
|
||||
@ -331,8 +274,41 @@ open class DropdownSelect: Control {
|
||||
}
|
||||
}
|
||||
|
||||
/// Resets to default settings.
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
|
||||
eyebrowLabel.reset()
|
||||
inlineDisplayLabel.reset()
|
||||
selectedOptionLabel.reset()
|
||||
errorLabel.reset()
|
||||
helperLabel.reset()
|
||||
|
||||
eyebrowLabel.labelTextStyle = .bodySmall
|
||||
inlineDisplayLabel.textStyle = .boldBodyLarge
|
||||
selectedOptionLabel.textStyle = .bodyLarge
|
||||
errorLabel.textStyle = .bodySmall
|
||||
helperLabel.textStyle = .bodySmall
|
||||
tooltipModel = nil
|
||||
label = nil
|
||||
errorText = nil
|
||||
error = false
|
||||
isEnabled = false
|
||||
readOnly = false
|
||||
inlineLabel = false
|
||||
helperText = nil
|
||||
transparentBackground = false
|
||||
required = false
|
||||
options = []
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
open func updateTitleLabel() {
|
||||
|
||||
//update the local vars for the label since we no long have a model
|
||||
var attributes: [any LabelAttributeModel] = []
|
||||
var updatedLabelText = label
|
||||
|
||||
@ -347,7 +323,6 @@ open class DropdownSelect: Control {
|
||||
attributes.append(optionColorAttr)
|
||||
}
|
||||
|
||||
// updateTooltip()
|
||||
if let tooltipModel {
|
||||
attributes.append(TooltipLabelAttribute(surface: surface, model: tooltipModel, presenter: self))
|
||||
}
|
||||
@ -357,20 +332,15 @@ open class DropdownSelect: Control {
|
||||
eyebrowLabel.tooltipModel = tooltipModel
|
||||
eyebrowLabel.surface = surface
|
||||
eyebrowLabel.isEnabled = isEnabled
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
open func updateInlineLabel() {
|
||||
|
||||
///Minimum width with inline text as per design
|
||||
widthConstraint?.constant = inlineLabel ? minWidthInlineLabel : minWidthDefault
|
||||
widthConstraint?.isActive = true
|
||||
|
||||
// inlineDisplayLabel.text = inlineLabel ? (label!.isEmpty ? ((label ?? "") + ":") : label) : ""
|
||||
// inlineDisplayLabel.text = inlineLabel ? (label!.isEmpty ? ((label ?? "") + ":") : label) : ""
|
||||
inlineDisplayLabel.text = inlineLabel ? label : ""
|
||||
inlineDisplayLabel.surface = surface
|
||||
inlineWidthConstraint?.constant = inlineDisplayLabel.intrinsicContentSize.width
|
||||
@ -381,7 +351,7 @@ open class DropdownSelect: Control {
|
||||
selectedOptionLabel.text = text ?? ""
|
||||
}
|
||||
|
||||
open func updateErrorLabel(){
|
||||
open func updateErrorLabel() {
|
||||
if showError, let errorText {
|
||||
errorLabel.text = errorText
|
||||
errorLabel.surface = surface
|
||||
@ -398,8 +368,7 @@ open class DropdownSelect: Control {
|
||||
}
|
||||
}
|
||||
|
||||
open func updateHelperLabel(){
|
||||
|
||||
open func updateHelperLabel() {
|
||||
if let helperText {
|
||||
helperLabel.text = helperText
|
||||
helperLabel.surface = surface
|
||||
@ -432,12 +401,6 @@ open class DropdownSelect: Control {
|
||||
inputToolbar.sizeToFit()
|
||||
return inputToolbar
|
||||
}
|
||||
|
||||
func updateTooltip() {
|
||||
self.tooltipModel = .init(title: tooltipTitle, content: tooltipContent)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension DropdownSelect: UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user