112 lines
3.4 KiB
Swift
112 lines
3.4 KiB
Swift
//
|
|
// ButtonViewController.swift
|
|
// VDSSample
|
|
//
|
|
// Created by Jarrod Courtney on 9/16/22.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VDS
|
|
import VDSColorTokens
|
|
|
|
class ButtonViewController: BaseViewController<Button> {
|
|
|
|
lazy var usePickerSelectorView = {
|
|
PickerSelectorView<Use>(title: "",
|
|
picker: self.picker,
|
|
items: [.primary, .secondary])
|
|
}()
|
|
|
|
lazy var buttonSizePickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: ButtonSize.allCases)
|
|
}()
|
|
|
|
var label = Label()
|
|
var disabledSwitch = Toggle()
|
|
var textField = TextField()
|
|
var widthTextField = NumericField()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
addContentTopView(view: .makeWrapper(for: component, edgeSpacing: 16.0), edgeSpacing: 0.0)
|
|
|
|
setupPicker()
|
|
setupModel()
|
|
}
|
|
|
|
override func setupForm(){
|
|
super.setupForm()
|
|
addFormRow(label: "Action", view: label)
|
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
|
addFormRow(label: "Use", view: usePickerSelectorView)
|
|
addFormRow(label: "Disabled", view: disabledSwitch)
|
|
addFormRow(label: "Text", view: textField)
|
|
addFormRow(label: "Width", view: widthTextField)
|
|
addFormRow(label: "Size", view: buttonSizePickerSelectorView)
|
|
|
|
|
|
disabledSwitch.onChange = { [weak self] sender in
|
|
self?.component.disabled = sender.isOn
|
|
}
|
|
|
|
textField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.component.text = text
|
|
}.store(in: &subscribers)
|
|
|
|
widthTextField
|
|
.numberPublisher
|
|
.sink { [weak self] number in
|
|
guard let self, let number else { return }
|
|
self.component.width = number.cgFloatValue
|
|
}.store(in: &subscribers)
|
|
|
|
}
|
|
|
|
func setupModel() {
|
|
//setup UI
|
|
component.text = "Button"
|
|
component.labelPublisher(label)
|
|
|
|
surfacePickerSelectorView.text = component.surface.rawValue
|
|
disabledSwitch.isOn = component.disabled
|
|
textField.text = component.text
|
|
usePickerSelectorView.text = component.use.rawValue
|
|
widthTextField.text = ""
|
|
buttonSizePickerSelectorView.text = ButtonSize.large.rawValue
|
|
}
|
|
|
|
func setupPicker(){
|
|
|
|
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.surface = item
|
|
self?.contentTopView.backgroundColor = item.color
|
|
}
|
|
|
|
usePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.use = item
|
|
self?.component.backgroundColor = item.color
|
|
}
|
|
|
|
buttonSizePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.size = item
|
|
self?.debugViewSwitch.toggle()
|
|
}
|
|
}
|
|
}
|
|
|
|
extension ButtonViewController: Componentable {
|
|
static func getComponent() -> TestViewWrapper {
|
|
let component = Self.makeComponent()
|
|
component.text = "Try me"
|
|
component.onClick = { c in print("\(c.text!) Click")}
|
|
component.use = .primary
|
|
component.size = .large
|
|
return TestViewWrapper(component: component, isTrailing: true)
|
|
}
|
|
}
|