Updating button default style
This commit is contained in:
parent
c2ac51c18c
commit
7fb91d9b1e
@ -24,7 +24,7 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
|||||||
public var action: ActionModelProtocol
|
public var action: ActionModelProtocol
|
||||||
public var enabled: Bool = true
|
public var enabled: Bool = true
|
||||||
public var width: CGFloat?
|
public var width: CGFloat?
|
||||||
public var style: Styler.Button.Style? {
|
public var style: Styler.Button.Style? = .primary {
|
||||||
didSet {
|
didSet {
|
||||||
guard let style = style else { return }
|
guard let style = style else { return }
|
||||||
setFacade(by: style)
|
setFacade(by: style)
|
||||||
@ -161,7 +161,7 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
|||||||
}
|
}
|
||||||
|
|
||||||
enabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
enabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||||
enabledFillColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
enabledFillColor_inverted = Color(uiColor: UIColor.clear)
|
||||||
enabledBorderColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
enabledBorderColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||||
disabledTextColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
disabledTextColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
||||||
disabledBorderColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
disabledBorderColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
||||||
|
|||||||
@ -76,31 +76,20 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
|||||||
/// The primary styling for a button. Should be used for main buttons
|
/// The primary styling for a button. Should be used for main buttons
|
||||||
public func stylePrimary() {
|
public func stylePrimary() {
|
||||||
|
|
||||||
enabledTitleColor = buttonModel?.enabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOndark).uiColor
|
buttonModel?.setPrimaryFacade()
|
||||||
disabledTitleColor = buttonModel?.disabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOndark).uiColor
|
|
||||||
layer.borderWidth = 0
|
|
||||||
backgroundColor = isEnabled ? buttonModel?.enabledColors.fill ?? Color(uiColor: VDSColor.elementsPrimaryOnlight).uiColor : buttonModel?.disabledColors.fill ?? Color(uiColor: VDSColor.interactiveDisabledOnlight).uiColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The secondary styling for a button. Should be used for secondary buttons
|
/// The secondary styling for a button. Should be used for secondary buttons
|
||||||
public func styleSecondary() {
|
public func styleSecondary() {
|
||||||
|
|
||||||
enabledTitleColor = buttonModel?.enabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOnlight).uiColor
|
buttonModel?.setSecondaryFacade()
|
||||||
disabledTitleColor = buttonModel?.disabledColors.text ?? Color(uiColor: VDSColor.interactiveDisabledOnlight).uiColor
|
|
||||||
backgroundColor = .clear
|
|
||||||
layer.borderWidth = buttonModel?.inverted ?? false ? 0 : 1
|
|
||||||
borderColor = isEnabled ? buttonModel?.enabledColors.border ?? Color(uiColor: VDSColor.elementsPrimaryOnlight).uiColor : buttonModel?.disabledColors.border ?? Color(uiColor: VDSColor.interactiveDisabledOnlight).uiColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Styles the button based on the model style
|
/// Styles the button based on the model style
|
||||||
private func style() {
|
private func style() {
|
||||||
|
|
||||||
switch buttonModel?.style {
|
if buttonModel?.style == .primary {
|
||||||
case .secondary:
|
layer.borderWidth = 0
|
||||||
styleSecondary()
|
|
||||||
|
|
||||||
default:
|
|
||||||
stylePrimary()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let titleColor = buttonModel?.enabledColors.text {
|
if let titleColor = buttonModel?.enabledColors.text {
|
||||||
@ -170,6 +159,8 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
|||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
|
|
||||||
guard let model = model as? ButtonModel else { return }
|
guard let model = model as? ButtonModel else { return }
|
||||||
|
|
||||||
|
style()
|
||||||
setTitle(model.title, for: .normal)
|
setTitle(model.title, for: .normal)
|
||||||
if let accessibilityText = model.accessibilityText {
|
if let accessibilityText = model.accessibilityText {
|
||||||
accessibilityLabel = accessibilityText
|
accessibilityLabel = accessibilityText
|
||||||
@ -208,10 +199,10 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
|||||||
layer.cornerRadius = getInnerPadding()
|
layer.cornerRadius = getInnerPadding()
|
||||||
contentEdgeInsets = getContentEdgeInsets()
|
contentEdgeInsets = getContentEdgeInsets()
|
||||||
|
|
||||||
if let contraint = buttonModel?.width, widthConstraint == nil {
|
if let contraint = buttonModel?.width, (widthConstraint == nil || widthConstraint?.constant != contraint) {
|
||||||
widthConstraint = widthAnchor.constraint(equalToConstant: contraint)
|
widthConstraint = widthAnchor.constraint(equalToConstant: contraint)
|
||||||
widthConstraint?.isActive = true
|
widthConstraint?.isActive = true
|
||||||
} else {
|
} else if minimumWidthConstraint == nil {
|
||||||
minimumWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: buttonSize.minimumWidth())
|
minimumWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: buttonSize.minimumWidth())
|
||||||
minimumWidthConstraint?.isActive = true
|
minimumWidthConstraint?.isActive = true
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user