refactored to sample

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-14 14:41:59 -05:00
parent c6e578f270
commit c742fbab35
30 changed files with 147 additions and 116 deletions

View File

@ -212,13 +212,13 @@ class BadgeIndicatorViewController: BaseViewController<BadgeIndicator> {
}
}
extension BadgeIndicatorViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension BadgeIndicatorViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.fillColor = .red
component.number = 23
component.kind = .simple
component.size = .medium
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -108,13 +108,13 @@ class BadgeViewController: BaseViewController<Badge> {
}
}
extension BadgeViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension BadgeViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.fillColor = .red
component.text = "Terms and conditions"
component.maxWidth = 70
component.numberOfLines = 3
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -199,8 +199,8 @@ class ButtonGroupViewController: BaseViewController<ButtonGroup> {
}
}
extension ButtonGroupViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension ButtonGroupViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.buttons = [
Button().with{ $0.use = .secondary; $0.text = "Secondary" },
@ -210,6 +210,6 @@ extension ButtonGroupViewController: Componentable {
TextLinkCaret().with { $0.text = "Text Link Caret" }
]
return TestViewWrapper(component: component, isTrailing: false)
return ComponentSample(component: component, canPinTrailing: true)
}
}

View File

@ -170,11 +170,11 @@ extension UITextField {
}
}
extension ButtonIconViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension ButtonIconViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.iconName = .addToFavorite
component.size = .large
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -99,13 +99,13 @@ class ButtonViewController: BaseViewController<Button> {
}
}
extension ButtonViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension ButtonViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
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)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -118,8 +118,8 @@ class CheckboxGroupViewController: BaseViewController<CheckboxGroup> {
}
extension CheckboxGroupViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension CheckboxGroupViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
var checkbox1 = CheckboxGroup.CheckboxModel()
@ -138,6 +138,6 @@ extension CheckboxGroupViewController: Componentable {
component.selectorModels = [checkbox1, checkbox2]
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -94,13 +94,13 @@ class CheckboxItemViewController: BaseViewController<CheckboxItem> {
}
}
extension CheckboxItemViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension CheckboxItemViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.labelText = "Terms and conditions"
component.childText = "I agree to Verizon's terms and conditions click here"
component.errorText = "Error Text"
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -62,9 +62,9 @@ class CheckboxViewController: BaseViewController<Checkbox> {
}
}
extension CheckboxViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension CheckboxViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -88,14 +88,14 @@ class IconViewController: BaseViewController<Icon> {
}
}
extension IconViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension IconViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
let name = Icon.Name.accessibility
let color = UIColor.VDSColor.paletteBlack
component.color = color.uiColor
component.name = name
component.size = .XLarge
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -168,8 +168,8 @@ class InputFieldViewController: BaseViewController<InputField> {
}
extension InputFieldViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension InputFieldViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.type = .text
component.width = 328
@ -179,6 +179,6 @@ extension InputFieldViewController: Componentable {
component.successText = "Good job entering a valid address!"
component.tooltipTitle = "Check the formatting of your address"
component.tooltipContent = "House/Building number then street name"
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -342,10 +342,10 @@ extension Slider {
}
extension LabelViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension LabelViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.text = "Helg¹ worldg Hell¹ worldg"
return TestViewWrapper(component: component, isTrailing: false)
return ComponentSample(component: component, canPinTrailing: true)
}
}

View File

@ -41,9 +41,9 @@ class LineViewController: BaseViewController<Line> {
}
}
extension LineViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension LineViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -83,9 +83,9 @@ class LoaderViewController: BaseViewController<Loader>, LoaderLaunchable {
}
}
extension LoaderViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension LoaderViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -146,8 +146,8 @@ class NotificationViewController: BaseViewController<VDS.Notification> {
}
}
extension NotificationViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension NotificationViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
let titleDefaultText = "This is title"
@ -160,6 +160,6 @@ extension NotificationViewController: Componentable {
component.primaryButtonModel = .init(text: firstButtonDefaultText, onClick: {b in print("\(b.text!) click")})
component.secondaryButtonModel = .init(text: secondButtonDefaultText, onClick: {b in print("\(b.text!) click")})
component.onCloseClick = {_ in print("notification on close click")}
return TestViewWrapper(component: component, isTrailing: false)
return ComponentSample(component: component, canPinTrailing: true)
}
}

View File

