updated to use a numeric field

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-12-21 09:54:01 -06:00
parent 7d0fe4c306
commit 73c5ae8114
17 changed files with 60 additions and 32 deletions

View File

@ -9,34 +9,47 @@ import Foundation
import UIKit
import VDS
class TextField: UITextField {
var textPadding = UIEdgeInsets(
public class TextField: UITextField {
public var isNumeric: Bool = false
public var textPadding = UIEdgeInsets(
top: 10,
left: 10,
bottom: 10,
right: 10
)
override init(frame: CGRect) {
public override init(frame: CGRect) {
super.init(frame: frame)
font = TypographicalStyle.BodyLarge.font
}
required init?(coder: NSCoder) {
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func textRect(forBounds bounds: CGRect) -> CGRect {
public override func textRect(forBounds bounds: CGRect) -> CGRect {
layer.borderColor = UIColor.black.cgColor
layer.borderWidth = 1
let rect = super.textRect(forBounds: bounds)
return rect.inset(by: textPadding)
}
override func editingRect(forBounds bounds: CGRect) -> CGRect {
public override func editingRect(forBounds bounds: CGRect) -> CGRect {
layer.borderColor = UIColor.black.cgColor
layer.borderWidth = 1
let rect = super.editingRect(forBounds: bounds)
return rect.inset(by: textPadding)
}
}
public class NumericField: TextField {
public override init(frame: CGRect) {
super.init(frame: frame)
isNumeric = true
}
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@ -50,10 +50,10 @@ class BadgeViewController: BaseViewController {
}()
var textField = TextField()
var maxWidthTextField = TextField()
var maxWidthTextField = NumericField()
var badge = Badge()
override func allTextFields() -> [UITextField]? { [textField, maxWidthTextField] }
override func allTextFields() -> [TextField]? { [textField, maxWidthTextField] }
override func viewDidLoad() {
super.viewDidLoad()

View File

@ -188,8 +188,23 @@ public class BaseViewController: UIViewController, Initable {
}
open func setup() {
if let textFields = allTextFields() {
for textField in textFields {
if textField.isNumeric {
let keypadToolbar: UIToolbar = UIToolbar()
// add a done button to the numberpad
keypadToolbar.items=[
UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: self, action: nil),
UIBarButtonItem(title: "Done", style: UIBarButtonItem.Style.done, target: textField, action: #selector(UITextField.resignFirstResponder))
]
keypadToolbar.sizeToFit()
// add a toolbar with a done button above the number pad
textField.inputAccessoryView = keypadToolbar
textField.keyboardType = .numberPad
}
textField.returnKeyType = .done
textField
.publisher(for: .editingDidEndOnExit)
@ -205,5 +220,5 @@ public class BaseViewController: UIViewController, Initable {
print("\(Self.self) updateView()")
}
open func allTextFields() -> [UITextField]? { nil }
open func allTextFields() -> [TextField]? { nil }
}

View File

@ -61,15 +61,15 @@ class ButtonGroupViewController: BaseViewController {
var label = Label()
var disabledSwitch = Toggle()
var widthTextField = TextField()
var percentageTextField = TextField()
var widthTextField = NumericField()
var percentageTextField = NumericField()
let largeButtonGroup = ButtonGroup()
let smallButtonGroup = ButtonGroup()
let largeLabel = Label().with{ $0.text = "Large Button Group"; $0.typograpicalStyle = .BoldTitleSmall }
let smallLabel = Label().with{ $0.text = "Small Button Group"; $0.typograpicalStyle = .BoldTitleSmall }
override func allTextFields() -> [UITextField]? { [widthTextField, percentageTextField] }
override func allTextFields() -> [TextField]? { [widthTextField, percentageTextField] }
override func viewDidLoad() {
super.viewDidLoad()

View File

@ -27,7 +27,7 @@ class ButtonViewController: BaseViewController {
var label = Label()
var disabledSwitch = Toggle()
var textField = TextField()
var widthTextField = TextField()
var widthTextField = NumericField()
var button: Button!
@ -41,7 +41,7 @@ class ButtonViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [textField, widthTextField] }
override func allTextFields() -> [TextField]? { [textField, widthTextField] }
func setupForm(){
addFormRow(label: "Button Action", view: label)

View File

@ -29,7 +29,7 @@ class CheckboxGroupViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [labelTextField, childTextField] }
override func allTextFields() -> [TextField]? { [labelTextField, childTextField] }
func setupForm() {
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))

View File

@ -30,7 +30,7 @@ class CheckboxViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [labelTextField, childTextField, errorTextField] }
override func allTextFields() -> [TextField]? { [labelTextField, childTextField, errorTextField] }
func setupForm(){
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))

View File

@ -38,7 +38,7 @@ class LabelViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [textField] }
override func allTextFields() -> [TextField]? { [textField] }
func setupForm(){
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))

View File

@ -31,7 +31,7 @@ class RadioBoxGroupViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [textField, subTextField, subTextRightField] }
override func allTextFields() -> [TextField]? { [textField, subTextField, subTextRightField] }
func setupForm() {
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))

View File

@ -29,7 +29,7 @@ class RadioButtonViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [labelTextField, childTextField] }
override func allTextFields() -> [TextField]? { [labelTextField, childTextField] }
func setupForm() {
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))

View File

@ -25,7 +25,7 @@ class TextEntryFieldViewController: BaseViewController {
var errorTextField = TextField()
var successTextField = TextField()
var helperTextField = TextField()
var widthTextField = TextField()
var widthTextField = NumericField()
var showErrorSwitch = Toggle()
var showSuccessSwitch = Toggle()
var tooltipTitleTextField = TextField()
@ -41,7 +41,7 @@ class TextEntryFieldViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [labelTextField, errorTextField, successTextField, helperTextField, widthTextField, tooltipTitleTextField, tooltipContentTextField] }
override func allTextFields() -> [TextField]? { [labelTextField, errorTextField, successTextField, helperTextField, widthTextField, tooltipTitleTextField, tooltipContentTextField] }
func setupForm(){
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))

View File

@ -34,7 +34,7 @@ class TextLinkCaretViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [textField] }
override func allTextFields() -> [TextField]? { [textField] }
func setupForm(){
addFormRow(label: "Button Action", view: label)

View File

@ -35,7 +35,7 @@ class TextLinkViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [textField] }
override func allTextFields() -> [TextField]? { [textField] }
func setupForm(){
addFormRow(label: "Button Action", view: label)

View File

@ -37,8 +37,8 @@ class TileContainerViewController: BaseViewController {
var showBackgroundImageSwitch = Toggle()
var showBorderSwitch = Toggle()
var showDropShadowSwitch = Toggle()
var heightTextField = TextField()
var widthTextField = TextField()
var heightTextField = NumericField()
var widthTextField = NumericField()
var tileContainer = TileContainer()
var backgroundImage = UIImage(named: "backgroundTest")!
@ -52,7 +52,7 @@ class TileContainerViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [widthTextField, heightTextField] }
override func allTextFields() -> [TextField]? { [widthTextField, heightTextField] }
func setupForm(){
formStackView.addArrangedSubview(Label().with{

View File

@ -32,9 +32,9 @@ class TiletViewController: BaseViewController {
var titleTextField = TextField()
var subTitleTextField = TextField()
var widthTextField = TextField()
var textPercentageTextField = TextField()
var textWidthTextField = TextField()
var widthTextField = NumericField()
var textPercentageTextField = NumericField()
var textWidthTextField = NumericField()
var tilet = Tilet()
@ -47,7 +47,7 @@ class TiletViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [titleTextField, subTitleTextField, widthTextField, textWidthTextField, textPercentageTextField] }
override func allTextFields() -> [TextField]? { [titleTextField, subTitleTextField, widthTextField, textWidthTextField, textPercentageTextField] }
func setupForm(){
addFormRow(label: "Surface", view: surfacePickerSelectorView)

View File

@ -51,7 +51,7 @@ class TitleLockupViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [UITextField]? { [eyebrowTextField, titleTextField, subTitleTextField] }
override func allTextFields() -> [TextField]? { [eyebrowTextField, titleTextField, subTitleTextField] }
func setupForm(){
addFormRow(label: "Surface", view: surfacePickerSelectorView)

View File

@ -52,7 +52,7 @@ class ToggleViewController: BaseViewController {
setupPicker()
}
override func allTextFields() -> [UITextField]? { [onTextField, offTextField] }
override func allTextFields() -> [TextField]? { [onTextField, offTextField] }
func setupForm() {