refactored buttons
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
95d72e329b
commit
5cf6e6be12
@ -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 {
|
extension BaseViewController {
|
||||||
func makeButton(_ text: String) -> Button {
|
func makeButton(_ text: String, label: UILabel) -> Button {
|
||||||
return Button().with{
|
return Button().with{
|
||||||
$0.text = text
|
$0.text = text
|
||||||
$0.publisher(for: .touchUpInside)
|
$0.labelPublisher(label)
|
||||||
.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 makeTextLink(_ text: String) -> TextLink {
|
func makeTextLink(_ text: String, label: UILabel) -> TextLink {
|
||||||
return TextLink().with{
|
return TextLink().with{
|
||||||
$0.text = text
|
$0.text = text
|
||||||
$0.publisher(for: .touchUpInside)
|
$0.labelPublisher(label)
|
||||||
.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 makeTextLinkCaret(_ text: String) -> TextLinkCaret {
|
func makeTextLinkCaret(_ text: String, label: UILabel) -> TextLinkCaret {
|
||||||
return TextLinkCaret().with{
|
return TextLinkCaret().with{
|
||||||
$0.text = text
|
$0.text = text
|
||||||
$0.publisher(for: .touchUpInside)
|
$0.labelPublisher(label)
|
||||||
.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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,7 @@ class ButtonGroupViewController: BaseViewController {
|
|||||||
items: RowQuantity.allCases)
|
items: RowQuantity.allCases)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
var label = Label()
|
||||||
var disabledSwitch = Toggle()
|
var disabledSwitch = Toggle()
|
||||||
var widthTextField = TextField()
|
var widthTextField = TextField()
|
||||||
|
|
||||||
@ -68,13 +68,13 @@ class ButtonGroupViewController: BaseViewController {
|
|||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
buttonGroup.buttons = [
|
buttonGroup.buttons = [
|
||||||
makeButton("Secondary").with{ $0.use = .secondary },
|
makeButton("Secondary", label: label).with{ $0.use = .secondary },
|
||||||
makeButton("Primary"),
|
makeButton("Primary", label: label),
|
||||||
makeTextLink("Large Text Link"),
|
makeTextLink("Large Text Link", label: label),
|
||||||
makeButton("Widge Label Button"),
|
makeButton("Widge Label Button", label: label),
|
||||||
makeTextLinkCaret("Text Link Caret"),
|
makeTextLinkCaret("Text Link Caret", label: label),
|
||||||
makeTextLink("Small Text Link").with{ $0.size = .small },
|
makeTextLink("Small Text Link", label: label).with{ $0.size = .small },
|
||||||
makeButton("Small Button").with{$0.size = .small; $0.use = .secondary }
|
makeButton("Small Button", label: label).with{$0.size = .small; $0.use = .secondary }
|
||||||
]
|
]
|
||||||
|
|
||||||
addContentTopView(view: buttonGroup)
|
addContentTopView(view: buttonGroup)
|
||||||
@ -87,6 +87,7 @@ class ButtonGroupViewController: BaseViewController {
|
|||||||
override func allTextFields() -> [UITextField]? { [widthTextField] }
|
override func allTextFields() -> [UITextField]? { [widthTextField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
|
addFormRow(label: "Button Action", view: label)
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
||||||
addFormRow(label: "Position", view: buttonPositionSelectorView)
|
addFormRow(label: "Position", view: buttonPositionSelectorView)
|
||||||
|
|||||||
@ -24,15 +24,16 @@ class ButtonViewController: BaseViewController {
|
|||||||
items: ButtonSize.allCases)
|
items: ButtonSize.allCases)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
var label = Label()
|
||||||
var disabledSwitch = Toggle()
|
var disabledSwitch = Toggle()
|
||||||
var textField = TextField()
|
var textField = TextField()
|
||||||
var widthTextField = TextField()
|
var widthTextField = TextField()
|
||||||
|
|
||||||
let button = Button()
|
var button: Button!
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
button = makeButton("Button", label: label)
|
||||||
addContentTopView(view: .makeWrapper(for: button))
|
addContentTopView(view: .makeWrapper(for: button))
|
||||||
|
|
||||||
setupForm()
|
setupForm()
|
||||||
@ -43,6 +44,7 @@ class ButtonViewController: BaseViewController {
|
|||||||
override func allTextFields() -> [UITextField]? { [textField, widthTextField] }
|
override func allTextFields() -> [UITextField]? { [textField, widthTextField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
|
addFormRow(label: "Button Action", view: label)
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
addFormRow(label: "Use", view: usePickerSelectorView)
|
addFormRow(label: "Use", view: usePickerSelectorView)
|
||||||
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
||||||
@ -73,21 +75,7 @@ class ButtonViewController: BaseViewController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupModel() {
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
//setup UI
|
//setup UI
|
||||||
surfacePickerSelectorView.text = button.surface.rawValue
|
surfacePickerSelectorView.text = button.surface.rawValue
|
||||||
disabledSwitch.isOn = button.disabled
|
disabledSwitch.isOn = button.disabled
|
||||||
|
|||||||
@ -18,10 +18,11 @@ class TextLinkCaretViewController: BaseViewController {
|
|||||||
items: TextLinkCaretPosition.allCases)
|
items: TextLinkCaretPosition.allCases)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
var label = Label()
|
||||||
var disabledSwitch = Toggle()
|
var disabledSwitch = Toggle()
|
||||||
var textField = TextField()
|
var textField = TextField()
|
||||||
lazy var textLinkCaret: TextLinkCaret = {
|
lazy var textLinkCaret: TextLinkCaret = {
|
||||||
makeTextLinkCaret("Text Link Caret")
|
makeTextLinkCaret("Text Link Caret", label: label)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
@ -36,6 +37,7 @@ class TextLinkCaretViewController: BaseViewController {
|
|||||||
override func allTextFields() -> [UITextField]? { [textField] }
|
override func allTextFields() -> [UITextField]? { [textField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
|
addFormRow(label: "Button Action", view: label)
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
||||||
addFormRow(label: "Label", view: textField)
|
addFormRow(label: "Label", view: textField)
|
||||||
|
|||||||
@ -18,10 +18,11 @@ class TextLinkViewController: BaseViewController {
|
|||||||
items: ButtonSize.allCases)
|
items: ButtonSize.allCases)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
var label = Label()
|
||||||
var disabledSwitch = Toggle()
|
var disabledSwitch = Toggle()
|
||||||
var textField = TextField()
|
var textField = TextField()
|
||||||
lazy var textLink: TextLink = {
|
lazy var textLink: TextLink = {
|
||||||
makeTextLink("Text Link")
|
makeTextLink("Text Link", label: label)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
@ -37,6 +38,7 @@ class TextLinkViewController: BaseViewController {
|
|||||||
override func allTextFields() -> [UITextField]? { [textField] }
|
override func allTextFields() -> [UITextField]? { [textField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
|
addFormRow(label: "Button Action", view: label)
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
||||||
addFormRow(label: "Label", view: textField)
|
addFormRow(label: "Label", view: textField)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user