diff --git a/VDSSample.xcodeproj/project.pbxproj b/VDSSample.xcodeproj/project.pbxproj index 581a243..128bc3d 100644 --- a/VDSSample.xcodeproj/project.pbxproj +++ b/VDSSample.xcodeproj/project.pbxproj @@ -34,6 +34,7 @@ /* Begin PBXBuildFile section */ 1808BEBE2BA4479500129230 /* CarouselScrollbarViewConttroller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1808BEBD2BA4479500129230 /* CarouselScrollbarViewConttroller.swift */; }; 1832AC5B2BA1347B008AE476 /* BreadcrumbsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1832AC5A2BA1347B008AE476 /* BreadcrumbsViewController.swift */; }; + 186D13CD2BBA990800986B53 /* DropdownSelectViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 186D13CC2BBA990800986B53 /* DropdownSelectViewController.swift */; }; 445BA07A29C088470036A7C5 /* NotificationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 445BA07929C088470036A7C5 /* NotificationViewController.swift */; }; 44604AD929CE1CF900E62B51 /* LineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD829CE1CF900E62B51 /* LineViewController.swift */; }; 5FC35BE928D5235A004EBEAC /* ButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE828D5235A004EBEAC /* ButtonViewController.swift */; }; @@ -132,6 +133,7 @@ /* Begin PBXFileReference section */ 1808BEBD2BA4479500129230 /* CarouselScrollbarViewConttroller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarouselScrollbarViewConttroller.swift; sourceTree = ""; }; 1832AC5A2BA1347B008AE476 /* BreadcrumbsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BreadcrumbsViewController.swift; sourceTree = ""; }; + 186D13CC2BBA990800986B53 /* DropdownSelectViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropdownSelectViewController.swift; sourceTree = ""; }; 445BA07929C088470036A7C5 /* NotificationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationViewController.swift; sourceTree = ""; }; 44604AD829CE1CF900E62B51 /* LineViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineViewController.swift; sourceTree = ""; }; 5FC35BE828D5235A004EBEAC /* ButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonViewController.swift; sourceTree = ""; }; @@ -328,6 +330,7 @@ EA89204D28B67332006B9984 /* CheckBoxGroupViewController.swift */, EAF7F09B2899B92400B287F5 /* CheckboxItemViewController.swift */, EA0D1C2E2A66CFE900E5C127 /* CheckboxViewController.swift */, + 186D13CC2BBA990800986B53 /* DropdownSelectViewController.swift */, EA985C00296CC21C00F2FF2E /* IconViewController.swift */, EAA5EEAC28EB6924003B3210 /* InputFieldViewController.swift */, EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */, @@ -504,6 +507,7 @@ 44604AD929CE1CF900E62B51 /* LineViewController.swift in Sources */, 1808BEBE2BA4479500129230 /* CarouselScrollbarViewConttroller.swift in Sources */, EA3C3BB528996775000CA526 /* StoryboardInitable.swift in Sources */, + 186D13CD2BBA990800986B53 /* DropdownSelectViewController.swift in Sources */, EA89201928B56DF5006B9984 /* RadioBoxGroupViewController.swift in Sources */, EA3C3BB628996775000CA526 /* MenuViewController.swift in Sources */, EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */, diff --git a/VDSSample/ViewControllers/DropdownSelectViewController.swift b/VDSSample/ViewControllers/DropdownSelectViewController.swift new file mode 100644 index 0000000..177aa4c --- /dev/null +++ b/VDSSample/ViewControllers/DropdownSelectViewController.swift @@ -0,0 +1,188 @@ +// +// DropdownSelectViewController.swift +// VDSSample +// +// Created by Kanamarlapudi, Vasavi on 28/03/24. +// + +import Foundation +import VDS + +class DropdownSelectViewController: BaseViewController { + + var disabledSwitch = Toggle() + var requiredSwitch = Toggle() + var labelTextField = TextField() + var errorTextField = TextField() + var helperTextField = TextField() + var inlineLabelSwitch = Toggle() + var readonlySwitch = Toggle() + var transparentBgSwitch = Toggle() + var errorSwitch = Toggle() + var tooltipTitleTextField = TextField() + var tooltipContentTextField = TextField() + var optionsSwitch = Toggle() + var moreOptions: [DropdownSelect.DropdownOptionModel] = [ + .init(text: "Alabama"), + .init(text: "Alaska"), + .init(text: "Arizona"), + .init(text: "Arkansas"), + .init(text: "California"), + .init(text: "Colorado"), + .init(text: "Connecticut"), + .init(text: "Delaware"), + .init(text: "District of Columbia"), + .init(text: "Florida"), + .init(text: "Georgia"), + .init(text: "Hawaii"), + .init(text: "Idaho"), + .init(text: "Illinois"), + .init(text: "Indiana"), + .init(text: "Iowa") + ] + + var some: [DropdownSelect.DropdownOptionModel] = [ + .init(text: "Alabama"), + .init(text: "Alaska"), + .init(text: "Arizona"), + .init(text: "Arkansas") + ] + + override func viewDidLoad() { + super.viewDidLoad() + addContentTopView(view: component) + setupModel() + setupPicker() + } + + override func setupForm(){ + addFormRow(label: "Surface", view: surfacePickerSelectorView) + addFormRow(label: "Disabled", view: disabledSwitch) + addFormRow(label: "Required", view: requiredSwitch) + addFormRow(label: "Label Text", view: labelTextField) + addFormRow(label: "Helper Text", view: helperTextField) + addFormRow(label: "Inline Label", view: .makeWrapper(for: inlineLabelSwitch)) + addFormRow(label: "Readonly", view: readonlySwitch) + addFormRow(label: "Transparent Background", view: transparentBgSwitch) + addFormRow(label: "Error", view: .makeWrapper(for: errorSwitch)) + addFormRow(label: "Error Text", view: errorTextField) + addFormRow(label: "ToolTip Title", view: tooltipTitleTextField) + addFormRow(label: "ToolTip Content", view: tooltipContentTextField) + addFormRow(label: "More Options", view: optionsSwitch) + + disabledSwitch.onChange = { [weak self] sender in + self?.component.isEnabled = !sender.isOn + } + + requiredSwitch.onChange = { [weak self] sender in + self?.component.required = sender.isOn + } + + optionsSwitch.onChange = { [weak self] sender in + guard let self else { return } + self.component.options = sender.isOn ? self.moreOptions : self.some + } + + readonlySwitch.onChange = { [weak self] sender in + self?.component.readOnly = sender.isOn + } + + transparentBgSwitch.onChange = { [weak self] sender in + self?.component.transparentBackground = sender.isOn + } + + errorSwitch + .publisher(for: .valueChanged) + .sink { [weak self] sender in + guard let self else { return } + component.showError = sender.isOn + if component.showError != sender.isOn { + self.errorSwitch.isOn = self.component.showError + } + }.store(in: &subscribers) + + labelTextField + .textPublisher + .sink { [weak self] text in + self?.component.labelText = text + }.store(in: &subscribers) + + helperTextField + .textPublisher + .sink { [weak self] text in + self?.component.helperText = text + }.store(in: &subscribers) + + errorTextField + .textPublisher + .sink { [weak self] text in + self?.component.errorText = text + }.store(in: &subscribers) + + tooltipTitleTextField + .textPublisher + .sink { [weak self] text in + self?.updateTooltip() + }.store(in: &subscribers) + + tooltipContentTextField + .textPublisher + .sink { [weak self] text in + self?.updateTooltip() + }.store(in: &subscribers) + + inlineLabelSwitch + .publisher(for: .valueChanged) + .sink { [weak self] sender in + guard let self else { return } + self.component.showInlineLabel = sender.isOn + }.store(in: &subscribers) + } + + func setupModel() { + component.labelText = "Street Address" + component.helperText = "For example: 123 Verizon St" + component.errorText = "Enter a valid address." + component.tooltipModel = .init(title: "Check the formatting of your address", content:"House/Building number then street name") + component.options = moreOptions + + /// callback to know which option chose + component.onItemSelected = { index, option in + print("selected index: \(index) text: \(option.text) value: \(option.value)") + } + + component.onChange = { dropdown in + guard let option = dropdown.selectedItem, let index = dropdown.selectId else { print("nothing selected"); return } + print("selected index: \(index) text: \(option.text) value: \(option.value)") + } + + //setup UI + disabledSwitch.isOn = !component.isEnabled + requiredSwitch.isOn = component.required + surfacePickerSelectorView.text = component.surface.rawValue + labelTextField.text = component.labelText + helperTextField.text = component.helperText + readonlySwitch.isOn = false + transparentBgSwitch.isOn = false + errorSwitch.isOn = component.showError + errorTextField.text = component.errorText + tooltipTitleTextField.text = component.tooltipModel?.title + tooltipContentTextField.text = component.tooltipModel?.content + optionsSwitch.isOn = true + } + + func setupPicker() { + surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.component.surface = item + self?.contentTopView.backgroundColor = item.color + } + } + + func updateTooltip() { + let title = tooltipTitleTextField.text ?? "" + let content = tooltipContentTextField.text ?? "" + + component.tooltipModel = !title.isEmpty || !content.isEmpty ? .init(title: title, + content: content) : nil + } +} diff --git a/VDSSample/ViewControllers/InputFieldViewController.swift b/VDSSample/ViewControllers/InputFieldViewController.swift index f82e09b..4101b7e 100644 --- a/VDSSample/ViewControllers/InputFieldViewController.swift +++ b/VDSSample/ViewControllers/InputFieldViewController.swift @@ -119,22 +119,21 @@ class InputFieldViewController: BaseViewController { func setupModel() { component.fieldType = .text component.width = 328 + component.text = "Starting Text" component.labelText = "Street Address" component.helperText = "For example: 123 Verizon St" component.errorText = "Enter a valid address." component.successText = "Good job entering a valid address!" component.tooltipModel = .init(title: "Check the formatting of your address", content:"House/Building number then street name") - component - .publisher(for: .valueChanged) - .sink { component in - if let text = component.value { - print("text entry: \(text)") - } else { - print("text entry: null") - } - }.store(in: &subscribers) - + component.onChange = { component in + if let text = component.value { + print("text entry: \(text)") + } else { + print("text entry: null") + } + } + //setup UI surfacePickerSelectorView.text = component.surface.rawValue helperTextPlacementPickerSelectorView.text = component.helperTextPlacement.rawValue @@ -166,8 +165,11 @@ class InputFieldViewController: BaseViewController { } func updateTooltip() { - component.tooltipModel = .init(title: tooltipTitleTextField.text, - content: tooltipContentTextField.text) + let title = tooltipTitleTextField.text ?? "" + let content = tooltipContentTextField.text ?? "" + + component.tooltipModel = !title.isEmpty || !content.isEmpty ? .init(title: title, + content: content) : nil } } diff --git a/VDSSample/ViewControllers/MenuViewController.swift b/VDSSample/ViewControllers/MenuViewController.swift index 131b767..86484c6 100644 --- a/VDSSample/ViewControllers/MenuViewController.swift +++ b/VDSSample/ViewControllers/MenuViewController.swift @@ -78,6 +78,7 @@ class MenuViewController: UITableViewController, TooltipLaunchable { MenuComponent(title: "Checkbox", completed: true, viewController: CheckboxViewController.self), MenuComponent(title: "CheckboxItem", completed: true, viewController: CheckboxItemViewController.self), MenuComponent(title: "CheckboxGroup", completed: true, viewController: CheckboxGroupViewController.self), + MenuComponent(title: "DropdownSelect", completed: true, viewController: DropdownSelectViewController.self), MenuComponent(title: "Icon", completed: true, viewController: IconViewController.self), MenuComponent(title: "InputField", completed: false, viewController: InputFieldViewController.self), MenuComponent(title: "Label", completed: true, viewController: LabelViewController.self), diff --git a/VDSSample/ViewControllers/TextAreaViewController.swift b/VDSSample/ViewControllers/TextAreaViewController.swift index a08f12e..0f8bf5f 100644 --- a/VDSSample/ViewControllers/TextAreaViewController.swift +++ b/VDSSample/ViewControllers/TextAreaViewController.swift @@ -131,16 +131,15 @@ class TextAreaViewController: BaseViewController