From 5c44d25339fcbf17deb23534d5cc1f5de297e8f4 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 16 Apr 2024 09:43:28 -0500 Subject: [PATCH 1/3] added TextLinkModel to the EntryFieldBase Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 6 ++++- .../TextFields/EntryFieldBase.swift | 19 +++++++++++++-- VDS/Components/TextFields/TextLinkModel.swift | 24 +++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 VDS/Components/TextFields/TextLinkModel.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index a7c2e6b4..bc1aeed4 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -89,6 +89,7 @@ EA5F86C82A1BD99100BC83E4 /* TabModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5F86C72A1BD99100BC83E4 /* TabModel.swift */; }; EA5F86CC2A1D28B500BC83E4 /* ReleaseNotes.txt in Resources */ = {isa = PBXBuildFile; fileRef = EA5F86CB2A1D28B500BC83E4 /* ReleaseNotes.txt */; }; EA5F86D02A1F936100BC83E4 /* TabsContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5F86CF2A1F936100BC83E4 /* TabsContainer.swift */; }; + EA6642952BCEBF9500D81DC4 /* TextLinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA6642942BCEBF9500D81DC4 /* TextLinkModel.swift */; }; EA6F330E2B911E9000BACAB9 /* TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA6F330D2B911E9000BACAB9 /* TextView.swift */; }; EA81410B2A0E8E3C004F60D2 /* ButtonIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA81410A2A0E8E3C004F60D2 /* ButtonIcon.swift */; }; EA8141102A127066004F60D2 /* UIColor+VDSColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA81410F2A127066004F60D2 /* UIColor+VDSColor.swift */; }; @@ -278,6 +279,7 @@ EA5F86C72A1BD99100BC83E4 /* TabModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabModel.swift; sourceTree = ""; }; EA5F86CB2A1D28B500BC83E4 /* ReleaseNotes.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = ReleaseNotes.txt; sourceTree = ""; }; EA5F86CF2A1F936100BC83E4 /* TabsContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsContainer.swift; sourceTree = ""; }; + EA6642942BCEBF9500D81DC4 /* TextLinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkModel.swift; sourceTree = ""; }; EA6F330D2B911E9000BACAB9 /* TextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = ""; }; EA81410A2A0E8E3C004F60D2 /* ButtonIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonIcon.swift; sourceTree = ""; }; EA81410F2A127066004F60D2 /* UIColor+VDSColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+VDSColor.swift"; sourceTree = ""; }; @@ -874,6 +876,7 @@ isa = PBXGroup; children = ( EAC9258B2911C9DE00091998 /* EntryFieldBase.swift */, + EA6642942BCEBF9500D81DC4 /* TextLinkModel.swift */, EAC925862911C9DE00091998 /* InputField */, EA985C21296E032000F2FF2E /* TextArea */, ); @@ -1108,6 +1111,7 @@ 71BFA70A2B7F70E6000DCE33 /* DropShadowable.swift in Sources */, EA0D1C452A6AD73000E5C127 /* RawRepresentable.swift in Sources */, EA985C23296E033A00F2FF2E /* TextArea.swift in Sources */, + EA6642952BCEBF9500D81DC4 /* TextLinkModel.swift in Sources */, 71FC86E22B97483000700965 /* Clamping.swift in Sources */, EAF7F0B3289B1ADC00B287F5 /* ActionLabelAttribute.swift in Sources */, 1855EC662BAABF2A002ACAC2 /* BreadcrumbItemModel.swift in Sources */, @@ -1213,7 +1217,7 @@ EAB2376829E9992800AABE9A /* TooltipAlertViewController.swift in Sources */, EA33623E2892EE950071C351 /* UIDevice.swift in Sources */, EA985C692971B90B00F2FF2E /* IconSize.swift in Sources */, - 71FC86E02B973AE500700965 /* DropShadowConfiguration.swift in Sources */, + 71FC86E02B973AE500700965 /* DropShadowConfiguration.swift in Sources */, EA3362302891EB4A0071C351 /* Font.swift in Sources */, EAF7F0AD289B142900B287F5 /* StrikeThroughLabelAttribute.swift in Sources */, EAB5FEF12927F4AA00998C17 /* SelfSizingCollectionView.swift in Sources */, diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index 32910ab4..d8edb79e 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -143,9 +143,13 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { } open var icon: Icon = Icon().with { - $0.size = .small + $0.size = .medium } + internal var actionTextLink = TextLink().with { $0.contentEdgeInsets = .top(-2) } + + internal var actionTextLinkModel: TextLinkModel? { didSet { setNeedsUpdate() } } + open var labelText: String? { didSet { setNeedsUpdate() } } open var helperText: String? { didSet { setNeedsUpdate() } } @@ -249,6 +253,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { //add the view to add input fields containerStackView.addArrangedSubview(controlContainerView) containerStackView.addArrangedSubview(icon) + containerStackView.addArrangedSubview(actionTextLink) containerStackView.setCustomSpacing(VDSLayout.space3X, after: controlContainerView) //get the container this is what show helper text, error text @@ -280,7 +285,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { errorLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() helperLabel.textColorConfiguration = secondaryColorConfiguration.eraseToAnyColorable() } - + /// Resets to default settings. open override func reset() { super.reset() @@ -315,6 +320,16 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { updateErrorLabel() updateHelperLabel() + if let actionTextLinkModel { + actionTextLink.text = actionTextLinkModel.text + actionTextLink.onClick = actionTextLinkModel.onClick + actionTextLink.isHidden = false + containerStackView.setCustomSpacing(VDSLayout.space2X, after: icon) + } else { + actionTextLink.isHidden = true + containerStackView.setCustomSpacing(0, after: icon) + } + backgroundColor = surface.color validator?.validate() internalErrorText = validator?.errorMessage diff --git a/VDS/Components/TextFields/TextLinkModel.swift b/VDS/Components/TextFields/TextLinkModel.swift new file mode 100644 index 00000000..1dbab0cf --- /dev/null +++ b/VDS/Components/TextFields/TextLinkModel.swift @@ -0,0 +1,24 @@ +// +// EntryFieldTextLinkModel.swift +// VDS +// +// Created by Matt Bruce on 4/16/24. +// + +import Foundation + +extension EntryFieldBase { + public struct TextLinkModel { + + ///Text that goes in the Tab + public var text: String + + ///Click event when you click on a tab + public var onClick: ((TextLink) -> Void)? + + public init(text: String, onClick: ((TextLink) -> Void)? = nil) { + self.text = text + self.onClick = onClick + } + } +} From 20468971990c49964080adb87c6f865bc632ea1c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 16 Apr 2024 09:50:40 -0500 Subject: [PATCH 2/3] refactored out of entryfieldbase to inputfield since this is the only place it is needed. Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 2 +- VDS/Components/TextFields/EntryFieldBase.swift | 17 +---------------- .../TextFields/InputField/InputField.swift | 17 +++++++++++++++++ .../{ => InputField}/TextLinkModel.swift | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) rename VDS/Components/TextFields/{ => InputField}/TextLinkModel.swift (94%) diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index bc1aeed4..9728129c 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -876,7 +876,6 @@ isa = PBXGroup; children = ( EAC9258B2911C9DE00091998 /* EntryFieldBase.swift */, - EA6642942BCEBF9500D81DC4 /* TextLinkModel.swift */, EAC925862911C9DE00091998 /* InputField */, EA985C21296E032000F2FF2E /* TextArea */, ); @@ -887,6 +886,7 @@ isa = PBXGroup; children = ( EAC925872911C9DE00091998 /* InputField.swift */, + EA6642942BCEBF9500D81DC4 /* TextLinkModel.swift */, ); path = InputField; sourceTree = ""; diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index d8edb79e..7ce12d75 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -145,11 +145,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { open var icon: Icon = Icon().with { $0.size = .medium } - - internal var actionTextLink = TextLink().with { $0.contentEdgeInsets = .top(-2) } - - internal var actionTextLinkModel: TextLinkModel? { didSet { setNeedsUpdate() } } - + open var labelText: String? { didSet { setNeedsUpdate() } } open var helperText: String? { didSet { setNeedsUpdate() } } @@ -253,7 +249,6 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { //add the view to add input fields containerStackView.addArrangedSubview(controlContainerView) containerStackView.addArrangedSubview(icon) - containerStackView.addArrangedSubview(actionTextLink) containerStackView.setCustomSpacing(VDSLayout.space3X, after: controlContainerView) //get the container this is what show helper text, error text @@ -320,16 +315,6 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { updateErrorLabel() updateHelperLabel() - if let actionTextLinkModel { - actionTextLink.text = actionTextLinkModel.text - actionTextLink.onClick = actionTextLinkModel.onClick - actionTextLink.isHidden = false - containerStackView.setCustomSpacing(VDSLayout.space2X, after: icon) - } else { - actionTextLink.isHidden = true - containerStackView.setCustomSpacing(0, after: icon) - } - backgroundColor = surface.color validator?.validate() internalErrorText = validator?.errorMessage diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index cb9501e8..e39d7f1e 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -77,6 +77,10 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { /// Representing the type of input. open var fieldType: FieldType = .text { didSet { setNeedsUpdate() } } + internal var actionTextLink = TextLink().with { $0.contentEdgeInsets = .top(-2) } + + public var actionTextLinkModel: TextLinkModel? { didSet { setNeedsUpdate() } } + /// The text of this TextField. private var _text: String? open var text: String? { @@ -134,6 +138,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { return state } } + /// If given, this will be shown if showSuccess if true. open var successText: String? { didSet { setNeedsUpdate() } } @@ -169,6 +174,8 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { stackView.addArrangedSubview(successLabel) stackView.setCustomSpacing(8, after: successLabel) + containerStackView.addArrangedSubview(actionTextLink) + successLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() backgroundColorConfiguration.setSurfaceColors(VDSColor.feedbackSuccessBackgroundOnlight, VDSColor.feedbackSuccessBackgroundOndark, forState: .success) @@ -204,6 +211,16 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { textField.isEnabled = isEnabled textField.textColor = textFieldTextColorConfiguration.getColor(self) + if let actionTextLinkModel { + actionTextLink.text = actionTextLinkModel.text + actionTextLink.onClick = actionTextLinkModel.onClick + actionTextLink.isHidden = false + containerStackView.setCustomSpacing(VDSLayout.space2X, after: icon) + } else { + actionTextLink.isHidden = true + containerStackView.setCustomSpacing(0, after: icon) + } + //show error or success if showError, let _ = errorText { successLabel.isHidden = true diff --git a/VDS/Components/TextFields/TextLinkModel.swift b/VDS/Components/TextFields/InputField/TextLinkModel.swift similarity index 94% rename from VDS/Components/TextFields/TextLinkModel.swift rename to VDS/Components/TextFields/InputField/TextLinkModel.swift index 1dbab0cf..d5d8c7ba 100644 --- a/VDS/Components/TextFields/TextLinkModel.swift +++ b/VDS/Components/TextFields/InputField/TextLinkModel.swift @@ -7,7 +7,7 @@ import Foundation -extension EntryFieldBase { +extension InputField { public struct TextLinkModel { ///Text that goes in the Tab From 9ce6428bdac0471013f06d9cf7e32b3cf4a67602 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 16 Apr 2024 09:51:57 -0500 Subject: [PATCH 3/3] made property internal Signed-off-by: Matt Bruce --- VDS/Components/TextFields/InputField/InputField.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index e39d7f1e..004b33ae 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -79,7 +79,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { internal var actionTextLink = TextLink().with { $0.contentEdgeInsets = .top(-2) } - public var actionTextLinkModel: TextLinkModel? { didSet { setNeedsUpdate() } } + internal var actionTextLinkModel: TextLinkModel? { didSet { setNeedsUpdate() } } /// The text of this TextField. private var _text: String?