added temp ButtonModel

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-03-17 15:55:33 -05:00
parent 05e23f7d58
commit 684a343b0f

View File

@ -13,6 +13,15 @@ import VDSColorTokens
/// A VDS Component that will render a view with information /// A VDS Component that will render a view with information
public class Notification: View { public class Notification: View {
public struct ButtonModel {
public var text: String
public var onClick: (Button) -> ()
public init(text: String, onClick: @escaping (Button) -> Void) {
self.text = text
self.onClick = onClick
}
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Enums // MARK: - Enums
//-------------------------------------------------- //--------------------------------------------------
@ -87,15 +96,25 @@ public class Notification: View {
$0.buttonPosition = .left $0.buttonPosition = .left
} }
#warning("we want to add only the things that are needed, everything else should be hidden, meaning don't access controls directly")
//Text //Text
open var titleText: String? { didSet{didChange()}} open var titleText: String? { didSet{didChange()}}
open var subTitleText: String? { didSet{didChange()}} open var subTitleText: String? { didSet{didChange()}}
//Buttons (will need to think about this one, probably create a model and follow how Tilelet is working) #warning("will need to think about this one, probably create a model that has 2 props - text, onClick = (Button) -> () so we are not accessing the button directly. The only reason why I leave it open is for things like accessibility, but not for setting properties outside of this class. More or less follow how Tilelet is working, look at that, below is a temp fix until we can discuss with the guys")
open var primaryButton: Button? { didSet{didChange()}} //Buttons
open var primaryButtonModel: ButtonModel? { didSet{didChange()}}
open var primaryButton = Button().with {
$0.size = .small
$0.use = .primary
}
open var secondaryButton: Button? { didSet{didChange()}} open var secondaryButtonModel: ButtonModel? { didSet{didChange()}}
open var secondaryButton = Button().with {
$0.size = .small
$0.use = .secondary
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Modal Properties // MARK: - Modal Properties
@ -208,15 +227,23 @@ public class Notification: View {
private func updateButtons() { private func updateButtons() {
var buttons: [Button] = [] var buttons: [Button] = []
if let primaryButton { if let primaryButtonModel {
primaryButton.size = .small primaryButton.text = primaryButtonModel.text
primaryButton.use = .primary primaryButton.onClickSubscriber = primaryButton
.publisher(for: .touchUpInside)
.sink(receiveValue: { button in
primaryButtonModel.onClick(button)
})
buttons.append(primaryButton) buttons.append(primaryButton)
} }
if let secondaryButton { if let secondaryButtonModel {
secondaryButton.size = .small secondaryButton.text = secondaryButtonModel.text
secondaryButton.use = .secondary secondaryButton.onClickSubscriber = secondaryButton
.publisher(for: .touchUpInside)
.sink(receiveValue: { button in
secondaryButtonModel.onClick(button)
})
buttons.append(secondaryButton) buttons.append(secondaryButton)
} }