component tester

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-12 10:03:33 -05:00
parent 62ee98c34e
commit 6f86f8755b
5 changed files with 77 additions and 12 deletions

View File

@ -98,3 +98,14 @@ class ButtonViewController: BaseViewController<Button> {
}
}
}
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)
}
}

View File

@ -10,16 +10,20 @@ import UIKit
import VDS
import VDSColorTokens
public typealias TestView = UIView
public typealias TestView = UIView & Surfaceable
public typealias TestViewWrapper = (component: TestView, isTrailing: Bool)
protocol Componentable {
static func getComponent() -> TestViewWrapper
}
public class TableViewTestController: UITableViewController, Initable {
public class TableViewTestController: UITableViewController, Initable, Surfaceable {
var components:[TestViewWrapper] = []
public var surface: Surface = .light {
didSet {
tableView.reloadData()
}
}
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
@ -44,12 +48,27 @@ public class TableViewTestController: UITableViewController, Initable {
tableView.separatorStyle = .none
tableView.rowHeight = UITableView.automaticDimension
tableView.reloadData()
let view = View(frame: .init(origin: .zero, size: .init(width: tableView.bounds.width, height: 100)))
let toggle = Toggle().with {
$0.showText = true
$0.textPosition = .right
$0.offText = "Light"
$0.onText = "Dark"
$0.onChange = { [weak self] toggle in
self?.surface = toggle.isOn ? .dark : .light
}
}
view.addSubview(toggle)
toggle.pinToSuperView(.init(top: 5, left: 16, bottom: 5, right: 16))
tableView.tableHeaderView = view
tableView.tableHeaderView?.frame.size.height = 40
}
public override func numberOfSections(in tableView: UITableView) -> Int {
components.count
}
public override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = UIView().with { $0.backgroundColor = VDSColor.paletteGray44 }
let label = Label().with {
@ -74,7 +93,9 @@ public class TableViewTestController: UITableViewController, Initable {
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? VDSCell else { return UITableViewCell() }
let wrapper = components[indexPath.row]
cell.prepareForReuse()
cell.surface = surface
let wrapper = components[indexPath.section]
cell.component = wrapper.component
cell.isTrailing = wrapper.isTrailing
return cell
@ -82,12 +103,18 @@ public class TableViewTestController: UITableViewController, Initable {
}
public class VDSCell: UITableViewCell, AppleGuidlinesTouchable {
public class VDSCell: UITableViewCell, AppleGuidlinesTouchable, Surfaceable {
public var isTrailing: Bool = true
public var surface: Surface = .light
public var component: TestView? {
didSet {
guard let component else { return }
contentView.addSubview(.makeWrapper(for: component, edgeSpacing: 16, isTrailing: isTrailing))
contentView.subviews.forEach { $0.removeFromSuperview() }
guard var component else { return }
let wrapper = UIView.makeWrapper(for: component, isTrailing: isTrailing)
contentView.addSubview(wrapper)
wrapper.pinToSuperView(.init(top: 16, left: 16, bottom: 16, right: 16))
backgroundColor = surface.color
component.surface = surface
}
}
@ -100,10 +127,5 @@ public class VDSCell: UITableViewCell, AppleGuidlinesTouchable {
return component.intrinsicContentSize
}
public override func prepareForReuse() {
super.prepareForReuse()
contentView.subviews.forEach { $0.removeFromSuperview() }
}
}

View File

@ -72,3 +72,12 @@ class TextLinkCaretViewController: BaseViewController<TextLinkCaret> {
}
}
}
extension TextLinkCaretViewController: Componentable {
static func getComponent() -> TestViewWrapper {
let component = Self.makeComponent()
component.text = "Text Link Caret"
component.onClick = { c in print("\(c.text!) Click")}
return TestViewWrapper(component: component, isTrailing: true)
}
}

View File

@ -74,3 +74,12 @@ class TextLinkViewController: BaseViewController<TextLink> {
}
}
}
extension TextLinkViewController: Componentable {
static func getComponent() -> TestViewWrapper {
let component = Self.makeComponent()
component.text = "Text Link"
component.onClick = { c in print("\(c.text!) Click")}
return TestViewWrapper(component: component, isTrailing: true)
}
}

View File

@ -229,3 +229,17 @@ class TileletViewController: BaseViewController<Tilelet> {
}
}
}
extension TileletViewController: Componentable {
static func getComponent() -> TestViewWrapper {
let component = Self.makeComponent()
let titleModel = Tilelet.TitleModel(text: "Save $XX on your monthly bill.")
let subTitleModel = Tilelet.SubTitleModel(text: "Enroll in Auto Pay & paper-free billing to save on your monthly bill.")
component.surface = .light
component.titleModel = titleModel
component.subTitleModel = subTitleModel
component.width = 250
return TestViewWrapper(component: component, isTrailing: true)
}
}