@ -111,8 +111,8 @@ class RadioBoxGroupViewController: BaseViewController<RadioBoxGroup>{
}
}
extension RadioBoxGroupViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension RadioBoxGroupViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
var radioBox1 = RadioBoxGroup.RadioBoxModel()
@ -131,6 +131,6 @@ extension RadioBoxGroupViewController: Componentable {
component.selectorModels = [radioBox1, radioBox2]
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -109,8 +109,8 @@ class RadioButtonGroupViewController: BaseViewController<RadioButtonGroup> {
}
extension RadioButtonGroupViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension RadioButtonGroupViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
var radioButton1 = RadioButtonGroup.RadioButtonModel()
@ -133,6 +133,6 @@ extension RadioButtonGroupViewController: Componentable {
component.selectorModels = [radioButton1, radioButton2, radioButton3]
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -98,13 +98,13 @@ class RadioButtonItemViewController: BaseViewController<RadioButtonItem> {
}
}
extension RadioButtonItemViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension RadioButtonItemViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.labelText = "Terms and conditions"
component.childText = "I agree to Verizon's terms and conditions click here"
component.errorText = "Error Text"
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -66,9 +66,9 @@ class RadioButtonViewController: BaseViewController<RadioButton> {
}
}
extension RadioButtonViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension RadioButtonViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -105,8 +105,8 @@ class RadioSwatchGroupViewController: BaseViewController<RadioSwatchGroup> {
}
}
extension RadioSwatchGroupViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension RadioSwatchGroupViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
var radioSwatch1 = RadioSwatchGroup.RadioSwatchModel()
@ -152,7 +152,7 @@ extension RadioSwatchGroupViewController: Componentable {
component.selectorModels = [radioSwatch1, radioSwatch2, radioSwatch3, radioSwatch4, radioSwatch5, radioSwatch6, radioSwatch7, radioSwatch8]
return TestViewWrapper(component: component, isTrailing: false)
return ComponentSample(component: component, canPinTrailing: true)
}
}

View File

