Digital ACT-191 ONEAPP-7135 story: added DropdownSelect component
This commit is contained in:
parent
ec42be0fc0
commit
250a1b4e5f
@ -10,5 +10,128 @@ import VDS
|
||||
|
||||
class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
||||
|
||||
var disabledSwitch = Toggle()
|
||||
var requiredSwitch = Toggle()
|
||||
var labelTextField = TextField()
|
||||
var errorTextField = TextField()
|
||||
var helperTextField = TextField()
|
||||
var inlineLabelSwitch = Toggle()
|
||||
var errorSwitch = Toggle()
|
||||
var tooltipTitleTextField = TextField()
|
||||
var tooltipContentTextField = TextField()
|
||||
var optionsField = TextField()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
addContentTopView(view: component)
|
||||
setupModel()
|
||||
setupPicker()
|
||||
}
|
||||
|
||||
override func setupForm(){
|
||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||
addFormRow(label: "Required", view: requiredSwitch)
|
||||
addFormRow(label: "Label Text", view: labelTextField)
|
||||
addFormRow(label: "Helper Text", view: helperTextField)
|
||||
addFormRow(label: "Inline Label", view: .makeWrapper(for: inlineLabelSwitch))
|
||||
addFormRow(label: "Error", view: .makeWrapper(for: errorSwitch))
|
||||
addFormRow(label: "Error Text", view: errorTextField)
|
||||
addFormRow(label: "ToolTip Title", view: tooltipTitleTextField)
|
||||
addFormRow(label: "ToolTip Content", view: tooltipContentTextField)
|
||||
addFormRow(label: "Options", view: optionsField)
|
||||
|
||||
disabledSwitch.onChange = { [weak self] sender in
|
||||
self?.component.isEnabled = !sender.isOn
|
||||
}
|
||||
|
||||
requiredSwitch.onChange = { [weak self] sender in
|
||||
self?.component.required = sender.isOn
|
||||
}
|
||||
|
||||
errorSwitch
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { [weak self] sender in
|
||||
guard let self else { return }
|
||||
component.showError = sender.isOn
|
||||
if component.showError != sender.isOn {
|
||||
self.errorSwitch.isOn = self.component.showError
|
||||
}
|
||||
}.store(in: &subscribers)
|
||||
|
||||
labelTextField
|
||||
.textPublisher
|
||||
.sink { [weak self] text in
|
||||
self?.component.label = text
|
||||
}.store(in: &subscribers)
|
||||
|
||||
helperTextField
|
||||
.textPublisher
|
||||
.sink { [weak self] text in
|
||||
self?.component.helperText = text
|
||||
}.store(in: &subscribers)
|
||||
|
||||
errorTextField
|
||||
.textPublisher
|
||||
.sink { [weak self] text in
|
||||
self?.component.errorText = text
|
||||
}.store(in: &subscribers)
|
||||
|
||||
tooltipTitleTextField
|
||||
.textPublisher
|
||||
.sink { [weak self] text in
|
||||
self?.component.tooltipTitle = text
|
||||
}.store(in: &subscribers)
|
||||
|
||||
tooltipContentTextField
|
||||
.textPublisher
|
||||
.sink { [weak self] text in
|
||||
self?.component.tooltipContent = text
|
||||
}.store(in: &subscribers)
|
||||
|
||||
inlineLabelSwitch
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { [weak self] sender in
|
||||
guard let self else { return }
|
||||
self.component.inlineLabel = sender.isOn
|
||||
}.store(in: &subscribers)
|
||||
|
||||
optionsField
|
||||
.textPublisher
|
||||
.sink { [weak self] options in
|
||||
self?.component.options = options.components(separatedBy: ",")
|
||||
}.store(in: &subscribers)
|
||||
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
|
||||
component.label = "Street Address"
|
||||
component.helperText = "For example: 123 Verizon St"
|
||||
component.errorText = "Enter a valid address."
|
||||
component.tooltipTitle = "Check the formatting of your address"
|
||||
component.tooltipContent = "House/Building Number then street name"
|
||||
component.options = ["One", "Two", "Three"]
|
||||
|
||||
//setup UI
|
||||
disabledSwitch.isOn = !component.isEnabled
|
||||
requiredSwitch.isOn = component.required
|
||||
surfacePickerSelectorView.text = component.surface.rawValue
|
||||
labelTextField.text = component.label
|
||||
helperTextField.text = component.helperText
|
||||
errorSwitch.isOn = component.showError
|
||||
errorTextField.text = component.errorText
|
||||
tooltipTitleTextField.text = component.tooltipTitle
|
||||
tooltipContentTextField.text = component.tooltipContent
|
||||
optionsField.text = "One,Two,Three"
|
||||
}
|
||||
|
||||
//Picker
|
||||
func setupPicker(){
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
self?.component.surface = item
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user