refactored out Typography and converted to TextStyle

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-01-13 14:04:15 -06:00
parent 443636b723
commit 9526a7ec40
15 changed files with 124 additions and 122 deletions

View File

@ -57,7 +57,7 @@
EA985BEC2968A91200F2FF2E /* TitleLockupTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */; }; EA985BEC2968A91200F2FF2E /* TitleLockupTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */; };
EA985BEE2968A92400F2FF2E /* TitleLockupSubTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */; }; EA985BEE2968A92400F2FF2E /* TitleLockupSubTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */; };
EA985BF02968A93600F2FF2E /* TitleLockupEyebrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */; }; EA985BF02968A93600F2FF2E /* TitleLockupEyebrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */; };
EA985BF22968B5BB00F2FF2E /* TitleLockupTypography.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF12968B5BB00F2FF2E /* TitleLockupTypography.swift */; }; EA985BF22968B5BB00F2FF2E /* TitleLockupTextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF12968B5BB00F2FF2E /* TitleLockupTextStyle.swift */; };
EA985BF5296C60C000F2FF2E /* Icon.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF4296C60C000F2FF2E /* Icon.swift */; }; EA985BF5296C60C000F2FF2E /* Icon.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF4296C60C000F2FF2E /* Icon.swift */; };
EA985BF7296C665E00F2FF2E /* IconName.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF6296C665E00F2FF2E /* IconName.swift */; }; EA985BF7296C665E00F2FF2E /* IconName.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF6296C665E00F2FF2E /* IconName.swift */; };
EA985BF9296C710100F2FF2E /* IconColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF8296C710100F2FF2E /* IconColor.swift */; }; EA985BF9296C710100F2FF2E /* IconColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF8296C710100F2FF2E /* IconColor.swift */; };
@ -98,7 +98,7 @@
EAF7F0A2289AFB3900B287F5 /* Errorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A1289AFB3900B287F5 /* Errorable.swift */; }; EAF7F0A2289AFB3900B287F5 /* Errorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A1289AFB3900B287F5 /* Errorable.swift */; };
EAF7F0A4289B017C00B287F5 /* LabelAttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */; }; EAF7F0A4289B017C00B287F5 /* LabelAttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */; };
EAF7F0A6289B0CE000B287F5 /* Resetable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A5289B0CE000B287F5 /* Resetable.swift */; }; EAF7F0A6289B0CE000B287F5 /* Resetable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A5289B0CE000B287F5 /* Resetable.swift */; };
EAF7F0AB289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AA289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift */; }; EAF7F0AB289B13FD00B287F5 /* TextStyleLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AA289B13FD00B287F5 /* TextStyleLabelAttribute.swift */; };
EAF7F0AD289B142900B287F5 /* StrikeThroughLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AC289B142900B287F5 /* StrikeThroughLabelAttribute.swift */; }; EAF7F0AD289B142900B287F5 /* StrikeThroughLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AC289B142900B287F5 /* StrikeThroughLabelAttribute.swift */; };
EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AE289B144C00B287F5 /* UnderlineLabelAttribute.swift */; }; EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AE289B144C00B287F5 /* UnderlineLabelAttribute.swift */; };
EAF7F0B1289B177F00B287F5 /* ColorLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */; }; EAF7F0B1289B177F00B287F5 /* ColorLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */; };
@ -172,7 +172,7 @@
EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupTitleModel.swift; sourceTree = "<group>"; }; EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupTitleModel.swift; sourceTree = "<group>"; };
EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupSubTitleModel.swift; sourceTree = "<group>"; }; EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupSubTitleModel.swift; sourceTree = "<group>"; };
EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupEyebrowModel.swift; sourceTree = "<group>"; }; EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupEyebrowModel.swift; sourceTree = "<group>"; };
EA985BF12968B5BB00F2FF2E /* TitleLockupTypography.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupTypography.swift; sourceTree = "<group>"; }; EA985BF12968B5BB00F2FF2E /* TitleLockupTextStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupTextStyle.swift; sourceTree = "<group>"; };
EA985BF4296C60C000F2FF2E /* Icon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Icon.swift; sourceTree = "<group>"; }; EA985BF4296C60C000F2FF2E /* Icon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Icon.swift; sourceTree = "<group>"; };
EA985BF6296C665E00F2FF2E /* IconName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconName.swift; sourceTree = "<group>"; }; EA985BF6296C665E00F2FF2E /* IconName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconName.swift; sourceTree = "<group>"; };
EA985BF8296C710100F2FF2E /* IconColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconColor.swift; sourceTree = "<group>"; }; EA985BF8296C710100F2FF2E /* IconColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconColor.swift; sourceTree = "<group>"; };
@ -213,7 +213,7 @@
EAF7F0A1289AFB3900B287F5 /* Errorable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errorable.swift; sourceTree = "<group>"; }; EAF7F0A1289AFB3900B287F5 /* Errorable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errorable.swift; sourceTree = "<group>"; };
EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeModel.swift; sourceTree = "<group>"; }; EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeModel.swift; sourceTree = "<group>"; };
EAF7F0A5289B0CE000B287F5 /* Resetable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resetable.swift; sourceTree = "<group>"; }; EAF7F0A5289B0CE000B287F5 /* Resetable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resetable.swift; sourceTree = "<group>"; };
EAF7F0AA289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypographicalStyleLabelAttribute.swift; sourceTree = "<group>"; }; EAF7F0AA289B13FD00B287F5 /* TextStyleLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyleLabelAttribute.swift; sourceTree = "<group>"; };
EAF7F0AC289B142900B287F5 /* StrikeThroughLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StrikeThroughLabelAttribute.swift; sourceTree = "<group>"; }; EAF7F0AC289B142900B287F5 /* StrikeThroughLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StrikeThroughLabelAttribute.swift; sourceTree = "<group>"; };
EAF7F0AE289B144C00B287F5 /* UnderlineLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnderlineLabelAttribute.swift; sourceTree = "<group>"; }; EAF7F0AE289B144C00B287F5 /* UnderlineLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnderlineLabelAttribute.swift; sourceTree = "<group>"; };
EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorLabelAttribute.swift; sourceTree = "<group>"; }; EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorLabelAttribute.swift; sourceTree = "<group>"; };
@ -493,7 +493,7 @@
EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */, EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */,
EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */, EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */,
EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */, EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */,
EA985BF12968B5BB00F2FF2E /* TitleLockupTypography.swift */, EA985BF12968B5BB00F2FF2E /* TitleLockupTextStyle.swift */,
); );
path = TitleLockup; path = TitleLockup;
sourceTree = "<group>"; sourceTree = "<group>";
@ -617,7 +617,7 @@
EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */, EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */,
EAF7F13228A2A16500B287F5 /* AttachmentLabelAttributeModel.swift */, EAF7F13228A2A16500B287F5 /* AttachmentLabelAttributeModel.swift */,
EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */, EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */,
EAF7F0AA289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift */, EAF7F0AA289B13FD00B287F5 /* TextStyleLabelAttribute.swift */,
EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */, EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */,
EAF7F0AC289B142900B287F5 /* StrikeThroughLabelAttribute.swift */, EAF7F0AC289B142900B287F5 /* StrikeThroughLabelAttribute.swift */,
EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */, EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */,
@ -776,7 +776,7 @@
EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */, EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */,
EAF7F11728A1475A00B287F5 /* RadioButton.swift in Sources */, EAF7F11728A1475A00B287F5 /* RadioButton.swift in Sources */,
EA985BEE2968A92400F2FF2E /* TitleLockupSubTitleModel.swift in Sources */, EA985BEE2968A92400F2FF2E /* TitleLockupSubTitleModel.swift in Sources */,
EA985BF22968B5BB00F2FF2E /* TitleLockupTypography.swift in Sources */, EA985BF22968B5BB00F2FF2E /* TitleLockupTextStyle.swift in Sources */,
EAB1D2CD28ABE76100DAE764 /* Withable.swift in Sources */, EAB1D2CD28ABE76100DAE764 /* Withable.swift in Sources */,
EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */, EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */,
EAF7F0952899861000B287F5 /* Checkbox.swift in Sources */, EAF7F0952899861000B287F5 /* Checkbox.swift in Sources */,
@ -809,7 +809,7 @@
EA1F266528B945070033E859 /* RadioSwatch.swift in Sources */, EA1F266528B945070033E859 /* RadioSwatch.swift in Sources */,
EA4DB18528CA967F00103EE3 /* SelectorGroupHandlerBase.swift in Sources */, EA4DB18528CA967F00103EE3 /* SelectorGroupHandlerBase.swift in Sources */,
EA89200228AECF2A006B9984 /* UIButton+Publisher.swift in Sources */, EA89200228AECF2A006B9984 /* UIButton+Publisher.swift in Sources */,
EAF7F0AB289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift in Sources */, EAF7F0AB289B13FD00B287F5 /* TextStyleLabelAttribute.swift in Sources */,
EAB1D29C28A5618900DAE764 /* RadioButtonGroup.swift in Sources */, EAB1D29C28A5618900DAE764 /* RadioButtonGroup.swift in Sources */,
EA985BE629688F6A00F2FF2E /* TiletBadgeModel.swift in Sources */, EA985BE629688F6A00F2FF2E /* TiletBadgeModel.swift in Sources */,
EA336171288B19200071C351 /* VDS.docc in Sources */, EA336171288B19200071C351 /* VDS.docc in Sources */,

