From 20468971990c49964080adb87c6f865bc632ea1c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 16 Apr 2024 09:50:40 -0500 Subject: [PATCH] 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