From db7bc5be2ba0e7fa58ca4a0366a2db33c64ee4b5 Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Fri, 29 Apr 2022 23:01:44 +0530 Subject: [PATCH] minor changes to button component --- .../Atomic/Atoms/Buttons/ButtonModel.swift | 8 ++--- .../Atomic/Atoms/Buttons/PillButton.swift | 36 +++++-------------- MVMCoreUI/Styles/Styler.swift | 11 ++++++ 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift index f16afc7f..92cde87c 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift @@ -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) } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift index b738205e..de955378 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift @@ -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 } diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 00c946b6..9cc487e8 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -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 + } + } } }