refactored ExpandDirect to the BadgeIndicatorModel

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-02-14 11:57:08 -06:00
parent fd29a57d19
commit 8fd74d5ef9
2 changed files with 37 additions and 36 deletions

View File

@ -43,12 +43,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
public enum SurfaceType: String, CaseIterable { public enum SurfaceType: String, CaseIterable {
case colorFill, media case colorFill, media
} }
/// Enum used to describe the badge indicator direction of icon button determining the expand direction.
public enum ExpandDirection: String, CaseIterable {
case right, center, left
}
/// Enum used to describe the size of button icon. /// Enum used to describe the size of button icon.
public enum Size: String, EnumSubset { public enum Size: String, EnumSubset {
case large case large
@ -106,6 +101,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
open var badgeIndicator = BadgeIndicator().with { open var badgeIndicator = BadgeIndicator().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
$0.size = .small $0.size = .small
$0.isHidden = true
} }
/// If set, this is used to render the badge indicator. /// If set, this is used to render the badge indicator.
@ -157,10 +153,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
/// Used to move the icon inside the button in both x and y axis. /// Used to move the icon inside the button in both x and y axis.
open var iconOffset: CGPoint = .init(x: 0, y: 0) { didSet { setNeedsUpdate() } } open var iconOffset: CGPoint = .init(x: 0, y: 0) { didSet { setNeedsUpdate() } }
/// Applies expand direction to Badge Indicator if shows badge indicator.
open var expandDirection: ExpandDirection = .right { didSet { setNeedsUpdate() } }
open var onChangeSubscriber: AnyCancellable? open var onChangeSubscriber: AnyCancellable?
open var inputId: String? { didSet { setNeedsUpdate() } } open var inputId: String? { didSet { setNeedsUpdate() } }
@ -203,7 +196,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted) $0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected)
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: [.selected, .highlighted])
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled])
}.eraseToAnyColorable() }.eraseToAnyColorable()
}() }()
@ -374,7 +366,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
super.initialSetup() super.initialSetup()
onClick = { control in onClick = { control in
guard control.isEnabled else { return } guard control.isEnabled else { return }
if let selectedIconName = control.selectedIconName, control.selectable { if control.selectedIconName != nil && control.selectable {
control.toggle() control.toggle()
} }
} }
@ -402,7 +394,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
showBadgeIndicator = false showBadgeIndicator = false
selectable = false selectable = false
badgeIndicatorModel = nil badgeIndicatorModel = nil
expandDirection = .right
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }
@ -482,27 +473,33 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
// MARK: - Private Methods // MARK: - Private Methods
//-------------------------------------------------- //--------------------------------------------------
private func updateBadgeIndicator() { private func updateBadgeIndicator() {
if let badgeIndicatorModel { badgeIndicator.isHidden = !showBadgeIndicator
badgeIndicator.kind = badgeIndicatorModel.kind
badgeIndicator.fillColor = badgeIndicatorModel.fillColor guard let badgeIndicatorModel else {
badgeIndicator.surface = badgeIndicatorModel.surface badgeIndicator.isHidden = true
badgeIndicator.size = badgeIndicatorModel.size return
badgeIndicator.maximumDigits = badgeIndicatorModel.maximumDigits
badgeIndicator.width = badgeIndicatorModel.width
badgeIndicator.height = badgeIndicatorModel.height
badgeIndicator.number = badgeIndicatorModel.number
badgeIndicator.leadingCharacter = badgeIndicatorModel.leadingCharacter
badgeIndicator.trailingText = badgeIndicatorModel.trailingText
badgeIndicator.dotSize = badgeIndicatorModel.dotSize
badgeIndicator.verticalPadding = badgeIndicatorModel.verticalPadding
badgeIndicator.horizontalPadding = badgeIndicatorModel.horizontalPadding
badgeIndicator.hideDot = badgeIndicatorModel.hideDot
badgeIndicator.hideBorder = badgeIndicatorModel.hideBorder
} }
badgeIndicator.surface = surface
badgeIndicator.kind = badgeIndicatorModel.kind
badgeIndicator.fillColor = badgeIndicatorModel.fillColor
badgeIndicator.size = badgeIndicatorModel.size
badgeIndicator.maximumDigits = badgeIndicatorModel.maximumDigits
badgeIndicator.width = badgeIndicatorModel.width
badgeIndicator.height = badgeIndicatorModel.height
badgeIndicator.number = badgeIndicatorModel.number
badgeIndicator.leadingCharacter = badgeIndicatorModel.leadingCharacter
badgeIndicator.trailingText = badgeIndicatorModel.trailingText
badgeIndicator.dotSize = badgeIndicatorModel.dotSize
badgeIndicator.verticalPadding = badgeIndicatorModel.verticalPadding
badgeIndicator.horizontalPadding = badgeIndicatorModel.horizontalPadding
badgeIndicator.hideDot = badgeIndicatorModel.hideDot
badgeIndicator.hideBorder = badgeIndicatorModel.hideBorder
} }
private func updateExpandDirectionalConstraints() { private func updateExpandDirectionalConstraints() {
switch expandDirection { guard let badgeIndicatorModel else { return }
switch badgeIndicatorModel.expandDirection {
case .right: case .right:
badgeIndicatorLeadingConstraint?.isActive = true badgeIndicatorLeadingConstraint?.isActive = true
badgeIndicatorTrailingConstraint?.isActive = false badgeIndicatorTrailingConstraint?.isActive = false

View File

@ -11,16 +11,20 @@ extension ButtonIcon {
//Model that represents the options available for the Badge Indicator //Model that represents the options available for the Badge Indicator
public struct BadgeIndicatorModel { public struct BadgeIndicatorModel {
/// Enum used to describe the badge indicator direction of icon button determining the expand direction.
public enum ExpandDirection: String, CaseIterable {
case right, center, left
}
/// Applies expand direction to Badge Indicator if shows badge indicator.
public var expandDirection: ExpandDirection = .right
/// Kind that will be used for the badge indicator. /// Kind that will be used for the badge indicator.
public var kind: BadgeIndicator.Kind public var kind: BadgeIndicator.Kind
/// Fill color that will be used for the badge indicator. /// Fill color that will be used for the badge indicator.
public var fillColor: BadgeIndicator.FillColor public var fillColor: BadgeIndicator.FillColor
/// Current Surface and this is used to pass down to child objects that implement Surfacable
public var surface: Surface
/// Size that will be used for the badge indicator. /// Size that will be used for the badge indicator.
public var size: BadgeIndicator.Size public var size: BadgeIndicator.Size
@ -57,10 +61,10 @@ extension ButtonIcon {
/// Hide Border that will be used for the badge indicator. /// Hide Border that will be used for the badge indicator.
public var hideBorder: Bool = false public var hideBorder: Bool = false
public init(kind: BadgeIndicator.Kind = .simple, fillColor: BadgeIndicator.FillColor = .red, surface: Surface = .light, size: BadgeIndicator.Size = .xxlarge, maximumDigits: BadgeIndicator.MaximumDigits = .two, width: CGFloat? = nil, height: CGFloat? = nil, number: Int? = nil, leadingCharacter: String = "", trailingText: String = "", dotSize: CGFloat? = nil, verticalPadding: CGFloat? = nil, horizontalPadding: CGFloat? = nil, hideDot: Bool = false, hideBorder: Bool = false) { public init(kind: BadgeIndicator.Kind = .simple, fillColor: BadgeIndicator.FillColor = .red, expandDirection: ExpandDirection = .right, size: BadgeIndicator.Size = .xxlarge, maximumDigits: BadgeIndicator.MaximumDigits = .two, width: CGFloat? = nil, height: CGFloat? = nil, number: Int? = nil, leadingCharacter: String = "", trailingText: String = "", dotSize: CGFloat? = nil, verticalPadding: CGFloat? = nil, horizontalPadding: CGFloat? = nil, hideDot: Bool = false, hideBorder: Bool = false) {
self.kind = kind self.kind = kind
self.fillColor = fillColor self.fillColor = fillColor
self.surface = surface self.expandDirection = expandDirection
self.size = size self.size = size
self.maximumDigits = maximumDigits self.maximumDigits = maximumDigits
self.width = width self.width = width