refactored enums for badge

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-01-13 09:51:46 -06:00
parent 3b97e60298
commit 25144ae1bc
2 changed files with 14 additions and 10 deletions

View File

@ -11,15 +11,19 @@ import VDSColorTokens
import VDSFormControlsTokens
import Combine
public enum BadgeFillColor: String, Codable, CaseIterable {
case red, yellow, green, orange, blue, black, white
}
/// Badges are visual labels used to convey status or highlight supplemental information.
@objc(VDSBadge)
public class Badge: View, Accessable {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum FillColor: String, Codable, CaseIterable {
case red, yellow, green, orange, blue, black, white
}
//--------------------------------------------------
// MARK: - Private Properties
//--------------------------------------------------
private var label = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical)
$0.adjustsFontSizeToFitWidth = false
@ -31,7 +35,7 @@ public class Badge: View, Accessable {
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var fillColor: BadgeFillColor = .red { didSet { didChange() }}
open var fillColor: FillColor = .red { didSet { didChange() }}
open var text: String = "" { didSet { didChange() }}
@ -102,8 +106,8 @@ public class Badge: View, Accessable {
//--------------------------------------------------
// MARK: - Configuration
//--------------------------------------------------
private var backgroundColorConfig: StateColorConfiguration<BadgeFillColor> = {
let config = StateColorConfiguration<BadgeFillColor>()
private var backgroundColorConfig: StateColorConfiguration<FillColor> = {
let config = StateColorConfiguration<FillColor>()
config.setSurfaceColors(VDSColor.backgroundBrandhighlight, VDSColor.backgroundBrandhighlight, forState: .red)
config.setSurfaceColors(VDSColor.paletteYellow62, VDSColor.paletteYellow62, forState: .yellow)
config.setSurfaceColors(VDSColor.paletteGreen26, VDSColor.paletteGreen34, forState: .green)

View File

@ -9,11 +9,11 @@ import Foundation
public struct TiletBadgeModel: Codable {
public var text: String = ""
public var fillColor: BadgeFillColor
public var fillColor:Badge.FillColor
public var surface: Surface
public var numberOfLines: Int
public var maxWidth: CGFloat?
public init(text: String, fillColor: BadgeFillColor = .red, surface: Surface = .light, numberOfLines: Int = 0, maxWidth: CGFloat? = nil) {
public init(text: String, fillColor: Badge.FillColor = .red, surface: Surface = .light, numberOfLines: Int = 0, maxWidth: CGFloat? = nil) {
self.text = text
self.fillColor = fillColor
self.surface = surface