refactored enums into class/structs that use them

also refactored models into class that are the parents

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-01-13 13:32:38 -06:00
parent 801f75a230
commit 669e0d7625
22 changed files with 391 additions and 330 deletions

View File

@ -61,7 +61,6 @@ public class Badge: View, Accessable {
private var maxWidthConstraint: NSLayoutConstraint? private var maxWidthConstraint: NSLayoutConstraint?
private var minWidthConstraint: NSLayoutConstraint? private var minWidthConstraint: NSLayoutConstraint?
//functions
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle
//-------------------------------------------------- //--------------------------------------------------

View File

@ -29,7 +29,7 @@ open class TextLinkCaret: ButtonBase {
} }
private var caretView = CaretView().with { private var caretView = CaretView().with {
$0.size = CaretView.CaretSize.small(.vertical) $0.size = CaretView.Size.small(.vertical)
$0.lineWidth = 2 $0.lineWidth = 2
} }
private var imageAttribute: ImageLabelAttribute? private var imageAttribute: ImageLabelAttribute?
@ -156,7 +156,7 @@ internal class CaretView: View {
public var direction: Direction = .right { didSet{ didChange() } } 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 { public var colorConfiguration: AnyColorable = ViewColorConfiguration().with {
$0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forDisabled: true) $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. /// Sizes of CaretView are derived from InVision design specs. They are provided for convenience.
public enum CaretSize { public enum Size {
case small(Orientation) case small(Orientation)
case medium(Orientation) case medium(Orientation)
case large(Orientation) case large(Orientation)
@ -218,7 +218,7 @@ internal class CaretView: View {
self.init(frame: .zero) self.init(frame: .zero)
} }
public convenience init(size: CaretSize){ public convenience init(size: Size){
let dimensions = size.dimensions() let dimensions = size.dimensions()
self.init(frame: .init(x: 0, y: 0, width: dimensions.width, height: dimensions.height)) self.init(frame: .init(x: 0, y: 0, width: dimensions.width, height: dimensions.height))
self.size = size self.size = size

View File

@ -10,35 +10,6 @@ import UIKit
import VDSColorTokens import VDSColorTokens
import Combine 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) @objc(VDSIcon)
public class Icon: View { public class Icon: View {
@ -57,9 +28,9 @@ public class Icon: View {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
open var color: IconColor = .black { didSet { didChange() }} open var color: Color = .black { didSet { didChange() }}
open var size: IconSize = .medium { didSet { didChange() }} open var size: Size = .medium { didSet { didChange() }}
open var name: IconName? { didSet { didChange() }} open var name: Name? { didSet { didChange() }}
//functions //functions
//-------------------------------------------------- //--------------------------------------------------
@ -95,9 +66,9 @@ public class Icon: View {
var imageColor = color.value var imageColor = color.value
//ensure the correct color for white/black colors //ensure the correct color for white/black colors
if surface == .dark && color == IconColor.black { if surface == .dark && color == Color.black {
imageColor = VDSColor.elementsPrimaryOndark imageColor = VDSColor.elementsPrimaryOndark
} else if surface == .light && color == IconColor.black { } else if surface == .light && color == Color.black {
imageColor = VDSColor.elementsPrimaryOnlight imageColor = VDSColor.elementsPrimaryOnlight
} }

View File

@ -9,7 +9,8 @@ import Foundation
import VDSColorTokens import VDSColorTokens
import UIKit import UIKit
public enum IconColor: String, CaseIterable { extension Icon {
public enum Color: String, CaseIterable {
case black case black
case white case white
case red case red
@ -88,3 +89,4 @@ public enum IconColor: String, CaseIterable {
} }
} }
} }
}

View File

@ -9,7 +9,8 @@ import Foundation
import UIKit import UIKit
import VDSColorTokens import VDSColorTokens
public struct IconName: RawRepresentable, Codable { extension Icon {
public struct Name: RawRepresentable, Codable {
public typealias RawValue = String public typealias RawValue = String
public var rawValue: String public var rawValue: String
@ -21,28 +22,29 @@ public struct IconName: RawRepresentable, Codable {
self.rawValue = name self.rawValue = name
} }
public static let checkmark = IconName(name: "checkmark") public static let checkmark = Name(name: "checkmark")
internal static let checkmarkBold = IconName(name: "checkmark-bold") internal static let checkmarkBold = Name(name: "checkmark-bold")
public static let checkmarkAlt = IconName(name: "checkmark-alt") public static let checkmarkAlt = Name(name: "checkmark-alt")
internal static let checkmarkAltBold = IconName(name: "checkmark-alt-bold") internal static let checkmarkAltBold = Name(name: "checkmark-alt-bold")
public static let close = IconName(name: "close") public static let close = Name(name: "close")
internal static let closeBold = IconName(name: "close-bold") internal static let closeBold = Name(name: "close-bold")
public static let error = IconName(name: "error") public static let error = Name(name: "error")
internal static let errorBold = IconName(name: "error-bold") internal static let errorBold = Name(name: "error-bold")
public static let info = IconName(name: "info") public static let info = Name(name: "info")
internal static let infoBold = IconName(name: "info-bold") internal static let infoBold = Name(name: "info-bold")
public static let multipleDocuments = IconName(name: "multiple-documents") public static let multipleDocuments = Name(name: "multiple-documents")
public static let leftArrow = IconName(name: "left-arrow") public static let leftArrow = Name(name: "left-arrow")
public static let leftCaret = IconName(name: "left-caret") public static let leftCaret = Name(name: "left-caret")
internal static let leftCaretBold = IconName(name: "left-caret-bold") internal static let leftCaretBold = Name(name: "left-caret-bold")
internal static let paginationLeftArrow = IconName(name: "pagination-left-arrow") internal static let paginationLeftArrow = Name(name: "pagination-left-arrow")
public static let rightArrow = IconName(name: "right-arrow") public static let rightArrow = Name(name: "right-arrow")
public static let rightCaret = IconName(name: "right-caret") public static let rightCaret = Name(name: "right-caret")
internal static let rightCaretBold = IconName(name: "right-caret-bold") internal static let rightCaretBold = Name(name: "right-caret-bold")
internal static let paginationRightArrow = IconName(name: "pagination-right-arrow") internal static let paginationRightArrow = Name(name: "pagination-right-arrow")
public static let warning = IconName(name: "warning") public static let warning = Name(name: "warning")
internal static let warningBold = IconName(name: "warning-bold") internal static let warningBold = Name(name: "warning-bold")
}
} }

View File

@ -51,7 +51,7 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel {
public func setAttribute(on attributedString: NSMutableAttributedString) { public func setAttribute(on attributedString: NSMutableAttributedString) {
if(shouldUnderline){ if(shouldUnderline){
attributedString.addAttribute(.underlineStyle, value: UnderlineStyle.single.value(), range: range) attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range)
} }
} }
} }

View File

@ -9,11 +9,18 @@ import Foundation
import UIKit import UIKit
public struct ImageLabelAttribute: AttachmentLabelAttributeModel { public struct ImageLabelAttribute: AttachmentLabelAttributeModel {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum Error: Swift.Error { public enum Error: Swift.Error {
case bundleNotFound case bundleNotFound
case imageNotFound(String) case imageNotFound(String)
case imageNotSet case imageNotSet
} }
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public var id = UUID() public var id = UUID()
public var location: Int public var location: Int
public var length: Int = 1 public var length: Int = 1
@ -21,6 +28,10 @@ public struct ImageLabelAttribute: AttachmentLabelAttributeModel {
public var image: UIImage? public var image: UIImage?
public var frame: CGRect? public var frame: CGRect?
public var tintColor: UIColor? public var tintColor: UIColor?
//--------------------------------------------------
// MARK: - Equatable
//--------------------------------------------------
public static func == (lhs: ImageLabelAttribute, rhs: ImageLabelAttribute) -> Bool { public static func == (lhs: ImageLabelAttribute, rhs: ImageLabelAttribute) -> Bool {
lhs.isEqual(rhs) lhs.isEqual(rhs)
} }
@ -29,6 +40,9 @@ public struct ImageLabelAttribute: AttachmentLabelAttributeModel {
return id == equatable.id && range == equatable.range && imageName == equatable.imageName return id == equatable.id && range == equatable.range && imageName == equatable.imageName
} }
//--------------------------------------------------
// MARK: - Private Functions
//--------------------------------------------------
private func imageAttachment(image: UIImage) -> NSTextAttachment { private func imageAttachment(image: UIImage) -> NSTextAttachment {
let attachment = NSTextAttachment() let attachment = NSTextAttachment()
attachment.image = tintColor != nil ? image.withTintColor(tintColor!) : image attachment.image = tintColor != nil ? image.withTintColor(tintColor!) : image
@ -36,6 +50,9 @@ public struct ImageLabelAttribute: AttachmentLabelAttributeModel {
return attachment return attachment
} }
//--------------------------------------------------
// MARK: - Public Functions
//--------------------------------------------------
public func getAttachment() throws -> NSTextAttachment { public func getAttachment() throws -> NSTextAttachment {
//get a local asset //get a local asset

View File

@ -10,6 +10,9 @@ import UIKit
public struct TypographicalStyleLabelAttribute: LabelAttributeModel { public struct TypographicalStyleLabelAttribute: LabelAttributeModel {
//--------------------------------------------------
// MARK: - Equatable
//--------------------------------------------------
public func isEqual(_ equatable: TypographicalStyleLabelAttribute) -> Bool { public func isEqual(_ equatable: TypographicalStyleLabelAttribute) -> Bool {
return id == equatable.id return id == equatable.id
&& range == equatable.range && range == equatable.range

View File

@ -9,7 +9,9 @@ import Foundation
import UIKit import UIKit
public struct UnderlineLabelAttribute: LabelAttributeModel { public struct UnderlineLabelAttribute: LabelAttributeModel {
//--------------------------------------------------
// MARK: - Equatable
//--------------------------------------------------
public func isEqual(_ equatable: UnderlineLabelAttribute) -> Bool { public func isEqual(_ equatable: UnderlineLabelAttribute) -> Bool {
return id == equatable.id return id == equatable.id
&& range == equatable.range && range == equatable.range
@ -18,12 +20,15 @@ public struct UnderlineLabelAttribute: LabelAttributeModel {
&& pattern == equatable.pattern && pattern == equatable.pattern
} }
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public var id = UUID() public var id = UUID()
public var location: Int public var location: Int
public var length: Int public var length: Int
public var color: UIColor? public var color: UIColor?
public var style: UnderlineStyle = .single public var style: Style = .single
public var pattern: UnderlineStyle.Pattern? public var pattern: Pattern?
public var underlineValue: NSUnderlineStyle { public var underlineValue: NSUnderlineStyle {
if let pattern = pattern?.value() { 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.location = location
self.length = length self.length = length
self.color = color self.color = color
@ -41,6 +49,9 @@ public struct UnderlineLabelAttribute: LabelAttributeModel {
self.pattern = pattern self.pattern = pattern
} }
//--------------------------------------------------
// MARK: - Public Functions
//--------------------------------------------------
public func setAttribute(on attributedString: NSMutableAttributedString) { public func setAttribute(on attributedString: NSMutableAttributedString) {
attributedString.addAttribute(.underlineStyle, value: underlineValue.rawValue, range: range) attributedString.addAttribute(.underlineStyle, value: underlineValue.rawValue, range: range)
if let color = color { if let color = color {
@ -49,7 +60,11 @@ public struct UnderlineLabelAttribute: LabelAttributeModel {
} }
} }
public enum UnderlineStyle: String, Codable { extension UnderlineLabelAttribute {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum Style: String, Codable {
case none case none
case single case single
case thick case thick
@ -70,6 +85,7 @@ public enum UnderlineStyle: String, Codable {
return NSUnderlineStyle.double.rawValue return NSUnderlineStyle.double.rawValue
} }
} }
}
public enum Pattern: String, Codable { public enum Pattern: String, Codable {
case dot case dot
@ -98,4 +114,3 @@ public enum UnderlineStyle: String, Codable {
} }
} }
} }

View File

@ -11,12 +11,15 @@ import VDSColorTokens
import VDSFormControlsTokens import VDSFormControlsTokens
import Combine import Combine
@objc(VDSEntryField)
open class EntryField: Control, Accessable {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum HelperTextPlacement: String, CaseIterable { public enum HelperTextPlacement: String, CaseIterable {
case bottom, right case bottom, right
} }
@objc(VDSEntryField)
open class EntryField: Control, Accessable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------

View File

@ -11,12 +11,15 @@ import VDSColorTokens
import VDSFormControlsTokens import VDSFormControlsTokens
import Combine import Combine
public enum InputFieldType: String, CaseIterable { @objc(VDSInputField)
public class InputField: EntryField, UITextFieldDelegate {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum FieldType: String, CaseIterable {
case text, number, calendar, inlineAction, password, creditCard, tel, date, securityCode case text, number, calendar, inlineAction, password, creditCard, tel, date, securityCode
} }
@objc(VDSInputField)
public class InputField: EntryField, UITextFieldDelegate {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------
@ -48,7 +51,7 @@ public class InputField: EntryField, UITextFieldDelegate {
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
open var type: InputFieldType = .text { didSet { didChange() }} open var type: FieldType = .text { didSet { didChange() }}
var _showError: Bool = false var _showError: Bool = false
open override var showError: Bool { open override var showError: Bool {
@ -86,6 +89,9 @@ public class InputField: EntryField, UITextFieldDelegate {
open var helperTextPlacement: HelperTextPlacement = .bottom { didSet { didChange() }} open var helperTextPlacement: HelperTextPlacement = .bottom { didSet { didChange() }}
//--------------------------------------------------
// MARK: - Private Properties
//--------------------------------------------------
private var successLabel = Label().with { private var successLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
$0.textPosition = .left $0.textPosition = .left
@ -105,7 +111,7 @@ public class InputField: EntryField, UITextFieldDelegate {
internal var minWidthConstraint: NSLayoutConstraint? internal var minWidthConstraint: NSLayoutConstraint?
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Overrides
//-------------------------------------------------- //--------------------------------------------------
open override func setup() { open override func setup() {
super.setup() super.setup()
@ -154,9 +160,6 @@ public class InputField: EntryField, UITextFieldDelegate {
return inputFieldStackView return inputFieldStackView
} }
//--------------------------------------------------
// MARK: - State
//--------------------------------------------------
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
@ -216,7 +219,7 @@ public class InputField: EntryField, UITextFieldDelegate {
} }
extension InputFieldType { extension InputField.FieldType {
var width: CGFloat { var width: CGFloat {
switch self { switch self {
case .inlineAction: case .inlineAction:

View File

@ -31,6 +31,9 @@ open class TileContainer: Control {
initialSetup() initialSetup()
} }
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum BackgroundColor: String, Codable, CaseIterable { public enum BackgroundColor: String, Codable, CaseIterable {
case white case white
case black case black
@ -215,7 +218,7 @@ open class TileContainer: Control {
} }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - State // MARK: - Private Functions
//-------------------------------------------------- //--------------------------------------------------
private func ratioSize(for width: CGFloat) -> CGSize { private func ratioSize(for width: CGFloat) -> CGSize {
var height: CGFloat = width var height: CGFloat = width
@ -247,6 +250,9 @@ open class TileContainer: Control {
return CGSize(width: width, height: height) return CGSize(width: width, height: height)
} }
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
@ -294,13 +300,18 @@ open class TileContainer: Control {
} }
} }
//--------------------------------------------------
// MARK: - Public Functions
//--------------------------------------------------
public func addContentView(_ view: UIView, shouldPin: Bool = true) { public func addContentView(_ view: UIView, shouldPin: Bool = true) {
containerView.addSubview(view) containerView.addSubview(view)
if shouldPin { if shouldPin {
view.pinToSuperView() view.pinToSuperView()
} }
} }
}
extension TileContainer {
class BackgroundColorConfiguration: ObjectColorable { class BackgroundColorConfiguration: ObjectColorable {
typealias ObjectType = TileContainer typealias ObjectType = TileContainer

View File

@ -12,8 +12,10 @@ import UIKit
@objc(VDSTilet) @objc(VDSTilet)
open class Tilet: TileContainer { open class Tilet: TileContainer {
//--------------------------------------------------
public enum TextPosition { // MARK: - Enums
//--------------------------------------------------
public enum TextPosition: String, Codable, CaseIterable {
case top case top
case bottom case bottom
} }
@ -328,8 +330,8 @@ open class Tilet: TileContainer {
titleLockup.titleModel = titleModel?.toTitleLockupTitleModel() titleLockup.titleModel = titleModel?.toTitleLockupTitleModel()
titleLockup.subTitleModel = subTitleModel?.toTitleLockupSubTitleModel() titleLockup.subTitleModel = subTitleModel?.toTitleLockupSubTitleModel()
if let style = subTitleModel?.typographicalStyle.value { if let style = subTitleModel?.textStyle.value {
titleLockup.otherTypograpicalStyle = style titleLockup.otherTextStyle = style
} }
if titleLockupContainerView.superview == nil { if titleLockupContainerView.superview == nil {

View File

@ -9,11 +9,11 @@ import Foundation
import UIKit import UIKit
public struct TiletDescriptiveIcon: Codable { public struct TiletDescriptiveIcon: Codable {
public var name: IconName = .multipleDocuments public var name: Icon.Name = .multipleDocuments
public var size: IconSize = .medium public var size: Icon.Size = .medium
public var surface: Surface = .dark 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.name = name
self.size = size self.size = size
self.surface = surface self.surface = surface
@ -21,10 +21,10 @@ public struct TiletDescriptiveIcon: Codable {
} }
public struct TiletDirectionalIcon: Codable { public struct TiletDirectionalIcon: Codable {
public var size: IconSize = .medium public var size: Icon.Size = .medium
public var surface: Surface = .dark public var surface: Surface = .dark
public init(size: IconSize, surface: Surface) { public init(size: Icon.Size, surface: Surface) {
self.size = size self.size = size
self.surface = surface self.surface = surface
} }

View File

@ -8,7 +8,10 @@
import Foundation import Foundation
public struct TiletSubTitleModel: Codable { public struct TiletSubTitleModel: Codable {
public enum SubTitleTypographicalStyle: String, Codable, EnumSubset { //--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum TextStyle: String, Codable, EnumSubset {
case BodyLarge case BodyLarge
case BoldBodyLarge case BoldBodyLarge
case BodyMedium case BodyMedium
@ -16,24 +19,33 @@ public struct TiletSubTitleModel: Codable {
case BodySmall case BodySmall
case BoldBodySmall case BoldBodySmall
public var defaultValue: TitleLockupOtherTypographicalStyle { .BodySmall } public var defaultValue: TitleLockup.OtherTextStyle { .BodySmall }
} }
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public var text: String = "" public var text: String = ""
public var typographicalStyle: SubTitleTypographicalStyle = .BodySmall public var textStyle: TextStyle = .BodySmall
public var textColor: Use = .primary public var textColor: Use = .primary
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
public init(text: String, public init(text: String,
textColor: Use = .primary, textColor: Use = .primary,
textAttributes: [any LabelAttributeModel]? = nil, textAttributes: [any LabelAttributeModel]? = nil,
typographicalStyle: SubTitleTypographicalStyle = .BodySmall) { textStyle: TextStyle = .BodySmall) {
self.text = text self.text = text
self.textColor = textColor self.textColor = textColor
self.typographicalStyle = typographicalStyle self.textStyle = textStyle
} }
public func toTitleLockupSubTitleModel() -> TitleLockupSubTitleModel { //--------------------------------------------------
TitleLockupSubTitleModel(text: text, // MARK: - Public Functions
//--------------------------------------------------
public func toTitleLockupSubTitleModel() -> TitleLockup.SubTitleModel {
TitleLockup.SubTitleModel(text: text,
textColor: textColor, textColor: textColor,
textAttributes: nil) textAttributes: nil)
} }

View File

@ -8,7 +8,10 @@
import Foundation import Foundation
public struct TiletTitleModel: Codable { public struct TiletTitleModel: Codable {
public enum TitleTypographicalStyle: String, EnumSubset, Codable { //--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum TextStyle: String, EnumSubset, Codable {
case TitleXLarge case TitleXLarge
case BoldTitleXLarge case BoldTitleXLarge
case TitleLarge case TitleLarge
@ -18,21 +21,30 @@ public struct TiletTitleModel: Codable {
case TitleSmall case TitleSmall
case BoldTitleSmall case BoldTitleSmall
public var defaultValue: TitleLockupTitleTypographicalStyle { .BoldTitleSmall } public var defaultValue: TitleLockup.TitleTextStyle { .BoldTitleSmall }
} }
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public var text: String = "" public var text: String = ""
public var typographicalStyle: TitleTypographicalStyle = .BoldTitleSmall public var textStyle: TextStyle = .BoldTitleSmall
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
public init(text: String, public init(text: String,
typographicalStyle: TitleTypographicalStyle = .BoldTitleSmall) { textStyle: TextStyle = .BoldTitleSmall) {
self.text = text self.text = text
self.typographicalStyle = typographicalStyle self.textStyle = textStyle
} }
public func toTitleLockupTitleModel() -> TitleLockupTitleModel { //--------------------------------------------------
TitleLockupTitleModel(text: text, // MARK: - Public Functions
//--------------------------------------------------
public func toTitleLockupTitleModel() -> TitleLockup.TitleModel {
TitleLockup.TitleModel(text: text,
textAttributes: nil, textAttributes: nil,
typographicalStyle: typographicalStyle.value) textStyle: textStyle.value)
} }
} }

View File

@ -10,22 +10,18 @@ import UIKit
import VDSColorTokens import VDSColorTokens
import Combine 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) @objc(VDSTitleLockup)
open class TitleLockup: View { open class TitleLockup: View {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum TextPosition: String, Codable, EnumSubset {
case left, center
public var defaultValue: VDS.TextPosition { .left }
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------
@ -177,28 +173,28 @@ open class TitleLockup: View {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
open var textPosition: TitleLockupTextPosition = .left { didSet { didChange() }} open var textPosition: TextPosition = .left { didSet { didChange() }}
//style //style
open var otherTypograpicalStyle: TitleLockupOtherTypographicalStyle = UIDevice.isIPad ? .BodyLarge : .BodyMedium { didSet { didChange() }} open var otherTextStyle: OtherTextStyle = UIDevice.isIPad ? .BodyLarge : .BodyMedium { didSet { didChange() }}
//first row //first row
open var eyebrowLabel = Label().with { open var eyebrowLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
} }
open var eyebrowModel: TitleLockupEyebrowModel? { didSet { didChange() }} open var eyebrowModel: EyebrowModel? { didSet { didChange() }}
//second row //second row
open var titleLabel = Label().with { open var titleLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
} }
open var titleModel: TitleLockupTitleModel? { didSet { didChange() }} open var titleModel: TitleModel? { didSet { didChange() }}
//third row //third row
open var subTitleLabel = Label().with { open var subTitleLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
} }
open var subTitleModel: TitleLockupSubTitleModel? { didSet { didChange() }} open var subTitleModel: SubTitleModel? { didSet { didChange() }}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle
@ -231,7 +227,7 @@ open class TitleLockup: View {
eyebrowModel = nil eyebrowModel = nil
titleModel = nil titleModel = nil
subTitleModel = nil subTitleModel = nil
otherTypograpicalStyle = .BodyLarge otherTextStyle = .BodyLarge
} }
@ -241,7 +237,7 @@ open class TitleLockup: View {
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
let allLabelsTextPosition = textPosition.labelTextPosition let allLabelsTextPosition = textPosition.value
var eyebrowTextIsEmpty = true var eyebrowTextIsEmpty = true
var titleTextIsEmpty = true var titleTextIsEmpty = true
var subTitleTextIsEmpty = true var subTitleTextIsEmpty = true
@ -249,7 +245,7 @@ open class TitleLockup: View {
if let eyebrowModel, !eyebrowModel.text.isEmpty { if let eyebrowModel, !eyebrowModel.text.isEmpty {
eyebrowTextIsEmpty = false eyebrowTextIsEmpty = false
eyebrowLabel.textPosition = allLabelsTextPosition eyebrowLabel.textPosition = allLabelsTextPosition
eyebrowLabel.typograpicalStyle = otherTypograpicalStyle.value eyebrowLabel.typograpicalStyle = otherTextStyle.value
eyebrowLabel.text = eyebrowModel.text eyebrowLabel.text = eyebrowModel.text
eyebrowLabel.attributes = eyebrowModel.textAttributes eyebrowLabel.attributes = eyebrowModel.textAttributes
eyebrowLabel.numberOfLines = eyebrowModel.numberOfLines eyebrowLabel.numberOfLines = eyebrowModel.numberOfLines
@ -261,7 +257,7 @@ open class TitleLockup: View {
if let titleModel, !titleModel.text.isEmpty { if let titleModel, !titleModel.text.isEmpty {
titleTextIsEmpty = false titleTextIsEmpty = false
titleLabel.textPosition = allLabelsTextPosition titleLabel.textPosition = allLabelsTextPosition
titleLabel.typograpicalStyle = titleModel.typographicalStyle.value titleLabel.typograpicalStyle = titleModel.textStyle.value
titleLabel.text = titleModel.text titleLabel.text = titleModel.text
titleLabel.attributes = titleModel.textAttributes titleLabel.attributes = titleModel.textAttributes
titleLabel.numberOfLines = titleModel.numberOfLines titleLabel.numberOfLines = titleModel.numberOfLines
@ -273,7 +269,7 @@ open class TitleLockup: View {
if let subTitleModel, !subTitleModel.text.isEmpty { if let subTitleModel, !subTitleModel.text.isEmpty {
subTitleTextIsEmpty = false subTitleTextIsEmpty = false
subTitleLabel.textPosition = allLabelsTextPosition subTitleLabel.textPosition = allLabelsTextPosition
subTitleLabel.typograpicalStyle = otherTypograpicalStyle.value subTitleLabel.typograpicalStyle = otherTextStyle.value
subTitleLabel.text = subTitleModel.text subTitleLabel.text = subTitleModel.text
subTitleLabel.attributes = subTitleModel.textAttributes subTitleLabel.attributes = subTitleModel.textAttributes
subTitleLabel.numberOfLines = subTitleModel.numberOfLines subTitleLabel.numberOfLines = subTitleModel.numberOfLines
@ -285,14 +281,14 @@ open class TitleLockup: View {
//if both first 2 rows not empty set spacing //if both first 2 rows not empty set spacing
if let eyebrowModel, let titleModel, !eyebrowModel.text.isEmpty, !titleModel.text.isEmpty { 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 { } else {
stackView.spacing = 0.0 stackView.spacing = 0.0
} }
//if either first 2 rows not empty and subtile not empty, create space else collapse //if either first 2 rows not empty and subtile not empty, create space else collapse
if let titleModel, (!eyebrowTextIsEmpty || !titleTextIsEmpty) && !subTitleTextIsEmpty { 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) stackView.setCustomSpacing(bottomSpace, after: titleLabel)
} else if (!eyebrowTextIsEmpty || !titleTextIsEmpty) && subTitleTextIsEmpty { } else if (!eyebrowTextIsEmpty || !titleTextIsEmpty) && subTitleTextIsEmpty {
stackView.setCustomSpacing(0.0, after: titleLabel) stackView.setCustomSpacing(0.0, after: titleLabel)

View File

@ -7,7 +7,8 @@
import Foundation import Foundation
public struct TitleLockupEyebrowModel { extension TitleLockup {
public struct EyebrowModel {
public var text: String public var text: String
public var textAttributes: [any LabelAttributeModel]? public var textAttributes: [any LabelAttributeModel]?
public var numberOfLines: Int public var numberOfLines: Int
@ -20,3 +21,4 @@ public struct TitleLockupEyebrowModel {
self.numberOfLines = numberOfLines self.numberOfLines = numberOfLines
} }
} }
}

View File

@ -7,7 +7,8 @@
import Foundation import Foundation
public struct TitleLockupSubTitleModel { extension TitleLockup {
public struct SubTitleModel {
public var text: String public var text: String
public var textColor: Use public var textColor: Use
public var textAttributes: [any LabelAttributeModel]? public var textAttributes: [any LabelAttributeModel]?
@ -23,3 +24,4 @@ public struct TitleLockupSubTitleModel {
self.numberOfLines = numberOfLines self.numberOfLines = numberOfLines
} }
} }
}

View File

@ -7,19 +7,21 @@
import Foundation import Foundation
public struct TitleLockupTitleModel { extension TitleLockup {
public struct TitleModel {
public var text: String public var text: String
public var textAttributes: [any LabelAttributeModel]? public var textAttributes: [any LabelAttributeModel]?
public var typographicalStyle: TitleLockupTitleTypographicalStyle public var textStyle: TitleTextStyle
public var numberOfLines: Int public var numberOfLines: Int
public init(text: String, public init(text: String,
textAttributes: [any LabelAttributeModel]? = nil, textAttributes: [any LabelAttributeModel]? = nil,
typographicalStyle: TitleLockupTitleTypographicalStyle = .BoldFeatureXSmall, textStyle: TitleTextStyle = .BoldFeatureXSmall,
numberOfLines: Int = 0) { numberOfLines: Int = 0) {
self.text = text self.text = text
self.textAttributes = textAttributes self.textAttributes = textAttributes
self.typographicalStyle = typographicalStyle self.textStyle = textStyle
self.numberOfLines = numberOfLines self.numberOfLines = numberOfLines
} }
} }
}

View File

@ -7,7 +7,11 @@
import Foundation import Foundation
public enum TitleLockupTitleTypographicalStyle: String, Codable, EnumSubset { extension TitleLockup {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum TitleTextStyle: String, Codable, EnumSubset {
case FeatureMedium case FeatureMedium
case BoldFeatureMedium case BoldFeatureMedium
@ -30,7 +34,7 @@ public enum TitleLockupTitleTypographicalStyle: String, Codable, EnumSubset {
public var defaultValue: TypographicalStyle {.BoldFeatureXSmall } public var defaultValue: TypographicalStyle {.BoldFeatureXSmall }
} }
public enum TitleLockupOtherTypographicalStyle: String, Codable, EnumSubset { public enum OtherTextStyle: String, Codable, EnumSubset {
case BodyLarge case BodyLarge
case BoldBodyLarge case BoldBodyLarge
case BodyMedium case BodyMedium
@ -40,3 +44,5 @@ public enum TitleLockupOtherTypographicalStyle: String, Codable, EnumSubset {
public var defaultValue: TypographicalStyle {.BodyLarge } public var defaultValue: TypographicalStyle {.BodyLarge }
} }
}

View File

@ -9,19 +9,6 @@ import Foundation
import UIKit import UIKit
import VDSColorTokens import VDSColorTokens
import Combine 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. A custom implementation of Apple's UISwitch.
@ -43,6 +30,20 @@ public class Toggle: ToggleBase{
@objc(VDSToggleBase) @objc(VDSToggleBase)
open class ToggleBase: Control, Accessable, DataTrackable { 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 // MARK: - Initializers
@ -138,11 +139,11 @@ open class ToggleBase: Control, Accessable, DataTrackable {
open var offText: String = "Off" { didSet { didChange() }} 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() }} open var inputId: String? { didSet { didChange() }}