diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index c9cceca8..16a5370c 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -61,11 +61,10 @@ public class Badge: View, Accessable { private var maxWidthConstraint: NSLayoutConstraint? private var minWidthConstraint: NSLayoutConstraint? - //functions //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - + open override func setup() { super.setup() diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index 7bc0e7dd..af95b24e 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -29,7 +29,7 @@ open class TextLinkCaret: ButtonBase { } private var caretView = CaretView().with { - $0.size = CaretView.CaretSize.small(.vertical) + $0.size = CaretView.Size.small(.vertical) $0.lineWidth = 2 } private var imageAttribute: ImageLabelAttribute? @@ -156,7 +156,7 @@ internal class CaretView: View { public var direction: Direction = .right { didSet{ didChange() } } - public var size: CaretSize? { didSet{ didChange() } } + public var size: Size? { didSet{ didChange() } } public var colorConfiguration: AnyColorable = ViewColorConfiguration().with { $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forDisabled: true) @@ -169,7 +169,7 @@ internal class CaretView: View { //------------------------------------------------------ /// Sizes of CaretView are derived from InVision design specs. They are provided for convenience. - public enum CaretSize { + public enum Size { case small(Orientation) case medium(Orientation) case large(Orientation) @@ -218,7 +218,7 @@ internal class CaretView: View { self.init(frame: .zero) } - public convenience init(size: CaretSize){ + public convenience init(size: Size){ let dimensions = size.dimensions() self.init(frame: .init(x: 0, y: 0, width: dimensions.width, height: dimensions.height)) self.size = size diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index 754d78de..6105b633 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -10,35 +10,6 @@ import UIKit import VDSColorTokens import Combine -public enum IconSize: String, CaseIterable, Codable { - case xsmall - case small - case medium - case large - case XLarge - - public var dimensions: CGSize { - switch self { - - case .xsmall: - return .init(width: 12, height: 12) - - case .small: - return .init(width: 16, height: 16) - - case .medium: - return .init(width: 20, height: 20) - - case .large: - return .init(width: 24, height: 24) - - case .XLarge: - return .init(width: 28, height: 28) - - } - } -} - @objc(VDSIcon) public class Icon: View { @@ -57,9 +28,9 @@ public class Icon: View { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - open var color: IconColor = .black { didSet { didChange() }} - open var size: IconSize = .medium { didSet { didChange() }} - open var name: IconName? { didSet { didChange() }} + open var color: Color = .black { didSet { didChange() }} + open var size: Size = .medium { didSet { didChange() }} + open var name: Name? { didSet { didChange() }} //functions //-------------------------------------------------- @@ -95,9 +66,9 @@ public class Icon: View { var imageColor = color.value //ensure the correct color for white/black colors - if surface == .dark && color == IconColor.black { + if surface == .dark && color == Color.black { imageColor = VDSColor.elementsPrimaryOndark - } else if surface == .light && color == IconColor.black { + } else if surface == .light && color == Color.black { imageColor = VDSColor.elementsPrimaryOnlight } diff --git a/VDS/Components/Icon/IconColor.swift b/VDS/Components/Icon/IconColor.swift index 49f8d85d..c9d4bf0e 100644 --- a/VDS/Components/Icon/IconColor.swift +++ b/VDS/Components/Icon/IconColor.swift @@ -9,82 +9,84 @@ import Foundation import VDSColorTokens import UIKit -public enum IconColor: String, CaseIterable { - case black - case white - case red - case gray95 - case gray85 - case gray65 - case gray44 - case gray20 - case gray11 - case orange91 - case orange46 - case orange39 - case orange15 - case yellow94 - case yellow62 - case yellow20 - case blue91 - case blue45 - case blue35 - case blue13 - case green89 - case green34 - case green26 - case green11 - - public var value: UIColor { - switch self { - case .black: - return VDSColor.paletteBlack - case .white: - return VDSColor.paletteWhite - case .red: - return VDSColor.paletteRed - case .gray95: - return VDSColor.paletteGray95 - case .gray85: - return VDSColor.paletteGray85 - case .gray65: - return VDSColor.paletteGray65 - case .gray44: - return VDSColor.paletteGray44 - case .gray20: - return VDSColor.paletteGray20 - case .gray11: - return VDSColor.paletteGray11 - case .orange91: - return VDSColor.paletteOrange91 - case .orange46: - return VDSColor.paletteOrange46 - case .orange39: - return VDSColor.paletteOrange39 - case .orange15: - return VDSColor.paletteOrange15 - case .yellow94: - return VDSColor.paletteYellow94 - case .yellow62: - return VDSColor.paletteYellow62 - case .yellow20: - return VDSColor.paletteYellow20 - case .blue91: - return VDSColor.paletteBlue91 - case .blue45: - return VDSColor.paletteBlue45 - case .blue35: - return VDSColor.paletteBlue35 - case .blue13: - return VDSColor.paletteBlue13 - case .green89: - return VDSColor.paletteGreen89 - case .green34: - return VDSColor.paletteGreen34 - case .green26: - return VDSColor.paletteGreen26 - case .green11: - return VDSColor.paletteGreen11 +extension Icon { + public enum Color: String, CaseIterable { + case black + case white + case red + case gray95 + case gray85 + case gray65 + case gray44 + case gray20 + case gray11 + case orange91 + case orange46 + case orange39 + case orange15 + case yellow94 + case yellow62 + case yellow20 + case blue91 + case blue45 + case blue35 + case blue13 + case green89 + case green34 + case green26 + case green11 + + public var value: UIColor { + switch self { + case .black: + return VDSColor.paletteBlack + case .white: + return VDSColor.paletteWhite + case .red: + return VDSColor.paletteRed + case .gray95: + return VDSColor.paletteGray95 + case .gray85: + return VDSColor.paletteGray85 + case .gray65: + return VDSColor.paletteGray65 + case .gray44: + return VDSColor.paletteGray44 + case .gray20: + return VDSColor.paletteGray20 + case .gray11: + return VDSColor.paletteGray11 + case .orange91: + return VDSColor.paletteOrange91 + case .orange46: + return VDSColor.paletteOrange46 + case .orange39: + return VDSColor.paletteOrange39 + case .orange15: + return VDSColor.paletteOrange15 + case .yellow94: + return VDSColor.paletteYellow94 + case .yellow62: + return VDSColor.paletteYellow62 + case .yellow20: + return VDSColor.paletteYellow20 + case .blue91: + return VDSColor.paletteBlue91 + case .blue45: + return VDSColor.paletteBlue45 + case .blue35: + return VDSColor.paletteBlue35 + case .blue13: + return VDSColor.paletteBlue13 + case .green89: + return VDSColor.paletteGreen89 + case .green34: + return VDSColor.paletteGreen34 + case .green26: + return VDSColor.paletteGreen26 + case .green11: + return VDSColor.paletteGreen11 + } } } } diff --git a/VDS/Components/Icon/IconName.swift b/VDS/Components/Icon/IconName.swift index 84fd2579..a24be628 100644 --- a/VDS/Components/Icon/IconName.swift +++ b/VDS/Components/Icon/IconName.swift @@ -9,40 +9,42 @@ import Foundation import UIKit import VDSColorTokens -public struct IconName: RawRepresentable, Codable { - public typealias RawValue = String - public var rawValue: String - - public init?(rawValue: String) { - self.rawValue = rawValue +extension Icon { + public struct Name: RawRepresentable, Codable { + public typealias RawValue = String + public var rawValue: String + + public init?(rawValue: String) { + self.rawValue = rawValue + } + + public init(name: String){ + self.rawValue = name + } + + public static let checkmark = Name(name: "checkmark") + internal static let checkmarkBold = Name(name: "checkmark-bold") + public static let checkmarkAlt = Name(name: "checkmark-alt") + internal static let checkmarkAltBold = Name(name: "checkmark-alt-bold") + public static let close = Name(name: "close") + internal static let closeBold = Name(name: "close-bold") + public static let error = Name(name: "error") + internal static let errorBold = Name(name: "error-bold") + public static let info = Name(name: "info") + internal static let infoBold = Name(name: "info-bold") + public static let multipleDocuments = Name(name: "multiple-documents") + + public static let leftArrow = Name(name: "left-arrow") + public static let leftCaret = Name(name: "left-caret") + internal static let leftCaretBold = Name(name: "left-caret-bold") + internal static let paginationLeftArrow = Name(name: "pagination-left-arrow") + + public static let rightArrow = Name(name: "right-arrow") + public static let rightCaret = Name(name: "right-caret") + internal static let rightCaretBold = Name(name: "right-caret-bold") + internal static let paginationRightArrow = Name(name: "pagination-right-arrow") + + public static let warning = Name(name: "warning") + internal static let warningBold = Name(name: "warning-bold") } - - public init(name: String){ - self.rawValue = name - } - - public static let checkmark = IconName(name: "checkmark") - internal static let checkmarkBold = IconName(name: "checkmark-bold") - public static let checkmarkAlt = IconName(name: "checkmark-alt") - internal static let checkmarkAltBold = IconName(name: "checkmark-alt-bold") - public static let close = IconName(name: "close") - internal static let closeBold = IconName(name: "close-bold") - public static let error = IconName(name: "error") - internal static let errorBold = IconName(name: "error-bold") - public static let info = IconName(name: "info") - internal static let infoBold = IconName(name: "info-bold") - public static let multipleDocuments = IconName(name: "multiple-documents") - - public static let leftArrow = IconName(name: "left-arrow") - public static let leftCaret = IconName(name: "left-caret") - internal static let leftCaretBold = IconName(name: "left-caret-bold") - internal static let paginationLeftArrow = IconName(name: "pagination-left-arrow") - - public static let rightArrow = IconName(name: "right-arrow") - public static let rightCaret = IconName(name: "right-caret") - internal static let rightCaretBold = IconName(name: "right-caret-bold") - internal static let paginationRightArrow = IconName(name: "pagination-right-arrow") - - public static let warning = IconName(name: "warning") - internal static let warningBold = IconName(name: "warning-bold") } diff --git a/VDS/Components/Label/Attributes/ActionLabelAttribute.swift b/VDS/Components/Label/Attributes/ActionLabelAttribute.swift index fe3b2012..dc0f9638 100644 --- a/VDS/Components/Label/Attributes/ActionLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ActionLabelAttribute.swift @@ -51,7 +51,7 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel { public func setAttribute(on attributedString: NSMutableAttributedString) { if(shouldUnderline){ - attributedString.addAttribute(.underlineStyle, value: UnderlineStyle.single.value(), range: range) + attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range) } } } diff --git a/VDS/Components/Label/Attributes/ImageLabelAttribute.swift b/VDS/Components/Label/Attributes/ImageLabelAttribute.swift index bf6e067a..fed62a91 100644 --- a/VDS/Components/Label/Attributes/ImageLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ImageLabelAttribute.swift @@ -9,11 +9,18 @@ import Foundation import UIKit public struct ImageLabelAttribute: AttachmentLabelAttributeModel { + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- public enum Error: Swift.Error { case bundleNotFound case imageNotFound(String) case imageNotSet } + + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- public var id = UUID() public var location: Int public var length: Int = 1 @@ -21,6 +28,10 @@ public struct ImageLabelAttribute: AttachmentLabelAttributeModel { public var image: UIImage? public var frame: CGRect? public var tintColor: UIColor? + + //-------------------------------------------------- + // MARK: - Equatable + //-------------------------------------------------- public static func == (lhs: ImageLabelAttribute, rhs: ImageLabelAttribute) -> Bool { lhs.isEqual(rhs) } @@ -29,6 +40,9 @@ public struct ImageLabelAttribute: AttachmentLabelAttributeModel { return id == equatable.id && range == equatable.range && imageName == equatable.imageName } + //-------------------------------------------------- + // MARK: - Private Functions + //-------------------------------------------------- private func imageAttachment(image: UIImage) -> NSTextAttachment { let attachment = NSTextAttachment() attachment.image = tintColor != nil ? image.withTintColor(tintColor!) : image @@ -36,6 +50,9 @@ public struct ImageLabelAttribute: AttachmentLabelAttributeModel { return attachment } + //-------------------------------------------------- + // MARK: - Public Functions + //-------------------------------------------------- public func getAttachment() throws -> NSTextAttachment { //get a local asset diff --git a/VDS/Components/Label/Attributes/TypographicalStyleLabelAttribute.swift b/VDS/Components/Label/Attributes/TypographicalStyleLabelAttribute.swift index fe923113..43851ac5 100644 --- a/VDS/Components/Label/Attributes/TypographicalStyleLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/TypographicalStyleLabelAttribute.swift @@ -10,6 +10,9 @@ import UIKit public struct TypographicalStyleLabelAttribute: LabelAttributeModel { + //-------------------------------------------------- + // MARK: - Equatable + //-------------------------------------------------- public func isEqual(_ equatable: TypographicalStyleLabelAttribute) -> Bool { return id == equatable.id && range == equatable.range diff --git a/VDS/Components/Label/Attributes/UnderlineLabelAttribute.swift b/VDS/Components/Label/Attributes/UnderlineLabelAttribute.swift index d1d9399b..64a9842c 100644 --- a/VDS/Components/Label/Attributes/UnderlineLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/UnderlineLabelAttribute.swift @@ -9,7 +9,9 @@ import Foundation import UIKit public struct UnderlineLabelAttribute: LabelAttributeModel { - + //-------------------------------------------------- + // MARK: - Equatable + //-------------------------------------------------- public func isEqual(_ equatable: UnderlineLabelAttribute) -> Bool { return id == equatable.id && range == equatable.range @@ -18,12 +20,15 @@ public struct UnderlineLabelAttribute: LabelAttributeModel { && pattern == equatable.pattern } + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- public var id = UUID() public var location: Int public var length: Int public var color: UIColor? - public var style: UnderlineStyle = .single - public var pattern: UnderlineStyle.Pattern? + public var style: Style = .single + public var pattern: Pattern? public var underlineValue: NSUnderlineStyle { if let pattern = pattern?.value() { @@ -33,7 +38,10 @@ public struct UnderlineLabelAttribute: LabelAttributeModel { } } - public init(location: Int, length: Int, style: UnderlineStyle = .single, color: UIColor? = nil, pattern: UnderlineStyle.Pattern? = nil) { + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + public init(location: Int, length: Int, style: Style = .single, color: UIColor? = nil, pattern: Pattern? = nil) { self.location = location self.length = length self.color = color @@ -41,7 +49,10 @@ public struct UnderlineLabelAttribute: LabelAttributeModel { self.pattern = pattern } - public func setAttribute(on attributedString: NSMutableAttributedString) { + //-------------------------------------------------- + // MARK: - Public Functions + //-------------------------------------------------- + public func setAttribute(on attributedString: NSMutableAttributedString) { attributedString.addAttribute(.underlineStyle, value: underlineValue.rawValue, range: range) if let color = color { attributedString.addAttribute(.underlineColor, value: color, range: range) @@ -49,25 +60,30 @@ public struct UnderlineLabelAttribute: LabelAttributeModel { } } -public enum UnderlineStyle: String, Codable { - case none - case single - case thick - case double - - func value() -> Int { - switch self { - case .none: - return 0 - - case .single: - return NSUnderlineStyle.single.rawValue - - case .thick: - return NSUnderlineStyle.thick.rawValue - - case .double: - return NSUnderlineStyle.double.rawValue +extension UnderlineLabelAttribute { + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- + public enum Style: String, Codable { + case none + case single + case thick + case double + + func value() -> Int { + switch self { + case .none: + return 0 + + case .single: + return NSUnderlineStyle.single.rawValue + + case .thick: + return NSUnderlineStyle.thick.rawValue + + case .double: + return NSUnderlineStyle.double.rawValue + } } } @@ -98,4 +114,3 @@ public enum UnderlineStyle: String, Codable { } } } - diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index b5f6193e..5a425837 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -11,12 +11,15 @@ import VDSColorTokens import VDSFormControlsTokens import Combine -public enum HelperTextPlacement: String, CaseIterable { - case bottom, right -} - @objc(VDSEntryField) open class EntryField: Control, Accessable { + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- + public enum HelperTextPlacement: String, CaseIterable { + case bottom, right + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index e4e84be1..f6e0e72e 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -11,12 +11,15 @@ import VDSColorTokens import VDSFormControlsTokens import Combine -public enum InputFieldType: String, CaseIterable { - case text, number, calendar, inlineAction, password, creditCard, tel, date, securityCode -} - @objc(VDSInputField) public class InputField: EntryField, UITextFieldDelegate { + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- + public enum FieldType: String, CaseIterable { + case text, number, calendar, inlineAction, password, creditCard, tel, date, securityCode + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -48,7 +51,7 @@ public class InputField: EntryField, UITextFieldDelegate { // MARK: - Public Properties //-------------------------------------------------- - open var type: InputFieldType = .text { didSet { didChange() }} + open var type: FieldType = .text { didSet { didChange() }} var _showError: Bool = false open override var showError: Bool { @@ -86,6 +89,9 @@ public class InputField: EntryField, UITextFieldDelegate { open var helperTextPlacement: HelperTextPlacement = .bottom { didSet { didChange() }} + //-------------------------------------------------- + // MARK: - Private Properties + //-------------------------------------------------- private var successLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left @@ -105,7 +111,7 @@ public class InputField: EntryField, UITextFieldDelegate { internal var minWidthConstraint: NSLayoutConstraint? //-------------------------------------------------- - // MARK: - Lifecycle + // MARK: - Overrides //-------------------------------------------------- open override func setup() { super.setup() @@ -154,9 +160,6 @@ public class InputField: EntryField, UITextFieldDelegate { return inputFieldStackView } - //-------------------------------------------------- - // MARK: - State - //-------------------------------------------------- open override func updateView() { super.updateView() @@ -216,7 +219,7 @@ public class InputField: EntryField, UITextFieldDelegate { } -extension InputFieldType { +extension InputField.FieldType { var width: CGFloat { switch self { case .inlineAction: diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index f27c7fc2..bd56dcdd 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -31,6 +31,9 @@ open class TileContainer: Control { initialSetup() } + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- public enum BackgroundColor: String, Codable, CaseIterable { case white case black @@ -215,7 +218,7 @@ open class TileContainer: Control { } //-------------------------------------------------- - // MARK: - State + // MARK: - Private Functions //-------------------------------------------------- private func ratioSize(for width: CGFloat) -> CGSize { var height: CGFloat = width @@ -247,6 +250,9 @@ open class TileContainer: Control { return CGSize(width: width, height: height) } + //-------------------------------------------------- + // MARK: - Overrides + //-------------------------------------------------- open override func updateView() { super.updateView() @@ -294,13 +300,18 @@ open class TileContainer: Control { } } + //-------------------------------------------------- + // MARK: - Public Functions + //-------------------------------------------------- public func addContentView(_ view: UIView, shouldPin: Bool = true) { containerView.addSubview(view) if shouldPin { view.pinToSuperView() } } - +} + +extension TileContainer { class BackgroundColorConfiguration: ObjectColorable { typealias ObjectType = TileContainer diff --git a/VDS/Components/Tilet/Tilet.swift b/VDS/Components/Tilet/Tilet.swift index 2b0baccc..08c4ad57 100644 --- a/VDS/Components/Tilet/Tilet.swift +++ b/VDS/Components/Tilet/Tilet.swift @@ -12,8 +12,10 @@ import UIKit @objc(VDSTilet) open class Tilet: TileContainer { - - public enum TextPosition { + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- + public enum TextPosition: String, Codable, CaseIterable { case top case bottom } @@ -328,8 +330,8 @@ open class Tilet: TileContainer { titleLockup.titleModel = titleModel?.toTitleLockupTitleModel() titleLockup.subTitleModel = subTitleModel?.toTitleLockupSubTitleModel() - if let style = subTitleModel?.typographicalStyle.value { - titleLockup.otherTypograpicalStyle = style + if let style = subTitleModel?.textStyle.value { + titleLockup.otherTextStyle = style } if titleLockupContainerView.superview == nil { diff --git a/VDS/Components/Tilet/TiletIconModels.swift b/VDS/Components/Tilet/TiletIconModels.swift index 79be1d07..d5347dad 100644 --- a/VDS/Components/Tilet/TiletIconModels.swift +++ b/VDS/Components/Tilet/TiletIconModels.swift @@ -9,11 +9,11 @@ import Foundation import UIKit public struct TiletDescriptiveIcon: Codable { - public var name: IconName = .multipleDocuments - public var size: IconSize = .medium + public var name: Icon.Name = .multipleDocuments + public var size: Icon.Size = .medium public var surface: Surface = .dark - public init(name: IconName = .multipleDocuments, size: IconSize, surface: Surface) { + public init(name: Icon.Name = .multipleDocuments, size: Icon.Size, surface: Surface) { self.name = name self.size = size self.surface = surface @@ -21,10 +21,10 @@ public struct TiletDescriptiveIcon: Codable { } public struct TiletDirectionalIcon: Codable { - public var size: IconSize = .medium + public var size: Icon.Size = .medium public var surface: Surface = .dark - public init(size: IconSize, surface: Surface) { + public init(size: Icon.Size, surface: Surface) { self.size = size self.surface = surface } diff --git a/VDS/Components/Tilet/TiletSubTitleModel.swift b/VDS/Components/Tilet/TiletSubTitleModel.swift index c2a2ca93..f39a854f 100644 --- a/VDS/Components/Tilet/TiletSubTitleModel.swift +++ b/VDS/Components/Tilet/TiletSubTitleModel.swift @@ -8,7 +8,10 @@ import Foundation public struct TiletSubTitleModel: Codable { - public enum SubTitleTypographicalStyle: String, Codable, EnumSubset { + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- + public enum TextStyle: String, Codable, EnumSubset { case BodyLarge case BoldBodyLarge case BodyMedium @@ -16,25 +19,34 @@ public struct TiletSubTitleModel: Codable { case BodySmall case BoldBodySmall - public var defaultValue: TitleLockupOtherTypographicalStyle { .BodySmall } + public var defaultValue: TitleLockup.OtherTextStyle { .BodySmall } } + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- public var text: String = "" - public var typographicalStyle: SubTitleTypographicalStyle = .BodySmall + public var textStyle: TextStyle = .BodySmall public var textColor: Use = .primary + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- public init(text: String, textColor: Use = .primary, textAttributes: [any LabelAttributeModel]? = nil, - typographicalStyle: SubTitleTypographicalStyle = .BodySmall) { + textStyle: TextStyle = .BodySmall) { self.text = text self.textColor = textColor - self.typographicalStyle = typographicalStyle + self.textStyle = textStyle } - public func toTitleLockupSubTitleModel() -> TitleLockupSubTitleModel { - TitleLockupSubTitleModel(text: text, - textColor: textColor, - textAttributes: nil) + //-------------------------------------------------- + // MARK: - Public Functions + //-------------------------------------------------- + public func toTitleLockupSubTitleModel() -> TitleLockup.SubTitleModel { + TitleLockup.SubTitleModel(text: text, + textColor: textColor, + textAttributes: nil) } } diff --git a/VDS/Components/Tilet/TiletTitleModel.swift b/VDS/Components/Tilet/TiletTitleModel.swift index fdf52187..cafae988 100644 --- a/VDS/Components/Tilet/TiletTitleModel.swift +++ b/VDS/Components/Tilet/TiletTitleModel.swift @@ -8,7 +8,10 @@ import Foundation public struct TiletTitleModel: Codable { - public enum TitleTypographicalStyle: String, EnumSubset, Codable { + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- + public enum TextStyle: String, EnumSubset, Codable { case TitleXLarge case BoldTitleXLarge case TitleLarge @@ -18,21 +21,30 @@ public struct TiletTitleModel: Codable { case TitleSmall case BoldTitleSmall - public var defaultValue: TitleLockupTitleTypographicalStyle { .BoldTitleSmall } + public var defaultValue: TitleLockup.TitleTextStyle { .BoldTitleSmall } } + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- public var text: String = "" - public var typographicalStyle: TitleTypographicalStyle = .BoldTitleSmall + public var textStyle: TextStyle = .BoldTitleSmall + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- public init(text: String, - typographicalStyle: TitleTypographicalStyle = .BoldTitleSmall) { + textStyle: TextStyle = .BoldTitleSmall) { self.text = text - self.typographicalStyle = typographicalStyle + self.textStyle = textStyle } - public func toTitleLockupTitleModel() -> TitleLockupTitleModel { - TitleLockupTitleModel(text: text, - textAttributes: nil, - typographicalStyle: typographicalStyle.value) + //-------------------------------------------------- + // MARK: - Public Functions + //-------------------------------------------------- + public func toTitleLockupTitleModel() -> TitleLockup.TitleModel { + TitleLockup.TitleModel(text: text, + textAttributes: nil, + textStyle: textStyle.value) } } diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 33633723..10d8306d 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -10,22 +10,18 @@ import UIKit import VDSColorTokens import Combine -public enum TitleLockupTextPosition: String, Codable, CaseIterable { - case left, center - - var labelTextPosition: TextPosition { - switch self { - case .left: - return .left - case .center: - return .center - } - } -} - @objc(VDSTitleLockup) open class TitleLockup: View { + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- + public enum TextPosition: String, Codable, EnumSubset { + case left, center + + public var defaultValue: VDS.TextPosition { .left } + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -177,28 +173,28 @@ open class TitleLockup: View { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - open var textPosition: TitleLockupTextPosition = .left { didSet { didChange() }} + open var textPosition: TextPosition = .left { didSet { didChange() }} //style - open var otherTypograpicalStyle: TitleLockupOtherTypographicalStyle = UIDevice.isIPad ? .BodyLarge : .BodyMedium { didSet { didChange() }} + open var otherTextStyle: OtherTextStyle = UIDevice.isIPad ? .BodyLarge : .BodyMedium { didSet { didChange() }} //first row open var eyebrowLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - open var eyebrowModel: TitleLockupEyebrowModel? { didSet { didChange() }} + open var eyebrowModel: EyebrowModel? { didSet { didChange() }} //second row open var titleLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - open var titleModel: TitleLockupTitleModel? { didSet { didChange() }} + open var titleModel: TitleModel? { didSet { didChange() }} //third row open var subTitleLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - open var subTitleModel: TitleLockupSubTitleModel? { didSet { didChange() }} + open var subTitleModel: SubTitleModel? { didSet { didChange() }} //-------------------------------------------------- // MARK: - Lifecycle @@ -231,7 +227,7 @@ open class TitleLockup: View { eyebrowModel = nil titleModel = nil subTitleModel = nil - otherTypograpicalStyle = .BodyLarge + otherTextStyle = .BodyLarge } @@ -241,7 +237,7 @@ open class TitleLockup: View { open override func updateView() { super.updateView() - let allLabelsTextPosition = textPosition.labelTextPosition + let allLabelsTextPosition = textPosition.value var eyebrowTextIsEmpty = true var titleTextIsEmpty = true var subTitleTextIsEmpty = true @@ -249,7 +245,7 @@ open class TitleLockup: View { if let eyebrowModel, !eyebrowModel.text.isEmpty { eyebrowTextIsEmpty = false eyebrowLabel.textPosition = allLabelsTextPosition - eyebrowLabel.typograpicalStyle = otherTypograpicalStyle.value + eyebrowLabel.typograpicalStyle = otherTextStyle.value eyebrowLabel.text = eyebrowModel.text eyebrowLabel.attributes = eyebrowModel.textAttributes eyebrowLabel.numberOfLines = eyebrowModel.numberOfLines @@ -261,7 +257,7 @@ open class TitleLockup: View { if let titleModel, !titleModel.text.isEmpty { titleTextIsEmpty = false titleLabel.textPosition = allLabelsTextPosition - titleLabel.typograpicalStyle = titleModel.typographicalStyle.value + titleLabel.typograpicalStyle = titleModel.textStyle.value titleLabel.text = titleModel.text titleLabel.attributes = titleModel.textAttributes titleLabel.numberOfLines = titleModel.numberOfLines @@ -273,7 +269,7 @@ open class TitleLockup: View { if let subTitleModel, !subTitleModel.text.isEmpty { subTitleTextIsEmpty = false subTitleLabel.textPosition = allLabelsTextPosition - subTitleLabel.typograpicalStyle = otherTypograpicalStyle.value + subTitleLabel.typograpicalStyle = otherTextStyle.value subTitleLabel.text = subTitleModel.text subTitleLabel.attributes = subTitleModel.textAttributes subTitleLabel.numberOfLines = subTitleModel.numberOfLines @@ -285,14 +281,14 @@ open class TitleLockup: View { //if both first 2 rows not empty set spacing if let eyebrowModel, let titleModel, !eyebrowModel.text.isEmpty, !titleModel.text.isEmpty { - stackView.spacing = topTypographicalStyleSpacingConfig.spacing(for: titleModel.typographicalStyle.value, neighboring: otherTypograpicalStyle.value) + stackView.spacing = topTypographicalStyleSpacingConfig.spacing(for: titleModel.textStyle.value, neighboring: otherTextStyle.value) } else { stackView.spacing = 0.0 } //if either first 2 rows not empty and subtile not empty, create space else collapse if let titleModel, (!eyebrowTextIsEmpty || !titleTextIsEmpty) && !subTitleTextIsEmpty { - let bottomSpace = bottomTypographicalStyleSpacingConfig.spacing(for: titleModel.typographicalStyle.value, neighboring: otherTypograpicalStyle.value) + let bottomSpace = bottomTypographicalStyleSpacingConfig.spacing(for: titleModel.textStyle.value, neighboring: otherTextStyle.value) stackView.setCustomSpacing(bottomSpace, after: titleLabel) } else if (!eyebrowTextIsEmpty || !titleTextIsEmpty) && subTitleTextIsEmpty { stackView.setCustomSpacing(0.0, after: titleLabel) diff --git a/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift b/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift index 786d3b09..fc5ea48e 100644 --- a/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift +++ b/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift @@ -7,16 +7,18 @@ import Foundation -public struct TitleLockupEyebrowModel { - public var text: String - public var textAttributes: [any LabelAttributeModel]? - public var numberOfLines: Int - - public init(text: String, - textAttributes: [any LabelAttributeModel]? = nil, - numberOfLines: Int = 0) { - self.text = text - self.textAttributes = textAttributes - self.numberOfLines = numberOfLines +extension TitleLockup { + public struct EyebrowModel { + public var text: String + public var textAttributes: [any LabelAttributeModel]? + public var numberOfLines: Int + + public init(text: String, + textAttributes: [any LabelAttributeModel]? = nil, + numberOfLines: Int = 0) { + self.text = text + self.textAttributes = textAttributes + self.numberOfLines = numberOfLines + } } } diff --git a/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift b/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift index f5b1380b..6be2782f 100644 --- a/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift +++ b/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift @@ -7,19 +7,21 @@ import Foundation -public struct TitleLockupSubTitleModel { - public var text: String - public var textColor: Use - public var textAttributes: [any LabelAttributeModel]? - public var numberOfLines: Int - - public init(text: String, - textColor: Use = .primary, - textAttributes: [any LabelAttributeModel]? = nil, - numberOfLines: Int = 0) { - self.text = text - self.textColor = textColor - self.textAttributes = textAttributes - self.numberOfLines = numberOfLines +extension TitleLockup { + public struct SubTitleModel { + public var text: String + public var textColor: Use + public var textAttributes: [any LabelAttributeModel]? + public var numberOfLines: Int + + public init(text: String, + textColor: Use = .primary, + textAttributes: [any LabelAttributeModel]? = nil, + numberOfLines: Int = 0) { + self.text = text + self.textColor = textColor + self.textAttributes = textAttributes + self.numberOfLines = numberOfLines + } } } diff --git a/VDS/Components/TitleLockup/TitleLockupTitleModel.swift b/VDS/Components/TitleLockup/TitleLockupTitleModel.swift index c351206c..ddf7a3a4 100644 --- a/VDS/Components/TitleLockup/TitleLockupTitleModel.swift +++ b/VDS/Components/TitleLockup/TitleLockupTitleModel.swift @@ -7,19 +7,21 @@ import Foundation -public struct TitleLockupTitleModel { - public var text: String - public var textAttributes: [any LabelAttributeModel]? - public var typographicalStyle: TitleLockupTitleTypographicalStyle - public var numberOfLines: Int - - public init(text: String, - textAttributes: [any LabelAttributeModel]? = nil, - typographicalStyle: TitleLockupTitleTypographicalStyle = .BoldFeatureXSmall, - numberOfLines: Int = 0) { - self.text = text - self.textAttributes = textAttributes - self.typographicalStyle = typographicalStyle - self.numberOfLines = numberOfLines +extension TitleLockup { + public struct TitleModel { + public var text: String + public var textAttributes: [any LabelAttributeModel]? + public var textStyle: TitleTextStyle + public var numberOfLines: Int + + public init(text: String, + textAttributes: [any LabelAttributeModel]? = nil, + textStyle: TitleTextStyle = .BoldFeatureXSmall, + numberOfLines: Int = 0) { + self.text = text + self.textAttributes = textAttributes + self.textStyle = textStyle + self.numberOfLines = numberOfLines + } } } diff --git a/VDS/Components/TitleLockup/TitleLockupTypography.swift b/VDS/Components/TitleLockup/TitleLockupTypography.swift index 0e67d58a..47955a03 100644 --- a/VDS/Components/TitleLockup/TitleLockupTypography.swift +++ b/VDS/Components/TitleLockup/TitleLockupTypography.swift @@ -7,36 +7,42 @@ import Foundation -public enum TitleLockupTitleTypographicalStyle: String, Codable, EnumSubset { +extension TitleLockup { + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- + public enum TitleTextStyle: String, Codable, EnumSubset { + + case FeatureMedium + case BoldFeatureMedium + case FeatureSmall + case BoldFeatureSmall + case FeatureXSmall + case BoldFeatureXSmall + + case Title2XLarge + case BoldTitle2XLarge + case TitleXLarge + case BoldTitleXLarge + case TitleLarge + case BoldTitleLarge + case TitleMedium + case BoldTitleMedium + case TitleSmall + case BoldTitleSmall + + public var defaultValue: TypographicalStyle {.BoldFeatureXSmall } + } - case FeatureMedium - case BoldFeatureMedium - case FeatureSmall - case BoldFeatureSmall - case FeatureXSmall - case BoldFeatureXSmall + public enum OtherTextStyle: String, Codable, EnumSubset { + case BodyLarge + case BoldBodyLarge + case BodyMedium + case BoldBodyMedium + case BodySmall + case BoldBodySmall + + public var defaultValue: TypographicalStyle {.BodyLarge } + } - case Title2XLarge - case BoldTitle2XLarge - case TitleXLarge - case BoldTitleXLarge - case TitleLarge - case BoldTitleLarge - case TitleMedium - case BoldTitleMedium - case TitleSmall - case BoldTitleSmall - - public var defaultValue: TypographicalStyle {.BoldFeatureXSmall } -} - -public enum TitleLockupOtherTypographicalStyle: String, Codable, EnumSubset { - case BodyLarge - case BoldBodyLarge - case BodyMedium - case BoldBodyMedium - case BodySmall - case BoldBodySmall - - public var defaultValue: TypographicalStyle {.BodyLarge } } diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index d5b86437..894516d1 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -9,19 +9,6 @@ import Foundation import UIKit import VDSColorTokens import Combine - -public enum ToggleTextSize: String, CaseIterable { - case small, large -} - -public enum ToggleTextWeight: String, CaseIterable { - case regular, bold -} - -public enum ToggleTextPosition: String, CaseIterable { - case left, right -} - /** A custom implementation of Apple's UISwitch. @@ -43,6 +30,20 @@ public class Toggle: ToggleBase{ @objc(VDSToggleBase) open class ToggleBase: Control, Accessable, DataTrackable { + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- + public enum TextSize: String, Codable, CaseIterable { + case small, large + } + + public enum TextWeight: String, Codable, CaseIterable { + case regular, bold + } + + public enum TextPosition: String, Codable, CaseIterable { + case left, right + } //-------------------------------------------------- // MARK: - Initializers @@ -138,11 +139,11 @@ open class ToggleBase: Control, Accessable, DataTrackable { open var offText: String = "Off" { didSet { didChange() }} - open var textSize: ToggleTextSize = .small { didSet { didChange() }} + open var textSize: TextSize = .small { didSet { didChange() }} - open var textWeight: ToggleTextWeight = .regular { didSet { didChange() }} + open var textWeight: TextWeight = .regular { didSet { didChange() }} - open var textPosition: ToggleTextPosition = .left { didSet { didChange() }} + open var textPosition: TextPosition = .left { didSet { didChange() }} open var inputId: String? { didSet { didChange() }}