// // RadioButtonItemViewController.swift // VDSSample // // Created by Matt Bruce on 7/18/23. // import Foundation import UIKit import VDS import VDSTokens import Combine class RadioButtonItemViewController: BaseViewController { var disabledSwitch = Toggle() var labelTextField = TextField() var childTextField = TextField() var errorTextField = TextField() var showErrorSwitch = Toggle() override func viewDidLoad() { super.viewDidLoad() addContentTopView(view: component) setupPicker() setupModel() } override func setupForm(){ super.setupForm() addActionRow() addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Label Text", view: labelTextField) addFormRow(label: "Child Text", view: childTextField) addFormRow(label: "Error", view: showErrorSwitch) addFormRow(label: "Error Text", view: errorTextField) showErrorSwitch.onChange = { [weak self] sender in guard let self else { return } self.component.showError = sender.isOn if self.component.showError != sender.isOn { self.showErrorSwitch.isOn = self.component.showError } } disabledSwitch.onChange = { [weak self] sender in self?.component.isEnabled = !sender.isOn } labelTextField .textPublisher .sink { [weak self] text in self?.component.labelText = text }.store(in: &subscribers) childTextField .textPublisher .sink { [weak self] text in self?.component.childText = text }.store(in: &subscribers) errorTextField .textPublisher .sink { [weak self] text in self?.component.errorText = text }.store(in: &subscribers) } func setupModel() { component.labelText = "Terms and conditions" component.childText = "I agree to Verizon's terms and conditions click here" component.errorText = "Error Text" component.onChange = { [weak self] item in let newText = "\(item.labelText!): \(item.isSelected)" self?.showErrorSwitch.isOn = item.showError self?.actionLabel.text = newText } //setup UI surfacePickerSelectorView.text = component.surface.rawValue disabledSwitch.isOn = !component.isEnabled labelTextField.text = component.labelText childTextField.text = component.childText showErrorSwitch.isOn = component.showError errorTextField.text = component.errorText } //Picker func setupPicker(){ surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.surface = item self?.contentTopView.backgroundColor = item.color } } } extension RadioButtonItemViewController: ComponentSampleable { static func makeSample() -> ComponentSample { let component = Self.makeComponent() component.labelText = "Terms and conditions" component.childText = "I agree to Verizon's terms and conditions click here" component.errorText = "Error Text" return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual) } }