From 1146006ca65026388fba022c045637134cdd4bed Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 12:47:40 -0600 Subject: [PATCH] updated badge Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 92 ++++++++++---------------------- 1 file changed, 28 insertions(+), 64 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 9541a483..b3ffb2bd 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -102,74 +102,36 @@ public class Badge: View, Accessable { //-------------------------------------------------- // MARK: - Configuration //-------------------------------------------------- - public func backgroundColor() -> UIColor { - var config: SurfaceColorConfiguration - switch fillColor { - case .red: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.backgroundBrandhighlight - $0.darkColor = VDSColor.backgroundBrandhighlight - } - case .yellow: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteYellow62 - $0.darkColor = VDSColor.paletteYellow62 - } - case .green: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteGreen26 - $0.darkColor = VDSColor.paletteGreen34 - } - case .orange: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteOrange39 - $0.darkColor = VDSColor.paletteOrange46 - } - case .blue: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteBlue35 - $0.darkColor = VDSColor.paletteBlue45 - } - case .black: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteBlack - $0.darkColor = VDSColor.paletteBlack - } - case .white: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteWhite - $0.darkColor = VDSColor.paletteWhite - } - } - - return config.getColor(self) - } - - public func textColorConfiguration() -> AnyColorable { + private var backgroundColorConfig: StateColorConfiguration = { + let config = StateColorConfiguration() + config.setSurfaceColors(VDSColor.backgroundBrandhighlight, VDSColor.backgroundBrandhighlight, forState: .red) + config.setSurfaceColors(VDSColor.paletteYellow62, VDSColor.paletteYellow62, forState: .yellow) + config.setSurfaceColors(VDSColor.paletteGreen26, VDSColor.paletteGreen34, forState: .green) + config.setSurfaceColors(VDSColor.paletteOrange39, VDSColor.paletteOrange46, forState: .orange) + config.setSurfaceColors(VDSColor.paletteBlue35, VDSColor.paletteBlue45, forState: .blue) + config.setSurfaceColors(VDSColor.paletteBlack, VDSColor.paletteBlack, forState: .black) + config.setSurfaceColors(VDSColor.paletteWhite, VDSColor.paletteWhite, forState: .white) + return config + }() + + private var textColorConfig = ViewColorConfiguration() + + public func updateTextColorConfig() { + textColorConfig.reset() switch fillColor { case .red, .black: - return DisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.elementsPrimaryOndark - $0.disabled.darkColor = VDSColor.elementsPrimaryOndark - $0.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.enabled.darkColor = VDSColor.elementsPrimaryOndark - }.eraseToAnyColorable() + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forDisabled: false) + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forDisabled: true) + case .yellow, .white: - return DisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.disabled.darkColor = VDSColor.elementsPrimaryOnlight - $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.enabled.darkColor = VDSColor.elementsPrimaryOnlight - }.eraseToAnyColorable() + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOnlight, forDisabled: false) + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOnlight, forDisabled: true) + case .orange, .green, .blue: - return DisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.elementsPrimaryOndark - $0.disabled.darkColor = VDSColor.elementsPrimaryOnlight - $0.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.enabled.darkColor = VDSColor.elementsPrimaryOnlight - }.eraseToAnyColorable() + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forDisabled: false) + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forDisabled: true) } } @@ -177,9 +139,11 @@ public class Badge: View, Accessable { // MARK: - State //-------------------------------------------------- open override func updateView() { - backgroundColor = backgroundColor() + updateTextColorConfig() - label.textColorConfiguration = textColorConfiguration() + backgroundColor = backgroundColorConfig.getColor(surface, forState: fillColor) + + label.textColorConfiguration = textColorConfig.eraseToAnyColorable() label.numberOfLines = numberOfLines label.text = text label.surface = surface