From d6071686a26a96019eb82123f2256db091dc5d37 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 23 Jan 2023 09:23:37 -0600 Subject: [PATCH 1/8] added primitive protocol Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 4 ++++ VDS/Protocols/Primitive.swift | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 VDS/Protocols/Primitive.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 1a162287..54eb1514 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -66,6 +66,7 @@ EA985C2D296F03FE00F2FF2E /* TileletIconModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985C2C296F03FE00F2FF2E /* TileletIconModels.swift */; }; EA985C672970C21600F2FF2E /* VDSLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985C662970C21600F2FF2E /* VDSLayout.swift */; }; EA985C692971B90B00F2FF2E /* IconSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985C682971B90B00F2FF2E /* IconSize.swift */; }; + EA985C7D297DAED300F2FF2E /* Primitive.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985C7C297DAED300F2FF2E /* Primitive.swift */; }; EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */; }; EAA5EEB728ECC03A003B3210 /* ToolTipLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */; }; EAA5EEB928ECD24B003B3210 /* Icons.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAA5EEB828ECD24B003B3210 /* Icons.xcassets */; }; @@ -181,6 +182,7 @@ EA985C2C296F03FE00F2FF2E /* TileletIconModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TileletIconModels.swift; sourceTree = ""; }; EA985C662970C21600F2FF2E /* VDSLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VDSLayout.swift; sourceTree = ""; }; EA985C682971B90B00F2FF2E /* IconSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconSize.swift; sourceTree = ""; }; + EA985C7C297DAED300F2FF2E /* Primitive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Primitive.swift; sourceTree = ""; }; EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLabelAttribute.swift; sourceTree = ""; }; EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolTipLabelAttribute.swift; sourceTree = ""; }; EAA5EEB828ECD24B003B3210 /* Icons.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Icons.xcassets; sourceTree = ""; }; @@ -400,6 +402,7 @@ EA3361AE288B26310071C351 /* FormFieldable.swift */, EA3361BE288B2EA60071C351 /* Handlerable.swift */, EA33624628931B050071C351 /* Initable.swift */, + EA985C7C297DAED300F2FF2E /* Primitive.swift */, EAF7F0A5289B0CE000B287F5 /* Resetable.swift */, EA3361C8289054C50071C351 /* Surfaceable.swift */, EA3361B7288B2AAA0071C351 /* ViewProtocol.swift */, @@ -799,6 +802,7 @@ EAB1D2CF28ABEF2B00DAE764 /* Typography.swift in Sources */, EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */, EAF7F0A2289AFB3900B287F5 /* Errorable.swift in Sources */, + EA985C7D297DAED300F2FF2E /* Primitive.swift in Sources */, EAB5FEF829393A7200998C17 /* ButtonGroupConstants.swift in Sources */, EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */, EA5E3058295105A40082B959 /* Tilelet.swift in Sources */, diff --git a/VDS/Protocols/Primitive.swift b/VDS/Protocols/Primitive.swift new file mode 100644 index 00000000..5e895780 --- /dev/null +++ b/VDS/Protocols/Primitive.swift @@ -0,0 +1,13 @@ +public protocol Primitive {} + +extension String: Primitive {} +extension Int: Primitive {} +extension Double: Primitive {} +extension Float: Primitive {} +extension Bool: Primitive {} +extension Array: Primitive where Element: Primitive {} +extension Dictionary: Primitive where Key == String, Value: Primitive {} + +public protocol PrimitiveUserInfo { + var userInfo: [String: Primitive] { get set } +} From dd311fc920216c609d645e78d387230dfc4ef0df Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 23 Jan 2023 09:26:41 -0600 Subject: [PATCH 2/8] applied UserInfoable to views/controls Signed-off-by: Matt Bruce --- VDS/Classes/Control.swift | 4 +++- VDS/Classes/View.swift | 4 +++- VDS/Components/Buttons/Button/ButtonBase.swift | 4 +++- VDS/Components/Label/Label.swift | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index cba0078d..4da338c3 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -10,7 +10,7 @@ import UIKit import Combine @objc(VDSControl) -open class Control: UIControl, Handlerable, ViewProtocol, Resettable { +open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoable { //-------------------------------------------------- // MARK: - Combine Properties @@ -23,6 +23,8 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable { //-------------------------------------------------- private var initialSetupPerformed = false + open var userInfo = [String: Primitive]() + open var surface: Surface = .light { didSet { didChange() } } open var disabled: Bool = false { didSet { isEnabled = !disabled } } diff --git a/VDS/Classes/View.swift b/VDS/Classes/View.swift index 1671b377..c00a5887 100644 --- a/VDS/Classes/View.swift +++ b/VDS/Classes/View.swift @@ -11,7 +11,7 @@ import Combine @objc(VDSView) -open class View: UIView, Handlerable, ViewProtocol, Resettable { +open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable { //-------------------------------------------------- // MARK: - Combine Properties @@ -24,6 +24,8 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable { //-------------------------------------------------- private var initialSetupPerformed = false + open var userInfo = [String: Primitive]() + open var surface: Surface = .light { didSet { didChange() }} open var disabled: Bool = false { didSet { isEnabled = !disabled } } diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 0314a04f..890b8f9c 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -18,7 +18,7 @@ public protocol Buttonable: UIControl, Surfaceable, Disabling { } @objc(VDSButtonBase) -open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettable { +open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettable, UserInfoable { //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- @@ -48,6 +48,8 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab open var disabled: Bool = false { didSet { isEnabled = !disabled } } + open var userInfo = [String: Primitive]() + var isHighlightAnimating = false open override var isHighlighted: Bool { didSet { diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index fca57836..2a4aefd4 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -11,7 +11,7 @@ import VDSColorTokens import Combine @objc(VDSLabel) -public class Label: UILabel, Handlerable, ViewProtocol, Resettable { +public class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { //-------------------------------------------------- // MARK: - Combine Properties @@ -37,6 +37,8 @@ public class Label: UILabel, Handlerable, ViewProtocol, Resettable { open var textPosition: TextPosition = .left { didSet { didChange() }} + open var userInfo = [String: Primitive]() + open override var isEnabled: Bool { get { !disabled } set { From 508d02e7b9c0a30b8c2f7ce88dddd6e0c5aa83b7 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 23 Jan 2023 09:27:04 -0600 Subject: [PATCH 3/8] updated naming Signed-off-by: Matt Bruce --- VDS/Protocols/Primitive.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VDS/Protocols/Primitive.swift b/VDS/Protocols/Primitive.swift index 5e895780..30982c67 100644 --- a/VDS/Protocols/Primitive.swift +++ b/VDS/Protocols/Primitive.swift @@ -8,6 +8,6 @@ extension Bool: Primitive {} extension Array: Primitive where Element: Primitive {} extension Dictionary: Primitive where Key == String, Value: Primitive {} -public protocol PrimitiveUserInfo { +public protocol UserInfoable { var userInfo: [String: Primitive] { get set } } From ef1ca0f6ab0ab4d98574ae1aff35dbef71dcc073 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 23 Jan 2023 09:27:36 -0600 Subject: [PATCH 4/8] marked private/internal subcomponents to open Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 7 +-- VDS/Components/Checkbox/Checkbox.swift | 14 ++--- VDS/Components/Icon/Icon.swift | 8 +-- VDS/Components/RadioBox/RadioBox.swift | 12 ++--- VDS/Components/RadioButton/RadioButton.swift | 12 ++--- .../TextFields/EntryField/EntryField.swift | 53 +++++++++---------- VDS/Components/Tilelet/Tilelet.swift | 34 ++++++------ VDS/Components/Toggle/Toggle.swift | 10 ++-- 8 files changed, 73 insertions(+), 77 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index d2759c52..b8d919c4 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -22,9 +22,9 @@ public class Badge: View, Accessable { } //-------------------------------------------------- - // MARK: - Private Properties + // MARK: - Public Properties //-------------------------------------------------- - private var label = Label().with { + open var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.adjustsFontSizeToFitWidth = false $0.lineBreakMode = .byTruncatingTail @@ -32,9 +32,6 @@ public class Badge: View, Accessable { $0.textStyle = .boldBodySmall } - //-------------------------------------------------- - // MARK: - Public Properties - //-------------------------------------------------- open var fillColor: FillColor = .red { didSet { didChange() }} open var text: String = "" { didSet { didChange() }} diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 12ab59c3..a1a6a0fd 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -73,28 +73,28 @@ open class CheckboxBase: Control, Accessable, DataTrackable, Errorable { $0.axis = .vertical } - private var label = Label().with { + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- + open var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left $0.textStyle = .boldBodyLarge } - private var childLabel = Label().with { + open var childLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left $0.textStyle = .bodyLarge } - private var errorLabel = Label().with { + open var errorLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left $0.textStyle = .bodyMedium } - //-------------------------------------------------- - // MARK: - Public Properties - //-------------------------------------------------- - public var selectorView = UIView().with { + open var selectorView = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false } diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index 6105b633..184ccf6f 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -19,15 +19,15 @@ public class Icon: View { private var widthConstraint: NSLayoutConstraint? private var heightConstraint: NSLayoutConstraint? - private var imageView = UIImageView().with { + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- + open var imageView = UIImageView().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.contentMode = .scaleAspectFill $0.clipsToBounds = true } - //-------------------------------------------------- - // MARK: - Public Properties - //-------------------------------------------------- open var color: Color = .black { didSet { didChange() }} open var size: Size = .medium { didSet { didChange() }} open var name: Name? { didSet { didChange() }} diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 975199af..bacd5278 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -67,27 +67,27 @@ open class RadioBoxBase: Control, Accessable, DataTrackable{ $0.isHidden = false } - private var textLabel = Label().with { + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- + open var textLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left $0.textStyle = .boldBodyLarge } - private var subTextLabel = Label().with { + open var subTextLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left $0.textStyle = .bodyLarge } - private var subTextRightLabel = Label().with { + open var subTextRightLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .right $0.textStyle = .bodyLarge } - //-------------------------------------------------- - // MARK: - Public Properties - //-------------------------------------------------- public var selectorView = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false } diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 1f01e85b..08b46faf 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -80,27 +80,27 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, Errorable { $0.axis = .vertical } - private var label = Label().with { + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- + open var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left $0.textStyle = .boldBodyLarge } - private var childLabel = Label().with { + open var childLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left $0.textStyle = .bodyLarge } - private var errorLabel = Label().with { + open var errorLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left $0.textStyle = .bodyMedium } - //-------------------------------------------------- - // MARK: - Public Properties - //-------------------------------------------------- public var selectorView = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false } diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index e4d4b9fd..5e500b9a 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -45,26 +45,7 @@ open class EntryField: Control, Accessable { $0.distribution = .fill } }() - - internal var titleLabel = Label().with { - $0.setContentCompressionResistancePriority(.required, for: .vertical) - $0.attributes = [] - $0.textPosition = .left - $0.textStyle = .bodySmall - } - - internal var errorLabel = Label().with { - $0.setContentCompressionResistancePriority(.required, for: .vertical) - $0.textPosition = .left - $0.textStyle = .bodySmall - } - - internal var helperLabel = Label().with { - $0.setContentCompressionResistancePriority(.required, for: .vertical) - $0.textPosition = .left - $0.textStyle = .bodySmall - } - + internal var containerView: UIView = { return UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false @@ -85,13 +66,7 @@ open class EntryField: Control, Accessable { $0.translatesAutoresizingMaskIntoConstraints = false } }() - - - internal var tooltipView: UIView? - internal var icon: Icon = Icon().with { - $0.size = .small - } - + //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- @@ -123,6 +98,30 @@ open class EntryField: Control, Accessable { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- + open var titleLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.attributes = [] + $0.textPosition = .left + $0.textStyle = .bodySmall + } + + open var errorLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.textStyle = .bodySmall + } + + open var helperLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.textStyle = .bodySmall + } + + open var tooltipView: UIView? + open var icon: Icon = Icon().with { + $0.size = .small + } + open var labelText: String? { didSet { didChange() }} open var helperText: String? { didSet { didChange() }} diff --git a/VDS/Components/Tilelet/Tilelet.swift b/VDS/Components/Tilelet/Tilelet.swift index 8ad347e8..dd35a951 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -50,8 +50,20 @@ open class Tilelet: TileContainer { private var titleLockupContainerView = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false } - - private var titleLockup = TitleLockup().with { + + private var badgeContainerView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + + private let iconContainerView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.backgroundColor = .clear + } + + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- + open var titleLockup = TitleLockup().with { let configs = [ TextStyle.DeviceSpacingConfig([.titleSmall, .boldTitleSmall], neighboring: [ @@ -113,28 +125,16 @@ open class Tilelet: TileContainer { $0.bottomTextStyleSpacingConfig = TextStyle.SpacingConfig(configs: configs) } - private var badgeContainerView = UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - - private var badge = Badge().with { + open var badge = Badge().with { $0.fillColor = .red } - private let iconContainerView = UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.backgroundColor = .clear - } + open var descriptiveIcon = Icon() - private var descriptiveIcon = Icon() - private var directionalIcon = Icon().with { + open var directionalIcon = Icon().with { $0.name = .rightArrow } - //-------------------------------------------------- - // MARK: - Public Properties - //-------------------------------------------------- - //style private var _textWidth: CGFloat? open var textWidth: CGFloat? { get { _textWidth } diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index e490d456..6af7354d 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -68,11 +68,7 @@ open class ToggleBase: Control, Accessable, DataTrackable { $0.axis = .horizontal $0.distribution = .fill } - - private var label = Label().with { - $0.setContentCompressionResistancePriority(.required, for: .vertical) - } - + private var toggleView = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false } @@ -121,6 +117,10 @@ open class ToggleBase: Control, Accessable, DataTrackable { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- + open var label = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } + open var isOn: Bool { get { isSelected } set { From d2d8140b70ac113a87c90344563fd3bb63103696 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 25 Jan 2023 09:53:56 -0600 Subject: [PATCH 5/8] added codable to enums Signed-off-by: Matt Bruce --- VDS/Components/Buttons/Button/Button.swift | 2 +- VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift | 2 +- VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift | 2 +- VDS/Components/Icon/IconColor.swift | 2 +- VDS/Components/TextFields/EntryField/EntryField.swift | 2 +- VDS/Components/TextFields/InputField/InputField.swift | 2 +- VDS/Components/TileContainer/TileContainer.swift | 6 +++--- VDS/Components/Tilelet/Tilelet.swift | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index 1bc94e2e..1a4bc3d4 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -11,7 +11,7 @@ import VDSColorTokens import VDSFormControlsTokens import Combine -public enum ButtonSize: String, Codable, CaseIterable { +public enum ButtonSize: String, CaseIterable, Codable { case large case small } diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 1bc28dba..6d3f2ef3 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -17,7 +17,7 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum ButtonPosition: String, CaseIterable { + public enum ButtonPosition: String, CaseIterable, Codable { case left, center, right } diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index 7c2f9fbd..184737dc 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -17,7 +17,7 @@ open class TextLinkCaret: ButtonBase { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum IconPosition: String, CaseIterable { + public enum IconPosition: String, CaseIterable, Codable { case left, right } diff --git a/VDS/Components/Icon/IconColor.swift b/VDS/Components/Icon/IconColor.swift index c9d4bf0e..10d7a174 100644 --- a/VDS/Components/Icon/IconColor.swift +++ b/VDS/Components/Icon/IconColor.swift @@ -10,7 +10,7 @@ import VDSColorTokens import UIKit extension Icon { - public enum Color: String, CaseIterable { + public enum Color: String, CaseIterable, Codable { case black case white case red diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index 5e500b9a..17104e46 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -16,7 +16,7 @@ open class EntryField: Control, Accessable { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum HelperTextPlacement: String, CaseIterable { + public enum HelperTextPlacement: String, CaseIterable, Codable { case bottom, right } diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index c4c4f120..3b498043 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -16,7 +16,7 @@ public class InputField: EntryField, UITextFieldDelegate { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum FieldType: String, CaseIterable { + public enum FieldType: String, CaseIterable, Codable { case text, number, calendar, inlineAction, password, creditCard, tel, date, securityCode } diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index e8ebe3f4..efccea75 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -34,14 +34,14 @@ open class TileContainer: Control { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum BackgroundColor: String, Codable, CaseIterable { + public enum BackgroundColor: String, CaseIterable, Codable { case white case black case gray case transparent } - public enum Padding: String, Codable, CaseIterable { + public enum Padding: String, CaseIterable, Codable { case padding2X case padding4X case padding6X @@ -64,7 +64,7 @@ open class TileContainer: Control { } } - public enum AspectRatio: String, Codable, CaseIterable { + public enum AspectRatio: String, CaseIterable, Codable { case ratio1x1 = "1:1" case ratio3x4 = "3:4" case ratio4x3 = "4:3" diff --git a/VDS/Components/Tilelet/Tilelet.swift b/VDS/Components/Tilelet/Tilelet.swift index dd35a951..918d5ee7 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -15,7 +15,7 @@ open class Tilelet: TileContainer { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum TextPosition: String, Codable, CaseIterable { + public enum TextPosition: String, CaseIterable, Codable { case top case bottom } From cb9ca6236b6256e003a92029cb739e4505e41a88 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 25 Jan 2023 09:54:18 -0600 Subject: [PATCH 6/8] migrated codable to extension Signed-off-by: Matt Bruce --- .../Tilelet/TileletBadgeModel.swift | 22 +++++----- .../Tilelet/TileletIconModels.swift | 42 ++++++++++++------- .../Tilelet/TileletSubTitleModel.swift | 34 ++++++++++----- .../Tilelet/TileletTitleModel.swift | 33 +++++++++++---- 4 files changed, 88 insertions(+), 43 deletions(-) diff --git a/VDS/Components/Tilelet/TileletBadgeModel.swift b/VDS/Components/Tilelet/TileletBadgeModel.swift index a9dbd875..515e6bb8 100644 --- a/VDS/Components/Tilelet/TileletBadgeModel.swift +++ b/VDS/Components/Tilelet/TileletBadgeModel.swift @@ -8,7 +8,7 @@ import Foundation extension Tilelet { - public struct BadgeModel: Codable { + public struct BadgeModel { public var text: String = "" public var fillColor: Badge.FillColor = .red public var surface: Surface = .light @@ -22,14 +22,16 @@ extension Tilelet { self.numberOfLines = numberOfLines self.maxWidth = maxWidth } - - public init(from decoder: Decoder) throws { - let container: KeyedDecodingContainer = try decoder.container(keyedBy: Tilelet.BadgeModel.CodingKeys.self) - self.text = try container.decode(String.self, forKey: Tilelet.BadgeModel.CodingKeys.text) - self.fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: Tilelet.BadgeModel.CodingKeys.fillColor) ?? .red - self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilelet.BadgeModel.CodingKeys.surface) ?? .light - self.numberOfLines = try container.decodeIfPresent(Int.self, forKey: Tilelet.BadgeModel.CodingKeys.numberOfLines) ?? 0 - self.maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: Tilelet.BadgeModel.CodingKeys.maxWidth) - } + } +} + +extension Tilelet.BadgeModel: Codable { + public init(from decoder: Decoder) throws { + let container: KeyedDecodingContainer = try decoder.container(keyedBy: Tilelet.BadgeModel.CodingKeys.self) + self.text = try container.decode(String.self, forKey: Tilelet.BadgeModel.CodingKeys.text) + self.fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: Tilelet.BadgeModel.CodingKeys.fillColor) ?? .red + self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilelet.BadgeModel.CodingKeys.surface) ?? .light + self.numberOfLines = try container.decodeIfPresent(Int.self, forKey: Tilelet.BadgeModel.CodingKeys.numberOfLines) ?? 0 + self.maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: Tilelet.BadgeModel.CodingKeys.maxWidth) } } diff --git a/VDS/Components/Tilelet/TileletIconModels.swift b/VDS/Components/Tilelet/TileletIconModels.swift index d4f8caf1..e3e0e587 100644 --- a/VDS/Components/Tilelet/TileletIconModels.swift +++ b/VDS/Components/Tilelet/TileletIconModels.swift @@ -10,7 +10,7 @@ import UIKit extension Tilelet { - public struct DescriptiveIcon: Codable { + public struct DescriptiveIcon { public var name: Icon.Name = .multipleDocuments public var size: Icon.Size = .medium public var surface: Surface = .dark @@ -20,16 +20,9 @@ extension Tilelet { self.size = size self.surface = surface } - - public init(from decoder: Decoder) throws { - let container: KeyedDecodingContainer = try decoder.container(keyedBy: Tilelet.DescriptiveIcon.CodingKeys.self) - self.name = try container.decodeIfPresent(Icon.Name.self, forKey: Tilelet.DescriptiveIcon.CodingKeys.name) ?? .multipleDocuments - self.size = try container.decodeIfPresent(Icon.Size.self, forKey: Tilelet.DescriptiveIcon.CodingKeys.size) ?? .medium - self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilelet.DescriptiveIcon.CodingKeys.surface) ?? .dark - } } - public struct DirectionalIcon: Codable { + public struct DirectionalIcon { public var size: Icon.Size = .medium public var surface: Surface = .dark @@ -37,11 +30,30 @@ extension Tilelet { self.size = size self.surface = surface } - - public init(from decoder: Decoder) throws { - let container: KeyedDecodingContainer = try decoder.container(keyedBy: Tilelet.DirectionalIcon.CodingKeys.self) - self.size = try container.decodeIfPresent(Icon.Size.self, forKey: Tilelet.DirectionalIcon.CodingKeys.size) ?? .medium - self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilelet.DirectionalIcon.CodingKeys.surface) ?? .dark - } + } +} + +extension Tilelet.DescriptiveIcon: Codable { + private enum CodingKeys: String, CodingKey { + case name, size, surface + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.name = try container.decodeIfPresent(Icon.Name.self, forKey: .name) ?? .multipleDocuments + self.size = try container.decodeIfPresent(Icon.Size.self, forKey: .size) ?? .medium + self.surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .dark + } +} + +extension Tilelet.DirectionalIcon: Codable { + private enum CodingKeys: String, CodingKey { + case size, surface + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.size = try container.decodeIfPresent(Icon.Size.self, forKey: .size) ?? .medium + self.surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .dark } } diff --git a/VDS/Components/Tilelet/TileletSubTitleModel.swift b/VDS/Components/Tilelet/TileletSubTitleModel.swift index 0c9078c3..6d6e1074 100644 --- a/VDS/Components/Tilelet/TileletSubTitleModel.swift +++ b/VDS/Components/Tilelet/TileletSubTitleModel.swift @@ -8,11 +8,11 @@ import Foundation extension Tilelet { - public struct SubTitleModel: Codable { + public struct SubTitleModel { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum TextStyle: String, Codable, EnumSubset { + public enum TextStyle: String, EnumSubset, Codable { case bodyLarge case boldBodyLarge case bodyMedium @@ -22,12 +22,12 @@ extension Tilelet { public var defaultValue: TitleLockup.OtherTextStyle { .bodySmall } } - //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- public var text: String = "" public var textStyle: TextStyle = .bodySmall + public var textAttributes: [any LabelAttributeModel]? public var textColor: Use = .primary //-------------------------------------------------- @@ -38,6 +38,7 @@ extension Tilelet { textAttributes: [any LabelAttributeModel]? = nil, textStyle: TextStyle = .bodySmall) { self.text = text + self.textAttributes = textAttributes self.textColor = textColor self.textStyle = textStyle } @@ -50,12 +51,25 @@ extension Tilelet { textColor: textColor, textAttributes: nil) } - - public init(from decoder: Decoder) throws { - let container: KeyedDecodingContainer = try decoder.container(keyedBy: Tilelet.SubTitleModel.CodingKeys.self) - self.text = try container.decode(String.self, forKey: Tilelet.SubTitleModel.CodingKeys.text) - self.textStyle = try container.decodeIfPresent(Tilelet.SubTitleModel.TextStyle.self, forKey: Tilelet.SubTitleModel.CodingKeys.textStyle) ?? .bodySmall - self.textColor = try container.decodeIfPresent(Use.self, forKey: Tilelet.SubTitleModel.CodingKeys.textColor) ?? .primary - } + } +} + +extension Tilelet.SubTitleModel: Codable { + private enum CodingKeys: String, CodingKey { + case text, textStyle, textColor + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.text = try container.decode(String.self, forKey: .text) + self.textStyle = try container.decodeIfPresent(TextStyle.self, forKey: .textStyle) ?? .bodySmall + self.textColor = try container.decodeIfPresent(Use.self, forKey: .textColor) ?? .primary + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(text, forKey: .text) + try container.encode(textStyle, forKey: .textStyle) + try container.encode(textColor, forKey: .textColor) } } diff --git a/VDS/Components/Tilelet/TileletTitleModel.swift b/VDS/Components/Tilelet/TileletTitleModel.swift index 404574e5..de08c83b 100644 --- a/VDS/Components/Tilelet/TileletTitleModel.swift +++ b/VDS/Components/Tilelet/TileletTitleModel.swift @@ -8,7 +8,7 @@ import Foundation extension Tilelet { - public struct TitleModel: Codable { + public struct TitleModel { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- @@ -24,21 +24,24 @@ extension Tilelet { public var defaultValue: TitleLockup.TitleTextStyle { .boldTitleSmall } } - //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- public var text: String = "" + public var textAttributes: [any LabelAttributeModel]? public var textStyle: TextStyle = .boldTitleSmall //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- public init(text: String, + textAttributes: [any LabelAttributeModel]? = nil, textStyle: TextStyle = .boldTitleSmall) { self.text = text + self.textAttributes = textAttributes self.textStyle = textStyle } + //-------------------------------------------------- // MARK: - Public Functions @@ -48,11 +51,25 @@ extension Tilelet { textAttributes: nil, textStyle: textStyle.value) } - - public init(from decoder: Decoder) throws { - let container: KeyedDecodingContainer = try decoder.container(keyedBy: Tilelet.TitleModel.CodingKeys.self) - self.text = try container.decode(String.self, forKey: Tilelet.TitleModel.CodingKeys.text) - self.textStyle = try container.decodeIfPresent(Tilelet.TitleModel.TextStyle.self, forKey: Tilelet.TitleModel.CodingKeys.textStyle) ?? .boldTitleSmall - } } } + +extension Tilelet.TitleModel: Codable { + + private enum CodingKeys: String, CodingKey { + case text, textStyle + } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.text = try container.decode(String.self, forKey: .text) + self.textStyle = try container.decodeIfPresent(TextStyle.self, forKey: .textStyle) ?? .boldTitleSmall + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(text, forKey: .text) + try container.encode(textStyle, forKey: .textStyle) + } + +} From 21ac83af4fdd586208ce1976a640e585976fb2f8 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 25 Jan 2023 11:50:11 -0600 Subject: [PATCH 7/8] removed codable Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 2 +- VDS/Components/Buttons/Button/Button.swift | 2 +- .../Buttons/ButtonGroup/ButtonGroup.swift | 2 +- .../Buttons/TextLinkCaret/TextLinkCaret.swift | 2 +- VDS/Components/Icon/IconColor.swift | 2 +- VDS/Components/Icon/IconName.swift | 2 +- VDS/Components/Icon/IconSize.swift | 2 +- .../Attributes/UnderlineLabelAttribute.swift | 4 +-- .../TextFields/EntryField/EntryField.swift | 2 +- .../TextFields/InputField/InputField.swift | 2 +- .../TileContainer/TileContainer.swift | 6 ++--- VDS/Components/Tilelet/Tilelet.swift | 2 +- .../Tilelet/TileletBadgeModel.swift | 11 -------- .../Tilelet/TileletIconModels.swift | 25 ------------------- .../Tilelet/TileletSubTitleModel.swift | 22 +--------------- .../Tilelet/TileletTitleModel.swift | 22 +--------------- VDS/Components/TitleLockup/TitleLockup.swift | 2 +- .../TitleLockup/TitleLockupTextStyle.swift | 4 +-- VDS/Components/Toggle/Toggle.swift | 6 ++--- VDS/Extensions/VDSLayout.swift | 2 +- VDS/Protocols/Surfaceable.swift | 2 +- VDS/Protocols/Useable.swift | 2 +- VDS/Typography/Typography.swift | 8 +++--- 23 files changed, 30 insertions(+), 106 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index b8d919c4..0cd56958 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -17,7 +17,7 @@ public class Badge: View, Accessable { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum FillColor: String, Codable, CaseIterable { + public enum FillColor: String, CaseIterable { case red, yellow, green, orange, blue, black, white } diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index 1a4bc3d4..f7274092 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -11,7 +11,7 @@ import VDSColorTokens import VDSFormControlsTokens import Combine -public enum ButtonSize: String, CaseIterable, Codable { +public enum ButtonSize: String, CaseIterable { case large case small } diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 6d3f2ef3..1bc28dba 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -17,7 +17,7 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum ButtonPosition: String, CaseIterable, Codable { + public enum ButtonPosition: String, CaseIterable { case left, center, right } diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index 184737dc..7c2f9fbd 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -17,7 +17,7 @@ open class TextLinkCaret: ButtonBase { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum IconPosition: String, CaseIterable, Codable { + public enum IconPosition: String, CaseIterable { case left, right } diff --git a/VDS/Components/Icon/IconColor.swift b/VDS/Components/Icon/IconColor.swift index 10d7a174..c9d4bf0e 100644 --- a/VDS/Components/Icon/IconColor.swift +++ b/VDS/Components/Icon/IconColor.swift @@ -10,7 +10,7 @@ import VDSColorTokens import UIKit extension Icon { - public enum Color: String, CaseIterable, Codable { + public enum Color: String, CaseIterable { case black case white case red diff --git a/VDS/Components/Icon/IconName.swift b/VDS/Components/Icon/IconName.swift index a24be628..2fed2c94 100644 --- a/VDS/Components/Icon/IconName.swift +++ b/VDS/Components/Icon/IconName.swift @@ -10,7 +10,7 @@ import UIKit import VDSColorTokens extension Icon { - public struct Name: RawRepresentable, Codable { + public struct Name: RawRepresentable { public typealias RawValue = String public var rawValue: String diff --git a/VDS/Components/Icon/IconSize.swift b/VDS/Components/Icon/IconSize.swift index ca1b8548..86b865f7 100644 --- a/VDS/Components/Icon/IconSize.swift +++ b/VDS/Components/Icon/IconSize.swift @@ -8,7 +8,7 @@ import Foundation extension Icon { - public enum Size: String, CaseIterable, Codable { + public enum Size: String, CaseIterable { case xsmall case small case medium diff --git a/VDS/Components/Label/Attributes/UnderlineLabelAttribute.swift b/VDS/Components/Label/Attributes/UnderlineLabelAttribute.swift index 64a9842c..c58945a6 100644 --- a/VDS/Components/Label/Attributes/UnderlineLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/UnderlineLabelAttribute.swift @@ -64,7 +64,7 @@ extension UnderlineLabelAttribute { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum Style: String, Codable { + public enum Style: String { case none case single case thick @@ -87,7 +87,7 @@ extension UnderlineLabelAttribute { } } - public enum Pattern: String, Codable { + public enum Pattern: String { case dot case dash case dashDot diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index 17104e46..5e500b9a 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -16,7 +16,7 @@ open class EntryField: Control, Accessable { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum HelperTextPlacement: String, CaseIterable, Codable { + public enum HelperTextPlacement: String, CaseIterable { case bottom, right } diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 3b498043..c4c4f120 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -16,7 +16,7 @@ public class InputField: EntryField, UITextFieldDelegate { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum FieldType: String, CaseIterable, Codable { + public enum FieldType: String, CaseIterable { case text, number, calendar, inlineAction, password, creditCard, tel, date, securityCode } diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index efccea75..c49e7235 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -34,14 +34,14 @@ open class TileContainer: Control { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum BackgroundColor: String, CaseIterable, Codable { + public enum BackgroundColor: String, CaseIterable { case white case black case gray case transparent } - public enum Padding: String, CaseIterable, Codable { + public enum Padding: String, CaseIterable { case padding2X case padding4X case padding6X @@ -64,7 +64,7 @@ open class TileContainer: Control { } } - public enum AspectRatio: String, CaseIterable, Codable { + public enum AspectRatio: String, CaseIterable { case ratio1x1 = "1:1" case ratio3x4 = "3:4" case ratio4x3 = "4:3" diff --git a/VDS/Components/Tilelet/Tilelet.swift b/VDS/Components/Tilelet/Tilelet.swift index 918d5ee7..3fcddb37 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -15,7 +15,7 @@ open class Tilelet: TileContainer { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum TextPosition: String, CaseIterable, Codable { + public enum TextPosition: String, CaseIterable { case top case bottom } diff --git a/VDS/Components/Tilelet/TileletBadgeModel.swift b/VDS/Components/Tilelet/TileletBadgeModel.swift index 515e6bb8..f11f6c8f 100644 --- a/VDS/Components/Tilelet/TileletBadgeModel.swift +++ b/VDS/Components/Tilelet/TileletBadgeModel.swift @@ -24,14 +24,3 @@ extension Tilelet { } } } - -extension Tilelet.BadgeModel: Codable { - public init(from decoder: Decoder) throws { - let container: KeyedDecodingContainer = try decoder.container(keyedBy: Tilelet.BadgeModel.CodingKeys.self) - self.text = try container.decode(String.self, forKey: Tilelet.BadgeModel.CodingKeys.text) - self.fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: Tilelet.BadgeModel.CodingKeys.fillColor) ?? .red - self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilelet.BadgeModel.CodingKeys.surface) ?? .light - self.numberOfLines = try container.decodeIfPresent(Int.self, forKey: Tilelet.BadgeModel.CodingKeys.numberOfLines) ?? 0 - self.maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: Tilelet.BadgeModel.CodingKeys.maxWidth) - } -} diff --git a/VDS/Components/Tilelet/TileletIconModels.swift b/VDS/Components/Tilelet/TileletIconModels.swift index e3e0e587..b8b932c4 100644 --- a/VDS/Components/Tilelet/TileletIconModels.swift +++ b/VDS/Components/Tilelet/TileletIconModels.swift @@ -32,28 +32,3 @@ extension Tilelet { } } } - -extension Tilelet.DescriptiveIcon: Codable { - private enum CodingKeys: String, CodingKey { - case name, size, surface - } - - public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - self.name = try container.decodeIfPresent(Icon.Name.self, forKey: .name) ?? .multipleDocuments - self.size = try container.decodeIfPresent(Icon.Size.self, forKey: .size) ?? .medium - self.surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .dark - } -} - -extension Tilelet.DirectionalIcon: Codable { - private enum CodingKeys: String, CodingKey { - case size, surface - } - - public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - self.size = try container.decodeIfPresent(Icon.Size.self, forKey: .size) ?? .medium - self.surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .dark - } -} diff --git a/VDS/Components/Tilelet/TileletSubTitleModel.swift b/VDS/Components/Tilelet/TileletSubTitleModel.swift index 6d6e1074..43ce158c 100644 --- a/VDS/Components/Tilelet/TileletSubTitleModel.swift +++ b/VDS/Components/Tilelet/TileletSubTitleModel.swift @@ -12,7 +12,7 @@ extension Tilelet { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum TextStyle: String, EnumSubset, Codable { + public enum TextStyle: String, EnumSubset { case bodyLarge case boldBodyLarge case bodyMedium @@ -53,23 +53,3 @@ extension Tilelet { } } } - -extension Tilelet.SubTitleModel: Codable { - private enum CodingKeys: String, CodingKey { - case text, textStyle, textColor - } - - public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - self.text = try container.decode(String.self, forKey: .text) - self.textStyle = try container.decodeIfPresent(TextStyle.self, forKey: .textStyle) ?? .bodySmall - self.textColor = try container.decodeIfPresent(Use.self, forKey: .textColor) ?? .primary - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(text, forKey: .text) - try container.encode(textStyle, forKey: .textStyle) - try container.encode(textColor, forKey: .textColor) - } -} diff --git a/VDS/Components/Tilelet/TileletTitleModel.swift b/VDS/Components/Tilelet/TileletTitleModel.swift index de08c83b..7170021d 100644 --- a/VDS/Components/Tilelet/TileletTitleModel.swift +++ b/VDS/Components/Tilelet/TileletTitleModel.swift @@ -12,7 +12,7 @@ extension Tilelet { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum TextStyle: String, EnumSubset, Codable { + public enum TextStyle: String, EnumSubset { case titleXLarge case boldTitleXLarge case titleLarge @@ -53,23 +53,3 @@ extension Tilelet { } } } - -extension Tilelet.TitleModel: Codable { - - private enum CodingKeys: String, CodingKey { - case text, textStyle - } - - public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - self.text = try container.decode(String.self, forKey: .text) - self.textStyle = try container.decodeIfPresent(TextStyle.self, forKey: .textStyle) ?? .boldTitleSmall - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(text, forKey: .text) - try container.encode(textStyle, forKey: .textStyle) - } - -} diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 9a059d35..127cb33b 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -16,7 +16,7 @@ open class TitleLockup: View { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum TextPosition: String, Codable, EnumSubset { + public enum TextPosition: String, EnumSubset { case left, center public var defaultValue: VDS.TextPosition { .left } diff --git a/VDS/Components/TitleLockup/TitleLockupTextStyle.swift b/VDS/Components/TitleLockup/TitleLockupTextStyle.swift index 8f8288d7..e8dc0319 100644 --- a/VDS/Components/TitleLockup/TitleLockupTextStyle.swift +++ b/VDS/Components/TitleLockup/TitleLockupTextStyle.swift @@ -11,7 +11,7 @@ extension TitleLockup { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum TitleTextStyle: String, Codable, EnumSubset { + public enum TitleTextStyle: String, EnumSubset { case featureMedium case boldFeatureMedium @@ -34,7 +34,7 @@ extension TitleLockup { public var defaultValue: TextStyle {.boldFeatureXSmall } } - public enum OtherTextStyle: String, Codable, EnumSubset { + public enum OtherTextStyle: String, EnumSubset { case bodyLarge case boldBodyLarge case bodyMedium diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 6af7354d..b66d7bed 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -33,15 +33,15 @@ open class ToggleBase: Control, Accessable, DataTrackable { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - public enum TextSize: String, Codable, CaseIterable { + public enum TextSize: String, CaseIterable { case small, large } - public enum TextWeight: String, Codable, CaseIterable { + public enum TextWeight: String, CaseIterable { case regular, bold } - public enum TextPosition: String, Codable, CaseIterable { + public enum TextPosition: String, CaseIterable { case left, right } diff --git a/VDS/Extensions/VDSLayout.swift b/VDS/Extensions/VDSLayout.swift index aa3d572a..9478e7fc 100644 --- a/VDS/Extensions/VDSLayout.swift +++ b/VDS/Extensions/VDSLayout.swift @@ -8,7 +8,7 @@ import Foundation public struct VDSLayout { - public enum Spacing: String, Codable, CaseIterable { + public enum Spacing: String, CaseIterable { case space1X case space2X case space3X diff --git a/VDS/Protocols/Surfaceable.swift b/VDS/Protocols/Surfaceable.swift index a26ddda4..916167f1 100644 --- a/VDS/Protocols/Surfaceable.swift +++ b/VDS/Protocols/Surfaceable.swift @@ -9,7 +9,7 @@ import Foundation import UIKit import VDSColorTokens -public enum Surface: String, Codable, Equatable { +public enum Surface: String, Equatable { case light, dark public var color: UIColor { return self == .dark ? VDSColor.backgroundPrimaryDark : VDSColor.backgroundSecondaryLight diff --git a/VDS/Protocols/Useable.swift b/VDS/Protocols/Useable.swift index 3f60ae18..43c4f4cc 100644 --- a/VDS/Protocols/Useable.swift +++ b/VDS/Protocols/Useable.swift @@ -9,7 +9,7 @@ import Foundation import UIKit import VDSColorTokens -public enum Use: String, Codable, Equatable { +public enum Use: String, Equatable { case primary, secondary } diff --git a/VDS/Typography/Typography.swift b/VDS/Typography/Typography.swift index 3def20c5..1853c1f0 100644 --- a/VDS/Typography/Typography.swift +++ b/VDS/Typography/Typography.swift @@ -8,7 +8,7 @@ import Foundation import VDSTypographyTokens -public enum TextPosition: String, Codable, CaseIterable { +public enum TextPosition: String, CaseIterable { case left, right, center var textAlignment: NSTextAlignment { @@ -23,7 +23,7 @@ public enum TextPosition: String, Codable, CaseIterable { } } -public enum TextStyle: String, Codable, CaseIterable { +public enum TextStyle: String, CaseIterable { case featureXLarge case boldFeatureXLarge @@ -64,7 +64,7 @@ public enum TextStyle: String, Codable, CaseIterable { //MARK: FontCategory extension TextStyle { - public enum FontCategory: String, Codable, CaseIterable { + public enum FontCategory: String, CaseIterable { case feature = "Feature" case title = "Title" case body = "Body" @@ -95,7 +95,7 @@ extension TextStyle { //MARK: FontSize extension TextStyle { - public enum FontSize: String, Codable, CaseIterable { + public enum FontSize: String, CaseIterable { case xxlarge = "2XLarge" case xlarge = "XLarge" case large = "Large" From 5e595e9ecee37fe40ea166a6df43925f4a5f2117 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 25 Jan 2023 12:19:25 -0600 Subject: [PATCH 8/8] updated models Signed-off-by: Matt Bruce --- VDS/Components/Tilelet/TileletBadgeModel.swift | 4 ++-- VDS/Components/Tilelet/TileletIconModels.swift | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/VDS/Components/Tilelet/TileletBadgeModel.swift b/VDS/Components/Tilelet/TileletBadgeModel.swift index f11f6c8f..bd7efcac 100644 --- a/VDS/Components/Tilelet/TileletBadgeModel.swift +++ b/VDS/Components/Tilelet/TileletBadgeModel.swift @@ -10,8 +10,8 @@ import Foundation extension Tilelet { public struct BadgeModel { public var text: String = "" - public var fillColor: Badge.FillColor = .red - public var surface: Surface = .light + public var fillColor: Badge.FillColor + public var surface: Surface public var numberOfLines: Int public var maxWidth: CGFloat? diff --git a/VDS/Components/Tilelet/TileletIconModels.swift b/VDS/Components/Tilelet/TileletIconModels.swift index b8b932c4..22a5a148 100644 --- a/VDS/Components/Tilelet/TileletIconModels.swift +++ b/VDS/Components/Tilelet/TileletIconModels.swift @@ -11,11 +11,11 @@ import UIKit extension Tilelet { public struct DescriptiveIcon { - public var name: Icon.Name = .multipleDocuments - public var size: Icon.Size = .medium - public var surface: Surface = .dark + public var name: Icon.Name + public var size: Icon.Size + public var surface: Surface - public init(name: Icon.Name = .multipleDocuments, size: Icon.Size, surface: Surface) { + public init(name: Icon.Name = .multipleDocuments, size: Icon.Size = .medium, surface: Surface = .dark) { self.name = name self.size = size self.surface = surface @@ -23,10 +23,10 @@ extension Tilelet { } public struct DirectionalIcon { - public var size: Icon.Size = .medium - public var surface: Surface = .dark + public var size: Icon.Size + public var surface: Surface - public init(size: Icon.Size, surface: Surface) { + public init(size: Icon.Size = .medium, surface: Surface = .dark) { self.size = size self.surface = surface }