From 68d2a5173ebf43d360fe18f3547b6ab55bef06a6 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 14 Apr 2023 15:48:57 -0500 Subject: [PATCH 1/2] added tooltip Signed-off-by: Matt Bruce --- VDS.xcworkspace/contents.xcworkspacedata | 176 +++++++++++++++++ VDSSample.xcodeproj/project.pbxproj | 12 +- .../ViewControllers/MenuViewController.swift | 5 +- .../TooltipViewController.swift | 114 +++++++++++ .../TrailingTooltipLabel.swift | 178 ++++++++++++++++++ 5 files changed, 482 insertions(+), 3 deletions(-) create mode 100644 VDSSample/ViewControllers/TooltipViewController.swift create mode 100644 VDSSample/ViewControllers/TrailingTooltipLabel.swift diff --git a/VDS.xcworkspace/contents.xcworkspacedata b/VDS.xcworkspace/contents.xcworkspacedata index 91951bf..267889d 100644 --- a/VDS.xcworkspace/contents.xcworkspacedata +++ b/VDS.xcworkspace/contents.xcworkspacedata @@ -4,6 +4,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/VDSSample.xcodeproj/project.pbxproj b/VDSSample.xcodeproj/project.pbxproj index 9ff01e7..50745fb 100644 --- a/VDSSample.xcodeproj/project.pbxproj +++ b/VDSSample.xcodeproj/project.pbxproj @@ -32,8 +32,8 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ - 44604AD929CE1CF900E62B51 /* LineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD829CE1CF900E62B51 /* LineViewController.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 */; }; EA0FC2C12912DC5500DF80B4 /* TextLinkCaretViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */; }; EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9C289966EF000CA526 /* AppDelegate.swift */; }; @@ -69,6 +69,8 @@ EAA5EEAD28EB6924003B3210 /* InputFieldViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEAC28EB6924003B3210 /* InputFieldViewController.swift */; }; EAB1D2C928AAAA1D00DAE764 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */; }; EAB1D2D428AC409F00DAE764 /* LabelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */; }; + EAB2376029E88D5D00AABE9A /* TooltipViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB2375F29E88D5D00AABE9A /* TooltipViewController.swift */; }; + EAB2376C29E9E74900AABE9A /* TrailingTooltipLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB2376B29E9E74900AABE9A /* TrailingTooltipLabel.swift */; }; EAB5FEEF2927E28400998C17 /* ButtonGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */; }; EAB5FEF32928153D00998C17 /* Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF22928153D00998C17 /* Helper.swift */; }; EAC9258029119FC400091998 /* TextLinkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257F29119FC400091998 /* TextLinkViewController.swift */; }; @@ -115,8 +117,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 44604AD829CE1CF900E62B51 /* LineViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineViewController.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 = ""; }; EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkCaretViewController.swift; sourceTree = ""; }; EA3C3B99289966EF000CA526 /* VDSSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VDSSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -153,6 +155,8 @@ EAA5EEAC28EB6924003B3210 /* InputFieldViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputFieldViewController.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 = ""; }; + EAB2375F29E88D5D00AABE9A /* TooltipViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TooltipViewController.swift; sourceTree = ""; }; + EAB2376B29E9E74900AABE9A /* TrailingTooltipLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailingTooltipLabel.swift; sourceTree = ""; }; EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonGroupViewController.swift; sourceTree = ""; }; EAB5FEF22928153D00998C17 /* Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helper.swift; sourceTree = ""; }; EAC9257F29119FC400091998 /* TextLinkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkViewController.swift; sourceTree = ""; }; @@ -303,6 +307,8 @@ EA5E305B295111050082B959 /* TileletViewController.swift */, EA5E30542950EA6E0082B959 /* TitleLockupViewController.swift */, EA3C3BB328996775000CA526 /* ToggleViewController.swift */, + EAB2375F29E88D5D00AABE9A /* TooltipViewController.swift */, + EAB2376B29E9E74900AABE9A /* TrailingTooltipLabel.swift */, ); path = ViewControllers; sourceTree = ""; @@ -466,11 +472,13 @@ 5FC35BE928D5235A004EBEAC /* ButtonViewController.swift in Sources */, EA89204A28B66CE2006B9984 /* KeyboardFrameChange.swift in Sources */, EA3C3BB428996775000CA526 /* PickerBase.swift in Sources */, + EAB2376C29E9E74900AABE9A /* TrailingTooltipLabel.swift in Sources */, EAB1D2C928AAAA1D00DAE764 /* BaseViewController.swift in Sources */, EA5E305C295111050082B959 /* TileletViewController.swift in Sources */, EAB5FEF32928153D00998C17 /* Helper.swift in Sources */, EA89204728B66CE2006B9984 /* KeyboardFrameChangeListener.swift in Sources */, EA4DB30428DCD25B00103EE3 /* BadgeViewController.swift in Sources */, + EAB2376029E88D5D00AABE9A /* TooltipViewController.swift in Sources */, EA89204828B66CE2006B9984 /* ScrollViewKeyboardAvoiding.swift in Sources */, EA0FC2C12912DC5500DF80B4 /* TextLinkCaretViewController.swift in Sources */, EAF7F09C2899B92400B287F5 /* CheckboxViewController.swift in Sources */, diff --git a/VDSSample/ViewControllers/MenuViewController.swift b/VDSSample/ViewControllers/MenuViewController.swift index 9e6ddb6..9ca67b6 100644 --- a/VDSSample/ViewControllers/MenuViewController.swift +++ b/VDSSample/ViewControllers/MenuViewController.swift @@ -90,7 +90,10 @@ class MenuViewController: UITableViewController { MenuComponent(title: "TileContainer", completed: true, viewController: TileContainerViewController.self), MenuComponent(title: "Tilelet", completed: false, viewController: TileletViewController.self), MenuComponent(title: "TitleLockup", completed: true, viewController: TitleLockupViewController.self), - MenuComponent(title: "Toggle", completed: true, viewController: ToggleViewController.self) + MenuComponent(title: "Toggle", completed: true, viewController: ToggleViewController.self), + MenuComponent(title: "Tooltip", completed: true, viewController: TooltipViewController.self), + MenuComponent(title: "TrailingTooltipLabel", completed: false, viewController: TrailingTooltipLabelViewController.self), + ] override func numberOfSections(in tableView: UITableView) -> Int { diff --git a/VDSSample/ViewControllers/TooltipViewController.swift b/VDSSample/ViewControllers/TooltipViewController.swift new file mode 100644 index 0000000..349fd47 --- /dev/null +++ b/VDSSample/ViewControllers/TooltipViewController.swift @@ -0,0 +1,114 @@ +// +// TooltipViewController.swift +// VDSSample +// +// Created by Matt Bruce on 4/13/23. +// + +import Foundation +import UIKit +import VDS +import VDSColorTokens +import Combine + +class TooltipViewController: BaseViewController { + + var disabledSwitch = Toggle() + var titleTextField = TextField() + var contentTextField = TextField() + var closeButtonTextField = TextField() + + lazy var sizePickerSelectorView = { + PickerSelectorView(title: Tooltip.Size.medium.rawValue, + picker: self.picker, + items: Tooltip.Size.allCases) + }() + + lazy var fillColorPickerSelectorView = { + PickerSelectorView(title: Tooltip.FillColor.primary.rawValue, + picker: self.picker, + items: Tooltip.FillColor.allCases) + }() + + var tooltip = Tooltip() + + override func viewDidLoad() { + super.viewDidLoad() + addContentTopView(view: .makeWrapper(for: tooltip)) + + setupForm() + setupPicker() + setupModel() + } + + override func allTextFields() -> [TextField]? { [titleTextField, contentTextField, closeButtonTextField] } + + func setupForm(){ + addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch)) + addFormRow(label: "Surface", view: surfacePickerSelectorView) + addFormRow(label: "Size", view: sizePickerSelectorView) + addFormRow(label: "FillColor", view: fillColorPickerSelectorView) + addFormRow(label: "Title", view: titleTextField) + addFormRow(label: "Content", view: contentTextField) + addFormRow(label: "Close Button Text", view: closeButtonTextField) + + disabledSwitch.onChange = { [weak self] sender in + self?.tooltip.disabled = sender.isOn + } + + titleTextField + .textPublisher + .sink { [weak self] text in + self?.tooltip.title = text + }.store(in: &subscribers) + + contentTextField + .textPublisher + .sink { [weak self] text in + self?.tooltip.content = text + }.store(in: &subscribers) + + closeButtonTextField + .textPublisher + .sink { [weak self] text in + self?.tooltip.closeButtonText = text + }.store(in: &subscribers) + } + + func setupModel() { + tooltip.title = "5G Ultra Wideband is available in your area." + tooltip.content = "$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in/promo credit applied over 36 mos.; promo credit ends if eligibility req’s are no longer met; 0% APR. Trade-in conditions apply.$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in." + + //setup UI + surfacePickerSelectorView.text = tooltip.surface.rawValue + disabledSwitch.isOn = tooltip.disabled + titleTextField.text = tooltip.title + contentTextField.text = tooltip.content + closeButtonTextField.text = tooltip.closeButtonText + } + + //Picker + func setupPicker(){ + surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.tooltip.surface = item + self?.contentTopView.backgroundColor = item.color + } + + sizePickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.tooltip.size = item + } + + fillColorPickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.tooltip.fillColor = item + } + } +} + +class TooltipPopup: UIAlertController { + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + + } +} diff --git a/VDSSample/ViewControllers/TrailingTooltipLabel.swift b/VDSSample/ViewControllers/TrailingTooltipLabel.swift new file mode 100644 index 0000000..960e6e5 --- /dev/null +++ b/VDSSample/ViewControllers/TrailingTooltipLabel.swift @@ -0,0 +1,178 @@ +// +// TrailingTooltipLabel.swift +// VDSSample +// +// Created by Matt Bruce on 4/14/23. +// + +import Foundation +import UIKit +import VDS +import VDSColorTokens + +class TrailingTooltipLabelViewController: BaseViewController { + + lazy var textSizePickerSelectorView = { + TextSizePickerSelectorView(title: "", + picker: self.picker) + }() + + lazy var fontCategoryPickerSelectorView = { + FontCategoryPickerSelectorView(title: "", + picker: self.picker) + }() + + lazy var sizePickerSelectorView = { + PickerSelectorView(title: Tooltip.Size.medium.rawValue, + picker: self.picker, + items: Tooltip.Size.allCases) + }() + + var boldSwitch = Toggle() + var disabledSwitch = Toggle() + var textField = TextField() + + var titleTextField = TextField() + var contentTextField = TextField() + var closeButtonTextField = TextField() + + private var isBold: Bool = false + + var tooltipLabel = TrailingTooltipLabel() + + override func viewDidLoad() { + super.viewDidLoad() + addContentTopView(view: tooltipLabel) + + setupForm() + setupPicker() + setupModel() + } + + override func allTextFields() -> [TextField]? { [textField, titleTextField, contentTextField, closeButtonTextField] } + + func setupForm(){ + addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch)) + addFormRow(label: "Bold", view: .makeWrapper(for: boldSwitch)) + addFormRow(label: "Surface", view: surfacePickerSelectorView) + addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView) + addFormRow(label: "Text Size", view: textSizePickerSelectorView) + addFormRow(label: "Text", view: textField) + + addFormRow(label: "Tooltip Size", view: sizePickerSelectorView) + addFormRow(label: "Tooltip Title", view: titleTextField) + addFormRow(label: "Tooltip Content", view: contentTextField) + addFormRow(label: "Tooltip Close Button Text", view: closeButtonTextField) + + disabledSwitch.onChange = { [weak self] sender in + self?.tooltipLabel.disabled = sender.isOn + } + + boldSwitch + .publisher(for: .valueChanged) + .sink { [weak self] sender in + self?.isBold = sender.isOn + self?.updateLabelStyle() + }.store(in: &subscribers) + + textField + .textPublisher + .sink { [weak self] text in + self?.tooltipLabel.labelText = text + }.store(in: &subscribers) + + titleTextField + .textPublisher + .sink { [weak self] text in + self?.tooltipLabel.tooltipTitle = text + }.store(in: &subscribers) + + contentTextField + .textPublisher + .sink { [weak self] text in + self?.tooltipLabel.tooltipContent = text + }.store(in: &subscribers) + + closeButtonTextField + .textPublisher + .sink { [weak self] text in + self?.tooltipLabel.tooltipCloseButtonText = text + }.store(in: &subscribers) + + } + + func setupModel() { + tooltipLabel.labelText = "Label Component" + tooltipLabel.labelTextStyle = .featureSmall + tooltipLabel.tooltipTitle = "5G Ultra Wideband is available in your area." + tooltipLabel.tooltipContent = "$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in/promo credit applied over 36 mos.; promo credit ends if eligibility req’s are no longer met; 0% APR. Trade-in conditions apply.$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in." + + //setup UI + surfacePickerSelectorView.text = tooltipLabel.surface.rawValue + disabledSwitch.isOn = tooltipLabel.disabled + boldSwitch.isOn = isBold + textField.text = tooltipLabel.labelText + + //set the font + fontCategory = .feature + fontCategoryPickerSelectorView.text = "Feature" + textSize = .small + textSizePickerSelectorView.text = "Small" + + //setup UI + surfacePickerSelectorView.text = tooltipLabel.surface.rawValue + disabledSwitch.isOn = tooltipLabel.disabled + titleTextField.text = tooltipLabel.tooltipTitle + contentTextField.text = tooltipLabel.tooltipContent + closeButtonTextField.text = tooltipLabel.tooltipCloseButtonText + + } + + //Picker + private var fontCategory: TextStyle.FontCategory = .feature { + didSet { + fontCategoryPickerSelectorView.text = fontCategory.rawValue + textSizePickerSelectorView.items = fontCategory.sizes + if textSizePickerSelectorView.items.count > 0 { + textSize = textSizePickerSelectorView.items[0] + } else { + textSize = nil + } + updateLabelStyle() + } + } + + private var textSize: TextStyle.FontSize? = .large { + didSet { + textSizePickerSelectorView.text = textSize?.rawValue ?? "" + updateLabelStyle() + } + + } + + func updateLabelStyle(){ + if let style = fontCategory.style(for: textSize, isBold: isBold) { + tooltipLabel.labelTextStyle = style + } + } + + func setupPicker(){ + surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.tooltipLabel.surface = item + self?.contentTopView.backgroundColor = item.color + } + + textSizePickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.textSize = item + } + + fontCategoryPickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.fontCategory = item + } + + sizePickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.tooltipLabel.tooltipSize = item + } + + } +} From b9cdc0dc4b2a108ef62cbaa0745701a7a510b02b Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 17 Apr 2023 13:25:09 -0500 Subject: [PATCH 2/2] updated controllers Signed-off-by: Matt Bruce --- VDSSample/ViewControllers/LabelViewController.swift | 13 ++++++++++++- .../ViewControllers/TrailingTooltipLabel.swift | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/VDSSample/ViewControllers/LabelViewController.swift b/VDSSample/ViewControllers/LabelViewController.swift index 087a53a..b921ad0 100644 --- a/VDSSample/ViewControllers/LabelViewController.swift +++ b/VDSSample/ViewControllers/LabelViewController.swift @@ -17,6 +17,12 @@ class LabelViewController: BaseViewController { picker: self.picker) }() + lazy var textPositionPickerSelectorView = { + PickerSelectorView(title: TextPosition.left.rawValue, + picker: self.picker, + items: TextPosition.allCases) + }() + lazy var fontCategoryPickerSelectorView = { FontCategoryPickerSelectorView(title: "", picker: self.picker) @@ -44,6 +50,7 @@ class LabelViewController: BaseViewController { addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch)) addFormRow(label: "Bold", view: .makeWrapper(for: boldSwitch)) addFormRow(label: "Surface", view: surfacePickerSelectorView) + addFormRow(label: "Text Position", view: textPositionPickerSelectorView) addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView) addFormRow(label: "Text Size", view: textSizePickerSelectorView) addFormRow(label: "Text", view: textField) @@ -65,7 +72,7 @@ class LabelViewController: BaseViewController { self?.label.text = text }.store(in: &subscribers) } - + func setupModel() { label.text = "Label Component" label.textStyle = .featureSmall @@ -116,6 +123,10 @@ class LabelViewController: BaseViewController { self?.label.surface = item self?.contentTopView.backgroundColor = item.color } + + textPositionPickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.label.textPosition = item + } textSizePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.textSize = item diff --git a/VDSSample/ViewControllers/TrailingTooltipLabel.swift b/VDSSample/ViewControllers/TrailingTooltipLabel.swift index 960e6e5..06e8d64 100644 --- a/VDSSample/ViewControllers/TrailingTooltipLabel.swift +++ b/VDSSample/ViewControllers/TrailingTooltipLabel.swift @@ -27,6 +27,12 @@ class TrailingTooltipLabelViewController: BaseViewController { picker: self.picker, items: Tooltip.Size.allCases) }() + + lazy var textPositionPickerSelectorView = { + PickerSelectorView(title: TextPosition.left.rawValue, + picker: self.picker, + items: TextPosition.allCases) + }() var boldSwitch = Toggle() var disabledSwitch = Toggle() @@ -55,6 +61,7 @@ class TrailingTooltipLabelViewController: BaseViewController { addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch)) addFormRow(label: "Bold", view: .makeWrapper(for: boldSwitch)) addFormRow(label: "Surface", view: surfacePickerSelectorView) + addFormRow(label: "Text Position", view: textPositionPickerSelectorView) addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView) addFormRow(label: "Text Size", view: textSizePickerSelectorView) addFormRow(label: "Text", view: textField) @@ -162,10 +169,14 @@ class TrailingTooltipLabelViewController: BaseViewController { self?.contentTopView.backgroundColor = item.color } + textPositionPickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.tooltipLabel.labelTextPosition = item + } + textSizePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.textSize = item } - + fontCategoryPickerSelectorView.onPickerDidSelect = { [weak self] item in self?.fontCategory = item }