Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-09-21 11:34:28 -05:00
parent 48c3e4b86a
commit ad3112d984

View File

@ -10,12 +10,11 @@ import Foundation
import VDS
open class BadgeModel: MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "badge"
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var text: String = ""
public var maxWidth: CGFloat?
@ -24,12 +23,13 @@ open class BadgeModel: MoleculeModelProtocol {
public var surface: Surface = .light
private enum CodingKeys: String, CodingKey {
case text, fillColor, surface, numberOfLines, maxWidth
case id, text, fillColor, surface, numberOfLines, maxWidth
}
required public convenience init(from decoder: Decoder) throws {
self.init()
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
text = try container.decode(String.self, forKey: .text)
fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red
surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .light
@ -39,6 +39,7 @@ open class BadgeModel: MoleculeModelProtocol {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(text, forKey: .text)
try container.encode(fillColor, forKey: .fillColor)
try container.encode(surface, forKey: .surface)