71 lines
2.0 KiB
Swift
71 lines
2.0 KiB
Swift
//
|
|
// CheckboxViewController.swift
|
|
// VDSSample
|
|
//
|
|
// Created by Matt Bruce on 8/1/22.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VDS
|
|
import VDSColorTokens
|
|
import Combine
|
|
|
|
class CheckboxViewController: BaseViewController<Checkbox> {
|
|
|
|
var disabledSwitch = Toggle()
|
|
var showErrorSwitch = Toggle()
|
|
let toggle = UISwitch()
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
addContentTopView(view: .makeWrapper(for: component, edgeSpacing: 16.0), edgeSpacing: 0.0)
|
|
setupPicker()
|
|
setupModel()
|
|
}
|
|
|
|
override func setupForm(){
|
|
super.setupForm()
|
|
addActionRow()
|
|
addFormRow(label: "Disabled", view: disabledSwitch)
|
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
|
addFormRow(label: "Error", view: showErrorSwitch)
|
|
|
|
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
|
|
}
|
|
|
|
component.onChangeActionPublisher("Checkbox", label: actionLabel)
|
|
}
|
|
|
|
func setupModel() {
|
|
//setup UI
|
|
surfacePickerSelectorView.text = component.surface.rawValue
|
|
disabledSwitch.isOn = !component.isEnabled
|
|
showErrorSwitch.isOn = component.showError
|
|
|
|
}
|
|
|
|
//Picker
|
|
func setupPicker(){
|
|
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.surface = item
|
|
self?.contentTopView.backgroundColor = item.color
|
|
}
|
|
}
|
|
}
|
|
|
|
extension CheckboxViewController: ComponentSampleable {
|
|
static func makeSample() -> ComponentSample {
|
|
let component = Self.makeComponent()
|
|
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
|
|
}
|
|
}
|