added id
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
48c3e4b86a
commit
ad3112d984
@ -10,12 +10,11 @@ import Foundation
|
|||||||
import VDS
|
import VDS
|
||||||
|
|
||||||
open class BadgeModel: MoleculeModelProtocol {
|
open class BadgeModel: MoleculeModelProtocol {
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public static var identifier: String = "badge"
|
public static var identifier: String = "badge"
|
||||||
|
public var id: String = UUID().uuidString
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var text: String = ""
|
public var text: String = ""
|
||||||
public var maxWidth: CGFloat?
|
public var maxWidth: CGFloat?
|
||||||
@ -24,12 +23,13 @@ open class BadgeModel: MoleculeModelProtocol {
|
|||||||
public var surface: Surface = .light
|
public var surface: Surface = .light
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
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 {
|
required public convenience init(from decoder: Decoder) throws {
|
||||||
self.init()
|
self.init()
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
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)
|
text = try container.decode(String.self, forKey: .text)
|
||||||
fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red
|
fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red
|
||||||
surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .light
|
surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .light
|
||||||
@ -39,6 +39,7 @@ open class BadgeModel: MoleculeModelProtocol {
|
|||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(id, forKey: .id)
|
||||||
try container.encode(text, forKey: .text)
|
try container.encode(text, forKey: .text)
|
||||||
try container.encode(fillColor, forKey: .fillColor)
|
try container.encode(fillColor, forKey: .fillColor)
|
||||||
try container.encode(surface, forKey: .surface)
|
try container.encode(surface, forKey: .surface)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user