diff --git a/VDSSample.xcodeproj/project.pbxproj b/VDSSample.xcodeproj/project.pbxproj index d26b820..a76db7d 100644 --- a/VDSSample.xcodeproj/project.pbxproj +++ b/VDSSample.xcodeproj/project.pbxproj @@ -53,6 +53,7 @@ EA89204C28B66CE2006B9984 /* ScrollWrapperView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89204528B66CE2006B9984 /* ScrollWrapperView.swift */; }; EA89204E28B67332006B9984 /* CheckBoxGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89204D28B67332006B9984 /* CheckBoxGroupViewController.swift */; }; EA89205128B68307006B9984 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89205028B68307006B9984 /* TextField.swift */; }; + EAA5EEAD28EB6924003B3210 /* TextEntryFieldViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEAC28EB6924003B3210 /* TextEntryFieldViewController.swift */; }; EAB1D2C928AAAA1D00DAE764 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */; }; EAB1D2D428AC409F00DAE764 /* LabelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */; }; EAC9258029119FC400091998 /* TextLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257F29119FC400091998 /* TextLink.swift */; }; @@ -117,6 +118,7 @@ EA89204528B66CE2006B9984 /* ScrollWrapperView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollWrapperView.swift; sourceTree = ""; }; EA89204D28B67332006B9984 /* CheckBoxGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckBoxGroupViewController.swift; sourceTree = ""; }; EA89205028B68307006B9984 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = ""; }; + EAA5EEAC28EB6924003B3210 /* TextEntryFieldViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextEntryFieldViewController.swift; sourceTree = ""; }; EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = ""; }; EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelViewController.swift; sourceTree = ""; }; EAC9257F29119FC400091998 /* TextLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLink.swift; sourceTree = ""; }; @@ -258,6 +260,7 @@ EA89201828B56DF5006B9984 /* RadioBoxGroupViewController.swift */, EAF7F11928A14A0E00B287F5 /* RadioButtonViewController.swift */, EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */, + EAA5EEAC28EB6924003B3210 /* TextEntryFieldViewController.swift */, EAC9257F29119FC400091998 /* TextLink.swift */, EA3C3BB328996775000CA526 /* ToggleViewController.swift */, ); @@ -422,6 +425,7 @@ EA89204828B66CE2006B9984 /* ScrollViewKeyboardAvoiding.swift in Sources */, EAF7F09C2899B92400B287F5 /* CheckboxViewController.swift in Sources */, EA89204E28B67332006B9984 /* CheckBoxGroupViewController.swift in Sources */, + EAA5EEAD28EB6924003B3210 /* TextEntryFieldViewController.swift in Sources */, EA89204928B66CE2006B9984 /* KeyboardFrameChangeListening.swift in Sources */, EAC9258029119FC400091998 /* TextLink.swift in Sources */, EAB1D2D428AC409F00DAE764 /* LabelViewController.swift in Sources */, diff --git a/VDSSample/ViewControllers/MenuViewController.swift b/VDSSample/ViewControllers/MenuViewController.swift index 2ccd546..9f5efe3 100644 --- a/VDSSample/ViewControllers/MenuViewController.swift +++ b/VDSSample/ViewControllers/MenuViewController.swift @@ -27,7 +27,7 @@ class MenuViewController: UITableViewController { MenuComponent(title: "RadioButtonGroup", viewController: RadioButtonViewController.self), MenuComponent(title: "RadioBoxGroup", viewController: RadioBoxGroupViewController.self), MenuComponent(title: "RadioSwatchGroup", viewController: RadioSwatchGroupViewController.self), - //MenuComponent(title: "TextEntryField", viewController: TextEntryFieldViewController.self), + MenuComponent(title: "TextEntryField", viewController: TextEntryFieldViewController.self), MenuComponent(title: "TextLink", viewController: TextLinkViewController.self), MenuComponent(title: "Toggle", viewController: ToggleViewController.self) ] diff --git a/VDSSample/ViewControllers/TextEntryFieldViewController.swift b/VDSSample/ViewControllers/TextEntryFieldViewController.swift new file mode 100644 index 0000000..d854e0a --- /dev/null +++ b/VDSSample/ViewControllers/TextEntryFieldViewController.swift @@ -0,0 +1,171 @@ +// +// TextEntryFieldViewController.swift +// VDSSample +// +// Created by Matt Bruce on 10/3/22. +// + +import Foundation +import UIKit +import VDS +import VDSColorTokens +import Combine + +class TextEntryFieldViewController: BaseViewController { + + lazy var helperTextPlacementPickerSelectorView = { + PickerSelectorView(title: "", + picker: self.picker, + items: HelperTextPlacement.allCases) + }() + + var disabledSwitch = UISwitch() + var requiredSwitch = UISwitch() + var labelTextField = TextField() + var errorTextField = TextField() + var successTextField = TextField() + var helperTextField = TextField() + var widthTextField = TextField() + var showErrorSwitch = UISwitch() + var showSuccessSwitch = UISwitch() + var tooltipTitleTextField = TextField() + var tooltipContentTextField = TextField() + + var textEntryField = TextEntryField() + + override func viewDidLoad() { + super.viewDidLoad() + addContentTopView(view: textEntryField) + setupForm() + setupPicker() + setupModel() + } + + func setupForm(){ + addFormRow(label: "Disabled", view: disabledSwitch) + addFormRow(label: "Required", view: requiredSwitch) + addFormRow(label: "Surface", view: surfacePickerSelectorView) + addFormRow(label: "Label Text", view: labelTextField) + addFormRow(label: "Helper Text Placement", view: helperTextPlacementPickerSelectorView) + addFormRow(label: "Helper Text", view: helperTextField) + addFormRow(label: "Error", view: showErrorSwitch) + addFormRow(label: "Error Text", view: errorTextField) + addFormRow(label: "Success", view: showSuccessSwitch) + addFormRow(label: "Success Text", view: successTextField) + addFormRow(label: "Width", view: widthTextField) + addFormRow(label: "ToolTip Title", view: tooltipTitleTextField) + addFormRow(label: "ToolTip Content", view: tooltipContentTextField) + + requiredSwitch + .publisher(for: .valueChanged) + .sink { [weak self] sender in + self?.textEntryField.required = sender.isOn + }.store(in: &subscribers) + + showErrorSwitch + .publisher(for: .valueChanged) + .sink { [weak self] sender in + self?.textEntryField.showError = sender.isOn + }.store(in: &subscribers) + + showSuccessSwitch + .publisher(for: .valueChanged) + .sink { [weak self] sender in + self?.textEntryField.showSuccess = sender.isOn + }.store(in: &subscribers) + + disabledSwitch + .publisher(for: .valueChanged) + .sink { [weak self] sender in + self?.textEntryField.disabled = sender.isOn + }.store(in: &subscribers) + + labelTextField + .textPublisher + .sink { [weak self] text in + self?.textEntryField.labelText = text + }.store(in: &subscribers) + + helperTextField + .textPublisher + .sink { [weak self] text in + self?.textEntryField.helperText = text + }.store(in: &subscribers) + + errorTextField + .textPublisher + .sink { [weak self] text in + self?.textEntryField.errorText = text + }.store(in: &subscribers) + + widthTextField + .textPublisher + .sink { [weak self] width in + guard let width = Float(width) else { return } + self?.textEntryField.width = CGFloat(width) + }.store(in: &subscribers) + + tooltipTitleTextField + .textPublisher + .sink { [weak self] text in + self?.textEntryField.tooltipTitle = text + }.store(in: &subscribers) + + tooltipContentTextField + .textPublisher + .sink { [weak self] text in + self?.textEntryField.tooltipContent = text + }.store(in: &subscribers) + + } + + func setupModel() { + textEntryField.type = .text + textEntryField.width = 328 + textEntryField.labelText = "Street Address" + textEntryField.helperText = "For example: 123 Verizon St" + textEntryField.errorText = "Enter a valid address." + textEntryField.successText = "Good job entering a valid address!" + textEntryField.tooltipTitle = "Check the formatting of your address" + textEntryField.tooltipContent = "House/Building number then street name" + + textEntryField + .publisher(for: .valueChanged) + .sink { textEntryField in + if let text = textEntryField.value { + print("text entry: \(text)") + } else { + print("text entry: null") + } + }.store(in: &subscribers) + + //setup UI + surfacePickerSelectorView.text = textEntryField.surface.rawValue + disabledSwitch.isOn = textEntryField.disabled + requiredSwitch.isOn = textEntryField.required + labelTextField.text = textEntryField.labelText + helperTextField.text = textEntryField.helperText + showErrorSwitch.isOn = textEntryField.showError + errorTextField.text = textEntryField.errorText + showSuccessSwitch.isOn = textEntryField.showSuccess + successTextField.text = textEntryField.successText + tooltipTitleTextField.text = textEntryField.tooltipTitle + tooltipContentTextField.text = textEntryField.tooltipContent + if let width = textEntryField.width { + widthTextField.text = String(describing: width) + } + } + + //Picker + func setupPicker(){ + surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.textEntryField.surface = item + self?.contentTopView.backgroundColor = item.color + } + + helperTextPlacementPickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.textEntryField.helperTextPlacement = item + } + } +} +