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,11 +61,10 @@ 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
//-------------------------------------------------- //--------------------------------------------------
open override func setup() { open override func setup() {
super.setup() super.setup()

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,82 +9,84 @@ import Foundation
import VDSColorTokens import VDSColorTokens
import UIKit import UIKit
public enum IconColor: String, CaseIterable { extension Icon {
case black public enum Color: String, CaseIterable {
case white case black
case red case white
case gray95 case red
case gray85 case gray95
case gray65 case gray85
case gray44 case gray65
case gray20 case gray44
case gray11 case gray20
case orange91 case gray11
case orange46 case orange91
case orange39 case orange46
case orange15 case orange39
case yellow94 case orange15
case yellow62 case yellow94
case yellow20 case yellow62
case blue91 case yellow20
case blue45 case blue91
case blue35 case blue45
case blue13 case blue35
case green89 case blue13
case green34 case green89
case green26 case green34
case green11 case green26
case green11
public var value: UIColor {
switch self { public var value: UIColor {
case .black: switch self {
return VDSColor.paletteBlack case .black:
case .white: return VDSColor.paletteBlack
return VDSColor.paletteWhite case .white:
case .red: return VDSColor.paletteWhite
return VDSColor.paletteRed case .red:
case .gray95: return VDSColor.paletteRed
return VDSColor.paletteGray95 case .gray95:
case .gray85: return VDSColor.paletteGray95
return VDSColor.paletteGray85 case .gray85:
case .gray65: return VDSColor.paletteGray85
return VDSColor.paletteGray65 case .gray65:
case .gray44: return VDSColor.paletteGray65
return VDSColor.paletteGray44 case .gray44:
case .gray20: return VDSColor.paletteGray44
return VDSColor.paletteGray20 case .gray20:
case .gray11: return VDSColor.paletteGray20
return VDSColor.paletteGray11 case .gray11:
case .orange91: return VDSColor.paletteGray11
return VDSColor.paletteOrange91 case .orange91:
case .orange46: return VDSColor.paletteOrange91
return VDSColor.paletteOrange46 case .orange46:
case .orange39: return VDSColor.paletteOrange46
return VDSColor.paletteOrange39 case .orange39:
case .orange15: return VDSColor.paletteOrange39
return VDSColor.paletteOrange15 case .orange15:
case .yellow94: return VDSColor.paletteOrange15
return VDSColor.paletteYellow94 case .yellow94:
case .yellow62: return VDSColor.paletteYellow94
return VDSColor.paletteYellow62 case .yellow62:
case .yellow20: return VDSColor.paletteYellow62
return VDSColor.paletteYellow20 case .yellow20:
case .blue91: return VDSColor.paletteYellow20
return VDSColor.paletteBlue91 case .blue91:
case .blue45: return VDSColor.paletteBlue91
return VDSColor.paletteBlue45 case .blue45:
case .blue35: return VDSColor.paletteBlue45
return VDSColor.paletteBlue35 case .blue35:
case .blue13: return VDSColor.paletteBlue35
return VDSColor.paletteBlue13 case .blue13:
case .green89: return VDSColor.paletteBlue13
return VDSColor.paletteGreen89 case .green89:
case .green34: return VDSColor.paletteGreen89
return VDSColor.paletteGreen34 case .green34:
case .green26: return VDSColor.paletteGreen34
return VDSColor.paletteGreen26 case .green26:
case .green11: return VDSColor.paletteGreen26
return VDSColor.paletteGreen11 case .green11:
return VDSColor.paletteGreen11
}
} }
} }
} }

View File

@ -9,40 +9,42 @@ import Foundation
import UIKit import UIKit
import VDSColorTokens import VDSColorTokens
public struct IconName: RawRepresentable, Codable { extension Icon {
public typealias RawValue = String public struct Name: RawRepresentable, Codable {
public var rawValue: String public typealias RawValue = String
public var rawValue: String
public init?(rawValue: String) {
self.rawValue = rawValue 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")
} }

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,7 +49,10 @@ public struct UnderlineLabelAttribute: LabelAttributeModel {
self.pattern = pattern 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) attributedString.addAttribute(.underlineStyle, value: underlineValue.rawValue, range: range)
if let color = color { if let color = color {
attributedString.addAttribute(.underlineColor, value: color, range: range) attributedString.addAttribute(.underlineColor, value: color, range: range)
@ -49,25 +60,30 @@ public struct UnderlineLabelAttribute: LabelAttributeModel {
} }
} }
public enum UnderlineStyle: String, Codable { extension UnderlineLabelAttribute {
case none //--------------------------------------------------
case single // MARK: - Enums
case thick //--------------------------------------------------
case double public enum Style: String, Codable {
case none
func value() -> Int { case single
switch self { case thick
case .none: case double
return 0
func value() -> Int {
case .single: switch self {
return NSUnderlineStyle.single.rawValue case .none:
return 0
case .thick:
return NSUnderlineStyle.thick.rawValue case .single:
return NSUnderlineStyle.single.rawValue
case .double:
return NSUnderlineStyle.double.rawValue case .thick:
return NSUnderlineStyle.thick.rawValue
case .double:
return NSUnderlineStyle.double.rawValue
}
} }
} }
@ -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
public enum HelperTextPlacement: String, CaseIterable {
case bottom, right
}
@objc(VDSEntryField) @objc(VDSEntryField)
open class EntryField: Control, Accessable { open class EntryField: Control, Accessable {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum HelperTextPlacement: String, CaseIterable {
case bottom, right
}
//-------------------------------------------------- //--------------------------------------------------
// 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 {
case text, number, calendar, inlineAction, password, creditCard, tel, date, securityCode
}
@objc(VDSInputField) @objc(VDSInputField)
public class InputField: EntryField, UITextFieldDelegate { public class InputField: EntryField, UITextFieldDelegate {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum FieldType: String, CaseIterable {
case text, number, calendar, inlineAction, password, creditCard, tel, date, securityCode
}
//-------------------------------------------------- //--------------------------------------------------
// 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,25 +19,34 @@ 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
textColor: textColor, //--------------------------------------------------
textAttributes: nil) public func toTitleLockupSubTitleModel() -> TitleLockup.SubTitleModel {
TitleLockup.SubTitleModel(text: text,
textColor: textColor,
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
textAttributes: nil, //--------------------------------------------------
typographicalStyle: typographicalStyle.value) public func toTitleLockupTitleModel() -> TitleLockup.TitleModel {
TitleLockup.TitleModel(text: text,
textAttributes: nil,
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,16 +7,18 @@
import Foundation import Foundation
public struct TitleLockupEyebrowModel { extension TitleLockup {
public var text: String public struct EyebrowModel {
public var textAttributes: [any LabelAttributeModel]? public var text: String
public var numberOfLines: Int public var textAttributes: [any LabelAttributeModel]?
public var numberOfLines: Int
public init(text: String,
textAttributes: [any LabelAttributeModel]? = nil, public init(text: String,
numberOfLines: Int = 0) { textAttributes: [any LabelAttributeModel]? = nil,
self.text = text numberOfLines: Int = 0) {
self.textAttributes = textAttributes self.text = text
self.numberOfLines = numberOfLines self.textAttributes = textAttributes
self.numberOfLines = numberOfLines
}
} }
} }

View File

@ -7,19 +7,21 @@
import Foundation import Foundation
public struct TitleLockupSubTitleModel { extension TitleLockup {
public var text: String public struct SubTitleModel {
public var textColor: Use public var text: String
public var textAttributes: [any LabelAttributeModel]? public var textColor: Use
public var numberOfLines: Int public var textAttributes: [any LabelAttributeModel]?
public var numberOfLines: Int
public init(text: String,
textColor: Use = .primary, public init(text: String,
textAttributes: [any LabelAttributeModel]? = nil, textColor: Use = .primary,
numberOfLines: Int = 0) { textAttributes: [any LabelAttributeModel]? = nil,
self.text = text numberOfLines: Int = 0) {
self.textColor = textColor self.text = text
self.textAttributes = textAttributes self.textColor = textColor
self.numberOfLines = numberOfLines self.textAttributes = textAttributes
self.numberOfLines = numberOfLines
}
} }
} }

View File

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

View File

@ -7,36 +7,42 @@
import Foundation 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 public enum OtherTextStyle: String, Codable, EnumSubset {
case BoldFeatureMedium case BodyLarge
case FeatureSmall case BoldBodyLarge
case BoldFeatureSmall case BodyMedium
case FeatureXSmall case BoldBodyMedium
case BoldFeatureXSmall 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 }
} }

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() }}