refactored buttons

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-12-06 15:58:15 -06:00
parent 95d72e329b
commit 5cf6e6be12
5 changed files with 44 additions and 57 deletions

View File

@ -24,49 +24,43 @@ extension UIView {
}
}
extension ButtonBase {
func labelPublisher(_ label: UILabel){
publisher(for: .touchUpInside)
.sink { control in
let newText = "\(control.text!) clicked - "
if let labelText = label.text {
let components = labelText.components(separatedBy: " - ")
let last: String = (components.last ?? "0").trimmingCharacters(in: .whitespaces)
let count = Int(last)!
label.text = "\(newText)\(count+1)"
} else {
label.text = "\(newText)1"
}
print("clicked me")
}.store(in: &subscribers)
}
}
extension BaseViewController {
func makeButton(_ text: String) -> Button {
func makeButton(_ text: String, label: UILabel) -> Button {
return Button().with{
$0.text = text
$0.publisher(for: .touchUpInside)
.sink { [weak self] control in
let alertController:UIAlertController = UIAlertController(title: "Alert",
message: "\(control.text!) Clicked",
preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
self?.present(alertController, animated: true)
print("clicked me")
}.store(in: &subscribers)
$0.labelPublisher(label)
}
}
func makeTextLink(_ text: String) -> TextLink {
func makeTextLink(_ text: String, label: UILabel) -> TextLink {
return TextLink().with{
$0.text = text
$0.publisher(for: .touchUpInside)
.sink { [weak self] control in
let alertController:UIAlertController = UIAlertController(title: "Alert",
message: "\(control.text!) Clicked",
preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
self?.present(alertController, animated: true)
print("clicked me")
}.store(in: &subscribers)
$0.labelPublisher(label)
}
}
func makeTextLinkCaret(_ text: String) -> TextLinkCaret {
func makeTextLinkCaret(_ text: String, label: UILabel) -> TextLinkCaret {
return TextLinkCaret().with{
$0.text = text
$0.publisher(for: .touchUpInside)
.sink { [weak self] control in
let alertController:UIAlertController = UIAlertController(title: "Alert",
message: "\(control.text!) Clicked",
preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
self?.present(alertController, animated: true)
print("clicked me")
}.store(in: &subscribers)
$0.labelPublisher(label)
}
}
}

View File

@ -59,7 +59,7 @@ class ButtonGroupViewController: BaseViewController {
items: RowQuantity.allCases)
}()
var label = Label()
var disabledSwitch = Toggle()
var widthTextField = TextField()
@ -68,13 +68,13 @@ class ButtonGroupViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
buttonGroup.buttons = [
makeButton("Secondary").with{ $0.use = .secondary },
makeButton("Primary"),
makeTextLink("Large Text Link"),
makeButton("Widge Label Button"),
makeTextLinkCaret("Text Link Caret"),
makeTextLink("Small Text Link").with{ $0.size = .small },
makeButton("Small Button").with{$0.size = .small; $0.use = .secondary }
makeButton("Secondary", label: label).with{ $0.use = .secondary },
makeButton("Primary", label: label),
makeTextLink("Large Text Link", label: label),
makeButton("Widge Label Button", label: label),
makeTextLinkCaret("Text Link Caret", label: label),
makeTextLink("Small Text Link", label: label).with{ $0.size = .small },
makeButton("Small Button", label: label).with{$0.size = .small; $0.use = .secondary }
]
addContentTopView(view: buttonGroup)
@ -87,6 +87,7 @@ class ButtonGroupViewController: BaseViewController {
override func allTextFields() -> [UITextField]? { [widthTextField] }
func setupForm(){
addFormRow(label: "Button Action", view: label)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Position", view: buttonPositionSelectorView)

View File

@ -24,15 +24,16 @@ class ButtonViewController: BaseViewController {
items: ButtonSize.allCases)
}()
var label = Label()
var disabledSwitch = Toggle()
var textField = TextField()
var widthTextField = TextField()
let button = Button()
var button: Button!
override func viewDidLoad() {
super.viewDidLoad()
button = makeButton("Button", label: label)
addContentTopView(view: .makeWrapper(for: button))
setupForm()
@ -43,6 +44,7 @@ class ButtonViewController: BaseViewController {
override func allTextFields() -> [UITextField]? { [textField, widthTextField] }
func setupForm(){
addFormRow(label: "Button Action", view: label)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Use", view: usePickerSelectorView)
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
@ -73,21 +75,7 @@ class ButtonViewController: BaseViewController {
}
func setupModel() {
button.text = "Button"
button
.publisher(for: .touchUpInside)
.sink { [weak self] control in
let alertController:UIAlertController = UIAlertController(title: "Alert",
message: "\(control.text!) Clicked",
preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
self?.present(alertController, animated: true)
print("clicked me")
}.store(in: &subscribers)
func setupModel() {
//setup UI
surfacePickerSelectorView.text = button.surface.rawValue
disabledSwitch.isOn = button.disabled

View File

@ -18,10 +18,11 @@ class TextLinkCaretViewController: BaseViewController {
items: TextLinkCaretPosition.allCases)
}()
var label = Label()
var disabledSwitch = Toggle()
var textField = TextField()
lazy var textLinkCaret: TextLinkCaret = {
makeTextLinkCaret("Text Link Caret")
makeTextLinkCaret("Text Link Caret", label: label)
}()
override func viewDidLoad() {
@ -36,6 +37,7 @@ class TextLinkCaretViewController: BaseViewController {
override func allTextFields() -> [UITextField]? { [textField] }
func setupForm(){
addFormRow(label: "Button Action", view: label)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Label", view: textField)

View File

@ -18,10 +18,11 @@ class TextLinkViewController: BaseViewController {
items: ButtonSize.allCases)
}()
var label = Label()
var disabledSwitch = Toggle()
var textField = TextField()
lazy var textLink: TextLink = {
makeTextLink("Text Link")
makeTextLink("Text Link", label: label)
}()
override func viewDidLoad() {
@ -37,6 +38,7 @@ class TextLinkViewController: BaseViewController {
override func allTextFields() -> [UITextField]? { [textField] }
func setupForm(){
addFormRow(label: "Button Action", view: label)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Label", view: textField)