vds_ios_sample/VDSSample/ViewControllers/BreadcrumbItemViewController.swift

83 lines
2.5 KiB
Swift

//
// BreadcrumbItemViewController.swift
// VDSSample
//
// Created by Kanamarlapudi, Vasavi on 11/03/24.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
class BreadcrumbItemViewController: BaseViewController<BreadcrumbItem> {
var label = Label()
var disabledSwitch = Toggle()
var selectedSwitch = Toggle()
var textField = TextField()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: .makeWrapper(for: component, edgeSpacing: 16.0), edgeSpacing: 0.0)
setupPicker()
setupModel()
}
override func allTextFields() -> [TextField]? { [textField] }
override func setupForm(){
super.setupForm()
addFormRow(label: "Action", view: label)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Label", view: textField)
addFormRow(label: "selected", view: selectedSwitch)
disabledSwitch.onChange = { [weak self] sender in
self?.component.isEnabled = !sender.isOn
}
selectedSwitch.onChange = { [weak self] sender in
guard let self else { return }
self.component.selectable = !self.component.selectable
}
textField
.textPublisher
.sink { [weak self] text in
self?.component.text = text
}.store(in: &subscribers)
}
func setupModel() {
component.text = "Billing statement FAQs"
component.labelPublisher(label)
// component.selectable = selectedSwitch.isOn
//setup UI
surfacePickerSelectorView.text = component.surface.rawValue
disabledSwitch.isOn = !component.isEnabled
// selectedSwitch.isOn = !component.isSelected
textField.text = component.text
}
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.surface = item
self?.contentTopView.backgroundColor = item.color
}
}
}
extension BreadcrumbItemViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.text = "Billing statement FAQs"
component.onClick = { c in print("\(c.text!) Click")}
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
}
}