minor changes to button component
This commit is contained in:
parent
779b79d27b
commit
db7bc5be2b
@ -63,11 +63,9 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
get {
|
||||
if let backgroundColor = _backgroundColor { return backgroundColor }
|
||||
if inverted {
|
||||
if style == .secondary { return Color(uiColor: VDSColor.elementsSecondaryOndark) }
|
||||
return Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
return enabled ? enabledFillColor_inverted : disabledFillColor_inverted
|
||||
}
|
||||
if style == .secondary { return Color(uiColor: UIColor.clear) }
|
||||
return Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
return enabled ? enabledFillColor : disabledFillColor
|
||||
}
|
||||
set {
|
||||
_backgroundColor = newValue
|
||||
@ -163,7 +161,7 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
|
||||
enabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
enabledFillColor_inverted = Color(uiColor: UIColor.clear)
|
||||
enabledBorderColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
enabledBorderColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
disabledTextColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
||||
disabledBorderColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
||||
}
|
||||
|
||||
@ -76,20 +76,20 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
/// The primary styling for a button. Should be used for main buttons
|
||||
public func stylePrimary() {
|
||||
|
||||
enabledTitleColor = buttonModel?.enabledColors.text ?? Color(uiColor: VDSColor.elementsSecondaryOnlight).uiColor
|
||||
disabledTitleColor = buttonModel?.disabledColors.text ?? Color(uiColor: VDSColor.elementsSecondaryOnlight).uiColor
|
||||
enabledTitleColor = buttonModel?.enabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOndark).uiColor
|
||||
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.elementsPrimaryOndark).uiColor
|
||||
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
|
||||
public func styleSecondary() {
|
||||
|
||||
enabledTitleColor = buttonModel?.enabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOnlight).uiColor
|
||||
disabledTitleColor = buttonModel?.disabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOndark).uiColor
|
||||
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.elementsPrimaryOndark).uiColor
|
||||
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
|
||||
@ -153,29 +153,13 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
verticalPadding = Padding.Two
|
||||
horizontalPadding = Padding.Four
|
||||
break
|
||||
default:
|
||||
case .tiny:
|
||||
verticalPadding = getInnerPadding()
|
||||
horizontalPadding = getInnerPadding()
|
||||
break
|
||||
}
|
||||
return UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)
|
||||
}
|
||||
|
||||
private func getMinimumWidth() -> CGFloat {
|
||||
|
||||
switch buttonSize {
|
||||
case .tiny:
|
||||
return MFSizeObject(standardSize: 49,
|
||||
standardiPadPortraitSize: 90,
|
||||
iPadProLandscapeSize: 135)?.getValueBased(onSize: size) ?? 49
|
||||
case .small:
|
||||
return MFSizeObject(standardSize: 1,
|
||||
standardiPadPortraitSize: 2,
|
||||
iPadProLandscapeSize: 3)?.getValueBased(onSize: size) ?? 1
|
||||
case .standard:
|
||||
return MFSizeObject(standardSize: 76,
|
||||
standardiPadPortraitSize: 90,
|
||||
iPadProLandscapeSize: 135)?.getValueBased(onSize: size) ?? 76
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
@ -240,9 +224,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
contentHorizontalAlignment = .center
|
||||
stylePrimary()
|
||||
|
||||
widthConstraint?.isActive = false
|
||||
|
||||
minimumWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: getMinimumWidth())
|
||||
minimumWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: buttonSize.minimumWidth())
|
||||
minimumWidthConstraint?.isActive = true
|
||||
}
|
||||
|
||||
|
||||
@ -194,6 +194,17 @@ open class Styler {
|
||||
return 20
|
||||
}
|
||||
}
|
||||
|
||||
func minimumWidth() -> CGFloat {
|
||||
switch self {
|
||||
case .standard:
|
||||
return 76
|
||||
case .small:
|
||||
return 0
|
||||
case .tiny:
|
||||
return 49
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user