updated model against extensions for now
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
e28cc4fc5b
commit
268fdc5c2a
@ -46,9 +46,9 @@ open class TileletModel: MoleculeModelProtocol {
|
|||||||
|
|
||||||
public var titleModel: Tilelet.TitleModel? {
|
public var titleModel: Tilelet.TitleModel? {
|
||||||
guard let title else { return nil }
|
guard let title else { return nil }
|
||||||
let style = title.fontStyle?.vdsTextStyle
|
let style: Tilelet.TitleModel.TextStyle? = title.fontStyle?.vdsSubsetStyle()
|
||||||
if let style, let found = Tilelet.TitleModel.TextStyle(rawValue: style.rawValue) {
|
if let style {
|
||||||
return .init(text: title.text, textStyle: found)
|
return .init(text: title.text, textStyle: style)
|
||||||
} else {
|
} else {
|
||||||
return .init(text: title.text)
|
return .init(text: title.text)
|
||||||
}
|
}
|
||||||
@ -56,92 +56,11 @@ open class TileletModel: MoleculeModelProtocol {
|
|||||||
|
|
||||||
public var subTitleModel: Tilelet.SubTitleModel? {
|
public var subTitleModel: Tilelet.SubTitleModel? {
|
||||||
guard let subTitle else { return nil }
|
guard let subTitle else { return nil }
|
||||||
let style = subTitle.fontStyle?.vdsTextStyle
|
let style: Tilelet.SubTitleModel.TextStyle? = subTitle.fontStyle?.vdsSubsetStyle()
|
||||||
if let style, let found = Tilelet.SubTitleModel.TextStyle(rawValue: style.rawValue) {
|
if let style {
|
||||||
return .init(text: subTitle.text, textStyle: found)
|
return .init(text: subTitle.text, textStyle: style)
|
||||||
} else {
|
} else {
|
||||||
return .init(text: subTitle.text)
|
return .init(text: subTitle.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Styler.Font {
|
|
||||||
public var vdsTextStyle: VDS.TextStyle? {
|
|
||||||
let raw = "\(self)"
|
|
||||||
let newRaw = raw.prefix(1).lowercased() + raw.dropFirst()
|
|
||||||
guard let style = VDS.TextStyle(rawValue: newRaw) else { return nil }
|
|
||||||
return style
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension TileContainer.BackgroundColor: Codable {}
|
|
||||||
extension TileContainer.Padding: Codable {}
|
|
||||||
extension TileContainer.AspectRatio: Codable {}
|
|
||||||
extension Surface: Codable {}
|
|
||||||
extension Badge.FillColor: Codable {}
|
|
||||||
extension Icon.Name: Codable {}
|
|
||||||
extension Icon.Size: Codable {}
|
|
||||||
|
|
||||||
extension Tilelet.BadgeModel: Codable {
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
|
||||||
case text, fillColor, surface, numberOfLines, maxWidth
|
|
||||||
}
|
|
||||||
|
|
||||||
public init(from decoder: Decoder) throws {
|
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
||||||
let text = try container.decode(String.self, forKey: .text)
|
|
||||||
let fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red
|
|
||||||
let surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .light
|
|
||||||
let numberOfLines = try container.decodeIfPresent(Int.self, forKey: .numberOfLines) ?? 0
|
|
||||||
let maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: .maxWidth)
|
|
||||||
self.init(text: text, fillColor: fillColor, surface: surface, numberOfLines: numberOfLines, maxWidth: maxWidth)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
||||||
try container.encode(fillColor, forKey: .fillColor)
|
|
||||||
try container.encode(surface, forKey: .surface)
|
|
||||||
try container.encode(numberOfLines, forKey: .numberOfLines)
|
|
||||||
try container.encodeIfPresent(maxWidth, forKey: .maxWidth)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
let name = try container.decode(Icon.Name.self, forKey: .name)
|
|
||||||
let size = try container.decodeIfPresent(Icon.Size.self, forKey: .size) ?? .medium
|
|
||||||
let surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .dark
|
|
||||||
self.init(name: name, size: size, surface: surface)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
||||||
try container.encode(name, forKey: .name)
|
|
||||||
try container.encode(size, forKey: .size)
|
|
||||||
try container.encode(surface, forKey: .surface)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
let size = try container.decodeIfPresent(Icon.Size.self, forKey: .size) ?? .medium
|
|
||||||
let surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .dark
|
|
||||||
self.init(size: size, surface: surface)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
||||||
try container.encode(size, forKey: .size)
|
|
||||||
try container.encode(surface, forKey: .surface)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user