diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 72a56ba4..eec78f9a 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -20,6 +20,10 @@ public class Badge: View, Accessable { private var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.adjustsFontSizeToFitWidth = false + $0.lineBreakMode = .byTruncatingTail + $0.textPosition = .left + $0.typograpicalStyle = .BoldBodySmall } //-------------------------------------------------- @@ -64,8 +68,6 @@ public class Badge: View, Accessable { addSubview(label) layer.cornerRadius = 2 - label.adjustsFontSizeToFitWidth = false - label.lineBreakMode = .byTruncatingTail label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 4).isActive = true label.topAnchor.constraint(equalTo: topAnchor, constant: 2).isActive = true @@ -75,6 +77,7 @@ public class Badge: View, Accessable { maxWidthConstraint = label.widthAnchor.constraint(lessThanOrEqualToConstant: 100) minWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: 23) minWidthConstraint?.isActive = true + } public override func reset() { @@ -162,10 +165,9 @@ public class Badge: View, Accessable { //-------------------------------------------------- open override func updateView() { backgroundColor = backgroundColor() + label.textColorConfiguration = textColorConfiguration() label.numberOfLines = numberOfLines - label.textPosition = .left - label.typograpicalStyle = .BoldBodySmall label.text = text label.surface = surface label.disabled = disabled diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index a0426c09..5b42cb77 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -55,49 +55,47 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er return true } - private var mainStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .vertical - } - }() + private var mainStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .vertical + } - private var selectorStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .horizontal - } - }() + private var selectorStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .horizontal + } - private var selectorLabelStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .vertical - } - }() + private var selectorLabelStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .vertical + } private var primaryLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BoldBodyLarge } private var secondaryLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodyLarge } private var errorLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodyMedium } //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - public var selectorView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - }() + public var selectorView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } //can't bind to @Proxy open override var isSelected: Bool { didSet { didChange() }} @@ -206,8 +204,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er //add the stackview to hold the 2 labels //top label if let labelText { - primaryLabel.textPosition = .left - primaryLabel.typograpicalStyle = .BoldBodyLarge primaryLabel.surface = surface primaryLabel.disabled = disabled primaryLabel.attributes = labelTextAttributes @@ -222,8 +218,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er //bottom label if let childText { - secondaryLabel.textPosition = .left - secondaryLabel.typograpicalStyle = .BodyLarge secondaryLabel.text = childText secondaryLabel.surface = surface secondaryLabel.disabled = disabled @@ -248,8 +242,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er //either add/remove the error from the main stack if let errorText, shouldShowError { - errorLabel.textPosition = .left - errorLabel.typograpicalStyle = .BodyMedium errorLabel.text = errorText errorLabel.surface = surface errorLabel.disabled = disabled diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 2893c0a9..029c3203 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -46,51 +46,52 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - private var mainStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .vertical - $0.spacing = 0 - } - }() + private var mainStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .vertical + $0.spacing = 0 + } + + private var selectorStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .horizontal + $0.spacing = 12 + } - private var selectorStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .horizontal - } - }() - - private var selectorLeftLabelStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .vertical - } - }() + private var selectorLeftLabelStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .vertical + $0.spacing = 4 + $0.isHidden = false + } private var textLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BoldBodyLarge } private var subTextLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodyLarge } private var subTextRightLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .right + $0.typograpicalStyle = .BodyLarge } //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - public var selectorView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - }() - + public var selectorView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + open var text: String = "Default Text" { didSet { didChange() }} open var textAttributes: [any LabelAttributeModel]? { didSet { didChange() }} @@ -177,10 +178,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ selectorLeftLabelStackView.addArrangedSubview(textLabel) selectorLeftLabelStackView.addArrangedSubview(subTextLabel) - selectorStackView.spacing = 12 - selectorLeftLabelStackView.spacing = 4 - selectorLeftLabelStackView.isHidden = false - updateSelector() selectorView.topAnchor.constraint(equalTo: topAnchor).isActive = true @@ -192,15 +189,12 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ mainStackView.leadingAnchor.constraint(equalTo: selectorView.leadingAnchor, constant: 16).isActive = true mainStackView.trailingAnchor.constraint(equalTo: selectorView.trailingAnchor, constant: -16).isActive = true mainStackView.bottomAnchor.constraint(equalTo: selectorView.bottomAnchor, constant: -16).isActive = true - } func updateLabels() { //add the stackview to hold the 2 labels //text label - textLabel.textPosition = .left - textLabel.typograpicalStyle = .BoldBodyLarge textLabel.text = text textLabel.surface = surface textLabel.disabled = disabled @@ -208,8 +202,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ //subText label if let subText { - subTextLabel.textPosition = .left - subTextLabel.typograpicalStyle = .BodyLarge subTextLabel.text = subText subTextLabel.surface = surface subTextLabel.disabled = disabled @@ -225,8 +217,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ //subTextRight label if let subTextRight { - subTextRightLabel.textPosition = .right - subTextRightLabel.typograpicalStyle = .BodyLarge subTextRightLabel.text = subTextRight subTextRightLabel.surface = surface subTextRightLabel.disabled = disabled diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index c2938af9..9a26565b 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -49,7 +49,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, public required init?(coder: NSCoder) { super.init(coder: coder) } - + //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- @@ -62,29 +62,23 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, guard labelText?.isEmpty == false || childText?.isEmpty == false || labelAttributedText?.string.isEmpty == false || childAttributedText?.string.isEmpty == false else { return false } return true } - - private var mainStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .vertical - } - }() - private var selectorStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .horizontal - } - }() + private var mainStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .vertical + } - private var selectorLabelStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .vertical - } - }() + private var selectorStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .horizontal + } + + private var selectorLabelStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .vertical + } private var primaryLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) @@ -97,20 +91,18 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, private var errorLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - + //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - public var selectorView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - }() - + public var selectorView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + open var labelText: String? { didSet { didChange() }} - + open var labelTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} - + open var labelAttributedText: NSAttributedString? { didSet { primaryLabel.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) @@ -118,9 +110,9 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, didChange() } } - + open var childText: String? { didSet { didChange() }} - + open var childTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var childAttributedText: NSAttributedString? { @@ -130,21 +122,21 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, didChange() } } - + open var showError: Bool = false { didSet { didChange() }} open var errorText: String? { didSet { didChange() }} - + open var inputId: String? { didSet { didChange() }} - + open var value: AnyHashable? { didSet { didChange() }} open var dataAnalyticsTrack: String? { didSet { didChange() }} - + open var dataClickStream: String? { didSet { didChange() }} - + open var dataTrack: String? { didSet { didChange() }} - + open var accessibilityHintEnabled: String? { didSet { didChange() }} open var accessibilityHintDisabled: String? { didSet { didChange() }} @@ -156,7 +148,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, open var accessibilityLabelEnabled: String? { didSet { didChange() }} open var accessibilityLabelDisabled: String? { didSet { didChange() }} - + //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- @@ -168,7 +160,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - + open override func setup() { super.setup() @@ -187,32 +179,39 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, selectorStackView.addArrangedSubview(selectorLabelStackView) selectorLabelStackView.addArrangedSubview(primaryLabel) selectorLabelStackView.addArrangedSubview(secondaryLabel) - + let selectorSize = getSelectorSize() selectorHeightConstraint = selectorView.heightAnchor.constraint(equalToConstant: selectorSize.height) selectorHeightConstraint?.isActive = true selectorWidthConstraint = selectorView.widthAnchor.constraint(equalToConstant: selectorSize.width) selectorWidthConstraint?.isActive = true - + updateSelector() mainStackView.topAnchor.constraint(equalTo: topAnchor).isActive = true mainStackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true mainStackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true mainStackView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true - + + //defaults + primaryLabel.textPosition = .left + primaryLabel.typograpicalStyle = .BoldBodyLarge + + secondaryLabel.textPosition = .left + secondaryLabel.typograpicalStyle = .BodyLarge + + errorLabel.textPosition = .left + errorLabel.typograpicalStyle = .BodyMedium } func updateLabels() { - + //deal with labels if shouldShowLabels { //add the stackview to hold the 2 labels //top label if let labelText { - primaryLabel.textPosition = .left - primaryLabel.typograpicalStyle = .BoldBodyLarge primaryLabel.text = labelText primaryLabel.surface = surface primaryLabel.disabled = disabled @@ -221,15 +220,13 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, } else if labelAttributedText != nil { primaryLabel.isHidden = false - + } else { primaryLabel.isHidden = true } //bottom label if let childText { - secondaryLabel.textPosition = .left - secondaryLabel.typograpicalStyle = .BodyLarge secondaryLabel.text = childText secondaryLabel.surface = surface secondaryLabel.disabled = disabled @@ -238,7 +235,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, } else if childAttributedText != nil { secondaryLabel.isHidden = false - + } else { secondaryLabel.isHidden = true } @@ -254,8 +251,6 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, //either add/remove the error from the main stack if let errorText, shouldShowError { - errorLabel.textPosition = .left - errorLabel.typograpicalStyle = .BodyMedium errorLabel.text = errorText errorLabel.surface = surface errorLabel.disabled = disabled @@ -273,11 +268,11 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, updateSelector() setAccessibilityLabel() } - + /// This will checkbox the state of the Selector and execute the actionBlock if provided. open func toggle() { guard !isSelected else { return } - + //removed error if showError && isSelected == false { showError.toggle() @@ -285,10 +280,10 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, isSelected.toggle() sendActions(for: .valueChanged) } - + //-------------------------------------------------- // MARK: - State - //-------------------------------------------------- + //-------------------------------------------------- open override func updateView() { updateLabels() updateSelector() @@ -353,7 +348,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, let bounds = selectorView.bounds let length = max(bounds.size.height, bounds.size.width) guard length > 0.0, shapeLayer == nil else { return } - + //get the colors let backgroundColor = radioButtonBackgroundColorConfiguration.getColor(self) let borderColor = radioButtonBorderColorConfiguration.getColor(self) @@ -367,9 +362,9 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, if shapeLayer == nil { let selectedBounds = radioButtonSelectedSize let bezierPath = UIBezierPath(ovalIn: CGRect(x: (bounds.width - selectedBounds.width) / 2, - y: (bounds.height - selectedBounds.height) / 2, + y: (bounds.height - selectedBounds.height) / 2, width: radioButtonSelectedSize.width, - height: radioButtonSelectedSize.height)) + height: radioButtonSelectedSize.height)) let shapeLayer = CAShapeLayer() self.shapeLayer = shapeLayer shapeLayer.frame = bounds diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index f548f18d..c3df2853 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -43,18 +43,14 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - public var selectorView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - }() - - public var fillView: UIImageView = { - return UIImageView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.contentMode = .scaleAspectFit - } - }() + public var selectorView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + + public var fillView = UIImageView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.contentMode = .scaleAspectFit + } open var fillImage: UIImage? { didSet { didChange() }} diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 5400b859..50594fad 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -58,34 +58,28 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { public required init?(coder: NSCoder) { super.init(coder: coder) } - + //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - private var stackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .horizontal - $0.distribution = .fill - } - }() + private var stackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .horizontal + $0.distribution = .fill + } private var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - private var toggleView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - }() - - private var knobView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.backgroundColor = .white - } - }() + private var toggleView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + + private var knobView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.backgroundColor = .white + } //-------------------------------------------------- // MARK: - Configuration Properties