// // CheckboxViewController.swift // VDSSample // // Created by Matt Bruce on 8/1/22. // import Foundation import UIKit import VDS import VDSColorTokens import Combine class CheckboxViewController: ModelScrollViewController { var disabledSwitch = UISwitch() var labelTextField = TextField() var childTextField = TextField() var errorTextField = TextField() var showErrorSwitch = UISwitch() var checkbox = SoloCheckbox() override func viewDidLoad() { super.viewDidLoad() addContentTopView(view: checkbox) setupForm() setupPicker() setupModel() } func setupForm(){ 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 .publisher(for: .valueChanged) .sink { [weak self] sender in self?.checkbox.showError = sender.isOn }.store(in: &subscribers) disabledSwitch .publisher(for: .valueChanged) .sink { [weak self] sender in self?.checkbox.disabled = sender.isOn }.store(in: &subscribers) labelTextField .textPublisher .sink { [weak self] text in self?.checkbox.labelText = text }.store(in: &subscribers) childTextField .textPublisher .sink { [weak self] text in self?.checkbox.childText = text }.store(in: &subscribers) errorTextField .textPublisher .sink { [weak self] text in self?.checkbox.errorText = text }.store(in: &subscribers) } func setupModel() { checkbox.labelText = "Terms and conditions" checkbox.childText = "I agree to Verizon's terms and conditions click here" checkbox.errorText = "Error Text" checkbox .publisher(for: .valueChanged) .sink { checkbox in print("checkbox selected: \(checkbox.isSelected)") }.store(in: &subscribers) //setup UI surfacePickerSelectorView.text = checkbox.surface.rawValue disabledSwitch.isOn = checkbox.disabled labelTextField.text = checkbox.labelText childTextField.text = checkbox.childText showErrorSwitch.isOn = checkbox.showError errorTextField.text = checkbox.errorText } //Picker func setupPicker(){ surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.checkbox.surface = item self?.contentTopView.backgroundColor = item.color } } }