diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index ac5cb29b..cf3539fb 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -93,7 +93,7 @@ open class DropdownSelect: EntryFieldBase { $0.setContentCompressionResistancePriority(.required, for: .horizontal) $0.textAlignment = .left $0.textStyle = .boldBodyLarge - $0.lineBreakMode = .byCharWrapping + $0.numberOfLines = 1 $0.sizeToFit() } @@ -102,7 +102,7 @@ open class DropdownSelect: EntryFieldBase { $0.setContentCompressionResistancePriority(.required, for: .horizontal) $0.textAlignment = .left $0.textStyle = .bodyLarge - $0.lineBreakMode = .byCharWrapping + $0.numberOfLines = 1 } open var dropdownField = UITextField().with { diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index 631cf029..2c2435be 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -58,7 +58,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { /// only used for helperTextPosition == .right internal let row1StackView = UIStackView().with { $0.axis = .horizontal - $0.spacing = 8 + $0.spacing = VDSLayout.space3X $0.alignment = .top $0.distribution = .fillEqually } @@ -66,7 +66,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { /// only used for helperTextPosition == .right internal let row2StackView = UIStackView().with { $0.axis = .horizontal - $0.spacing = 8 + $0.spacing = VDSLayout.space3X $0.alignment = .top $0.distribution = .fillEqually } @@ -101,6 +101,13 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { /// This is set by a local method. internal var bottomContainerView: UIView! + //-------------------------------------------------- + // MARK: - Constraints + //-------------------------------------------------- + internal var widthConstraint: NSLayoutConstraint? + internal var trailingEqualsConstraint: NSLayoutConstraint? + internal var trailingLessThanEqualsConstraint: NSLayoutConstraint? + //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- @@ -228,11 +235,27 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { open override func setup() { super.setup() + let layoutGuide = UILayoutGuide() + addLayoutGuide(layoutGuide) + layoutGuide + .pinTop() + .pinLeading() + .pinBottom() + + trailingEqualsConstraint = layoutGuide.pinTrailing(anchor: trailingAnchor) + + // width constraints + trailingLessThanEqualsConstraint = layoutGuide.pinTrailingLessThanOrEqualTo(anchor: trailingAnchor)?.deactivate() + widthConstraint = layoutGuide.widthAnchor.constraint(equalToConstant: 0).deactivate() + // Add mainStackView to the view addSubview(mainStackView) - - mainStackView.pinToSuperView() - + + mainStackView.pinTop(anchor: layoutGuide.topAnchor) + mainStackView.pinLeading(anchor: layoutGuide.leadingAnchor) + mainStackView.pinBottom(anchor: layoutGuide.bottomAnchor) + mainStackView.pinTrailing(anchor: layoutGuide.trailingAnchor) + //add ContainerStackView //this is the horizontal stack that contains //InputContainer, Icons, Buttons @@ -265,12 +288,18 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { // Initial position of the helper label updateHelperTextPosition() + + // colorconfigs + titleLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() + errorLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() + helperLabel.textColorConfiguration = secondaryColorConfiguration.eraseToAnyColorable() } /// Updates the UI open override func updateView() { super.updateView() updateContainerView() + updateContainerWidth() updateTitleLabel() updateErrorLabel() updateHelperLabel() @@ -411,7 +440,21 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { containerView.layer.borderWidth = VDSFormControls.borderWidth containerView.layer.cornerRadius = VDSFormControls.borderRadius } - + + internal func updateContainerWidth() { + widthConstraint?.deactivate() + trailingLessThanEqualsConstraint?.deactivate() + trailingEqualsConstraint?.deactivate() + + if let width, width >= minWidth, width <= maxWidth { + widthConstraint?.constant = width + widthConstraint?.activate() + trailingLessThanEqualsConstraint?.activate() + } else { + trailingEqualsConstraint?.activate() + } + } + internal func updateHelperTextPosition() { titleLabel.removeFromSuperview() diff --git a/VDS/Components/Tilelet/Tilelet.swift b/VDS/Components/Tilelet/Tilelet.swift index 98ce49aa..5dcd5a09 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -532,7 +532,7 @@ open class Tilelet: TileContainerBase { var showIconContainerView = false if let descriptiveIconModel { descriptiveIcon.name = descriptiveIconModel.name - descriptiveIcon.color = descriptiveIconModel.color + descriptiveIcon.colorConfiguration = descriptiveIconModel.colorConfiguration descriptiveIcon.size = descriptiveIconModel.size descriptiveIcon.surface = backgroundColorSurface descriptiveIcon.accessibilityLabel = descriptiveIconModel.accessibleText @@ -541,8 +541,8 @@ open class Tilelet: TileContainerBase { if let directionalIconModel { directionalIcon.name = directionalIconModel.iconType.iconName - directionalIcon.color = directionalIconModel.color - directionalIcon.size = directionalIconModel.size + directionalIcon.colorConfiguration = directionalIconModel.colorConfiguration + directionalIcon.size = directionalIconModel.size.value directionalIcon.surface = backgroundColorSurface directionalIcon.accessibilityLabel = directionalIconModel.accessibleText showIconContainerView = true diff --git a/VDS/Components/Tilelet/TileletIconModels.swift b/VDS/Components/Tilelet/TileletIconModels.swift index 788a2155..7fc408a3 100644 --- a/VDS/Components/Tilelet/TileletIconModels.swift +++ b/VDS/Components/Tilelet/TileletIconModels.swift @@ -17,29 +17,29 @@ extension Tilelet { public var name: Icon.Name /// Color of the icon. - public var color: UIColor + public var colorConfiguration: SurfaceColorConfiguration /// Enum for a preset height and width for the icon. public var size: Icon.Size /// Accessible Text for the Icon public var accessibleText: String - - /// Current Surface and this is used to pass down to child objects that implement Surfacable - public var surface: Surface - public init(name: Icon.Name = .multipleDocuments, color: UIColor = VDSColor.paletteBlack, size: Icon.Size = .medium, accessibleText: String? = nil, surface: Surface = .dark) { + public init(name: Icon.Name = .multipleDocuments, + colorConfiguration: SurfaceColorConfiguration = .init(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark), + size: Icon.Size = .medium, + accessibleText: String? = nil) { + self.name = name - self.color = color + self.colorConfiguration = colorConfiguration self.accessibleText = accessibleText ?? name.rawValue self.size = size - self.surface = surface } } /// Model that represents the options available for the directional icon. public struct DirectionalIcon { - public enum IconType { + public enum IconType: String, CaseIterable { case rightArrow case externalLink @@ -48,9 +48,17 @@ extension Tilelet { } } - /// Color of the icon. - public var color: UIColor + public enum IconSize: String, EnumSubset { + case small + case medium + case large + + public var defaultValue: Icon.Size { .medium } + } + /// Color of the icon. + public var colorConfiguration: SurfaceColorConfiguration + /// Accessible Text for the Icon public var accessibleText: String @@ -58,17 +66,17 @@ extension Tilelet { public var iconType: IconType /// Enum for a preset height and width for the icon. - public var size: Icon.Size - - /// Current Surface and this is used to pass down to child objects that implement Surfacable - public var surface: Surface - - public init(iconType: IconType = .rightArrow, color: UIColor = VDSColor.paletteBlack, size: Icon.Size = .medium, accessibleText: String? = nil, surface: Surface = .dark) { + public var size: IconSize + + public init(iconType: IconType = .rightArrow, + colorConfiguration: SurfaceColorConfiguration = .init(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark), + size: IconSize = .medium, + accessibleText: String? = nil) { + self.iconType = iconType - self.color = color + self.colorConfiguration = colorConfiguration self.accessibleText = accessibleText ?? iconType.iconName.rawValue self.size = size - self.surface = surface } } }