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