@ -10,15 +10,31 @@ import UIKit
import VDS
import VDSColorTokens
public typealias TestView = UIView & Surfaceable
public typealias TestViewWrapper = (component: TestView, isTrailing: Bool)
protocol Componentable {
static func getComponent() -> TestViewWrapper
public typealias ComponentSampleView = UIView & Surfaceable
public struct ComponentSample {
public var component: ComponentSampleView
public var canPinLeading: Bool
public var canPinTrailing: Bool
public var canPinTop: Bool
public var canPinBottom: Bool
public init(component: ComponentSampleView, canPinLeading: Bool = true, canPinTrailing: Bool = true, canPinTop: Bool = true, canPinBottom: Bool = true) {
self.component = component
self.canPinLeading = canPinLeading
self.canPinTrailing = canPinTrailing
self.canPinTop = canPinTop
self.canPinBottom = canPinBottom
}
}
protocol ComponentSampleable {
static func makeSample() -> ComponentSample
}
public class TableViewTestController: UITableViewController, Initable, Surfaceable {
var components:[TestViewWrapper] = []
var components:[ComponentSample] = []
public var surface: Surface = .light {
didSet {
tableView.reloadData()
@ -38,8 +54,8 @@ public class TableViewTestController: UITableViewController, Initable, Surfaceab
public override func viewDidLoad() {
super.viewDidLoad()
MenuViewController.items.forEach { menuItem in
if let componentable = menuItem.viewController as? Componentable.Type {
components.append(componentable.getComponent())
if let componentable = menuItem.viewController as? ComponentSampleable.Type {
components.append(componentable.makeSample())
}
}
tableView.register(VDSCell.self, forCellReuseIdentifier: "cell")
@ -84,44 +100,59 @@ public class TableViewTestController: UITableViewController, Initable, Surfaceab
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? VDSCell else { return UITableViewCell() }
cell.prepareForReuse()
cell.surface = surface
let wrapper = components[indexPath.section]
cell.isTrailing = wrapper.isTrailing
cell.component = wrapper.component
cell.sample = components[indexPath.section]
return cell
}
}
public class VDSCell: UITableViewCell, AppleGuidlinesTouchable, Surfaceable {
public var isTrailing: Bool = true
public var surface: Surface = .light
public var shouldWrap: Bool = true
public var component: TestView? {
public var sample: ComponentSample? {
didSet {
contentView.subviews.forEach { $0.removeFromSuperview() }
let edges: UIEdgeInsets = .init(top: 16, left: 16, bottom: 16, right: 16)
guard var component else { return }
if shouldWrap {
let wrapper = UIView.makeWrapper(for: component, isTrailing: isTrailing)
contentView.addSubview(wrapper)
wrapper.pinToSuperView(edges)
} else {
contentView.addSubview(component)
component.pinToSuperView(edges)
}
backgroundColor = surface.color
guard let sample else { return }
var component = sample.component
component.surface = surface
let wrapper = View()
wrapper.addSubview(component)
if sample.canPinTop {
component.pinTop(anchor: wrapper.topAnchor, constant: edges.top)
} else {
component.pinTopGreaterThanOrEqualTo(anchor: wrapper.topAnchor, constant: edges.top)
}
if sample.canPinLeading {
component.pinLeading(anchor: wrapper.leadingAnchor, constant: edges.left)
} else {
component.pinLeadingGreaterThanOrEqualTo(anchor: wrapper.leadingAnchor, constant: edges.left)
}
if sample.canPinTrailing {
component.pinTrailing(anchor: wrapper.trailingAnchor, constant: edges.right)
} else {
component.pinTrailingLessThanOrEqualTo(anchor: wrapper.trailingAnchor, constant: edges.right)
}
if sample.canPinBottom {
component.pinBottom(anchor: wrapper.bottomAnchor, constant: edges.bottom)
} else {
component.pinBottomLessThanOrEqualTo(anchor: wrapper.bottomAnchor, constant: edges.bottom)
}
contentView.addSubview(wrapper)
wrapper.pinToSuperView(edges)
backgroundColor = .systemYellow //surface.color
}
}
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
Self.acceptablyOutsideBounds(point: point, bounds: bounds)
}
public override var intrinsicContentSize: CGSize {
guard let component else { return .zero }
return component.intrinsicContentSize
}
}

View File

@ -143,8 +143,8 @@ class TabsViewController: BaseViewController<Tabs> {
}
}
extension TabsViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension TabsViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.tabModels = [
.init(text: "Accessories"),
@ -153,6 +153,6 @@ extension TabsViewController: Componentable {
.init(text: "Contact Us")
]
return TestViewWrapper(component: component, isTrailing: false)
return ComponentSample(component: component, canPinTrailing: true)
}
}

View File

@ -139,8 +139,8 @@ class TextAreaViewController: BaseViewController<TextArea> {
}
}
extension TextAreaViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension TextAreaViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.width = 328
component.labelText = "Street Address"
@ -148,6 +148,6 @@ extension TextAreaViewController: Componentable {
component.errorText = "Enter a valid address."
component.tooltipTitle = "Check the formatting of your address"
component.tooltipContent = "House/Building number then street name"
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

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

View File

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

View File

@ -148,11 +148,11 @@ class TileContainerViewController: BaseViewController<TileContainer> {
}
}
extension TileContainerViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension TileContainerViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.width = 150
component.color = .black
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -230,8 +230,8 @@ class TileletViewController: BaseViewController<Tilelet> {
}
}
extension TileletViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension TileletViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
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.")
@ -240,6 +240,6 @@ extension TileletViewController: Componentable {
component.titleModel = titleModel
component.subTitleModel = subTitleModel
component.width = 250
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -173,8 +173,8 @@ class TitleLockupViewController: BaseViewController<TitleLockup> {
}
}
extension TitleLockupViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension TitleLockupViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
let eyebrowModel = TitleLockup.EyebrowModel(text: "Today only.")
let titleModel = TitleLockup.TitleModel(text: "Get more of our best")
@ -184,6 +184,6 @@ extension TitleLockupViewController: Componentable {
component.titleModel = titleModel
component.subTitleModel = subTitleModel
component.debugBorder(show: true)
return TestViewWrapper(component: component, isTrailing: false)
return ComponentSample(component: component, canPinTrailing: true)
}
}

View File

@ -116,9 +116,9 @@ class ToggleViewController: BaseViewController<Toggle> {
}
}
extension ToggleViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension ToggleViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -101,12 +101,12 @@ class TooltipViewController: BaseViewController<Tooltip> {
}
}
extension TooltipViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension TooltipViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.title = "5G Ultra Wideband is available in your area."
component.content = "$799.99 (128 GB only) "
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}

View File

@ -168,13 +168,13 @@ class TrailingTooltipLabelViewController: BaseViewController<TrailingTooltipLabe
}
}
extension TrailingTooltipLabelViewController: Componentable {
static func getComponent() -> TestViewWrapper {
extension TrailingTooltipLabelViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.labelText = "5G Ultra Wideband is available in your area"
component.tooltipTitle = "5G Ultra Wideband is available in your area."
component.tooltipContent = "$799.99 (128 GB only)"
return TestViewWrapper(component: component, isTrailing: true)
return ComponentSample(component: component, canPinTrailing: false)
}
}