View File

@ -42,8 +42,8 @@ open class Button: ButtonBase, Useable {
textColorConfiguration.getColor(self) textColorConfiguration.getColor(self)
} }
open override var textStyle: TypographicalStyle { open override var textStyle: TextStyle {
size == .large ? TypographicalStyle.BoldBodyLarge : TypographicalStyle.BoldBodySmall size == .large ? TextStyle.BoldBodyLarge : TextStyle.BoldBodySmall
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -66,7 +66,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
} }
} }
open var textStyle: TypographicalStyle { .defaultStyle } open var textStyle: TextStyle { .defaultStyle }
open var textColor: UIColor { .black } open var textColor: UIColor { .black }

View File

@ -26,8 +26,8 @@ open class TextLink: ButtonBase {
open override var availableSizes: [ButtonSize] { [.large, .small] } open override var availableSizes: [ButtonSize] { [.large, .small] }
open override var textStyle: TypographicalStyle { open override var textStyle: TextStyle {
size == .large ? TypographicalStyle.BodyLarge : TypographicalStyle.BodySmall size == .large ? TextStyle.BodyLarge : TextStyle.BodySmall
} }
open override var textColor: UIColor { open override var textColor: UIColor {

View File

@ -24,8 +24,8 @@ open class TextLinkCaret: ButtonBase {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
open override var textStyle: TypographicalStyle { open override var textStyle: TextStyle {
TypographicalStyle.BoldBodyLarge TextStyle.BoldBodyLarge
} }
private var caretView = CaretView().with { private var caretView = CaretView().with {

View File

@ -40,10 +40,10 @@ public extension NSAttributedString {
static func createAttributeModelFor(key: NSAttributedString.Key, range: NSRange, value: Any) -> (any LabelAttributeModel)? { static func createAttributeModelFor(key: NSAttributedString.Key, range: NSRange, value: Any) -> (any LabelAttributeModel)? {
guard let value = value as? AnyHashable else { return nil } guard let value = value as? AnyHashable else { return nil }
guard let font = value as? UIFont, let style = TypographicalStyle.style(for: font.fontName, size: font.pointSize), key == .font guard let font = value as? UIFont, let style = TextStyle.style(for: font.fontName, size: font.pointSize), key == .font
else { else {
return AnyAttribute(location: range.location, length: range.length, key: key, value: value) return AnyAttribute(location: range.location, length: range.length, key: key, value: value)
} }
return TypographicalStyleLabelAttribute(location: range.location, length: range.length, style: style) return TextStyleLabelAttribute(location: range.location, length: range.length, textStyle: style)
} }
} }

View File

@ -8,16 +8,16 @@
import Foundation import Foundation
import UIKit import UIKit
public struct TypographicalStyleLabelAttribute: LabelAttributeModel { public struct TextStyleLabelAttribute: LabelAttributeModel {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Equatable // MARK: - Equatable
//-------------------------------------------------- //--------------------------------------------------
public func isEqual(_ equatable: TypographicalStyleLabelAttribute) -> Bool { public func isEqual(_ equatable: TextStyleLabelAttribute) -> Bool {
return id == equatable.id return id == equatable.id
&& range == equatable.range && range == equatable.range
&& color == equatable.color && textColor == equatable.textColor
&& style == equatable.style && textStyle == equatable.textStyle
} }
//-------------------------------------------------- //--------------------------------------------------
@ -26,19 +26,19 @@ public struct TypographicalStyleLabelAttribute: LabelAttributeModel {
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 style: TypographicalStyle public var textStyle: TextStyle
public var color: UIColor public var textColor: UIColor
public var textPosition: TextPosition public var textPosition: TextPosition
public var lineBreakMode: NSLineBreakMode public var lineBreakMode: NSLineBreakMode
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
//-------------------------------------------------- //--------------------------------------------------
public init(location: Int, length: Int, style: TypographicalStyle, color: UIColor = .black, textPosition: TextPosition = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping) { public init(location: Int, length: Int, textStyle: TextStyle, textColor: UIColor = .black, textPosition: TextPosition = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping) {
self.location = location self.location = location
self.length = length self.length = length
self.style = style self.textStyle = textStyle
self.color = color self.textColor = textColor
self.textPosition = textPosition self.textPosition = textPosition
self.lineBreakMode = lineBreakMode self.lineBreakMode = lineBreakMode
} }
@ -46,23 +46,23 @@ public struct TypographicalStyleLabelAttribute: LabelAttributeModel {
public func setAttribute(on attributedString: NSMutableAttributedString) { public func setAttribute(on attributedString: NSMutableAttributedString) {
attributedString.removeAttribute(.font, range: range) attributedString.removeAttribute(.font, range: range)
attributedString.removeAttribute(.foregroundColor, range: range) attributedString.removeAttribute(.foregroundColor, range: range)
attributedString.addAttribute(.font, value: style.font, range: range) attributedString.addAttribute(.font, value: textStyle.font, range: range)
attributedString.addAttribute(.foregroundColor, value: color, range: range) attributedString.addAttribute(.foregroundColor, value: textColor, range: range)
setStyleAttributes(attributedString) setStyleAttributes(attributedString)
} }
private func setStyleAttributes(_ attributedString: NSMutableAttributedString) { private func setStyleAttributes(_ attributedString: NSMutableAttributedString) {
//set letterSpacing //set letterSpacing
if style.letterSpacing > 0.0 { if textStyle.letterSpacing > 0.0 {
attributedString.removeAttribute(.kern, range: range) attributedString.removeAttribute(.kern, range: range)
attributedString.addAttribute(.kern, value: style.letterSpacing, range: range) attributedString.addAttribute(.kern, value: textStyle.letterSpacing, range: range)
} }
//set lineHeight //set lineHeight
if style.lineHeight > 0.0 { if textStyle.lineHeight > 0.0 {
let lineHeight = style.lineHeight let lineHeight = textStyle.lineHeight
let adjustment = lineHeight > style.font.lineHeight ? 2.0 : 1.0 let adjustment = lineHeight > textStyle.font.lineHeight ? 2.0 : 1.0
let baselineOffset = (lineHeight - style.font.lineHeight) / 2.0 / adjustment let baselineOffset = (lineHeight - textStyle.font.lineHeight) / 2.0 / adjustment
let paragraph = NSMutableParagraphStyle().with { let paragraph = NSMutableParagraphStyle().with {
$0.maximumLineHeight = lineHeight $0.maximumLineHeight = lineHeight
$0.minimumLineHeight = lineHeight $0.minimumLineHeight = lineHeight

View File

@ -33,7 +33,7 @@ public class Label: UILabel, Handlerable, ViewProtocol, Resettable {
open var attributes: [any LabelAttributeModel]? { didSet { didChange() }} open var attributes: [any LabelAttributeModel]? { didSet { didChange() }}
open var textStyle: TypographicalStyle = .defaultStyle { didSet { didChange() }} open var textStyle: TextStyle = .defaultStyle { didSet { didChange() }}
open var textPosition: TextPosition = .left { didSet { didChange() }} open var textPosition: TextPosition = .left { didSet { didChange() }}

View File

@ -100,7 +100,7 @@ public class InputField: EntryField, UITextFieldDelegate {
private var textField = UITextField().with { private var textField = UITextField().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
$0.font = TypographicalStyle.BodyLarge.font $0.font = TextStyle.BodyLarge.font
} }
public var textFieldTextColorConfiguration: AnyColorable = ViewColorConfiguration().with { public var textFieldTextColorConfiguration: AnyColorable = ViewColorConfiguration().with {

View File

@ -48,7 +48,7 @@ public class TextArea: EntryField {
private var textView = UITextView().with { private var textView = UITextView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
$0.font = TypographicalStyle.BodyLarge.font $0.font = TextStyle.BodyLarge.font
$0.sizeToFit() $0.sizeToFit()
$0.isScrollEnabled = false $0.isScrollEnabled = false
} }

View File

@ -53,7 +53,7 @@ open class Tilet: TileContainer {
private var titleLockup = TitleLockup().with { private var titleLockup = TitleLockup().with {
let configs = [ let configs = [
TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall], TextStyle.DeviceSpacingConfig([.TitleSmall, .BoldTitleSmall],
neighboring: [ neighboring: [
.BodySmall, .BoldBodySmall, .BodySmall, .BoldBodySmall,
.BodyMedium, .BoldBodyMedium .BodyMedium, .BoldBodyMedium
@ -61,7 +61,7 @@ open class Tilet: TileContainer {
spacing: 8.0, spacing: 8.0,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.TitleMedium, .BoldTitleMedium, TextStyle.DeviceSpacingConfig([.TitleMedium, .BoldTitleMedium,
.TitleLarge, .BoldTitleLarge], .TitleLarge, .BoldTitleLarge],
neighboring: [ neighboring: [
.BodySmall, .BoldBodySmall, .BodySmall, .BoldBodySmall,
@ -70,7 +70,7 @@ open class Tilet: TileContainer {
spacing: 8.0, spacing: 8.0,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge], TextStyle.DeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge],
neighboring: [ neighboring: [
.BodySmall, .BoldBodySmall, .BodySmall, .BoldBodySmall,
.BodyMedium, .BoldBodyMedium, .BodyMedium, .BoldBodyMedium,
@ -80,7 +80,7 @@ open class Tilet: TileContainer {
spacing: 12.0, spacing: 12.0,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall, TextStyle.DeviceSpacingConfig([.TitleSmall, .BoldTitleSmall,
.TitleMedium, .BoldTitleMedium], .TitleMedium, .BoldTitleMedium],
neighboring: [ neighboring: [
.BodySmall, .BoldBodySmall, .BodySmall, .BoldBodySmall,
@ -90,7 +90,7 @@ open class Tilet: TileContainer {
spacing: 8.0, spacing: 8.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.TitleLarge, .BoldTitleLarge], TextStyle.DeviceSpacingConfig([.TitleLarge, .BoldTitleLarge],
neighboring: [ neighboring: [
.BodySmall, .BoldBodySmall, .BodySmall, .BoldBodySmall,
.BodyMedium, .BoldBodyMedium, .BodyMedium, .BoldBodyMedium,
@ -100,7 +100,7 @@ open class Tilet: TileContainer {
spacing: 12.0, spacing: 12.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge], TextStyle.DeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge],
neighboring: [ neighboring: [
.BodyLarge, .BoldBodyLarge, .BodyLarge, .BoldBodyLarge,
.TitleMedium, .BoldTitleMedium .TitleMedium, .BoldTitleMedium
@ -110,7 +110,7 @@ open class Tilet: TileContainer {
] ]
$0.bottomTypographicalStyleSpacingConfig = TypographicalStyleSpacingConfig(configs: configs) $0.bottomTextStyleSpacingConfig = TextStyle.SpacingConfig(configs: configs)
} }
private var badgeContainerView = UIView().with { private var badgeContainerView = UIView().with {
@ -300,7 +300,7 @@ open class Tilet: TileContainer {
if showTitleLockup { if showTitleLockup {
//flip the surface for the titleLockup //flip the surface for the titleLockup
titleLockup.surface = color == .black ? .dark : .light titleLockup.surface = color == .black ? Surface.dark : Surface.light
//titleLockup //titleLockup
if let textWidth { if let textWidth {

View File

@ -50,124 +50,124 @@ open class TitleLockup: View {
// MARK: - Configuration Properties // MARK: - Configuration Properties
//-------------------------------------------------- //--------------------------------------------------
// Sizes are from InVision design specs. // Sizes are from InVision design specs.
open var topTypographicalStyleSpacingConfig: TypographicalStyleSpacingConfig = { open var topTextStyleSpacingConfig: TextStyle.SpacingConfig = {
let configs = [ let configs = [
TypographicalStyleDeviceSpacingConfig([.BoldTitleLarge, .TitleLarge], TextStyle.DeviceSpacingConfig([.BoldTitleLarge, .TitleLarge],
neighboring: [.BodySmall, .BodyMedium, .BodyLarge], neighboring: [.BodySmall, .BodyMedium, .BodyLarge],
spacing: 12.0, spacing: 12.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge], TextStyle.DeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
neighboring: [.TitleMedium, .BodyLarge], neighboring: [.TitleMedium, .BodyLarge],
spacing: 12.0, spacing: 12.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall], TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
neighboring: [.TitleMedium, .TitleLarge], neighboring: [.TitleMedium, .TitleLarge],
spacing: 16.0, spacing: 16.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall], TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
neighboring: [.BodyLarge], neighboring: [.BodyLarge],
spacing: 12.0, spacing: 12.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium], TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
neighboring: [.TitleMedium, .TitleLarge], neighboring: [.TitleMedium, .TitleLarge],
spacing: 16.0, spacing: 16.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium], TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
neighboring: [.BodyLarge], neighboring: [.BodyLarge],
spacing: 12.0, spacing: 12.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge], TextStyle.DeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
neighboring: [.BodyLarge, .BodyMedium, .BodySmall, .TitleMedium], neighboring: [.BodyLarge, .BodyMedium, .BodySmall, .TitleMedium],
spacing: 12.0, spacing: 12.0,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall], TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
neighboring: [.BodyLarge, .BodyMedium, .TitleMedium], neighboring: [.BodyLarge, .BodyMedium, .TitleMedium],
spacing: 12.0, spacing: 12.0,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall], TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall],
neighboring: [.TitleLarge, .BodyLarge], neighboring: [.TitleLarge, .BodyLarge],
spacing: 12.0, spacing: 12.0,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium], TextStyle.DeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
neighboring: [.TitleLarge, .TitleXLarge], neighboring: [.TitleLarge, .TitleXLarge],
spacing: 16.0, spacing: 16.0,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium], TextStyle.DeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
neighboring: [.BodyLarge], neighboring: [.BodyLarge],
spacing: 12.0, spacing: 12.0,
deviceType: .iPhone) deviceType: .iPhone)
] ]
return TypographicalStyleSpacingConfig(configs: configs) return TextStyle.SpacingConfig(configs: configs)
}() }()
open var bottomTypographicalStyleSpacingConfig: TypographicalStyleSpacingConfig = { open var bottomTextStyleSpacingConfig: TextStyle.SpacingConfig = {
let configs = [ let configs = [
TypographicalStyleDeviceSpacingConfig([.BoldTitleLarge, .TitleLarge], TextStyle.DeviceSpacingConfig([.BoldTitleLarge, .TitleLarge],
neighboring: [.BodySmall, .BodyMedium, .BodyLarge], neighboring: [.BodySmall, .BodyMedium, .BodyLarge],
spacing: 12.0, spacing: 12.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge], TextStyle.DeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
neighboring: [.TitleMedium, .BodyLarge], neighboring: [.TitleMedium, .BodyLarge],
spacing: 16.0, spacing: 16.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall], TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
neighboring: [.TitleMedium, .TitleLarge], neighboring: [.TitleMedium, .TitleLarge],
spacing: 24.0, spacing: 24.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall], TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
neighboring: [.BodyLarge], neighboring: [.BodyLarge],
spacing: 24.0, spacing: 24.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium], TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
neighboring: [.TitleMedium, .TitleLarge], neighboring: [.TitleMedium, .TitleLarge],
spacing: 24.0, spacing: 24.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium], TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
neighboring: [.BodyLarge], neighboring: [.BodyLarge],
spacing: 24.0, spacing: 24.0,
deviceType: .iPad), deviceType: .iPad),
TypographicalStyleDeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge], TextStyle.DeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
neighboring: [.BodyLarge, .BodyMedium, .BodySmall, .TitleMedium], neighboring: [.BodyLarge, .BodyMedium, .BodySmall, .TitleMedium],
spacing: 12.0, spacing: 12.0,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall], TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
neighboring: [.BodyLarge, .BodyMedium, .TitleMedium], neighboring: [.BodyLarge, .BodyMedium, .TitleMedium],
spacing: 16, spacing: 16,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall], TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall],
neighboring: [.TitleLarge, .BodyLarge], neighboring: [.TitleLarge, .BodyLarge],
spacing: 16.0, spacing: 16.0,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium], TextStyle.DeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
neighboring: [.TitleLarge, .TitleXLarge], neighboring: [.TitleLarge, .TitleXLarge],
spacing: 24.0, spacing: 24.0,
deviceType: .iPhone), deviceType: .iPhone),
TypographicalStyleDeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium], TextStyle.DeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
neighboring: [.BodyLarge], neighboring: [.BodyLarge],
spacing: 24.0, spacing: 24.0,
deviceType: .iPhone) deviceType: .iPhone)
] ]
return TypographicalStyleSpacingConfig(configs: configs) return TextStyle.SpacingConfig(configs: configs)
}() }()
//-------------------------------------------------- //--------------------------------------------------
@ -281,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.textStyle.value, neighboring: otherTextStyle.value) stackView.spacing = topTextStyleSpacingConfig.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.textStyle.value, neighboring: otherTextStyle.value) let bottomSpace = bottomTextStyleSpacingConfig.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)
@ -300,10 +300,3 @@ open class TitleLockup: View {
subTitleLabel.isHidden = subTitleTextIsEmpty subTitleLabel.isHidden = subTitleTextIsEmpty
} }
} }
extension TypographicalStyle {
func isWithin(_ collection: [TypographicalStyle]) -> Bool {
(collection.first(where: {$0 == self}) != nil)
}
}

View File

@ -1,5 +1,5 @@
// //
// TitleLockupTypography.swift // TitleLockupTextStyle.swift
// VDS // VDS
// //
// Created by Matt Bruce on 1/6/23. // Created by Matt Bruce on 1/6/23.
@ -31,7 +31,7 @@ extension TitleLockup {
case TitleSmall case TitleSmall
case BoldTitleSmall case BoldTitleSmall
public var defaultValue: TypographicalStyle {.BoldFeatureXSmall } public var defaultValue: TextStyle {.BoldFeatureXSmall }
} }
public enum OtherTextStyle: String, Codable, EnumSubset { public enum OtherTextStyle: String, Codable, EnumSubset {
@ -42,7 +42,7 @@ extension TitleLockup {
case BodySmall case BodySmall
case BoldBodySmall case BoldBodySmall
public var defaultValue: TypographicalStyle {.BodyLarge } public var defaultValue: TextStyle {.BodyLarge }
} }
} }

View File

@ -102,7 +102,7 @@ open class ToggleBase: Control, Accessable, DataTrackable {
$0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forState: .selected) $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forState: .selected)
} }
private var textStyle: TypographicalStyle { private var textStyle: TextStyle {
if textSize == .small { if textSize == .small {
if textWeight == .bold { if textWeight == .bold {
return .BoldBodySmall return .BoldBodySmall

View File

@ -23,7 +23,7 @@ public enum TextPosition: String, Codable, CaseIterable {
} }
} }
public enum TypographicalStyle: String, Codable, CaseIterable { public enum TextStyle: String, Codable, CaseIterable {
case FeatureXLarge case FeatureXLarge
case BoldFeatureXLarge case BoldFeatureXLarge
@ -57,13 +57,13 @@ public enum TypographicalStyle: String, Codable, CaseIterable {
case Micro case Micro
case BoldMicro case BoldMicro
public static var defaultStyle: TypographicalStyle { public static var defaultStyle: TextStyle {
return .BodyLarge return .BodyLarge
} }
} }
//MARK: FontCategory //MARK: FontCategory
extension TypographicalStyle { extension TextStyle {
public enum FontCategory: String, Codable, CaseIterable { public enum FontCategory: String, Codable, CaseIterable {
case feature = "Feature" case feature = "Feature"
case title = "Title" case title = "Title"
@ -83,9 +83,9 @@ extension TypographicalStyle {
} }
} }
public func style(for fontSize: FontSize?, isBold: Bool = false) -> TypographicalStyle? { public func style(for fontSize: FontSize?, isBold: Bool = false) -> TextStyle? {
let styleName = "\(isBold ? "Bold" : "")\(self.rawValue)\(fontSize?.rawValue ?? "")" let styleName = "\(isBold ? "Bold" : "")\(self.rawValue)\(fontSize?.rawValue ?? "")"
guard let style = TypographicalStyle(rawValue: styleName) else { guard let style = TextStyle(rawValue: styleName) else {
return nil return nil
} }
return style return style
@ -94,7 +94,7 @@ extension TypographicalStyle {
} }
//MARK: FontSize //MARK: FontSize
extension TypographicalStyle { extension TextStyle {
public enum FontSize: String, Codable, CaseIterable { public enum FontSize: String, Codable, CaseIterable {
case xxlarge = "2XLarge" case xxlarge = "2XLarge"
case xlarge = "XLarge" case xlarge = "XLarge"
@ -106,7 +106,7 @@ extension TypographicalStyle {
} }
//MARK: PointSize //MARK: PointSize
extension TypographicalStyle { extension TextStyle {
public var pointSize: CGFloat { public var pointSize: CGFloat {
switch self { switch self {
case .FeatureXLarge, .BoldFeatureXLarge: case .FeatureXLarge, .BoldFeatureXLarge:
@ -142,7 +142,7 @@ extension TypographicalStyle {
} }
//MARK: LineHeight //MARK: LineHeight
extension TypographicalStyle { extension TextStyle {
public var lineHeight: CGFloat { public var lineHeight: CGFloat {
switch self { switch self {
case .FeatureXLarge, .BoldFeatureXLarge: case .FeatureXLarge, .BoldFeatureXLarge:
@ -178,7 +178,7 @@ extension TypographicalStyle {
} }
//MARK: LetterSpacing //MARK: LetterSpacing
extension TypographicalStyle { extension TextStyle {
public var letterSpacing: CGFloat { public var letterSpacing: CGFloat {
switch self { switch self {
case .FeatureXLarge, case .FeatureXLarge,
@ -202,14 +202,14 @@ extension TypographicalStyle {
} }
//MARK: Alignments //MARK: Alignments
extension TypographicalStyle { extension TextStyle {
public var aligments: [TextPosition] { public var aligments: [TextPosition] {
return [.left, .center] return [.left, .center]
} }
} }
//MARK: Fonts //MARK: Fonts
extension TypographicalStyle { extension TextStyle {
public var fontFace: Fonts { public var fontFace: Fonts {
switch self { switch self {
case .BoldFeatureXLarge, case .BoldFeatureXLarge,
@ -261,8 +261,8 @@ extension TypographicalStyle {
} }
} }
extension TypographicalStyle { extension TextStyle {
public static func style(for fontName: String, size: CGFloat) -> TypographicalStyle? { public static func style(for fontName: String, size: CGFloat) -> TextStyle? {
//filter all styles by fontName //filter all styles by fontName
let styles = allCases.filter{$0.fontFace.fontName == fontName }.sorted { lhs, rhs in lhs.pointSize < rhs.pointSize } let styles = allCases.filter{$0.fontFace.fontName == fontName }.sorted { lhs, rhs in lhs.pointSize < rhs.pointSize }
@ -282,35 +282,44 @@ extension TypographicalStyle {
} }
} }
public struct TypographicalStyleSpacingConfig { extension TextStyle {
public var defaultSpacing: CGFloat = 8.0 public func isWithin(_ collection: [TextStyle]) -> Bool {
public var configs: [TypographicalStyleDeviceSpacingConfig] (collection.first(where: {$0 == self}) != nil)
}
}
public func spacing(for style: TypographicalStyle, neighboring: TypographicalStyle) -> CGFloat { extension TextStyle {
let deviceType: TypographicalStyleDeviceSpacingConfig.DeviceType = UIDevice.isIPad ? .iPad : .iPhone public struct SpacingConfig {
if let config = configs.first(where: public var defaultSpacing: CGFloat = 8.0
{ style.isWithin($0.primaryStyles) && neighboring.isWithin($0.neighboringStyles) && public var configs: [TextStyle.DeviceSpacingConfig]
($0.deviceType == deviceType || $0.deviceType == .all )})
{ public func spacing(for style: TextStyle, neighboring: TextStyle) -> CGFloat {
return config.spacing let deviceType: TextStyle.DeviceSpacingConfig.DeviceType = UIDevice.isIPad ? .iPad : .iPhone
if let config = configs.first(where:
{ style.isWithin($0.primaryStyles) && neighboring.isWithin($0.neighboringStyles) &&
($0.deviceType == deviceType || $0.deviceType == .all )})
{
return config.spacing
}
return defaultSpacing
} }
return defaultSpacing
} }
}
public struct TypographicalStyleDeviceSpacingConfig { public struct DeviceSpacingConfig {
public enum DeviceType { public enum DeviceType {
case iPhone, iPad, all case iPhone, iPad, all
} }
public var spacing: CGFloat public var spacing: CGFloat
public var deviceType: DeviceType = .iPhone public var deviceType: DeviceType = .iPhone
public var primaryStyles: [TypographicalStyle] public var primaryStyles: [TextStyle]
public var neighboringStyles: [TypographicalStyle] public var neighboringStyles: [TextStyle]
public init(_ primaryStyles: [TypographicalStyle], neighboring: [TypographicalStyle], spacing: CGFloat, deviceType: DeviceType = .iPhone) { public init(_ primaryStyles: [TextStyle], neighboring: [TextStyle], spacing: CGFloat, deviceType: DeviceType = .iPhone) {
self.spacing = spacing self.spacing = spacing
self.primaryStyles = primaryStyles self.primaryStyles = primaryStyles
self.neighboringStyles = neighboring self.neighboringStyles = neighboring
self.deviceType = deviceType self.deviceType = deviceType
}
} }
} }