fixes and color addition

This commit is contained in:
Pfeil, Scott Robert 2020-01-30 11:56:37 -05:00
parent f367b03233
commit 58a40a7752
2 changed files with 49 additions and 1 deletions

View File

@ -27,6 +27,12 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol {
public var enabled: Bool = true public var enabled: Bool = true
public var style: ButtonStyle? public var style: ButtonStyle?
public var size: ButtonSize? = .standard public var size: ButtonSize? = .standard
public var fillColor: Color?
public var textColor: Color?
public var borderColor: Color?
public var disabledFillColor: Color?
public var disabledTextColor: Color?
public var disabledBorderColor: Color?
public var required: Bool? public var required: Bool?
public var requiredGroups: [String]? public var requiredGroups: [String]?
@ -43,6 +49,12 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol {
case enabled case enabled
case style case style
case size case size
case fillColor
case textColor
case borderColor
case disabledFillColor
case disabledTextColor
case disabledBorderColor
case required case required
case requiredGroups case requiredGroups
} }
@ -65,6 +77,12 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol {
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
self.enabled = enabled self.enabled = enabled
} }
fillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .fillColor)
textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor)
borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor)
disabledFillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledFillColor)
disabledTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledTextColor)
disabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBorderColor)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -76,6 +94,13 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol {
try container.encode(enabled, forKey: .enabled) try container.encode(enabled, forKey: .enabled)
try container.encodeIfPresent(style, forKey: .style) try container.encodeIfPresent(style, forKey: .style)
try container.encodeIfPresent(size, forKey: .size) try container.encodeIfPresent(size, forKey: .size)
try container.encodeIfPresent(fillColor, forKey: .fillColor)
try container.encodeIfPresent(textColor, forKey: .textColor)
try container.encodeIfPresent(borderColor, forKey: .borderColor)
try container.encodeIfPresent(disabledFillColor, forKey: .disabledFillColor)
try container.encodeIfPresent(disabledTextColor, forKey: .disabledTextColor)
try container.encodeIfPresent(disabledBorderColor, forKey: .disabledBorderColor)
try container.encodeIfPresent(required, forKey: .required) try container.encodeIfPresent(required, forKey: .required)
try container.encodeIfPresent(requiredGroups, forKey: .requiredGroups)
} }
} }

View File

@ -45,7 +45,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol, FormValidation
setTitleColor(.black, for: .normal) setTitleColor(.black, for: .normal)
setTitleColor(.mvmCoolGray6, for: .disabled) setTitleColor(.mvmCoolGray6, for: .disabled)
backgroundColor = .clear backgroundColor = .clear
layer.borderWidth = 1; layer.borderWidth = 1
if isEnabled { if isEnabled {
layer.borderColor = UIColor.black.cgColor layer.borderColor = UIColor.black.cgColor
} else { } else {
@ -61,6 +61,29 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol, FormValidation
default: default:
stylePrimary() stylePrimary()
} }
if let titleColor = buttonModel?.textColor {
setTitleColor(titleColor.uiColor, for: .normal)
}
if let disabledTitleColor = buttonModel?.disabledTextColor {
setTitleColor(disabledTitleColor.uiColor, for: .disabled)
}
if isEnabled {
if let fillColor = buttonModel?.fillColor {
backgroundColor = fillColor.uiColor
}
if let borderColor = buttonModel?.borderColor {
layer.borderWidth = 1
layer.borderColor = borderColor.cgColor
}
} else {
if let fillColor = buttonModel?.disabledFillColor {
backgroundColor = fillColor.uiColor
}
if let borderColor = buttonModel?.disabledBorderColor {
layer.borderWidth = 1
layer.borderColor = borderColor.cgColor
}
}
} }
private func getInnerPadding() -> CGFloat { private func getInnerPadding() -> CGFloat {