refactored type

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-29 14:34:21 -05:00
parent 87c202d23b
commit 27af806281
2 changed files with 33 additions and 29 deletions

View File

@ -35,10 +35,11 @@ open class Notification: View {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
/// Type of Notification.
public enum Style: String, CaseIterable {
case info, success, warning, error
func styleIconName() -> Icon.Name {
func iconName() -> Icon.Name {
switch self {
case .info:
return .infoBold
@ -52,6 +53,7 @@ open class Notification: View {
}
}
/// Orientation of Notification.
public enum Layout: String, CaseIterable {
case vertical, horizontal
}
@ -80,26 +82,6 @@ open class Notification: View {
$0.spacing = VDSLayout.Spacing.space2X.value
}
private var edgeSpacing: CGFloat {
return UIDevice.isIPad ? VDSLayout.Spacing.space5X.value : VDSLayout.Spacing.space4X.value
}
private var minViewHeight: CGFloat {
return UIDevice.isIPad ? VDSLayout.Spacing.space16X.value : VDSLayout.Spacing.space12X.value
}
private var minContentHeight: CGFloat {
return UIDevice.isIPad ? VDSLayout.Spacing.space5X.value : VDSLayout.Spacing.space4X.value
}
private var minViewWidth: CGFloat {
return 288
}
private var maxViewWidth: CGFloat {
return 1232
}
internal var onCloseSubscriber: AnyCancellable?
private var maxWidthConstraint: NSLayoutConstraint?
@ -181,9 +163,11 @@ open class Notification: View {
open var hideCloseButton: Bool = false { didSet{setNeedsUpdate()}}
/// Add this attribute determine your type of Notification.
open var type: Style = .info { didSet{setNeedsUpdate()}}
open var style: Style = .info { didSet{setNeedsUpdate()}}
var _layout: Layout = .vertical
/// Determines the orientation of buttons and text in the Notification.
open var layout: Layout {
set {
if !UIDevice.isIPad, newValue == .horizontal { return }
@ -198,7 +182,7 @@ open class Notification: View {
// MARK: - Configuration
//--------------------------------------------------
private var backgroundColorConfiguration: AnyColorable = {
let config = KeyedColorConfiguration<Notification, Style>(keyPath: \.type)
let config = KeyedColorConfiguration<Notification, Style>(keyPath: \.style)
config.setSurfaceColors(VDSColor.feedbackInformationBackgroundOnlight, VDSColor.feedbackInformationBackgroundOndark, forKey: .info)
config.setSurfaceColors(VDSColor.feedbackWarningBackgroundOnlight, VDSColor.feedbackWarningBackgroundOndark, forKey: .warning)
config.setSurfaceColors(VDSColor.feedbackSuccessBackgroundOnlight, VDSColor.feedbackSuccessBackgroundOndark, forKey: .success)
@ -211,6 +195,26 @@ open class Notification: View {
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: true)
}
private var edgeSpacing: CGFloat {
return UIDevice.isIPad ? VDSLayout.Spacing.space5X.value : VDSLayout.Spacing.space4X.value
}
private var minViewHeight: CGFloat {
return UIDevice.isIPad ? VDSLayout.Spacing.space16X.value : VDSLayout.Spacing.space12X.value
}
private var minContentHeight: CGFloat {
return UIDevice.isIPad ? VDSLayout.Spacing.space5X.value : VDSLayout.Spacing.space4X.value
}
private var minViewWidth: CGFloat {
return 288
}
private var maxViewWidth: CGFloat {
return 1232
}
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
@ -257,7 +261,7 @@ open class Notification: View {
primaryButtonModel = nil
secondaryButtonModel = nil
type = .info
style = .info
typeIcon.size = UIDevice.isIPad ? .medium : .small
typeIcon.name = .infoBold
@ -288,7 +292,7 @@ open class Notification: View {
//--------------------------------------------------
private func updateIcons() {
let iconColor = surface == .dark ? VDSColor.paletteWhite : VDSColor.paletteBlack
typeIcon.name = type.styleIconName()
typeIcon.name = style.iconName()
typeIcon.color = iconColor
closeButton.color = iconColor
closeButton.isHidden = hideCloseButton

View File

@ -76,7 +76,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
}.eraseToAnyColorable()
/// Representing the type of input.
open var type: FieldType = .text { didSet { setNeedsUpdate() }}
open var fieldType: FieldType = .text { didSet { setNeedsUpdate() }}
var _showError: Bool = false
/// Whether not to show the error.
@ -159,7 +159,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
successLabel.textPosition = .left
successLabel.textStyle = .bodySmall
type = .text
fieldType = .text
showSuccess = false
successText = nil
helperTextPlacement = .bottom
@ -198,12 +198,12 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
}
//set the width constraints
if let width, width > type.width {
if let width, width > fieldType.width {
widthConstraint?.constant = width
widthConstraint?.isActive = true
minWidthConstraint?.isActive = false
} else {
minWidthConstraint?.constant = type.width
minWidthConstraint?.constant = fieldType.width
widthConstraint?.isActive = false
minWidthConstraint?.isActive = true
}