Adding pill button's inverted state logic
This commit is contained in:
parent
e0a93cc71f
commit
b2a25f840a
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import VDSColorTokens
|
||||
|
||||
public typealias FacadeElements = (fill: UIColor?, text: UIColor?, border: UIColor?)
|
||||
|
||||
@ -17,7 +18,6 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
//--------------------------------------------------
|
||||
//Making static property as class property so that subclasses can override getter function of the property
|
||||
open class var identifier: String { "button" }
|
||||
public var backgroundColor: Color?
|
||||
public var accessibilityIdentifier: String?
|
||||
public var accessibilityText: String?
|
||||
public var title: String
|
||||
@ -58,6 +58,22 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
public var disabledTextColor_inverted: Color?
|
||||
public var disabledBorderColor_inverted: Color?
|
||||
|
||||
private var _backgroundColor: Color?
|
||||
public var backgroundColor: Color? {
|
||||
get {
|
||||
if let backgroundColor = _backgroundColor { return backgroundColor }
|
||||
if inverted {
|
||||
if style == .secondary { return Color(uiColor: VDSColor.elementsSecondaryOndark) }
|
||||
return Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
}
|
||||
if style == .secondary { return Color(uiColor: VDSColor.elementsSecondaryOnlight) }
|
||||
return Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
}
|
||||
set {
|
||||
_backgroundColor = newValue
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
@ -117,38 +133,39 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
func setPrimaryFacade() {
|
||||
|
||||
if enabledFillColor == nil && enabledTextColor == nil {
|
||||
enabledFillColor = Color(uiColor: .mvmBlack)
|
||||
enabledTextColor = Color(uiColor: .mvmWhite)
|
||||
enabledFillColor = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
enabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
}
|
||||
|
||||
if disabledFillColor == nil && disabledTextColor == nil {
|
||||
disabledFillColor = Color(uiColor: .mvmCoolGray6)
|
||||
disabledTextColor = Color(uiColor: .mvmWhite)
|
||||
disabledFillColor = Color(uiColor: VDSColor.interactiveDisabledOnlight)
|
||||
disabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
}
|
||||
|
||||
enabledFillColor_inverted = Color(uiColor: .mvmWhite)
|
||||
enabledTextColor_inverted = Color(uiColor: .mvmBlack)
|
||||
disabledFillColor_inverted = Color(uiColor: .mvmCoolGray6)
|
||||
disabledTextColor_inverted = Color(uiColor: .mvmBlack)
|
||||
enabledFillColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
enabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
disabledFillColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
||||
disabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
}
|
||||
|
||||
/// Defines the default appearance for the Secondary style.
|
||||
func setSecondaryFacade() {
|
||||
|
||||
if enabledTextColor == nil && enabledBorderColor == nil {
|
||||
enabledTextColor = Color(uiColor: .mvmBlack)
|
||||
enabledBorderColor = Color(uiColor: .mvmBlack)
|
||||
enabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
enabledBorderColor = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
}
|
||||
|
||||
if disabledTextColor == nil && disabledBorderColor == nil {
|
||||
disabledTextColor = Color(uiColor: .mvmCoolGray6)
|
||||
disabledBorderColor = Color(uiColor: .mvmCoolGray6)
|
||||
disabledTextColor = Color(uiColor: VDSColor.interactiveDisabledOnlight)
|
||||
disabledBorderColor = Color(uiColor: VDSColor.interactiveDisabledOnlight)
|
||||
}
|
||||
|
||||
enabledTextColor_inverted = Color(uiColor: .mvmWhite)
|
||||
enabledBorderColor_inverted = Color(uiColor: .mvmWhite)
|
||||
disabledTextColor_inverted = Color(uiColor: .mvmCoolGray6)
|
||||
disabledBorderColor_inverted = Color(uiColor: .mvmCoolGray6)
|
||||
enabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
enabledFillColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
enabledBorderColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
disabledTextColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
||||
disabledBorderColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
||||
}
|
||||
|
||||
public func setFacade(by style: Styler.Button.Style) {
|
||||
@ -194,7 +211,6 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
|
||||
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
|
||||
title = try typeContainer.decode(String.self, forKey: .title)
|
||||
@ -245,6 +261,8 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
self.disabledBorderColor = disabledBorderColor
|
||||
}
|
||||
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
|
||||
if let width = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .width) {
|
||||
self.width = width
|
||||
}
|
||||
@ -257,7 +275,7 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
try container.encode(enabled, forKey: .enabled)
|
||||
try container.encode(inverted, forKey: .inverted)
|
||||
try container.encodeModel(action, forKey: .action)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(_backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||
try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText)
|
||||
try container.encodeIfPresent(enabledFillColor, forKey: .fillColor)
|
||||
|
||||
@ -81,7 +81,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
enabledTitleColor = buttonModel?.enabledColors.text ?? .mvmBlack
|
||||
disabledTitleColor = buttonModel?.disabledColors.text ?? .mvmCoolGray6
|
||||
backgroundColor = .clear
|
||||
layer.borderWidth = 1
|
||||
layer.borderWidth = buttonModel?.inverted ?? false ? 0 : 1
|
||||
borderColor = isEnabled ? buttonModel?.enabledColors.border ?? .mvmBlack : buttonModel?.disabledColors.border ?? .mvmCoolGray6
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user