minor changes to button component

This commit is contained in:
Sumanth Nadigadda 2022-04-29 23:01:44 +05:30
parent 779b79d27b
commit db7bc5be2b
3 changed files with 23 additions and 32 deletions

View File

@ -63,11 +63,9 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
get { get {
if let backgroundColor = _backgroundColor { return backgroundColor } if let backgroundColor = _backgroundColor { return backgroundColor }
if inverted { if inverted {
if style == .secondary { return Color(uiColor: VDSColor.elementsSecondaryOndark) } return enabled ? enabledFillColor_inverted : disabledFillColor_inverted
return Color(uiColor: VDSColor.elementsPrimaryOndark)
} }
if style == .secondary { return Color(uiColor: UIColor.clear) } return enabled ? enabledFillColor : disabledFillColor
return Color(uiColor: VDSColor.elementsPrimaryOnlight)
} }
set { set {
_backgroundColor = newValue _backgroundColor = newValue
@ -163,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: UIColor.clear) enabledFillColor_inverted = Color(uiColor: UIColor.clear)
enabledBorderColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight) 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)
} }

View File

@ -76,20 +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.elementsSecondaryOnlight).uiColor enabledTitleColor = buttonModel?.enabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOndark).uiColor
disabledTitleColor = buttonModel?.disabledColors.text ?? Color(uiColor: VDSColor.elementsSecondaryOnlight).uiColor disabledTitleColor = buttonModel?.disabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOndark).uiColor
layer.borderWidth = 0 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 /// 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 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 backgroundColor = .clear
layer.borderWidth = buttonModel?.inverted ?? false ? 0 : 1 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 /// Styles the button based on the model style
@ -153,29 +153,13 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
verticalPadding = Padding.Two verticalPadding = Padding.Two
horizontalPadding = Padding.Four horizontalPadding = Padding.Four
break break
default: case .tiny:
verticalPadding = getInnerPadding()
horizontalPadding = getInnerPadding()
break break
} }
return UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding) 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 // MARK: - MVMCoreViewProtocol
@ -240,9 +224,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
contentHorizontalAlignment = .center contentHorizontalAlignment = .center
stylePrimary() stylePrimary()
widthConstraint?.isActive = false minimumWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: buttonSize.minimumWidth())
minimumWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: getMinimumWidth())
minimumWidthConstraint?.isActive = true minimumWidthConstraint?.isActive = true
} }

View File

@ -194,6 +194,17 @@ open class Styler {
return 20 return 20
} }
} }
func minimumWidth() -> CGFloat {
switch self {
case .standard:
return 76
case .small:
return 0
case .tiny:
return 49
}
}
} }
} }